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);
}
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);
}
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);
}
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()));
}
}
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);
}
}
Aggregations