use of io.swagger.models.parameters.BodyParameter in project java-chassis by ServiceComb.
the class ClassUtils method getOrCreateBodyClass.
// 将一系列body parameter包装成一个class
public static Class<?> getOrCreateBodyClass(OperationGenerator operationGenerator, List<BodyParameter> bodyParameters) {
SwaggerGenerator swaggerGenerator = operationGenerator.getSwaggerGenerator();
Method method = operationGenerator.getProviderMethod();
String clsName = swaggerGenerator.ensureGetPackageName() + "." + method.getName() + "Body";
Class<?> cls = getClassByName(swaggerGenerator.getClassLoader(), clsName);
if (cls != null) {
return cls;
}
ClassConfig classConfig = new ClassConfig();
classConfig.setClassName(clsName);
// 2.预备body与明确body混合
for (BodyParameter bp : bodyParameters) {
JavaType javaType = ConverterMgr.findJavaType(swaggerGenerator.getClassLoader(), swaggerGenerator.ensureGetPackageName(), swaggerGenerator.getSwagger(), bp);
classConfig.addField(bp.getName(), javaType);
}
return JavassistUtils.createClass(classConfig);
}
use of io.swagger.models.parameters.BodyParameter in project java-chassis by ServiceComb.
the class ArgumentsMapperFactory method processBodyFieldArgMapper.
// 将多个provider参数映射为契约body的field
// value为field在provider参数中的下标
protected void processBodyFieldArgMapper(ArgumentsMapperConfig config, int swaggerIdx) {
Class<?>[] swaggerParameterTypes = config.getSwaggerMethod().getParameterTypes();
Class<?> swaggerParameterType = swaggerParameterTypes[swaggerIdx];
BodyParameter bp = (BodyParameter) config.getSwaggerParameters().get(swaggerIdx);
Model model = bp.getSchema();
if (RefModel.class.isInstance(model)) {
String refName = ((RefModel) model).getSimpleRef();
model = config.getSwagger().getDefinitions().get(refName);
}
Map<Integer, Field> fieldMap = new HashMap<>();
for (String propertyName : model.getProperties().keySet()) {
// 理论上应该只在provider的body类型的参数中查找,不过正常定义契约不会有问题的,先不用处理了
int providerIdx = findInParameters(propertyName, config.getProviderParameters());
if (providerIdx >= 0) {
Field field = ReflectionUtils.findField(swaggerParameterType, propertyName);
field.setAccessible(true);
fieldMap.put(providerIdx, field);
continue;
}
String msg = generateSkipParamInfo("body parameter field", config, propertyName);
LOGGER.warn(msg);
}
ArgumentMapper bodyFieldArg = createBodyFieldArgMapper(config, swaggerIdx, fieldMap);
config.addArgumentMapper(bodyFieldArg);
}
use of io.swagger.models.parameters.BodyParameter in project java-chassis by ServiceComb.
the class PendingBodyParameter method createBodyParameter.
public BodyParameter createBodyParameter(String paramName) {
String modelType = ParamUtils.generateBodyParameterName(operationGenerator.getProviderMethod());
RefModel model = toRefModel(modelType);
BodyParameter bodyParameter = new BodyParameter();
bodyParameter.setName(paramName);
bodyParameter.setSchema(model);
return bodyParameter;
}
use of io.swagger.models.parameters.BodyParameter in project java-chassis by ServiceComb.
the class OperationGenerator method replaceBodyBasedParameter.
protected void replaceBodyBasedParameter(Parameter bodyBasedParameter) {
if (ParamUtils.isRealBodyParameter(bodyBasedParameter)) {
return;
}
int idx = swaggerParameters.indexOf(bodyBasedParameter);
String bodyParamName = bodyBasedParameter.getName();
BodyParameter bodyParameter = ((PendingBodyParameter) bodyBasedParameter).createBodyParameter(bodyParamName);
swaggerParameters.set(idx, bodyParameter);
}
use of io.swagger.models.parameters.BodyParameter in project swagger-core by swagger-api.
the class SimpleReaderTest method scanClassWithImplicitExamplePostClass.
@Test(description = "scan a resource with operation implicit post example (dataTypeClass)")
public void scanClassWithImplicitExamplePostClass() {
Swagger swagger = getSwagger(ClassWithExamplePostClass.class);
Parameter param = swagger.getPaths().get("/external/info2").getPost().getParameters().get(0);
BodyParameter bp = (BodyParameter) param;
assertNotNull(bp.getExamples());
assertTrue(bp.getExamples().size() == 1);
String value = bp.getExamples().get("application/json");
assertEquals("[\"a\",\"b\"]", value);
}
Aggregations