Search in sources :

Example 56 with Parameter

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

the class SpecFilterTest method filterAwaySecretParameters.

@Test(description = "it should filter away secret parameters")
public void filterAwaySecretParameters() throws IOException {
    final Swagger swagger = getSwagger("specFiles/sampleSpec.json");
    final RemoveInternalParamsFilter filter = new RemoveInternalParamsFilter();
    final Swagger filtered = new SpecFilter().filter(swagger, filter, null, null, null);
    if (filtered.getPaths() != null) {
        for (Map.Entry<String, Path> entry : filtered.getPaths().entrySet()) {
            final Operation get = entry.getValue().getGet();
            for (Parameter param : get.getParameters()) {
                final String description = param.getDescription();
                assertNotNull(description);
                assertFalse(description.startsWith("secret"));
            }
        }
    } else {
        fail("paths should not be null");
    }
}
Also used : Path(io.swagger.models.Path) Swagger(io.swagger.models.Swagger) Parameter(io.swagger.models.parameters.Parameter) Operation(io.swagger.models.Operation) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) SpecFilter(io.swagger.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Example 57 with Parameter

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

the class ParameterSerializationTest method deserializeRefBodyParameter.

@Test(description = "it should deserialize a ref BodyParameter")
public void deserializeRefBodyParameter() throws IOException {
    final String json = "{\"in\":\"body\",\"required\":false,\"schema\":{\"$ref\":\"#/definitions/Cat\"}}";
    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 58 with Parameter

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

the class ParameterSerializationTest method deserializeArrayQueryParameter.

@Test(description = "it should deserialize a QueryParameter with array")
public void deserializeArrayQueryParameter() throws IOException {
    final String json = "{" + "   \"in\":\"query\"," + "   \"required\":false," + "   \"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)

Example 59 with Parameter

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

the class ParameterSerializationTest method deserializeNumberEnumPathParameter.

@Test(description = "it should deserialize a number path parameter with enum")
public void deserializeNumberEnumPathParameter() throws IOException {
    final String json = "{" + "   \"in\":\"path\"," + "   \"required\":true," + "   \"items\":{" + "      \"type\":\"integer\"" + "   }," + "   \"enum\":[1,2,3]" + "}";
    final Parameter p = m.readValue(json, Parameter.class);
    SerializationMatchers.assertEqualsToJson(p, json);
    assertEquals(((PathParameter) p).getEnumValue(), Arrays.asList(1, 2, 3));
}
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 60 with Parameter

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

the class ParameterSerializationTest method deserializeBodyParameter.

@Test(description = "it should deserialize a BodyParameter")
public void deserializeBodyParameter() throws IOException {
    final String json = "{" + "   \"in\":\"body\"," + "   \"required\":false," + "   \"schema\":{" + "      \"properties\":{" + "         \"name\":{" + "            \"type\":\"string\"" + "         }" + "      }" + "   }" + "}";
    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)92 BodyParameter (io.swagger.models.parameters.BodyParameter)54 QueryParameter (io.swagger.models.parameters.QueryParameter)53 PathParameter (io.swagger.models.parameters.PathParameter)51 Test (org.testng.annotations.Test)51 HeaderParameter (io.swagger.models.parameters.HeaderParameter)38 Swagger (io.swagger.models.Swagger)33 FormParameter (io.swagger.models.parameters.FormParameter)27 Operation (io.swagger.models.Operation)20 SerializableParameter (io.swagger.models.parameters.SerializableParameter)15 Type (java.lang.reflect.Type)14 ArrayList (java.util.ArrayList)14 Annotation (java.lang.annotation.Annotation)10 Path (io.swagger.models.Path)9 Method (java.lang.reflect.Method)9 JavaType (com.fasterxml.jackson.databind.JavaType)7 ContextParameter (io.servicecomb.swagger.extend.parameter.ContextParameter)6 Property (io.swagger.models.properties.Property)6 HashMap (java.util.HashMap)6 AnnotatedParameter (com.fasterxml.jackson.databind.introspect.AnnotatedParameter)5