use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.
the class RestOperationMeta method init.
public void init(OperationMeta operationMeta) {
this.operationMeta = operationMeta;
Swagger swagger = operationMeta.getSchemaMeta().getSwagger();
Operation operation = operationMeta.getSwaggerOperation();
this.produces = operation.getProduces();
if (produces == null) {
this.produces = swagger.getProduces();
}
setAbsolutePath(concatPath(swagger.getBasePath(), operationMeta.getOperationPath()));
this.createProduceProcessors();
Method method = operationMeta.getMethod();
Type[] genericParamTypes = method.getGenericParameterTypes();
if (genericParamTypes.length != operation.getParameters().size()) {
throw new Error("Param count is not equal between swagger and method, path=" + absolutePath);
}
// 初始化所有rest param
for (int idx = 0; idx < genericParamTypes.length; idx++) {
Parameter parameter = operation.getParameters().get(idx);
Type genericParamType = genericParamTypes[idx];
RestParam param = new RestParam(idx, parameter, genericParamType);
addParam(param);
}
this.pathBuilder = new URLPathBuilder(absolutePath, paramMap);
}
use of io.swagger.models.parameters.Parameter 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);
}
use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class SwaggerJerseyJaxrs method extractParameters.
@Override
public List<Parameter> extractParameters(List<Annotation> annotations, Type type, Set<Type> typesToSkip, Iterator<SwaggerExtension> chain) {
if (shouldIgnoreType(type, typesToSkip)) {
// stop the processing chain
return Collections.emptyList();
}
for (Annotation annotation : annotations) {
if (annotation instanceof FormDataParam) {
final FormDataParam fd = (FormDataParam) annotation;
final Class<?> cls = TypeFactory.defaultInstance().constructType(type).getRawClass();
final Parameter param;
if (java.io.InputStream.class.isAssignableFrom(cls)) {
param = new FormParameter().type("file").name(fd.value());
} else {
FormParameter fp = new FormParameter().name(fd.value());
Property schema = ModelConverters.getInstance().readAsProperty(type);
if (schema != null) {
fp.setProperty(schema);
}
param = fp;
}
return Collections.singletonList(param);
}
}
return super.extractParameters(annotations, type, typesToSkip, chain);
}
use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class FormDataBodyPartTest method testFormDataBodyPart.
@Test(description = "FormDataBodyPart should be ignored when generating the Swagger document")
public void testFormDataBodyPart() {
final Swagger swagger = new Reader(new Swagger()).read(ResourceWithFormData.class);
final List<Parameter> parameters = swagger.getPath("/test/document/{documentName}.json").getPost().getParameters();
assertEquals(parameters.size(), 3);
assertEquals(parameters.get(0).getName(), "documentName");
assertEquals(parameters.get(1).getName(), "input");
assertEquals(parameters.get(2).getName(), "id");
}
use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class SwaggerJersey2Jaxrs method extractParameters.
@Override
public List<Parameter> extractParameters(final List<Annotation> annotations, final Type type, final Set<Type> typesToSkip, final Iterator<SwaggerExtension> chain) {
List<Parameter> parameters = new ArrayList<Parameter>();
if (shouldIgnoreType(type, typesToSkip)) {
return parameters;
}
for (final Annotation annotation : annotations) {
// just handle the jersey specific annotation
if (annotation instanceof FormDataParam) {
FormDataParam fd = (FormDataParam) annotation;
if (java.io.InputStream.class.isAssignableFrom(constructType(type).getRawClass())) {
final Parameter param = new FormParameter().type("file").name(fd.value());
parameters.add(param);
} else {
final FormParameter fp = new FormParameter().name(fd.value());
final Property schema = ModelConverters.getInstance().readAsProperty(type);
if (schema != null) {
fp.setProperty(schema);
}
parameters.add(fp);
}
}
}
// Only call down to the other items in the chain if no parameters were produced
if (parameters.isEmpty()) {
parameters = super.extractParameters(annotations, type, typesToSkip, chain);
}
return parameters;
}
Aggregations