Search in sources :

Example 26 with ArrayModel

use of io.swagger.models.ArrayModel 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;
}
Also used : RefModel(io.swagger.models.RefModel) 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) Model(io.swagger.models.Model) RefModel(io.swagger.models.RefModel) ArrayModel(io.swagger.models.ArrayModel) BodyParameter(io.swagger.models.parameters.BodyParameter) ModelImpl(io.swagger.models.ModelImpl) ArrayModel(io.swagger.models.ArrayModel) 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 27 with ArrayModel

use of io.swagger.models.ArrayModel in project java-chassis by ServiceComb.

the class TestApiOperation method testSet.

private void testSet(Path path) {
    Operation operation = path.getPost();
    Model result200 = operation.getResponses().get("200").getResponseSchema();
    Assert.assertEquals(ArrayModel.class, result200.getClass());
    Assert.assertEquals(true, ((ArrayModel) result200).getUniqueItems());
}
Also used : Model(io.swagger.models.Model) ArrayModel(io.swagger.models.ArrayModel) ApiOperation(io.swagger.annotations.ApiOperation) Operation(io.swagger.models.Operation)

Aggregations

ArrayModel (io.swagger.models.ArrayModel)27 Test (org.testng.annotations.Test)21 Model (io.swagger.models.Model)17 BodyParameter (io.swagger.models.parameters.BodyParameter)17 Operation (io.swagger.models.Operation)15 RefProperty (io.swagger.models.properties.RefProperty)14 Property (io.swagger.models.properties.Property)10 Path (io.swagger.models.Path)9 RefModel (io.swagger.models.RefModel)9 StringProperty (io.swagger.models.properties.StringProperty)9 Swagger (io.swagger.models.Swagger)7 ArrayProperty (io.swagger.models.properties.ArrayProperty)6 ComposedModel (io.swagger.models.ComposedModel)4 ModelImpl (io.swagger.models.ModelImpl)4 SwaggerDeserializationResult (io.swagger.parser.util.SwaggerDeserializationResult)4 Response (io.swagger.models.Response)3 ApiOperation (io.swagger.annotations.ApiOperation)2 FormParameter (io.swagger.models.parameters.FormParameter)2 HeaderParameter (io.swagger.models.parameters.HeaderParameter)2 Parameter (io.swagger.models.parameters.Parameter)2