Java Code Examples for io.swagger.jaxrs.config.BeanConfig#setHost()

The following examples show how to use io.swagger.jaxrs.config.BeanConfig#setHost() . 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: EmoService.java    From emodb with Apache License 2.0 6 votes vote down vote up
private void evaluateSwagger()
        throws Exception {
    if (!runPerServiceMode(swagger)) {
        return;
    }

    // Add swagger providers
    _environment.jersey().register(io.swagger.jaxrs.listing.ApiListingResource.class);
    _environment.jersey().register(io.swagger.jaxrs.listing.SwaggerSerializers.class);

    // Configure and initialize swagger
    BeanConfig beanConfig = new BeanConfig();
    beanConfig.setVersion("1.0");
    beanConfig.setTitle("EMO REST Resources");
    beanConfig.setSchemes(new String[] {"http"});
    beanConfig.setHost("localhost:8080");
    beanConfig.setBasePath("/");
    // add the packages that swagger should scan to pick up the resources
    beanConfig.setResourcePackage("com.bazaarvoice.emodb.web.resources");
    // this is a MUST and should be the last property - this creates a new SwaggerContextService and initialize the scanner.
    beanConfig.setScan(true);
}
 
Example 2
Source File: MaprMusicApp.java    From mapr-music with Apache License 2.0 5 votes vote down vote up
public MaprMusicApp() {
    // Configure and Initialize Swagger
    BeanConfig beanConfig = new BeanConfig();
    beanConfig.setVersion("1.0.0");
    beanConfig.setSchemes(new String[]{"http"});
    beanConfig.setHost("localhost:8080");
    beanConfig.setBasePath("/mapr-music-rest/api/1.0/");
    beanConfig.setResourcePackage("com.mapr.music.api");
    beanConfig.setScan(true);
}
 
Example 3
Source File: Application.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Application() {
	super(Settings.WEB_ROOT_PACKAGE_NAME + ".jersey");
	BeanConfig beanConfig = new BeanConfig();
	beanConfig.setSchemes(new String[] { WebUtil.getHttpScheme() });
	beanConfig.setHost(WebUtil.getHttpHost());
	beanConfig.setBasePath("/" + WebUtil.REST_API_PATH);
	beanConfig.setTitle(Settings.getString(SettingCodes.API_TITLE, Bundle.SETTINGS, DefaultSettings.API_TITLE));
	beanConfig.setVersion(Settings.getString(SettingCodes.API_VERSION, Bundle.SETTINGS, DefaultSettings.API_VERSION));
	beanConfig.setContact(Settings.getContactEmail());
	beanConfig.setResourcePackage(Settings.WEB_ROOT_PACKAGE_NAME + ".jersey.resource");
	beanConfig.setScan(true);
}
 
Example 4
Source File: RestApplication.java    From microprofile-samples with Apache License 2.0 5 votes vote down vote up
public RestApplication() {
    final BeanConfig beanConfig = new BeanConfig();
    beanConfig.setTitle("TOP CDs");
    beanConfig.setDescription("Gives the TOP selling CDs");
    beanConfig.setVersion("1.0.0");
    beanConfig.setSchemes(new String[] { "http" });
    beanConfig.setHost("localhost:8080/msTopCDs");
    beanConfig.setBasePath("/");
    beanConfig.setResourcePackage("org.eclipse.microprofile.sample.swagger.rest");
    beanConfig.setPrettyPrint(true);
    beanConfig.setScan(true);
}
 
Example 5
Source File: SwaggerServletContextListener.java    From EDDI with Apache License 2.0 5 votes vote down vote up
private BeanConfig getBeanConfig() {
    BeanConfig beanConfig = new BeanConfig();
    beanConfig.setHost(getConfig("swagger.host"));
    beanConfig.setSchemes(getConfig("swagger.schemes").split(","));
    beanConfig.setTitle(getConfig("swagger.title"));
    beanConfig.setVersion(getConfig("swagger.version"));
    beanConfig.setContact(getConfig("swagger.contact"));
    beanConfig.setLicense(getConfig("swagger.license"));
    beanConfig.setBasePath(getConfig("swagger.base_path"));
    beanConfig.setLicenseUrl(getConfig("swagger.licenseUrl"));
    beanConfig.setDescription(getConfig("swagger.description"));
    beanConfig.setPrettyPrint(getConfig("swagger.pretty_print"));
    beanConfig.setTermsOfServiceUrl(getConfig("swagger.terms_of_service_url"));

    // Must be called last
    beanConfig.setResourcePackage(resourcePackages());
    beanConfig.setScan(true);

    Swagger swagger = beanConfig.getSwagger();

    if ("basic".equals(getConfig("webServer.securityHandlerType"))) {
        swagger.securityDefinition("eddi_auth", new BasicAuthDefinition());
    } else if ("keycloak".equals(getConfig("webServer.securityHandlerType"))) {
        OAuth2Definition oAuth2Definition = new OAuth2Definition()
                .implicit(getConfig("swagger.oauth2.implicitAuthorizationUrl"));
        oAuth2Definition.setDescription("client_id is 'eddi-engine'");
        swagger.securityDefinition("eddi_auth", oAuth2Definition);
    }

    return beanConfig;
}
 
