Search in sources :

Example 26 with Parameter

use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.

the class SwaggerJersey2JaxrsTest method scanClassAnfFieldLevelAnnotations.

@Test(description = "scan class level and field level annotations")
public void scanClassAnfFieldLevelAnnotations() {
    final Swagger swagger = new Reader(new Swagger()).read(ResourceWithKnownInjections.class);
    final List<Parameter> resourceParameters = swagger.getPaths().get("/resource/{id}").getGet().getParameters();
    assertNotNull(resourceParameters);
    assertEquals(resourceParameters.size(), 4);
    assertEquals(getName(resourceParameters, 0), "fieldParam");
    assertEquals(getName(resourceParameters, 1), "skip");
    assertEquals(getName(resourceParameters, 2), "limit");
    assertEquals(getName(resourceParameters, 3), "methodParam");
}
Also used : Swagger(io.swagger.models.Swagger) Reader(io.swagger.jaxrs.Reader) HeaderParameter(io.swagger.models.parameters.HeaderParameter) FormParameter(io.swagger.models.parameters.FormParameter) Parameter(io.swagger.models.parameters.Parameter) Test(org.testng.annotations.Test)

Example 27 with Parameter

use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.

the class ParameterSerializationTest method deserializePathParameter.

@Test(description = "it should deserialize a PathParameter")
public void deserializePathParameter() throws IOException {
    final String json = "{\"in\":\"query\",\"required\":true,\"type\":\"string\"}";
    final Parameter p = m.readValue(json, Parameter.class);
    SerializationMatchers.assertEqualsToJson(p, json);
    assertTrue(p.getRequired());
}
Also used : BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) Test(org.testng.annotations.Test)

Example 28 with Parameter

use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.

the class ParameterSerializationTest method deserializeIntegerArrayPathParameter.

@Test(description = "it should deserialize a PathParameter with integer array ")
public void deserializeIntegerArrayPathParameter() throws IOException {
    final String json = "{" + "   \"in\":\"path\"," + "   \"required\":true," + "   \"type\":\"array\"," + "   \"items\":{" + "      \"type\":\"integer\"," + "      \"format\":\"int32\"" + "   }," + "   \"collectionFormat\":\"multi\"" + "}";
    final Parameter p = m.readValue(json, Parameter.class);
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) Test(org.testng.annotations.Test)

Example 29 with Parameter

use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.

the class ParameterSerializationTest method deserializeEnumPathParameter.

@Test(description = "it should deserialize a path parameter with enum")
public void deserializeEnumPathParameter() throws IOException {
    final String json = "{" + "   \"in\":\"path\"," + "   \"required\":true," + "   \"items\":{" + "      \"type\":\"string\"" + "   }," + "   \"enum\":[\"a\",\"b\",\"c\"]" + "}";
    final Parameter p = m.readValue(json, Parameter.class);
    SerializationMatchers.assertEqualsToJson(p, json);
    assertEquals(((PathParameter) p).getEnum(), Arrays.asList("a", "b", "c"));
}
Also used : BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) Test(org.testng.annotations.Test)

Example 30 with Parameter

use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.

the class ParameterSerializationTest method deserializeStringArrayPathParameter.

@Test(description = "it should deserialize a PathParameter with string array")
public void deserializeStringArrayPathParameter() throws IOException {
    final String json = "{" + "   \"in\":\"path\"," + "   \"required\":true," + "   \"type\":\"array\"," + "   \"items\":{" + "      \"type\":\"string\"" + "   }," + "   \"collectionFormat\":\"multi\"" + "}";
    final Parameter p = m.readValue(json, Parameter.class);
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) Test(org.testng.annotations.Test)

Aggregations

Parameter (io.swagger.models.parameters.Parameter)186 BodyParameter (io.swagger.models.parameters.BodyParameter)102 QueryParameter (io.swagger.models.parameters.QueryParameter)101 PathParameter (io.swagger.models.parameters.PathParameter)89 Test (org.testng.annotations.Test)80 HeaderParameter (io.swagger.models.parameters.HeaderParameter)66 Swagger (io.swagger.models.Swagger)63 FormParameter (io.swagger.models.parameters.FormParameter)52 Operation (io.swagger.models.Operation)31 SerializableParameter (io.swagger.models.parameters.SerializableParameter)29 Test (org.junit.Test)25 Type (java.lang.reflect.Type)23 ArrayList (java.util.ArrayList)23 Path (io.swagger.models.Path)19 Annotation (java.lang.annotation.Annotation)17 JavaType (com.fasterxml.jackson.databind.JavaType)14 Response (io.swagger.models.Response)14 Method (java.lang.reflect.Method)14 Property (io.swagger.models.properties.Property)13 ModelImpl (io.swagger.models.ModelImpl)12