use of io.swagger.models.properties.RefProperty in project syndesis by syndesisio.
the class UnifiedXmlDataShapeGenerator method createRequestBodySchema.
private static Element createRequestBodySchema(final Swagger swagger, final Operation operation, final Map<String, SchemaPrefixAndElement> moreSchemas) {
final Optional<BodyParameter> bodyParameter = findBodyParameter(operation);
if (!bodyParameter.isPresent()) {
return null;
}
final BodyParameter body = bodyParameter.get();
final Model bodySchema = body.getSchema();
final ModelImpl bodySchemaToUse;
if (bodySchema instanceof RefModel) {
bodySchemaToUse = dereference((RefModel) bodySchema, swagger);
} else if (bodySchema instanceof ArrayModel) {
final Property items = ((ArrayModel) bodySchema).getItems();
if (items instanceof RefProperty) {
bodySchemaToUse = dereference((RefProperty) items, swagger);
} else {
bodySchemaToUse = new ModelImpl();
final String name = nameOrDefault(items, "array");
bodySchemaToUse.name(name);
bodySchemaToUse.addProperty(name, items);
}
} else {
bodySchemaToUse = (ModelImpl) bodySchema;
}
final String targetNamespace = xmlTargetNamespaceOrNull(bodySchemaToUse);
final Element schema = newXmlSchema(targetNamespace);
final Element bodyElement = addElement(schema, "element");
bodyElement.addAttribute("name", nameOf(bodySchemaToUse));
final Element complexBody = addElement(bodyElement, "complexType");
final Element bodySequence = addElement(complexBody, "sequence");
defineElementPropertiesOf(bodySequence, bodySchemaToUse, swagger, moreSchemas);
defineAttributePropertiesOf(complexBody, bodySchemaToUse);
return schema;
}
use of io.swagger.models.properties.RefProperty in project syndesis by syndesisio.
the class UnifiedXmlDataShapeGenerator method createResponseBodySchema.
private static Element createResponseBodySchema(final Swagger swagger, final Operation operation, final Map<String, SchemaPrefixAndElement> moreSchemas) {
final Optional<Response> maybeResponse = findResponse(operation);
if (!maybeResponse.isPresent()) {
return null;
}
final Response body = maybeResponse.get();
final Property bodySchema = body.getSchema();
if (bodySchema instanceof RefProperty) {
return defineComplexElement((RefProperty) bodySchema, null, swagger, moreSchemas);
} else if (bodySchema instanceof ArrayProperty) {
final ArrayProperty array = (ArrayProperty) bodySchema;
final String targetNamespace = xmlTargetNamespaceOrNull(array);
final Element schema = newXmlSchema(targetNamespace);
defineElementProperty(ofNullable(array.getName()).orElse("array"), array, schema, swagger, moreSchemas);
return schema;
} else {
throw new IllegalArgumentException("Unsupported response schema type: " + bodySchema);
}
}
use of io.swagger.models.properties.RefProperty in project java-chassis by ServiceComb.
the class TestSwaggerUtils method isComplexProperty.
@Test
public void isComplexProperty() {
Property property = new RefProperty("ref");
Assert.assertTrue(SwaggerUtils.isComplexProperty(property));
property = new ObjectProperty();
Assert.assertTrue(SwaggerUtils.isComplexProperty(property));
property = new MapProperty();
Assert.assertTrue(SwaggerUtils.isComplexProperty(property));
property = new ArrayProperty(new ObjectProperty());
Assert.assertTrue(SwaggerUtils.isComplexProperty(property));
property = new ArrayProperty(new StringProperty());
Assert.assertFalse(SwaggerUtils.isComplexProperty(property));
property = new StringProperty();
Assert.assertFalse(SwaggerUtils.isComplexProperty(property));
}
use of io.swagger.models.properties.RefProperty in project vertx-swagger by bobxwang.
the class RouteReaderExtension method applyResponses.
@Override
public void applyResponses(ReaderContext context, Operation operation, Method method) {
final Map<Integer, Response> result = new HashMap<>();
final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class);
if (apiOperation != null && StringUtils.isNotBlank(apiOperation.responseReference())) {
final Response response = new Response().description(SUCCESSFUL_OPERATION);
response.schema(new RefProperty(apiOperation.responseReference()));
result.put(apiOperation.code(), response);
}
final Type responseType = getResponseType(method);
if (isValidResponse(responseType)) {
final Property property = ModelConverters.getInstance().readAsProperty(responseType);
if (property != null) {
final Property responseProperty = ContainerWrapper.wrapContainer(getResponseContainer(apiOperation), property);
final int responseCode = apiOperation == null ? 200 : apiOperation.code();
final Map<String, Property> defaultResponseHeaders = apiOperation == null ? Collections.emptyMap() : parseResponseHeaders(context, apiOperation.responseHeaders());
final Response response = new Response().description(SUCCESSFUL_OPERATION).schema(responseProperty).headers(defaultResponseHeaders);
result.put(responseCode, response);
appendModels(context.getSwagger(), responseType);
}
}
final ApiResponses responseAnnotation = ReflectionUtils.getAnnotation(method, ApiResponses.class);
if (responseAnnotation != null) {
for (ApiResponse apiResponse : responseAnnotation.value()) {
final Map<String, Property> responseHeaders = parseResponseHeaders(context, apiResponse.responseHeaders());
final Response response = new Response().description(apiResponse.message()).headers(responseHeaders);
if (StringUtils.isNotEmpty(apiResponse.reference())) {
response.schema(new RefProperty(apiResponse.reference()));
} else if (!ReflectionUtils.isVoid(apiResponse.response())) {
final Type type = apiResponse.response();
final Property property = ModelConverters.getInstance().readAsProperty(type);
if (property != null) {
response.schema(ContainerWrapper.wrapContainer(apiResponse.responseContainer(), property));
appendModels(context.getSwagger(), type);
}
}
result.put(apiResponse.code(), response);
}
}
for (Map.Entry<Integer, Response> responseEntry : result.entrySet()) {
if (responseEntry.getKey() == 0) {
operation.defaultResponse(responseEntry.getValue());
} else {
operation.response(responseEntry.getKey(), responseEntry.getValue());
}
}
}
Aggregations