Example 6
Source File: SwaggerActivator.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void activate(ServiceActivatorContext serviceActivatorContext) throws ServiceRegistryException {

    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(SwaggerArchive.SWAGGER_CONFIGURATION_PATH);

    if (in == null) {
        // No config available. Print a warning and return
        System.err.println("WARN: No swagger configuration found. Swagger not activated.");
        return;
    }
    SwaggerConfig config = new SwaggerConfig(in);

    BeanConfig beanConfig = new BeanConfig();
    beanConfig.setHost((String) config.get(SwaggerConfig.Key.HOST));
    beanConfig.setLicense((String) config.get(SwaggerConfig.Key.LICENSE));
    beanConfig.setLicenseUrl((String) config.get(SwaggerConfig.Key.LICENSE_URL));
    beanConfig.setTermsOfServiceUrl((String) config.get(SwaggerConfig.Key.TERMS_OF_SERVICE_URL));
    beanConfig.setResourcePackage((String) config.get(SwaggerConfig.Key.PACKAGES));
    beanConfig.setVersion((String) config.get(SwaggerConfig.Key.VERSION));
    beanConfig.setBasePath((String) config.get(SwaggerConfig.Key.ROOT));
    beanConfig.setContact((String) config.get(SwaggerConfig.Key.CONTACT));
    beanConfig.setDescription((String) config.get(SwaggerConfig.Key.DESCRIPTION));
    beanConfig.setTitle((String) config.get(SwaggerConfig.Key.TITLE));
    beanConfig.setPrettyPrint((String) config.get(SwaggerConfig.Key.PRETTY_PRINT));
    beanConfig.setSchemes((String[]) config.get(SwaggerConfig.Key.SCHEMES));

    beanConfig.setScan(true);

}
 
Example 7
Source File: SwaggerParser.java    From james-project with Apache License 2.0 5 votes vote down vote up
private static BeanConfig getBeanConfig(String packageName, WebAdminConfiguration configuration) {
    BeanConfig beanConfig = new BeanConfig();
    beanConfig.setResourcePackage(packageName);
    beanConfig.setVersion(API_DOC_VERSION);
    beanConfig.setTitle(API_DOC_TITLE);
    beanConfig.setDescription(API_DOC_DESCRIPTION);
    beanConfig.setHost(configuration.getHost() + HOST_PORT_SEPARATOR + configuration.getPort().get().getValue());
    beanConfig.setSchemes(SCHEMES);
    beanConfig.setScan(true);
    beanConfig.scanAndRead();
    return beanConfig;
}
 
Example 8
Source File: SwaggerBootstrapServlet.java    From render with GNU General Public License v2.0 5 votes vote down vote up
public static BeanConfig loadConfig(final File file)
        throws IllegalArgumentException {

    final BeanConfig beanConfig = new BeanConfig();
    final Properties properties = new Properties();

    final String path = file.getAbsolutePath();
    if (file.exists()) {

        try (final FileInputStream in = new FileInputStream(file)) {
            properties.load(in);
        } catch (final Exception e) {
            throw new IllegalArgumentException("failed to load properties from " + path, e);
        }

        LOG.info("loaded swagger properties from {}", path);

    } else {
        LOG.warn("{} not found, using default configuration for swagger", path);
    }

    beanConfig.setTitle(properties.getProperty("title", "Render Web Service APIs"));

    // default to empty contact so that swagger-ui will hide created by line
    beanConfig.setContact(properties.getProperty("contact", ""));

    // default to empty host so that swagger-ui will use same host for try-it-out requests
    beanConfig.setHost(properties.getProperty("host", ""));

    beanConfig.setBasePath(properties.getProperty("basePath", "/render-ws"));

    return beanConfig;
}
 
