Search in sources :

Example 6 with SwaggerConfig

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

the class ApiDeclarationServlet method init.

@Override
public void init(ServletConfig servletConfig) throws javax.servlet.ServletException {
    super.init(servletConfig);
    final ServletContext servletContext = servletConfig.getServletContext();
    final Scanner scanner = (Scanner) servletContext.getAttribute("scanner");
    if (scanner != null) {
        Swagger swagger = (Swagger) servletContext.getAttribute("swagger");
        if (swagger == null) {
            swagger = new Swagger();
        }
        final SwaggerConfig configurator = (SwaggerConfig) servletContext.getAttribute("reader");
        if (configurator != null) {
            configurator.configure(swagger);
        }
        final Set<Class<?>> classes = scanner.classes();
        if (classes != null) {
            Reader.read(swagger, classes);
        }
        servletContext.setAttribute("swagger", swagger);
    }
}
Also used : Scanner(io.swagger.config.Scanner) SwaggerConfig(io.swagger.config.SwaggerConfig) Swagger(io.swagger.models.Swagger) ServletContext(javax.servlet.ServletContext)

Example 7 with SwaggerConfig

use of io.swagger.config.SwaggerConfig in project ORCID-Source by ORCID.

the class SwaggerJSONResource method scan.

protected synchronized Swagger scan(Application app) {
    Swagger swagger = null;
    Scanner scanner = ScannerFactory.getScanner();
    ModelConverters.getInstance().addConverter(new SwaggerModelConverter());
    LOGGER.debug("[SWAGGER] using scanner " + scanner);
    if (scanner != null) {
        SwaggerSerializers.setPrettyPrint(scanner.getPrettyPrint());
        swagger = (Swagger) context.getAttribute("swagger");
        Set<Class<?>> 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 configurator = (SwaggerConfig) context.getAttribute("reader");
                if (configurator != null) {
                    LOGGER.debug("configuring swagger with " + configurator);
                    configurator.configure(swagger);
                } else {
                    LOGGER.debug("no configurator");
                }
            }
            context.setAttribute("swagger", swagger);
        }
    }
    initialized = true;
    return swagger;
}
Also used : Scanner(io.swagger.config.Scanner) SwaggerConfig(io.swagger.config.SwaggerConfig) Swagger(io.swagger.models.Swagger) Reader(io.swagger.jaxrs.Reader)

Aggregations

SwaggerConfig (io.swagger.config.SwaggerConfig)7 Swagger (io.swagger.models.Swagger)5 Scanner (io.swagger.config.Scanner)4 Reader (io.swagger.jaxrs.Reader)3 Test (org.testng.annotations.Test)2 JaxrsScanner (io.swagger.jaxrs.config.JaxrsScanner)1 SwaggerContextService (io.swagger.jaxrs.config.SwaggerContextService)1 ServletContext (javax.servlet.ServletContext)1