Java Code Examples for io.swagger.models.Operation#setDescription()

The following examples show how to use io.swagger.models.Operation#setDescription() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApiOperationProcessor.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public void process(SwaggerGenerator swaggerGenerator,
    OperationGenerator operationGenerator, ApiOperation apiOperationAnnotation) {
  Operation operation = operationGenerator.getOperation();

  operationGenerator.setHttpMethod(apiOperationAnnotation.httpMethod());

  if (!StringUtils.isEmpty(apiOperationAnnotation.value())) {
    operation.setSummary(apiOperationAnnotation.value());
  }

  if (!StringUtils.isEmpty(apiOperationAnnotation.notes())) {
    operation.setDescription(apiOperationAnnotation.notes());
  }

  operation.setOperationId(apiOperationAnnotation.nickname());
  operation.getVendorExtensions().putAll(BaseReaderUtils.parseExtensions(apiOperationAnnotation.extensions()));

  convertTags(apiOperationAnnotation.tags(), operation);
  SwaggerUtils.setCommaConsumes(operation, apiOperationAnnotation.consumes());
  SwaggerUtils.setCommaProduces(operation, apiOperationAnnotation.produces());
  convertProtocols(apiOperationAnnotation.protocols(), operation);
  AnnotationUtils.addResponse(swaggerGenerator.getSwagger(),
      operation,
      apiOperationAnnotation);

  // responseReference未解析
  // hidden未解析
  // authorizations未解析
}
 
Example 2
Source File: SwaggerExtension.java    From Web-API with MIT License 4 votes vote down vote up
@Override
public void decorateOperation(Operation operation, Method method,
                              Iterator<io.swagger.jaxrs.ext.SwaggerExtension> chain) {
    // Automatically add query params
    operation.addParameter(new RefParameter("details"));
    operation.addParameter(new RefParameter("accept"));
    operation.addParameter(new RefParameter("pretty"));

    // Automatically add 500 as a possible response
    operation.addResponse("500", new RefResponse("500"));

    // Automatically add error codes depending on thrown exceptions
    for (Class<?> execClass : method.getExceptionTypes()) {
        if (BadRequestException.class.isAssignableFrom(execClass)) {
            operation.addResponse("400", new RefResponse("400"));
        }
        if (NotFoundException.class.isAssignableFrom(execClass)) {
            operation.addResponse("404", new RefResponse("404"));
        }
        if (NotImplementedException.class.isAssignableFrom(execClass)) {
            operation.addResponse("501", new RefResponse("501"));
        }
    }

    Permission[] perms = method.getAnnotationsByType(Permission.class);
    if (perms.length > 0) {
        // Automatically add 401 & 403 as a possible response
        operation.addResponse("401", new RefResponse("401"));
        operation.addResponse("403", new RefResponse("403"));

        // Automatically add required permission notes if we have a @Permission annotation
        Path path = method.getDeclaringClass().getAnnotation(Path.class);
        String prefix = path != null ? path.value() + "." : "";

        StringBuilder permStr = new StringBuilder("  \n\n **Required permissions:**  \n\n");
        for (Permission perm : perms) {
            permStr.append("- **").append(prefix).append(String.join(".", perm.value())).append("**  \n");
        }

        operation.setDescription(operation.getDescription() + permStr.toString());

        // Add security definitions
        operation.addSecurity("ApiKeyHeader", new ArrayList<>());
        operation.addSecurity("ApiKeyQuery", new ArrayList<>());
    }
    super.decorateOperation(operation, method, chain);
}