Search in sources :

Example 6 with SwaggerDefinition

use of io.swagger.annotations.SwaggerDefinition in project java-chassis by ServiceComb.

the class SwaggerDefinitionProcessor method process.

@Override
public void process(Object annotation, SwaggerGenerator swaggerGenerator) {
    SwaggerDefinition definitionAnnotation = (SwaggerDefinition) annotation;
    Swagger swagger = swaggerGenerator.getSwagger();
    swaggerGenerator.setBasePath(definitionAnnotation.basePath());
    swagger.setHost(definitionAnnotation.host());
    convertConsumes(definitionAnnotation, swagger);
    convertProduces(definitionAnnotation, swagger);
    convertSchemes(definitionAnnotation, swagger);
    convertTags(definitionAnnotation, swagger);
    convertInfo(definitionAnnotation.info(), swagger);
    swagger.setExternalDocs(convertExternalDocs(definitionAnnotation.externalDocs()));
}
Also used : Swagger(io.swagger.models.Swagger) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition)

Example 7 with SwaggerDefinition

use of io.swagger.annotations.SwaggerDefinition in project incubator-servicecomb-java-chassis by apache.

the class SwaggerDefinitionProcessor method process.

@Override
public void process(Object annotation, SwaggerGenerator swaggerGenerator) {
    SwaggerDefinition definitionAnnotation = (SwaggerDefinition) annotation;
    Swagger swagger = swaggerGenerator.getSwagger();
    swaggerGenerator.setBasePath(definitionAnnotation.basePath());
    swagger.setHost(definitionAnnotation.host());
    convertConsumes(definitionAnnotation, swagger);
    convertProduces(definitionAnnotation, swagger);
    convertSchemes(definitionAnnotation, swagger);
    convertTags(definitionAnnotation, swagger);
    convertInfo(definitionAnnotation.info(), swagger);
    swagger.setExternalDocs(convertExternalDocs(definitionAnnotation.externalDocs()));
}
Also used : Swagger(io.swagger.models.Swagger) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition)

Example 8 with SwaggerDefinition

use of io.swagger.annotations.SwaggerDefinition in project vertx-swagger by bobxwang.

the class Reader method read.

private void read(ReaderContext context) {
    Class<?> clasz = context.getCls();
    final SwaggerDefinition swaggerDefinition = clasz.getAnnotation(SwaggerDefinition.class);
    if (swaggerDefinition != null) {
        readSwaggerConfig(swaggerDefinition);
    }
    for (Method method : clasz.getDeclaredMethods()) {
        if (!method.isAnnotationPresent(BBRouter.class)) {
            continue;
        }
        final Operation operation = new Operation();
        String operationPath = null;
        String httpMethod = null;
        final Type[] genericParameterTypes = method.getGenericParameterTypes();
        final Annotation[][] paramAnnotations = method.getParameterAnnotations();
        for (ReaderExtension extension : ReaderExtensions.getExtensions()) {
            if (operationPath == null) {
                operationPath = extension.getPath(context, method);
            }
            if (httpMethod == null) {
                httpMethod = extension.getHttpMethod(context, method);
            }
            if (operationPath == null || httpMethod == null) {
                continue;
            }
            if (extension.isReadable(context)) {
                extension.setDeprecated(operation, method);
                extension.applyConsumes(context, operation, method);
                extension.applyProduces(context, operation, method);
                extension.applyOperationId(operation, method);
                extension.applySummary(operation, method);
                extension.applyDescription(operation, method);
                extension.applySchemes(context, operation, method);
                extension.applySecurityRequirements(context, operation, method);
                extension.applyTags(context, operation, method);
                extension.applyResponses(context, operation, method);
                extension.applyImplicitParameters(context, operation, method);
                extension.applyExtensions(context, operation, method);
                for (int i = 0; i < genericParameterTypes.length; i++) {
                    extension.applyParameters(context, operation, genericParameterTypes[i], paramAnnotations[i]);
                }
            }
        }
        if (httpMethod != null) {
            if (operation.getResponses() == null) {
                operation.defaultResponse(new Response().description("successful operation"));
            }
            final Map<String, String> regexMap = new HashMap<>();
            final String parsedPath = PathUtils.parsePath(operationPath, regexMap);
            final String swaggerPath = getSwaggerPath(parsedPath);
            Path path = swagger.getPath(swaggerPath);
            if (path == null) {
                path = new Path();
                swagger.path(swaggerPath, path);
            }
            path.set(httpMethod.toLowerCase(), operation);
        }
    }
}
Also used : Path(io.swagger.models.Path) Method(java.lang.reflect.Method) Operation(io.swagger.models.Operation) Response(io.swagger.models.Response) Type(java.lang.reflect.Type) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition)

Aggregations

SwaggerDefinition (io.swagger.annotations.SwaggerDefinition)8 Tag (io.swagger.models.Tag)4 ApiKeyAuthDefinition (io.swagger.annotations.ApiKeyAuthDefinition)3 BasicAuthDefinition (io.swagger.annotations.BasicAuthDefinition)3 OAuth2Definition (io.swagger.annotations.OAuth2Definition)3 Scope (io.swagger.annotations.Scope)3 ExternalDocs (io.swagger.models.ExternalDocs)3 Operation (io.swagger.models.Operation)2 Path (io.swagger.models.Path)2 Response (io.swagger.models.Response)2 Swagger (io.swagger.models.Swagger)2 Method (java.lang.reflect.Method)2 Type (java.lang.reflect.Type)2 HashMap (java.util.HashMap)2 AnnotatedParameter (com.fasterxml.jackson.databind.introspect.AnnotatedParameter)1 AuthorizationScope (io.swagger.annotations.AuthorizationScope)1 ReaderListener (io.swagger.jaxrs.config.ReaderListener)1 FormParameter (io.swagger.models.parameters.FormParameter)1 HeaderParameter (io.swagger.models.parameters.HeaderParameter)1 Parameter (io.swagger.models.parameters.Parameter)1