Search in sources :

Example 71 with RefProperty

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;
}
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 72 with RefProperty

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);
    }
}
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 73 with RefProperty

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));
}
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 74 with RefProperty

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());
        }
    }
}
Also used : HashMap(java.util.HashMap) ApiResponse(io.swagger.annotations.ApiResponse) RefProperty(io.swagger.models.properties.RefProperty) Response(io.swagger.models.Response) ApiResponse(io.swagger.annotations.ApiResponse) Type(java.lang.reflect.Type) JavaType(com.fasterxml.jackson.databind.JavaType) ApiOperation(io.swagger.annotations.ApiOperation) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty) RefProperty(io.swagger.models.properties.RefProperty) Map(java.util.Map) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

RefProperty (io.swagger.models.properties.RefProperty)74 Property (io.swagger.models.properties.Property)50 ArrayProperty (io.swagger.models.properties.ArrayProperty)46 StringProperty (io.swagger.models.properties.StringProperty)35 Test (org.testng.annotations.Test)35 Model (io.swagger.models.Model)23 MapProperty (io.swagger.models.properties.MapProperty)20 ModelImpl (io.swagger.models.ModelImpl)18 Response (io.swagger.models.Response)18 IntegerProperty (io.swagger.models.properties.IntegerProperty)18 Operation (io.swagger.models.Operation)17 RefModel (io.swagger.models.RefModel)17 LongProperty (io.swagger.models.properties.LongProperty)14 Path (io.swagger.models.Path)12 Swagger (io.swagger.models.Swagger)12 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)12 ArrayModel (io.swagger.models.ArrayModel)11 BodyParameter (io.swagger.models.parameters.BodyParameter)11 Map (java.util.Map)11