Search in sources :

Example 16 with SpecFilter

use of io.swagger.core.filter.SpecFilter in project swagger-core by swagger-api.

the class SpecFilterTest method shouldContainAllTopLevelTags.

@Test(description = "it should contain all tags in the top level Swagger object")
public void shouldContainAllTopLevelTags() throws IOException {
    final Swagger swagger = getSwagger("specFiles/petstore.json");
    final NoOpOperationsFilter filter = new NoOpOperationsFilter();
    final Swagger filtered = new SpecFilter().filter(swagger, filter, null, null, null);
    assertEquals(getTagNames(filtered), Sets.newHashSet("pet", "user", "store"));
}
Also used : Swagger(io.swagger.models.Swagger) SpecFilter(io.swagger.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Example 17 with SpecFilter

use of io.swagger.core.filter.SpecFilter in project swagger-core by swagger-api.

the class SpecFilterTest method retainNonBrokenReferenceModelComposedProperties.

@Test(description = "it should retain non-broken reference model composed properties")
public void retainNonBrokenReferenceModelComposedProperties() throws IOException {
    final Swagger swagger = getSwagger("specFiles/paramAndResponseRefComposed.json");
    assertNotNull(swagger.getDefinitions().get("User"));
    final NoOpOperationsFilter noOpfilter = new NoOpOperationsFilter();
    Swagger filtered = new SpecFilter().filter(swagger, noOpfilter, null, null, null);
    assertNotNull(filtered.getDefinitions().get("User"));
    final RemoveUnreferencedDefinitionsFilter refFilter = new RemoveUnreferencedDefinitionsFilter();
    filtered = new SpecFilter().filter(swagger, refFilter, null, null, null);
    assertNotNull(filtered.getDefinitions().get("User"));
    assertNotNull(filtered.getDefinitions().get("Pet"));
}
Also used : Swagger(io.swagger.models.Swagger) SpecFilter(io.swagger.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Example 18 with SpecFilter

use of io.swagger.core.filter.SpecFilter in project swagger-core by swagger-api.

the class SpecFilterTest method filterAwaySecretParameters.

@Test(description = "it should filter away secret parameters")
public void filterAwaySecretParameters() throws IOException {
    final Swagger swagger = getSwagger("specFiles/sampleSpec.json");
    final RemoveInternalParamsFilter filter = new RemoveInternalParamsFilter();
    final Swagger filtered = new SpecFilter().filter(swagger, filter, null, null, null);
    if (filtered.getPaths() != null) {
        for (Map.Entry<String, Path> entry : filtered.getPaths().entrySet()) {
            final Operation get = entry.getValue().getGet();
            for (Parameter param : get.getParameters()) {
                final String description = param.getDescription();
                assertNotNull(description);
                assertFalse(description.startsWith("secret"));
            }
        }
    } else {
        fail("paths should not be null");
    }
}
Also used : Path(io.swagger.models.Path) Swagger(io.swagger.models.Swagger) Parameter(io.swagger.models.parameters.Parameter) Operation(io.swagger.models.Operation) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) SpecFilter(io.swagger.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Example 19 with SpecFilter

use of io.swagger.core.filter.SpecFilter in project swagger-core by swagger-api.

the class SpecFilterTest method shouldNotContainTopLevelUserTags.

@Test(description = "it should not contain user tags in the top level Swagger object")
public void shouldNotContainTopLevelUserTags() throws IOException {
    final Swagger swagger = getSwagger("specFiles/petstore.json");
    final NoUserOperationsFilter filter = new NoUserOperationsFilter();
    final Swagger filtered = new SpecFilter().filter(swagger, filter, null, null, null);
    assertEquals(getTagNames(filtered), Sets.newHashSet("pet", "store"));
}
Also used : Swagger(io.swagger.models.Swagger) SpecFilter(io.swagger.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Example 20 with SpecFilter

use of io.swagger.core.filter.SpecFilter in project swagger-core by swagger-api.

the class SpecFilterTest method filterWithNullDefinitions.

@Test(description = "it should filter with null definitions")
public void filterWithNullDefinitions() throws IOException {
    final Swagger swagger = getSwagger("specFiles/petstore.json");
    swagger.setDefinitions(null);
    final InternalModelPropertiesRemoverFilter filter = new InternalModelPropertiesRemoverFilter();
    final Swagger filtered = new SpecFilter().filter(swagger, filter, null, null, null);
    assertNotNull(filtered);
}
Also used : Swagger(io.swagger.models.Swagger) SpecFilter(io.swagger.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Aggregations

SpecFilter (io.swagger.core.filter.SpecFilter)21 Swagger (io.swagger.models.Swagger)21 Test (org.testng.annotations.Test)18 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 Map (java.util.Map)4 SwaggerSpecFilter (io.swagger.core.filter.SwaggerSpecFilter)3 Path (io.swagger.models.Path)3 ApiOperation (io.swagger.annotations.ApiOperation)2 Model (io.swagger.models.Model)2 Operation (io.swagger.models.Operation)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 SwaggerContextService (io.swagger.jaxrs.config.SwaggerContextService)1 ModelImpl (io.swagger.models.ModelImpl)1 Parameter (io.swagger.models.parameters.Parameter)1 IOException (java.io.IOException)1