Search in sources :

Example 1 with JaxrsScanner

use of io.swagger.jaxrs.config.JaxrsScanner in project swagger-core by swagger-api.

the class BaseApiListingResource method scan.

private static synchronized Swagger scan(Application app, ServletContext context, ServletConfig sc, UriInfo uriInfo) {
    Swagger swagger = null;
    SwaggerContextService ctxService = new SwaggerContextService().withServletConfig(sc).withBasePath(getBasePath(uriInfo));
    Scanner scanner = ctxService.getScanner();
    if (scanner != null) {
        SwaggerSerializers.setPrettyPrint(scanner.getPrettyPrint());
        swagger = new SwaggerContextService().withServletConfig(sc).withBasePath(getBasePath(uriInfo)).getSwagger();
        Set<Class<?>> classes;
        if (scanner instanceof JaxrsScanner) {
            JaxrsScanner jaxrsScanner = (JaxrsScanner) scanner;
            classes = jaxrsScanner.classesFromContext(app, sc);
        } else {
            classes = scanner.classes();
        }
        if (classes != null) {
            Reader reader = new Reader(swagger, ReaderConfigUtils.getReaderConfig(context));
            swagger = reader.read(classes);
            if (scanner instanceof SwaggerConfig) {
                swagger = ((SwaggerConfig) scanner).configure(swagger);
            } else {
                SwaggerConfig swaggerConfig = ctxService.getConfig();
                if (swaggerConfig != null) {
                    LOGGER.debug("configuring swagger with " + swaggerConfig);
                    swaggerConfig.configure(swagger);
                } else {
                    LOGGER.debug("no configurator");
                }
            }
            new SwaggerContextService().withServletConfig(sc).withBasePath(getBasePath(uriInfo)).updateSwagger(swagger);
        }
    }
    if (SwaggerContextService.isScannerIdInitParamDefined(sc)) {
        initializedScanner.put(sc.getServletName() + "_" + SwaggerContextService.getScannerIdFromInitParam(sc), true);
    } else if (SwaggerContextService.isConfigIdInitParamDefined(sc)) {
        initializedConfig.put(sc.getServletName() + "_" + SwaggerContextService.getConfigIdFromInitParam(sc), true);
    } else if (SwaggerContextService.isUsePathBasedConfigInitParamDefined(sc)) {
        initializedConfig.put(sc.getServletName() + "_" + ctxService.getBasePath(), true);
    } else {
        initialized = true;
    }
    return swagger;
}
Also used : SwaggerContextService(io.swagger.jaxrs.config.SwaggerContextService) Scanner(io.swagger.config.Scanner) JaxrsScanner(io.swagger.jaxrs.config.JaxrsScanner) SwaggerConfig(io.swagger.config.SwaggerConfig) JaxrsScanner(io.swagger.jaxrs.config.JaxrsScanner) Swagger(io.swagger.models.Swagger) Reader(io.swagger.jaxrs.Reader)

Aggregations

Scanner (io.swagger.config.Scanner)1 SwaggerConfig (io.swagger.config.SwaggerConfig)1 Reader (io.swagger.jaxrs.Reader)1 JaxrsScanner (io.swagger.jaxrs.config.JaxrsScanner)1 SwaggerContextService (io.swagger.jaxrs.config.SwaggerContextService)1 Swagger (io.swagger.models.Swagger)1