Search in sources :

Example 6 with Parameter

use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.

the class ApiImplicitParamClassProcessor method process.

@Override
public void process(Object annotation, SwaggerGenerator swaggerGenerator) {
    ApiImplicitParam paramAnnotation = (ApiImplicitParam) annotation;
    Parameter parameter = AnnotationUtils.createParameter(swaggerGenerator.getSwagger(), paramAnnotation);
    swaggerGenerator.getSwagger().addParameter(parameter.getName(), parameter);
}
Also used : Parameter(io.swagger.models.parameters.Parameter) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam)

Example 7 with Parameter

use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.

the class ClassUtils method createInterface.

private static Class<?> createInterface(Swagger swagger, ClassLoader classLoader, String packageName, String intfName) {
    ClassConfig classConfig = new ClassConfig();
    classConfig.setClassName(intfName);
    classConfig.setIntf(true);
    StringBuilder sbMethod = new StringBuilder();
    StringBuilder sbMethodGenericSignature = new StringBuilder();
    for (Path path : swagger.getPaths().values()) {
        for (Operation operation : path.getOperations()) {
            boolean hasGenericSignature = false;
            sbMethod.setLength(0);
            sbMethodGenericSignature.setLength(0);
            Response result = operation.getResponses().get(SwaggerConst.SUCCESS_KEY);
            JavaType resultJavaType = ConverterMgr.findJavaType(classLoader, packageName, swagger, result.getSchema());
            hasGenericSignature = hasGenericSignature || resultJavaType.hasGenericTypes();
            sbMethod.append(JavassistUtils.getNameForGenerateCode(resultJavaType)).append(" ").append(operation.getOperationId()).append("(");
            sbMethodGenericSignature.append("(");
            for (Parameter parameter : operation.getParameters()) {
                String paramName = parameter.getName();
                paramName = correctMethodParameterName(paramName);
                JavaType paramJavaType = ConverterMgr.findJavaType(classLoader, packageName, swagger, parameter);
                hasGenericSignature = hasGenericSignature || paramJavaType.hasGenericTypes();
                String code = String.format("%s %s,", paramJavaType.getRawClass().getName(), paramName);
                sbMethod.append(code);
                sbMethodGenericSignature.append(paramJavaType.getGenericSignature());
            }
            if (!operation.getParameters().isEmpty()) {
                sbMethod.setLength(sbMethod.length() - 1);
            }
            sbMethod.append(");");
            sbMethodGenericSignature.append(")");
            sbMethodGenericSignature.append(resultJavaType.getGenericSignature());
            if (hasGenericSignature) {
                classConfig.addMethod(sbMethod.toString(), sbMethodGenericSignature.toString());
            } else {
                classConfig.addMethod(sbMethod.toString(), null);
            }
        }
    }
    return JavassistUtils.createClass(classLoader, classConfig);
}
Also used : Path(io.swagger.models.Path) Response(io.swagger.models.Response) JavaType(com.fasterxml.jackson.databind.JavaType) ClassConfig(io.servicecomb.common.javassist.ClassConfig) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) Operation(io.swagger.models.Operation)

Example 8 with Parameter

use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.

the class OperationGenerator method copyToSwaggerParameters.

protected void copyToSwaggerParameters() {
    for (Parameter parameter : providerParameters) {
        if (ContextParameter.class.isInstance(parameter)) {
            continue;
        }
        int annotationIdx = ParamUtils.findParameterByName(parameter.getName(), methodAnnotationParameters);
        if (annotationIdx != -1) {
            Parameter annotationParameter = methodAnnotationParameters.remove(annotationIdx);
            swaggerParameters.add(annotationParameter);
            continue;
        }
        swaggerParameters.add(parameter);
    }
    swaggerParameters.addAll(methodAnnotationParameters);
}
Also used : PendingBodyParameter(io.servicecomb.swagger.extend.parameter.PendingBodyParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) ContextParameter(io.servicecomb.swagger.extend.parameter.ContextParameter)

Example 9 with Parameter

use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.

the class ArgumentsMapperFactory method collectSwaggerArgumentsMapper.

protected void collectSwaggerArgumentsMapper(ArgumentsMapperConfig config) {
    for (int swaggerIdx = 0; swaggerIdx < config.getSwaggerParameters().size(); swaggerIdx++) {
        Parameter swaggerParameter = config.getSwaggerParameters().get(swaggerIdx);
        int providerIdx = findInParameters(swaggerParameter.getName(), config.getProviderParameters());
        if (providerIdx >= 0) {
            // 如果body参数,不一定能直接映射
            if (BodyParameter.class.isInstance(swaggerParameter)) {
                mapBodyArg(config, providerIdx, swaggerIdx);
                continue;
            }
            // 直接映射
            config.addArgumentMapper(createArgumentSame(swaggerIdx, providerIdx));
            continue;
        }
        if (BodyParameter.class.isInstance(swaggerParameter)) {
            processBodyArgMapper(config, swaggerIdx);
            continue;
        }
        LOGGER.warn(generateSkipParamInfo("parameter", config, swaggerParameter.getName()));
    }
}
Also used : BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) ContextParameter(io.servicecomb.swagger.extend.parameter.ContextParameter)

Example 10 with Parameter

use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.

the class OpMeta method init.

protected void init() {
    Class<?> swaggerInterface = ClassUtils.getOrCreateInterface(swagger, null, null);
    for (OperationGenerator operationGenerator : providerGenerator.getOperationGeneratorMap().values()) {
        String methodName = operationGenerator.getProviderMethod().getName();
        Method swaggerMethod = ReflectUtils.findMethod(swaggerInterface, methodName);
        List<Parameter> swaggerParameters = findParameter(swagger, methodName);
        List<Parameter> providerParameters = findParameter(providerGenerator, methodName);
        ARGS_MAPPER argsMapper = factory.createArgumentsMapper(swagger, swaggerMethod, swaggerParameters, operationGenerator.getProviderMethod(), providerParameters);
        swaggerMethodMap.put(methodName, swaggerMethod);
        operationArgsMapperMap.put(methodName, argsMapper);
    }
}
Also used : Parameter(io.swagger.models.parameters.Parameter) Method(java.lang.reflect.Method) OperationGenerator(io.servicecomb.swagger.generator.core.OperationGenerator)

Aggregations

Parameter (io.swagger.models.parameters.Parameter)186 BodyParameter (io.swagger.models.parameters.BodyParameter)102 QueryParameter (io.swagger.models.parameters.QueryParameter)101 PathParameter (io.swagger.models.parameters.PathParameter)89 Test (org.testng.annotations.Test)80 HeaderParameter (io.swagger.models.parameters.HeaderParameter)66 Swagger (io.swagger.models.Swagger)63 FormParameter (io.swagger.models.parameters.FormParameter)52 Operation (io.swagger.models.Operation)31 SerializableParameter (io.swagger.models.parameters.SerializableParameter)29 Test (org.junit.Test)25 Type (java.lang.reflect.Type)23 ArrayList (java.util.ArrayList)23 Path (io.swagger.models.Path)19 Annotation (java.lang.annotation.Annotation)17 JavaType (com.fasterxml.jackson.databind.JavaType)14 Response (io.swagger.models.Response)14 Method (java.lang.reflect.Method)14 Property (io.swagger.models.properties.Property)13 ModelImpl (io.swagger.models.ModelImpl)12