use of io.swagger.models.Swagger in project swagger-core by swagger-api.
the class SimpleReaderTest method scanResourceWithApiResponseResponseContainerValue.
@Test(description = "scan resource with ApiResponse.responseContainer() value")
public void scanResourceWithApiResponseResponseContainerValue() {
Swagger swagger = getSwagger(ResourceWithApiResponseResponseContainer.class);
Path paths = swagger.getPaths().get("/{id}");
Map<String, Response> responses1 = paths.getGet().getResponses();
assertEquals(responses1.get("200").getSchema().getClass(), MapProperty.class);
assertEquals(responses1.get("400").getSchema().getClass(), ArrayProperty.class);
Map<String, Response> responses2 = paths.getPut().getResponses();
assertEquals(responses2.get("201").getSchema().getClass(), RefProperty.class);
assertEquals(responses2.get("401").getSchema().getClass(), ArrayProperty.class);
Map<String, Response> responses3 = paths.getPost().getResponses();
assertEquals(responses3.get("202").getSchema().getClass(), RefProperty.class);
assertEquals(responses3.get("402").getSchema().getClass(), RefProperty.class);
Map<String, Response> responses4 = paths.getDelete().getResponses();
assertEquals(responses4.get("203").getSchema().getClass(), RefProperty.class);
assertEquals(responses4.get("403").getSchema().getClass(), RefProperty.class);
Path paths2 = swagger.getPaths().get("/{id}/name");
Map<String, Response> responses5 = paths2.getGet().getResponses();
assertEquals(responses5.get("203").getSchema().getClass(), ArrayProperty.class);
assertNull(((ArrayProperty) responses5.get("203").getSchema()).getUniqueItems());
assertNotEquals(responses5.get("203").getHeaders().get("foo").getClass(), MapProperty.class);
assertEquals(responses5.get("403").getSchema().getClass(), ArrayProperty.class);
assertEquals(((ArrayProperty) responses5.get("403").getSchema()).getUniqueItems(), Boolean.TRUE);
Map<String, Response> responses6 = paths2.getPut().getResponses();
assertEquals(responses6.get("203").getSchema().getClass(), ArrayProperty.class);
assertEquals(((ArrayProperty) responses6.get("203").getSchema()).getUniqueItems(), Boolean.TRUE);
assertEquals(responses6.get("203").getHeaders().get("foo").getClass(), ArrayProperty.class);
assertEquals(((ArrayProperty) responses6.get("203").getHeaders().get("foo")).getUniqueItems(), Boolean.TRUE);
assertEquals(responses6.get("403").getSchema().getClass(), ArrayProperty.class);
}
use of io.swagger.models.Swagger in project swagger-core by swagger-api.
the class SimpleReaderTest method scanResourceWithApiOperationCodeValue.
@Test(description = "scan resource with ApiOperation.code() value")
public void scanResourceWithApiOperationCodeValue() {
Swagger swagger = getSwagger(ResourceWithApiOperationCode.class);
Map<String, Response> responses1 = getGetResponses(swagger, "/{id}");
assertEquals(responses1.size(), 3);
assertTrue(responses1.containsKey("202"));
assertFalse(responses1.containsKey("200"));
assertEquals(responses1.get("202").getDescription(), "successful operation");
Map<String, Response> responses2 = getPutResponses(swagger, "/{id}");
assertEquals(responses2.size(), 3);
assertTrue(responses2.containsKey("200"));
assertEquals(responses2.get("200").getDescription(), "successful operation");
}
use of io.swagger.models.Swagger in project swagger-core by swagger-api.
the class SimpleReaderTest method scanResourceWithApiOperationNickname.
@Test(description = "scan a resource with custom operation nickname")
public void scanResourceWithApiOperationNickname() {
Swagger swagger = getSwagger(NicknamedOperation.class);
assertEquals(swagger.getPaths().size(), 1);
assertNotNull(swagger.getPaths().get("/external/info"));
Operation op = swagger.getPaths().get("/external/info").getGet();
assertNotNull(op);
assertEquals(op.getOperationId(), "getMyNicknameTest");
}
use of io.swagger.models.Swagger 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.Swagger 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);
}
Aggregations