Search in sources :

Example 86 with Property

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

the class DefaultParameterExtension method extractParameters.

@Override
public List<Parameter> extractParameters(List<Annotation> annotations, Type type, Set<Type> typesToSkip, Iterator<SwaggerExtension> chain) {
    if (shouldIgnoreType(type, typesToSkip)) {
        return new ArrayList<Parameter>();
    }
    List<Parameter> parameters = new ArrayList<Parameter>();
    Parameter parameter = null;
    for (Annotation annotation : annotations) {
        if (annotation instanceof QueryParam) {
            QueryParam param = (QueryParam) annotation;
            QueryParameter qp = new QueryParameter().name(param.value());
            Property schema = createProperty(type);
            if (schema != null) {
                qp.setProperty(schema);
            }
            parameter = qp;
        } else if (annotation instanceof PathParam) {
            PathParam param = (PathParam) annotation;
            PathParameter pp = new PathParameter().name(param.value());
            Property schema = createProperty(type);
            if (schema != null) {
                pp.setProperty(schema);
            }
            parameter = pp;
        } else if (annotation instanceof HeaderParam) {
            HeaderParam param = (HeaderParam) annotation;
            HeaderParameter hp = new HeaderParameter().name(param.value());
            Property schema = createProperty(type);
            if (schema != null) {
                hp.setProperty(schema);
            }
            parameter = hp;
        } else if (annotation instanceof CookieParam) {
            CookieParam param = (CookieParam) annotation;
            CookieParameter cp = new CookieParameter().name(param.value());
            Property schema = createProperty(type);
            if (schema != null) {
                cp.setProperty(schema);
            }
            parameter = cp;
        } else if (annotation instanceof FormParam) {
            FormParam param = (FormParam) annotation;
            FormParameter fp = new FormParameter().name(param.value());
            Property schema = createProperty(type);
            if (schema != null) {
                fp.setProperty(schema);
            }
            parameter = fp;
        } else {
            handleAdditionalAnnotation(parameters, annotation, type, typesToSkip);
        }
    }
    if (parameter != null) {
        parameters.add(parameter);
    }
    return parameters;
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParam(javax.ws.rs.HeaderParam) ArrayList(java.util.ArrayList) PathParameter(io.swagger.models.parameters.PathParameter) FormParameter(io.swagger.models.parameters.FormParameter) Annotation(java.lang.annotation.Annotation) CookieParam(javax.ws.rs.CookieParam) QueryParam(javax.ws.rs.QueryParam) HeaderParameter(io.swagger.models.parameters.HeaderParameter) CookieParameter(io.swagger.models.parameters.CookieParameter) FormParameter(io.swagger.models.parameters.FormParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) CookieParameter(io.swagger.models.parameters.CookieParameter) PathParam(javax.ws.rs.PathParam) HeaderParameter(io.swagger.models.parameters.HeaderParameter) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) FormParam(javax.ws.rs.FormParam)

Example 87 with Property

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

the class Reader method addResponse.

private void addResponse(Operation operation, ApiResponse apiResponse) {
    Map<String, Property> responseHeaders = parseResponseHeaders(apiResponse.responseHeaders());
    Response response = new Response().description(apiResponse.message()).headers(responseHeaders);
    if (apiResponse.code() == 0) {
        operation.defaultResponse(response);
    } else {
        operation.response(apiResponse.code(), response);
    }
    if (StringUtils.isNotEmpty(apiResponse.reference())) {
        response.schema(new RefProperty(apiResponse.reference()));
    } else if (!isVoid(apiResponse.response())) {
        Type responseType = apiResponse.response();
        final Property property = ModelConverters.getInstance().readAsProperty(responseType);
        if (property != null) {
            response.schema(ContainerWrapper.wrapContainer(apiResponse.responseContainer(), property));
            appendModels(responseType);
        }
    }
}
Also used : Response(io.swagger.models.Response) ApiResponse(io.swagger.annotations.ApiResponse) Type(java.lang.reflect.Type) JavaType(com.fasterxml.jackson.databind.JavaType) ParameterizedType(java.lang.reflect.ParameterizedType) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty) RefProperty(io.swagger.models.properties.RefProperty) RefProperty(io.swagger.models.properties.RefProperty)

Example 88 with Property

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

the class JsonDeserializationTest method givenMapProperty_shouldDeserializeMaxProperties.

@Test
public void givenMapProperty_shouldDeserializeMaxProperties() {
    String path = "json-schema-validation/map.json";
    MapProperty property = (MapProperty) TestUtils.deserializeJsonFileFromClasspath(path, Property.class);
    assertNotNull(property.getMaxProperties());
    assertEquals(property.getMaxProperties().intValue(), 10);
}
Also used : MapProperty(io.swagger.models.properties.MapProperty) MapProperty(io.swagger.models.properties.MapProperty) StringProperty(io.swagger.models.properties.StringProperty) ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 89 with Property

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

the class JsonDeserializationTest method givenMapProperty_shouldDeserializeMinProperties.

@Test
public void givenMapProperty_shouldDeserializeMinProperties() {
    String path = "json-schema-validation/map.json";
    MapProperty property = (MapProperty) TestUtils.deserializeJsonFileFromClasspath(path, Property.class);
    assertNotNull(property.getMinProperties());
    assertEquals(property.getMinProperties().intValue(), 1);
}
Also used : MapProperty(io.swagger.models.properties.MapProperty) MapProperty(io.swagger.models.properties.MapProperty) StringProperty(io.swagger.models.properties.StringProperty) ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 90 with Property

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

the class JsonDeserializationTest method shouldDeserializeArrayPropertyMaxItems.

@Test
public void shouldDeserializeArrayPropertyMaxItems() throws Exception {
    String path = "json-schema-validation/array.json";
    ArrayProperty property = (ArrayProperty) TestUtils.deserializeJsonFileFromClasspath(path, Property.class);
    assertNotNull(property.getMaxItems());
    assertEquals(property.getMaxItems().intValue(), 10);
}
Also used : ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) MapProperty(io.swagger.models.properties.MapProperty) StringProperty(io.swagger.models.properties.StringProperty) ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

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