Example 9
Source File: Server.java    From redpipe with Apache License 2.0 4 votes vote down vote up
protected void setupSwagger(VertxResteasyDeployment deployment) {
	ModelConverters.getInstance().addConverter(new RxModelConverter());
	
	// Swagger
	ServletContext servletContext = new RedpipeServletContext();
	AppGlobals.get().setGlobal(ServletContext.class, servletContext);

	ServletConfig servletConfig = new ServletConfig(){

		@Override
		public String getServletName() {
			return "pretend-servlet";
		}

		@Override
		public ServletContext getServletContext() {
			return servletContext;
		}

		@Override
		public String getInitParameter(String name) {
			return getServletContext().getInitParameter(name);
		}

		@Override
		public Enumeration<String> getInitParameterNames() {
			return getServletContext().getInitParameterNames();
		}
	};
	AppGlobals.get().setGlobal(ServletConfig.class, servletConfig);

	ReaderConfigUtils.initReaderConfig(servletConfig);

	BeanConfig swaggerConfig = new MyBeanConfig();
	swaggerConfig.setVersion("1.0");
	swaggerConfig.setSchemes(new String[]{"http"});
	swaggerConfig.setHost("localhost:"+AppGlobals.get().getConfig().getInteger("http_port", 9000));
	swaggerConfig.setBasePath("/");
	Set<String> resourcePackages = new HashSet<>();
	for (Class<?> klass : deployment.getActualResourceClasses()) {
		resourcePackages.add(klass.getPackage().getName());
	}
	swaggerConfig.setResourcePackage(String.join(",", resourcePackages));
	swaggerConfig.setServletConfig(servletConfig);
	swaggerConfig.setPrettyPrint(true);
	swaggerConfig.setScan(true);
	
	deployment.getRegistry().addPerInstanceResource(ApiListingResource.class);
	deployment.getProviderFactory().register(SwaggerSerializers.class);
}
 
Example 10
Source File: SwaggerServiceActivator.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@Override
public void activate(ServiceActivatorContext serviceActivatorContext) throws ServiceRegistryException {

    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(SwaggerArchive.SWAGGER_CONFIGURATION_PATH);

    if (in == null) {
        // try again, we must go deeper.
        in = Thread.currentThread().getContextClassLoader().getResourceAsStream("WEB-INF/classes/" + SwaggerArchive.SWAGGER_CONFIGURATION_PATH);
    }

    if (in == null) {
        // No config available. Print a warning and return
        SwaggerMessages.MESSAGES.noConfigurationFound();
        return;
    }

    try {
        SwaggerConfig config = new SwaggerConfig(in);

        BeanConfig beanConfig = new BeanConfig();
        beanConfig.setHost((String) config.get(SwaggerConfig.Key.HOST));
        beanConfig.setLicense((String) config.get(SwaggerConfig.Key.LICENSE));
        beanConfig.setLicenseUrl((String) config.get(SwaggerConfig.Key.LICENSE_URL));
        beanConfig.setTermsOfServiceUrl((String) config.get(SwaggerConfig.Key.TERMS_OF_SERVICE_URL));

        // some type inconsistencies in the API (String vs String[])
        String[] packages = (String[]) config.get(SwaggerConfig.Key.PACKAGES);

        if (packages != null) {
            StringBuffer sb = new StringBuffer();
            for (String s : packages) {
                sb.append(s).append(',');
            }

            beanConfig.setResourcePackage(sb.toString());
        }

        beanConfig.setVersion((String) config.get(SwaggerConfig.Key.VERSION));
        beanConfig.setBasePath((String) config.get(SwaggerConfig.Key.ROOT));
        beanConfig.setContact((String) config.get(SwaggerConfig.Key.CONTACT));
        beanConfig.setDescription((String) config.get(SwaggerConfig.Key.DESCRIPTION));
        beanConfig.setTitle((String) config.get(SwaggerConfig.Key.TITLE));
        beanConfig.setPrettyPrint((String) config.get(SwaggerConfig.Key.PRETTY_PRINT));
        beanConfig.setSchemes((String[]) config.get(SwaggerConfig.Key.SCHEMES));

        beanConfig.setScan(true);
    } catch (IOException e) {
        throw new ServiceRegistryException(e);
    }

}