Search in sources :

Example 76 with ArrayProperty

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);
    }
}
Also used : Response(io.swagger.models.Response) ArrayProperty(io.swagger.models.properties.ArrayProperty) XmlSchemaHelper.isElement(io.syndesis.server.connector.generator.swagger.util.XmlSchemaHelper.isElement) XmlSchemaHelper.addElement(io.syndesis.server.connector.generator.swagger.util.XmlSchemaHelper.addElement) Element(org.dom4j.Element) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) RefProperty(io.swagger.models.properties.RefProperty)

Example 77 with ArrayProperty

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);
    }
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property)

Example 78 with ArrayProperty

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));
}
Also used : ObjectProperty(io.swagger.models.properties.ObjectProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) MapProperty(io.swagger.models.properties.MapProperty) StringProperty(io.swagger.models.properties.StringProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) RefProperty(io.swagger.models.properties.RefProperty) Test(org.junit.Test)

Example 79 with ArrayProperty

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);
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) FileProperty(io.swagger.models.properties.FileProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) FileProperty(io.swagger.models.properties.FileProperty) Property(io.swagger.models.properties.Property)

Example 80 with ArrayProperty

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;
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) StringProperty(io.swagger.models.properties.StringProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DateProperty(io.swagger.models.properties.DateProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) RefProperty(io.swagger.models.properties.RefProperty)

Aggregations

ArrayProperty (io.swagger.models.properties.ArrayProperty)82 Property (io.swagger.models.properties.Property)62 StringProperty (io.swagger.models.properties.StringProperty)42 RefProperty (io.swagger.models.properties.RefProperty)39 Test (org.testng.annotations.Test)36 MapProperty (io.swagger.models.properties.MapProperty)25 Model (io.swagger.models.Model)23 IntegerProperty (io.swagger.models.properties.IntegerProperty)23 LongProperty (io.swagger.models.properties.LongProperty)14 ModelImpl (io.swagger.models.ModelImpl)13 BooleanProperty (io.swagger.models.properties.BooleanProperty)12 DoubleProperty (io.swagger.models.properties.DoubleProperty)12 RefModel (io.swagger.models.RefModel)10 FloatProperty (io.swagger.models.properties.FloatProperty)10 Operation (io.swagger.models.Operation)9 ByteArrayProperty (io.swagger.models.properties.ByteArrayProperty)9 DecimalProperty (io.swagger.models.properties.DecimalProperty)9 HashMap (java.util.HashMap)9 Response (io.swagger.models.Response)7 Swagger (io.swagger.models.Swagger)7