Search in sources :

Example 31 with Property

use of io.swagger.models.properties.Property in project swagger-core by swagger-api.

the class JodaDateTimeConverterTest method testJodaDateTime.

@Test
public void testJodaDateTime() {
    final Map<String, Model> models = ModelConverters.getInstance().read(ModelWithJodaDateTime.class);
    // don't create a Joda DateTime object
    assertEquals(models.size(), 1);
    final Model model = models.get("ModelWithJodaDateTime");
    final Property dateTimeProperty = model.getProperties().get("createdAt");
    assertTrue(dateTimeProperty instanceof DateTimeProperty);
    assertEquals((int) dateTimeProperty.getPosition(), 1);
    assertTrue(dateTimeProperty.getRequired());
    assertEquals(dateTimeProperty.getDescription(), "creation timestamp");
    final Property nameProperty = model.getProperties().get("name");
    assertTrue(nameProperty instanceof StringProperty);
    assertEquals((int) nameProperty.getPosition(), 2);
    assertEquals(nameProperty.getDescription(), "name of the model");
}
Also used : DateTimeProperty(io.swagger.models.properties.DateTimeProperty) Model(io.swagger.models.Model) StringProperty(io.swagger.models.properties.StringProperty) StringProperty(io.swagger.models.properties.StringProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ApiModelProperty(io.swagger.annotations.ApiModelProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 32 with Property

use of io.swagger.models.properties.Property in project swagger-core by swagger-api.

the class JodaLocalDateConverterTest method testJodaLocalDate.

@Test
public void testJodaLocalDate() {
    final Map<String, Model> models = ModelConverters.getInstance().read(ModelWithJodaLocalDate.class);
    assertEquals(models.size(), 1);
    final Model model = models.get("ModelWithJodaLocalDate");
    final Property dateTimeProperty = model.getProperties().get("createdAt");
    assertTrue(dateTimeProperty instanceof DateProperty);
    assertEquals((int) dateTimeProperty.getPosition(), 1);
    assertTrue(dateTimeProperty.getRequired());
    assertEquals(dateTimeProperty.getDescription(), "creation localDate");
    final Property nameProperty = model.getProperties().get("name");
    assertTrue(nameProperty instanceof StringProperty);
    assertEquals((int) nameProperty.getPosition(), 2);
    assertEquals(nameProperty.getDescription(), "name of the model");
}
Also used : DateProperty(io.swagger.models.properties.DateProperty) Model(io.swagger.models.Model) StringProperty(io.swagger.models.properties.StringProperty) DateProperty(io.swagger.models.properties.DateProperty) StringProperty(io.swagger.models.properties.StringProperty) ApiModelProperty(io.swagger.annotations.ApiModelProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 33 with Property

use of io.swagger.models.properties.Property in project swagger-core by swagger-api.

the class SpecFilter method locateReferencedDefinitions.

private void locateReferencedDefinitions(Map<String, Property> props, Set<String> nestedReferencedDefinitions, Swagger swagger) {
    if (props == null)
        return;
    for (String keyProp : props.keySet()) {
        Property p = props.get(keyProp);
        String ref = getPropertyRef(p);
        if (ref != null) {
            locateReferencedDefinitions(ref, nestedReferencedDefinitions, swagger);
        }
    }
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty)

Example 34 with Property

use of io.swagger.models.properties.Property in project swagger-core by swagger-api.

the class ServletReaderExtension method parseResponseHeaders.

private static Map<String, Property> parseResponseHeaders(ReaderContext context, ResponseHeader[] headers) {
    Map<String, Property> responseHeaders = null;
    for (ResponseHeader header : headers) {
        final String name = header.name();
        if (StringUtils.isNotEmpty(name)) {
            if (responseHeaders == null) {
                responseHeaders = new HashMap<String, Property>();
            }
            final Class<?> cls = header.response();
            if (!ReflectionUtils.isVoid(cls)) {
                final Property property = ModelConverters.getInstance().readAsProperty(cls);
                if (property != null) {
                    final Property responseProperty = ContainerWrapper.wrapContainer(header.responseContainer(), property, ContainerWrapper.ARRAY, ContainerWrapper.LIST, ContainerWrapper.SET);
                    responseProperty.setDescription(header.description());
                    responseHeaders.put(name, responseProperty);
                    appendModels(context.getSwagger(), cls);
                }
            }
        }
    }
    return responseHeaders;
}
Also used : ResponseHeader(io.swagger.annotations.ResponseHeader) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty) RefProperty(io.swagger.models.properties.RefProperty)

Example 35 with Property

use of io.swagger.models.properties.Property in project swagger-core by swagger-api.

the class ServletReaderExtension method applyResponses.

@Override
public void applyResponses(ReaderContext context, Operation operation, Method method) {
    final Map<Integer, Response> result = new HashMap<Integer, Response>();
    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.<String, Property>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

Property (io.swagger.models.properties.Property)145 Test (org.testng.annotations.Test)96 ArrayProperty (io.swagger.models.properties.ArrayProperty)86 StringProperty (io.swagger.models.properties.StringProperty)75 RefProperty (io.swagger.models.properties.RefProperty)65 MapProperty (io.swagger.models.properties.MapProperty)59 Model (io.swagger.models.Model)52 IntegerProperty (io.swagger.models.properties.IntegerProperty)48 LongProperty (io.swagger.models.properties.LongProperty)35 DoubleProperty (io.swagger.models.properties.DoubleProperty)32 FloatProperty (io.swagger.models.properties.FloatProperty)27 BooleanProperty (io.swagger.models.properties.BooleanProperty)25 ObjectProperty (io.swagger.models.properties.ObjectProperty)25 Operation (io.swagger.models.Operation)24 DateTimeProperty (io.swagger.models.properties.DateTimeProperty)23 DateProperty (io.swagger.models.properties.DateProperty)22 ApiModelProperty (io.swagger.annotations.ApiModelProperty)20 FileProperty (io.swagger.models.properties.FileProperty)18 ModelImpl (io.swagger.models.ModelImpl)17 Response (io.swagger.models.Response)16