Search in sources :

Example 16 with Swagger

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

the class ReaderTest method scanImplicitParamOverriddenMethodTest.

@Test(description = "scan indirect implicit params from overridden method")
public void scanImplicitParamOverriddenMethodTest() {
    final Swagger swagger = new Reader(new Swagger()).read(IndirectImplicitParamsImpl.class);
    assertNotNull(swagger);
    assertEquals(swagger.getPath("/v1/users").getPost().getParameters().size(), 2);
}
Also used : Swagger(io.swagger.models.Swagger) Reader(io.swagger.jaxrs.Reader) Test(org.testng.annotations.Test)

Example 17 with Swagger

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

the class ReaderTest method scanExternalDocsOnMethod.

@Test(description = "scan external docs on method")
public void scanExternalDocsOnMethod() {
    Swagger swagger = getSwagger(ResourceWithExternalDocs.class);
    ExternalDocs externalDocsForGet = swagger.getPath("/testString").getGet().getExternalDocs();
    assertNull(externalDocsForGet);
    ExternalDocs externalDocsForPost = swagger.getPath("/testString").getPost().getExternalDocs();
    assertNotNull(externalDocsForPost);
    assertEquals("Test Description", externalDocsForPost.getDescription());
    assertEquals("https://swagger.io/", externalDocsForPost.getUrl());
}
Also used : Swagger(io.swagger.models.Swagger) ResourceWithExternalDocs(io.swagger.resources.ResourceWithExternalDocs) ExternalDocs(io.swagger.models.ExternalDocs) Test(org.testng.annotations.Test)

Example 18 with Swagger

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

the class SimpleReaderTest method scanResourceWithCustomHttpMethodAnnotations.

@Test(description = "scan a resource with custom http method annotations")
public void scanResourceWithCustomHttpMethodAnnotations() {
    Swagger swagger = getSwagger(ResourceWithCustomHTTPMethodAnnotations.class);
    Operation get = getGet(swagger, "/");
    assertNotNull(get);
    Operation post = getPost(swagger, "/");
    assertNotNull(post);
    Operation patch = getPatch(swagger, "/");
    assertNotNull(patch);
    Operation put = getPut(swagger, "/");
    assertNotNull(put);
    Operation delete = getDelete(swagger, "/");
    assertNotNull(delete);
}
Also used : Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation) NicknamedOperation(io.swagger.resources.NicknamedOperation) Test(org.testng.annotations.Test)

Example 19 with Swagger

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

the class SimpleReaderTest method scanClassWithImplicitExamplePostClass.

@Test(description = "scan a resource with operation implicit post example (dataTypeClass)")
public void scanClassWithImplicitExamplePostClass() {
    Swagger swagger = getSwagger(ClassWithExamplePostClass.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 20 with Swagger

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

the class SimpleScannerWithDecoratorExtensionTest method scanSimpleResourceWithDecorator.

/**
     * Test for method annotated with vendor annotation which could be used for swagger documentation.
     */
@Test(description = "scan a simple resource with custom decorator")
public void scanSimpleResourceWithDecorator() {
    final Swagger swagger = getSwagger(SimpleResourceWithVendorAnnotation.class);
    assertEquals(swagger.getPaths().size(), 2);
    final Operation get = getGet(swagger, "/{id}");
    assertNotNull(get);
    assertEquals(get.getParameters().size(), 2);
    final Response response = get.getResponses().get(RESPONSE_STATUS_401);
    assertNotNull(response);
    assertEquals(response.getDescription(), RESPONSE_DESCRIPTION);
}
Also used : Response(io.swagger.models.Response) Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation) Test(org.testng.annotations.Test)

Aggregations

Swagger (io.swagger.models.Swagger)164 Test (org.testng.annotations.Test)114 Operation (io.swagger.models.Operation)39 Parameter (io.swagger.models.parameters.Parameter)30 QueryParameter (io.swagger.models.parameters.QueryParameter)30 BodyParameter (io.swagger.models.parameters.BodyParameter)26 Reader (io.swagger.jaxrs.Reader)23 PathParameter (io.swagger.models.parameters.PathParameter)22 SpecFilter (io.swagger.core.filter.SpecFilter)21 Test (org.junit.Test)19 Path (io.swagger.models.Path)18 Response (io.swagger.models.Response)14 SerializableParameter (io.swagger.models.parameters.SerializableParameter)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 Model (io.swagger.models.Model)10 NicknamedOperation (io.swagger.resources.NicknamedOperation)10 HeaderParameter (io.swagger.models.parameters.HeaderParameter)9 BeanConfig (io.swagger.jaxrs.config.BeanConfig)8 Map (java.util.Map)8 Info (io.swagger.models.Info)7