Search in sources :

Example 41 with Swagger

use of io.swagger.models.Swagger 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);
}
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 42 with Swagger

use of io.swagger.models.Swagger 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);
}
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 43 with Swagger

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

the class SimpleReaderTest method scanResourceWithResponseStatusReturnType.

@Test(description = "scan a resource with Response.Status return type per 877")
public void scanResourceWithResponseStatusReturnType() {
    Swagger swagger = getSwagger(Resource877.class);
    assertNotNull(swagger.getTags());
    assertEquals(swagger.getTags().size(), 1);
    Tag tag = swagger.getTags().get(0);
    assertEquals(tag.getName(), "externalinfo");
    assertNull(tag.getDescription());
    assertNull(tag.getExternalDocs());
}
Also used : Swagger(io.swagger.models.Swagger) Tag(io.swagger.models.Tag) Test(org.testng.annotations.Test)

Example 44 with Swagger

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

the class SwaggerJersey2JaxrsTest method scanClassAnfFieldLevelAnnotations.

@Test(description = "scan class level and field level annotations")
public void scanClassAnfFieldLevelAnnotations() {
    final Swagger swagger = new Reader(new Swagger()).read(ResourceWithKnownInjections.class);
    final List<Parameter> resourceParameters = swagger.getPaths().get("/resource/{id}").getGet().getParameters();
    assertNotNull(resourceParameters);
    assertEquals(resourceParameters.size(), 4);
    assertEquals(getName(resourceParameters, 0), "fieldParam");
    assertEquals(getName(resourceParameters, 1), "skip");
    assertEquals(getName(resourceParameters, 2), "limit");
    assertEquals(getName(resourceParameters, 3), "methodParam");
}
Also used : Swagger(io.swagger.models.Swagger) Reader(io.swagger.jaxrs.Reader) HeaderParameter(io.swagger.models.parameters.HeaderParameter) FormParameter(io.swagger.models.parameters.FormParameter) Parameter(io.swagger.models.parameters.Parameter) Test(org.testng.annotations.Test)

Example 45 with Swagger

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

the class SwaggerSerializerTest method prettyPrintTest.

@Test
public void prettyPrintTest() throws IOException {
    final String json = ResourceUtils.loadClassResource(getClass(), "uber.json");
    final Swagger swagger = Json.mapper().readValue(json, Swagger.class);
    final String outputStream = OutputReplacer.OUT.run(new OutputReplacer.Function() {

        @Override
        public void run() {
            Json.prettyPrint(swagger);
        }
    });
    SerializationMatchers.assertEqualsToJson(swagger, outputStream);
}
Also used : Swagger(io.swagger.models.Swagger) OutputReplacer(io.swagger.util.OutputReplacer) 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