Search in sources :

Example 31 with Swagger

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

the class SimpleReaderTest method scanClassWithExamplePostClass.

@Test(description = "scan a resource with operation post example (dataTypeClass)")
public void scanClassWithExamplePostClass() {
    Swagger swagger = getSwagger(ClassWithExamplePostClass.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);
}
Also used : 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) BodyParameter(io.swagger.models.parameters.BodyParameter) Test(org.testng.annotations.Test)

Example 32 with Swagger

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

the class SimpleReaderTest method scanResourceWithMapReturnType.

@Test(description = "scan a resource with map return type")
public void scanResourceWithMapReturnType() {
    Swagger swagger = getSwagger(ResourceWithMapReturnValue.class);
    Operation get = getGet(swagger, "/{id}");
    assertNotNull(get);
    assertNotNull(get.getResponses());
    Response response = get.getResponses().get("200");
    assertNotNull(response);
    Property schema = response.getSchema();
    assertEquals(schema.getClass(), MapProperty.class);
}
Also used : ResourceWithResponse(io.swagger.resources.ResourceWithResponse) Response(io.swagger.models.Response) Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation) NicknamedOperation(io.swagger.resources.NicknamedOperation) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty) RefProperty(io.swagger.models.properties.RefProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) Test(org.testng.annotations.Test)

Example 33 with Swagger

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

the class SimpleReaderTest method scanResourceWithApiOperationTags.

@Test(description = "scan a resource with tags in test 841")
public void scanResourceWithApiOperationTags() {
    Swagger swagger = getSwagger(Resource841.class);
    assertEquals(swagger.getTags().size(), 3);
    List<String> rootTags = getGet(swagger, "/fun").getTags();
    assertEquals(rootTags.size(), 2);
    assertEquals(rootTags, Arrays.asList("tag1", "tag2"));
    List<String> thisTags = getGet(swagger, "/fun/this").getTags();
    assertEquals(thisTags.size(), 1);
    assertEquals(thisTags, Arrays.asList("tag1"));
    List<String> thatTags = getGet(swagger, "/fun/that").getTags();
    assertEquals(thatTags.size(), 1);
    assertEquals(thatTags, Arrays.asList("tag2"));
}
Also used : Swagger(io.swagger.models.Swagger) Test(org.testng.annotations.Test)

Example 34 with Swagger

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

the class SimpleReaderTest method scanClassWithImplicitExampleQuery.

@Test(description = "scan a resource with implicit operation query example")
public void scanClassWithImplicitExampleQuery() {
    Swagger swagger = getSwagger(ClassWithExamplePost.class);
    Parameter param = swagger.getPaths().get("/external/info2").getGet().getParameters().get(0);
    QueryParameter bp = (QueryParameter) param;
    assertNotNull(bp.getExample());
    Object value = bp.getExample();
    assertEquals("77", 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)

Example 35 with Swagger

use of io.swagger.models.Swagger 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());
}
Also used : 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) Operation(io.swagger.models.Operation) NicknamedOperation(io.swagger.resources.NicknamedOperation) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) 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