Search in sources :

Example 36 with Swagger

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);
}
Also used : Path(io.swagger.models.Path) ResourceWithResponse(io.swagger.resources.ResourceWithResponse) Response(io.swagger.models.Response) Swagger(io.swagger.models.Swagger) Test(org.testng.annotations.Test)

Example 37 with Swagger

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");
}
Also used : ResourceWithResponse(io.swagger.resources.ResourceWithResponse) Response(io.swagger.models.Response) Swagger(io.swagger.models.Swagger) Test(org.testng.annotations.Test)

Example 38 with Swagger

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");
}
Also used : Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation) NicknamedOperation(io.swagger.resources.NicknamedOperation) Test(org.testng.annotations.Test)

Example 39 with Swagger

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"));
}
Also used : SerializableParameter(io.swagger.models.parameters.SerializableParameter) Swagger(io.swagger.models.Swagger) SerializableParameter(io.swagger.models.parameters.SerializableParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Test(org.testng.annotations.Test)

Example 40 with Swagger

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);
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Swagger(io.swagger.models.Swagger) SerializableParameter(io.swagger.models.parameters.SerializableParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Test(org.testng.annotations.Test)

Aggregations

Swagger (io.swagger.models.Swagger)184 Test (org.testng.annotations.Test)115 Operation (io.swagger.models.Operation)45 Parameter (io.swagger.models.parameters.Parameter)33 QueryParameter (io.swagger.models.parameters.QueryParameter)33 BodyParameter (io.swagger.models.parameters.BodyParameter)29 Path (io.swagger.models.Path)26 PathParameter (io.swagger.models.parameters.PathParameter)25 Reader (io.swagger.jaxrs.Reader)23 SpecFilter (io.swagger.core.filter.SpecFilter)21 Test (org.junit.Test)19 SwaggerParser (io.swagger.parser.SwaggerParser)16 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)16 Response (io.swagger.models.Response)14 SerializableParameter (io.swagger.models.parameters.SerializableParameter)14 HashMap (java.util.HashMap)14 Info (io.swagger.models.Info)12 Map (java.util.Map)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 Model (io.swagger.models.Model)10