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"));
}
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");
}
}
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"));
}
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"));
}
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();
}
Aggregations