use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class SimpleReaderTest method scanSimpleResource.
@Test(description = "scan a simple resource")
public void scanSimpleResource() {
Swagger swagger = getSwagger(SimpleResource.class);
assertEquals(swagger.getPaths().size(), 3);
Operation get = getGet(swagger, "/{id}");
assertNotNull(get);
assertEquals(get.getParameters().size(), 2);
PathParameter param1 = (PathParameter) get.getParameters().get(0);
assertEquals(param1.getIn(), "path");
assertEquals(param1.getName(), "id");
assertTrue(param1.getRequired());
assertEquals(param1.getDescription(), "sample param data");
assertEquals(param1.getDefaultValue(), "5");
Parameter param2 = get.getParameters().get(1);
assertEquals(param2.getIn(), "query");
assertEquals(param2.getName(), "limit");
assertFalse(param2.getRequired());
assertNull(param2.getDescription());
List<Parameter> params = getPutParameters(swagger, "/{bodyparams}");
BodyParameter bodyParam1 = (BodyParameter) params.get(0);
assertEquals(bodyParam1.getIn(), "body");
assertEquals(bodyParam1.getName(), "body");
assertTrue(bodyParam1.getRequired());
BodyParameter bodyParam2 = (BodyParameter) params.get(1);
assertEquals(bodyParam2.getIn(), "body");
assertEquals(bodyParam2.getName(), "body");
assertFalse(bodyParam2.getRequired());
}
use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class SimpleReaderTest method scanResourceWithParamEnums.
@Test(description = "scan a resource with param enums")
public void scanResourceWithParamEnums() {
Swagger swagger = getSwagger(ResourceWithEnums.class);
SerializableParameter param = (SerializableParameter) getGetParameters(swagger, "/{id}").get(2);
List<String> _enum = param.getEnum();
assertEquals(_enum, Arrays.asList("a", "b", "c", "d", "e"));
List<Parameter> checkEnumHandling = getGetParameters(swagger, "/checkEnumHandling/{v0}");
List<String> allEnumValues = Lists.newArrayList(Collections2.transform(Arrays.asList(TestEnum.values()), Functions.toStringFunction()));
SerializableParameter v0 = (SerializableParameter) checkEnumHandling.get(0);
assertEquals(v0.getEnum(), allEnumValues);
SerializableParameter v1 = (SerializableParameter) checkEnumHandling.get(1);
assertEquals(((StringProperty) v1.getItems()).getEnum(), allEnumValues);
SerializableParameter v2 = (SerializableParameter) checkEnumHandling.get(2);
assertEquals(((StringProperty) v2.getItems()).getEnum(), allEnumValues);
SerializableParameter v3 = (SerializableParameter) checkEnumHandling.get(3);
assertEquals(v3.getEnum(), Arrays.asList("A", "B", "C"));
}
use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class SimpleReaderTest method scanClassWithExampleQuery.
@Test(description = "scan a resource with query param example")
public void scanClassWithExampleQuery() {
Swagger swagger = getSwagger(ClassWithExamplePost.class);
Parameter param = swagger.getPaths().get("/external/info").getGet().getParameters().get(0);
QueryParameter bp = (QueryParameter) param;
assertNotNull(bp.getExample());
Object value = bp.getExample();
assertEquals("a,b,c", value);
}
use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class SimpleReaderTest method scanClassWithImplicitExamplePost.
@Test(description = "scan a resource with operation implicit post example")
public void scanClassWithImplicitExamplePost() {
Swagger swagger = getSwagger(ClassWithExamplePost.class);
Parameter param = swagger.getPaths().get("/external/info2").getPost().getParameters().get(0);
BodyParameter bp = (BodyParameter) param;
assertNotNull(bp.getExamples());
assertTrue(bp.getExamples().size() == 1);
String value = bp.getExamples().get("application/json");
assertEquals("[\"a\",\"b\"]", value);
}
use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class SimpleReaderTest method scanClassWithExamplePost.
@Test(description = "scan a resource with operation post example")
public void scanClassWithExamplePost() {
Swagger swagger = getSwagger(ClassWithExamplePost.class);
Parameter param = swagger.getPaths().get("/external/info").getPost().getParameters().get(0);
BodyParameter bp = (BodyParameter) param;
assertNotNull(bp.getExamples());
assertTrue(bp.getExamples().size() == 1);
String value = bp.getExamples().get("application/json");
assertEquals("[\"a\",\"b\"]", value);
}
Aggregations