use of io.swagger.models.properties.ArrayProperty 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.ArrayProperty in project syndesis by syndesisio.
the class UnifiedXmlDataShapeGeneratorTest method propertyFrom.
private static Map<String, ArrayProperty> propertyFrom(final String json) {
try {
final ObjectNode object = (ObjectNode) MAPPER.readTree(json);
final String propertyName = object.fieldNames().next();
final JsonNode node = object.elements().next();
final ArrayProperty array = MAPPER.readerFor(Property.class).readValue(node);
return Collections.singletonMap(propertyName, array);
} catch (final IOException e) {
throw new AssertionError("Unable to deserialize given parameter", e);
}
}
use of io.swagger.models.properties.ArrayProperty 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.ArrayProperty in project java-chassis by ServiceComb.
the class PartArrayProcessor method fillParameter.
@Override
public void fillParameter(Swagger swagger, Operation operation, FormParameter parameter, JavaType type, Annotation annotation) {
Property property = new ArrayProperty(new FileProperty());
parameter.setProperty(property);
}
use of io.swagger.models.properties.ArrayProperty in project endpoints-java by cloudendpoints.
the class SwaggerGenerator method convertToSwaggerProperty.
private Property convertToSwaggerProperty(Field f) {
Property p = null;
Class<? extends Property> propertyClass = FIELD_TYPE_TO_PROPERTY_CLASS_MAP.get(f.type());
if (propertyClass != null) {
try {
p = propertyClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
// cannot happen, as Property subclasses are guaranteed to have a default constructor
}
} else {
if (f.type() == FieldType.OBJECT) {
p = new RefProperty(f.schemaReference().get().name());
} else if (f.type() == FieldType.ARRAY) {
p = new ArrayProperty(convertToSwaggerProperty(f.arrayItemSchema()));
} else if (f.type() == FieldType.ENUM) {
p = new StringProperty()._enum(getEnumValues(f.schemaReference().type()));
}
}
if (p == null) {
throw new IllegalArgumentException("could not convert field " + f);
}
// the spec explicitly disallows description on $ref
if (!(p instanceof RefProperty)) {
p.description(f.description());
}
return p;
}
Aggregations