Search in sources :

Example 51 with Swagger

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

the class SpecFilterTest method removeUnreferencedDefinitionsOfRecuriveModels.

@Test(description = "recursive models, e.g. A-> A or A-> B and B -> A should not result in stack overflow")
public void removeUnreferencedDefinitionsOfRecuriveModels() throws IOException {
    final Swagger swagger = getSwagger("specFiles/recursivemodels.json");
    final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
    final Swagger filtered = new SpecFilter().filter(swagger, remover, null, null, null);
    assertNotNull(filtered.getDefinitions().get("SelfReferencingModel"));
    assertNotNull(filtered.getDefinitions().get("IndirectRecursiveModelA"));
    assertNotNull(filtered.getDefinitions().get("IndirectRecursiveModelB"));
}
Also used : Swagger(io.swagger.models.Swagger) SpecFilter(io.swagger.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Example 52 with Swagger

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

the class SpecFilterTest method filterNoPropertiesModels.

@Test(description = "it should filter models where some fields have no properties")
public void filterNoPropertiesModels() throws IOException {
    final String modelName = "Array";
    final ModelImpl model = new ModelImpl().type(ModelImpl.OBJECT).name(modelName);
    final Swagger swagger = new Swagger();
    swagger.addDefinition(modelName, model);
    final Map<String, Model> filtered = new SpecFilter().filterDefinitions(new NoOpOperationsFilter(), swagger.getDefinitions(), null, null, null);
    if (filtered.size() != 1) {
        fail("ModelImpl with no properties failed to filter");
    }
}
Also used : Swagger(io.swagger.models.Swagger) Model(io.swagger.models.Model) ModelImpl(io.swagger.models.ModelImpl) SpecFilter(io.swagger.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Example 53 with Swagger

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

the class SpecFilterTest method retainNonBrokenReferenceModelProperties.

@Test(description = "it should retain non-broken reference model properties")
public void retainNonBrokenReferenceModelProperties() throws IOException {
    final Swagger swagger = getSwagger("specFiles/paramAndResponseRefArray.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);
    // ArrayProperty
    assertNotNull(filtered.getDefinitions().get("User"));
    // ArrayModel
    assertNotNull(filtered.getDefinitions().get("Pet"));
}
Also used : Swagger(io.swagger.models.Swagger) SpecFilter(io.swagger.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Example 54 with Swagger

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

the class SpecFilterTest method removeUnreferencedModelOverride.

@Test(description = "broken references should not result in NPE")
public void removeUnreferencedModelOverride() throws IOException {
    final Swagger swagger = getSwagger("specFiles/brokenrefmodel.json");
    final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
    final Swagger filtered = new SpecFilter().filter(swagger, remover, null, null, null);
    assertNotNull(filtered.getDefinitions().get("RootModel"));
}
Also used : Swagger(io.swagger.models.Swagger) SpecFilter(io.swagger.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Example 55 with Swagger

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

the class SpecFilterTest method cloneEverythingConcurrent.

@Test(description = "it should clone everything concurrently")
public void cloneEverythingConcurrent() throws IOException {
    final Swagger swagger = getSwagger("specFiles/petstore.json");
    ThreadGroup tg = new ThreadGroup("SpecFilterTest" + "|" + System.currentTimeMillis());
    final Map<String, Swagger> filteredMap = new ConcurrentHashMap<String, Swagger>();
    for (int i = 0; i < 10; i++) {
        final int id = i;
        new Thread(tg, "SpecFilterTest") {

            public void run() {
                try {
                    filteredMap.put("filtered " + id, new SpecFilter().filter(swagger, new NoOpOperationsFilter(), null, null, null));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }
    new Thread(new FailureHandler(tg, filteredMap, swagger)).start();
}
Also used : Swagger(io.swagger.models.Swagger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SpecFilter(io.swagger.core.filter.SpecFilter) IOException(java.io.IOException) 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