Search in sources :

Example 6 with SpecFilter

use of io.swagger.core.filter.SpecFilter 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 7 with SpecFilter

use of io.swagger.core.filter.SpecFilter 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)

Example 8 with SpecFilter

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

the class SpecFilterTest method filterAwayInternalModelProperties.

@Test(description = "it should filter away internal model properties")
public void filterAwayInternalModelProperties() throws IOException {
    final Swagger swagger = getSwagger("specFiles/sampleSpec.json");
    final InternalModelPropertiesRemoverFilter filter = new InternalModelPropertiesRemoverFilter();
    final Swagger filtered = new SpecFilter().filter(swagger, filter, null, null, null);
    for (Map.Entry<String, Model> entry : filtered.getDefinitions().entrySet()) {
        for (String propName : entry.getValue().getProperties().keySet()) {
            assertFalse(propName.startsWith("_"));
        }
    }
}
Also used : Swagger(io.swagger.models.Swagger) Model(io.swagger.models.Model) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) SpecFilter(io.swagger.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Example 9 with SpecFilter

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

the class SpecFilterTest method filterAwayStoreResource.

@Test(description = "it should filter away the store resource")
public void filterAwayStoreResource() 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);
    if (filtered.getPaths() != null) {
        for (Map.Entry<String, Path> entry : filtered.getPaths().entrySet()) {
            assertNotEquals(entry.getKey(), "/user");
        }
    } else {
        fail("paths should not be null");
    }
}
Also used : Path(io.swagger.models.Path) Swagger(io.swagger.models.Swagger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) SpecFilter(io.swagger.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Example 10 with SpecFilter

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

the class BaseApiListingResource method process.

protected Swagger process(Application app, ServletContext servletContext, ServletConfig sc, HttpHeaders headers, UriInfo uriInfo) {
    SwaggerContextService ctxService = new SwaggerContextService().withServletConfig(sc).withBasePath(getBasePath(uriInfo));
    Swagger swagger = ctxService.getSwagger();
    synchronized (ApiListingResource.class) {
        if (SwaggerContextService.isScannerIdInitParamDefined(sc)) {
            if (!initializedScanner.containsKey(sc.getServletName() + "_" + SwaggerContextService.getScannerIdFromInitParam(sc))) {
                swagger = scan(app, servletContext, sc, uriInfo);
            }
        } else {
            if (SwaggerContextService.isConfigIdInitParamDefined(sc)) {
                if (!initializedConfig.containsKey(sc.getServletName() + "_" + SwaggerContextService.getConfigIdFromInitParam(sc))) {
                    swagger = scan(app, servletContext, sc, uriInfo);
                }
            } else if (SwaggerContextService.isUsePathBasedConfigInitParamDefined(sc)) {
                if (!initializedConfig.containsKey(sc.getServletName() + "_" + ctxService.getBasePath())) {
                    swagger = scan(app, servletContext, sc, uriInfo);
                }
            } else if (!initialized) {
                swagger = scan(app, servletContext, sc, uriInfo);
            }
        }
    }
    if (swagger != null) {
        SwaggerSpecFilter filterImpl = FilterFactory.getFilter();
        if (filterImpl != null) {
            SpecFilter f = new SpecFilter();
            swagger = f.filter(swagger, filterImpl, getQueryParams(uriInfo.getQueryParameters()), getCookies(headers), getHeaders(headers));
        }
    }
    return swagger;
}
Also used : SwaggerContextService(io.swagger.jaxrs.config.SwaggerContextService) Swagger(io.swagger.models.Swagger) SwaggerSpecFilter(io.swagger.core.filter.SwaggerSpecFilter) SwaggerSpecFilter(io.swagger.core.filter.SwaggerSpecFilter) SpecFilter(io.swagger.core.filter.SpecFilter)

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