io.swagger.config.ScannerFactory Java Examples

The following examples show how to use io.swagger.config.ScannerFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainApplication.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
/***
 * The context path must be set before configuring swagger
 * @param environment
 */
void configureSwagger(Environment environment, String basePath) {
  environment.jersey().register(new ApiListingResource());
  environment.jersey().register(new SwaggerJsonBareService());
  environment.jersey().register(new SwaggerSerializers());
  ScannerFactory.setScanner(new DefaultJaxrsScanner());
  environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
  BeanConfig config = new BeanConfig();

  // api specific configuration
  config.setTitle("SciGraph");
  config.setVersion("1.0.1");
  config.setResourcePackage("io.scigraph.services.resources");
  config.setScan(true);
  // TODO: Fix this so the swagger client generator can work correctly
  config.setBasePath("/" + basePath);
}
 
Example #2
Source File: SwaggerServletContextListener.java    From EDDI with Apache License 2.0 5 votes vote down vote up
@Override
public void contextInitialized(ServletContextEvent event) {
    BeanConfig beanConfig = getBeanConfig();
    ServletContext servletContext = event.getServletContext();
    servletContext.setAttribute("scanner", ScannerFactory.getScanner());
    servletContext.setAttribute("swagger", beanConfig.getSwagger());
    servletContext.setAttribute("reader", beanConfig);
}
 
Example #3
Source File: ApidocResourceTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
protected void addBrooklynResources() {
    ScannerFactory.setScanner(new RestApiResourceScanner());

    for (Object o : BrooklynRestApi.getApidocResources()) {
        addResource(o);
    }
    super.addBrooklynResources();
}
 
Example #4
Source File: SwaggerSpecResource.java    From Cheddar with Apache License 2.0 5 votes vote down vote up
protected synchronized Swagger scanResourcesForJaxrsAnnotations(final Application app, final ServletConfig sc) {
    Swagger swagger = null;
    final Scanner scanner = ScannerFactory.getScanner();
    LOGGER.debug("using scanner " + scanner);

    if (scanner != null) {
        SwaggerSerializers.setPrettyPrint(scanner.getPrettyPrint());

        swagger = getSwagger();

        Set<Class<?>> classes = null;
        if (scanner instanceof JaxrsScanner) {
            final JaxrsScanner jaxrsScanner = (JaxrsScanner) scanner;
            classes = jaxrsScanner.classesFromContext(app, sc);
        } else {
            classes = scanner.classes();
        }
        if (classes != null) {
            final Reader reader = new Reader(swagger);
            swagger = reader.read(classes);
            if (scanner instanceof SwaggerConfig) {
                swagger = ((SwaggerConfig) scanner).configure(swagger);
            } else {
                LOGGER.debug("no configurator");
            }
        }
    }
    initialized = true;
    return swagger;
}
 
Example #5
Source File: SwaggerSpecResource.java    From Cheddar with Apache License 2.0 5 votes vote down vote up
/**
 * Will get the swagger configuration from the scanner, if it is of type BeanConfig and return the object. This will
 * be used in the parsing and formating of the resulting swagger specification.
 *
 * @return swagger configuration. If the scanner is not of type io.swagger.jaxrs.config.BeanConfig then null will be
 *         returned.
 */

private Swagger getSwagger() {
    final Scanner scanner = ScannerFactory.getScanner();
    if (scanner instanceof BeanConfig) {
        return ((BeanConfig) scanner).getSwagger();
    }
    return null;
}
 
Example #6
Source File: ScannerInjectHelper.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public void setServer(JAXRSServerFactoryBean server) {
    ScannerFactory.setScanner(new RestApiResourceScanner(server.getResourceClasses()));
}
 
Example #7
Source File: RestApiSetup.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public static void initSwagger() {
    ScannerFactory.setScanner(new RestApiResourceScanner());
}
 
Example #8
Source File: RestApiSetup.java    From brooklyn-server with Apache License 2.0 3 votes vote down vote up
public static void install(ServletContextHandler context) {
    ScannerFactory.setScanner(new RestApiResourceScanner());

    CampRestApp app = new CampRestApp();

    CXFNonSpringJaxrsServlet servlet = new CXFNonSpringJaxrsServlet(app);
    final ServletHolder servletHolder = new ServletHolder(servlet);

    context.addServlet(servletHolder, "/*");
}