Search in sources :

Example 96 with Swagger

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

the class SpecFilterTest method cloneWithoutModels.

@Test(description = "it should clone everything from JSON without models")
public void cloneWithoutModels() throws IOException {
    final String json = ResourceUtils.loadClassResource(getClass(), "specFiles/noModels.json");
    final Swagger swagger = Json.mapper().readValue(json, Swagger.class);
    final Swagger filtered = new SpecFilter().filter(swagger, new NoOpOperationsFilter(), null, null, null);
    SerializationMatchers.assertEqualsToJson(filtered, json);
}
Also used : Swagger(io.swagger.models.Swagger) SpecFilter(io.swagger.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Example 97 with Swagger

use of io.swagger.models.Swagger 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 98 with Swagger

use of io.swagger.models.Swagger 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 99 with Swagger

use of io.swagger.models.Swagger 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 100 with Swagger

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

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