io.swagger.jaxrs.listing.ApiListingResource Java Examples

The following examples show how to use io.swagger.jaxrs.listing.ApiListingResource. 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: WebServicesConfiguration.java    From microservices-transactions-tcc with Apache License 2.0 6 votes vote down vote up
private void configureSwagger() {
	// Available at localhost:port/swagger.json
	this.register(ApiListingResource.class);
	this.register(SwaggerSerializers.class);

	BeanConfig config = new BeanConfig();
	// config.setConfigId(title);
	config.setTitle(title);
	config.setDescription(description);
	config.setVersion(version);
	config.setContact(contact);
	config.setSchemes(schemes.split(","));
	config.setBasePath(basePath);
	config.setResourcePackage(resourcePackage);
	config.setPrettyPrint(prettyPrint);
	config.setScan(scan);	
}
 
Example #2
Source File: WebServicesConfiguration.java    From microservices-transactions-tcc with Apache License 2.0 6 votes vote down vote up
private void configureSwagger() {
	// Available at localhost:port/swagger.json
	this.register(ApiListingResource.class);
	this.register(SwaggerSerializers.class);

	BeanConfig config = new BeanConfig();
	// config.setConfigId(title);
	config.setTitle(title);
	config.setDescription(description);
	config.setVersion(version);
	config.setContact(contact);
	config.setSchemes(schemes.split(","));
	config.setBasePath(basePath);
	config.setResourcePackage(resourcePackage);
	config.setPrettyPrint(prettyPrint);
	config.setScan(scan);	
}
 
Example #3
Source File: InventoryItemApi.java    From cqrs-eventsourcing-kafka with Apache License 2.0 6 votes vote down vote up
@Override
public void run(InventoryItemApiConfiguration configuration, Environment environment) throws Exception {
    configureObjectMapper(environment);

    CommandDispatcher commandDispatcher = configuration.getCommandDispatcherFactory().build(environment);

    environment.jersey().register(new ApiListingResource());
    environment.jersey().register(SseFeature.class);

    InventoryItemResource resource = new InventoryItemResource(new InventoryItemsQuery(), commandDispatcher);
    environment.jersey().register(resource);
    environment.lifecycle().manage(new KafkaDenormalizer(configuration));
    environment.lifecycle().manage(new HazelcastManaged());

    StreamBroadcaster broadcaster = configuration.getStreamBroadcasterFactory().build(environment);
    broadcaster.addObserver(resource);

    configureSwagger(environment);
}
 
Example #4
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 #5
Source File: ManagementApplication.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
public ManagementApplication() {

        BeanConfig beanConfig = new BeanConfig();
        beanConfig.setVersion(Version.RUNTIME_VERSION.MAJOR_VERSION);
        beanConfig.setResourcePackage("io.gravitee.am.management.handlers.management.api.resources");
        beanConfig.setTitle("Gravitee.io - Access Management API");
        beanConfig.setBasePath("/management");
        beanConfig.setScan(true);

        register(OrganizationsResource.class);
        register(PlatformResource.class);
        register(CurrentUserResource.class);

        register(ObjectMapperResolver.class);
        register(ManagementExceptionMapper.class);
        register(UnrecognizedPropertyExceptionMapper.class);
        register(ThrowableMapper.class);
        register(ClientErrorExceptionMapper.class);
        register(Oauth2ExceptionMapper.class);
        register(ValidationExceptionMapper.class);
        register(JsonMappingExceptionMapper.class);
        register(WebApplicationExceptionMapper.class);

        register(UriBuilderRequestFilter.class);
        register(ByteArrayOutputStreamWriter.class);

        register(ApiListingResource.class);
        register(SwaggerSerializers.class);

        property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
    }
 
Example #6
Source File: SwaggerModule.java    From EDDI with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    registerConfigFiles(this.configFiles);


    Multibinder.newSetBinder(binder(), ServletContextListener.class)
            .addBinding().to(SwaggerServletContextListener.class);
    bind(ApiListingResource.class);
    bind(SwaggerSerializers.class);
}
 
Example #7
Source File: SwaggerRestApplicationInterceptor.java    From thorntail with Apache License 2.0 5 votes vote down vote up
/**
 * As per the JAX-RS specification, if a deployment sub-classes JAX-RS Application and returns a non-empty collection for
 * either {@link Application#getClasses()} or {@link Application#getSingletons()}, then, only the references mentioned in
 * those collections should be used as REST resources. This poses a slight problem when the developers <i>expect</i> to see
 * their Swagger resources, but don't see it (due to specification conformance). This method takes care of adding the
 * relevant resources (if required).
 */
@SuppressWarnings("unchecked")
@AroundInvoke
public Object aroundInvoke(InvocationContext context) throws Exception {
    Object response = context.proceed();

    // Verify if we need to do anything at all or not. This is to avoid the potential misconfiguration where this
    // interceptor gets added to beans that should not be included.
    Method method = context.getMethod();
    if (Application.class.isAssignableFrom(method.getDeclaringClass())) {
        if ("getClasses".equals(method.getName())) {
            Set<Class<?>> classes = new HashSet<>((Set<Class<?>>) response);

            // Check the response for singletons as well.
            Method getSingletons = Application.class.getDeclaredMethod("getSingletons");
            Set singletons = (Set) getSingletons.invoke(context.getTarget());
            if (!classes.isEmpty() || !singletons.isEmpty()) {
                classes.add(ApiListingResource.class);
                classes.add(SwaggerSerializers.class);
                response = classes;
                SwaggerMessages.MESSAGES.addingSwaggerResourcesToCustomApplicationSubClass();
            }
        }
    } else {
        SwaggerMessages.MESSAGES.warnInvalidBeanTarget(method.getDeclaringClass());
    }

    return response;
}
 
Example #8
Source File: JerseyConfig.java    From maintain with MIT License 5 votes vote down vote up
private void configureSwagger() {
		this.register(ApiListingResource.class);
		this.register(SwaggerSerializers.class);

		BeanConfig config = new BeanConfig();
		config.setTitle("基于Spring Boot,Jersey, Swagger的Restful API");
		config.setVersion("1.0.0");
		config.setContact("赵配");
//		config.setSchemes(new String[] { "http", "https" });
		config.setSchemes(new String[] { "http" });
		config.setBasePath(this.apiPath);
		config.setResourcePackage("online.zhaopei.myproject.jerseyservice");
		config.setPrettyPrint(true);
		config.setScan(true);
	}
 
Example #9
Source File: ServerApplication.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Override
public void run(ServerConfig configuration, Environment environment) throws Exception {
    environment.getApplicationContext().setContextPath(ServerConfig.getContextPath());
    environment.jersey().register(RESTExceptionMapper.class);
    environment.jersey().setUrlPattern(ServerConfig.getApiBasePath());
    environment.getObjectMapper().setFilters(TaggedLogAPIEntity.getFilterProvider());
    environment.getObjectMapper().registerModule(new EntityJsonModule());

    // Automatically scan all REST resources
    new PackagesResourceConfig(ServerConfig.getResourcePackage()).getClasses().forEach(environment.jersey()::register);

    // Swagger resources
    environment.jersey().register(ApiListingResource.class);

    BeanConfig swaggerConfig = new BeanConfig();
    swaggerConfig.setTitle(ServerConfig.getServerName());
    swaggerConfig.setVersion(ServerConfig.getServerVersion().version);
    swaggerConfig.setBasePath(ServerConfig.getApiBasePath());
    swaggerConfig.setResourcePackage(ServerConfig.getResourcePackage());
    swaggerConfig.setLicense(ServerConfig.getLicense());
    swaggerConfig.setLicenseUrl(ServerConfig.getLicenseUrl());
    swaggerConfig.setDescription(Version.str());
    swaggerConfig.setScan(true);

    // Simple CORS filter
    environment.servlets().addFilter(SimpleCORSFiler.class.getName(), new SimpleCORSFiler())
        .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");

    // Register authentication provider
    BasicAuthBuilder authBuilder = new BasicAuthBuilder(configuration.getAuthConfig(), environment);
    environment.jersey().register(authBuilder.getBasicAuthProvider());
    if (configuration.getAuthConfig().isEnabled()) {
        environment.jersey().getResourceConfig().getResourceFilterFactories()
            .add(new BasicAuthResourceFilterFactory(authBuilder.getBasicAuthenticator()));
    }
    registerAppServices(environment);
}
 
Example #10
Source File: ServiceApp.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Override
public void run(AlertDropWizardConfiguration configuration, Environment environment) throws Exception {
    if (StringUtils.isNotEmpty(configuration.getApplicationConfPath())) {
        // setup config if given
        System.setProperty("config.resource", configuration.getApplicationConfPath());
        ConfigFactory.invalidateCaches();
        ConfigFactory.load();
    }

    environment.getApplicationContext().setContextPath("/rest");
    environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);

    environment.jersey().register(MetadataResource.class);
    environment.jersey().register(CoordinatorResource.class);

    // swagger resources
    environment.jersey().register(new ApiListingResource());
    BeanConfig swaggerConfig = new BeanConfig();
    swaggerConfig.setTitle("Alert engine service: metadata and coordinator");
    swaggerConfig.setVersion("v1.2");
    swaggerConfig.setBasePath("/rest");
    swaggerConfig
        .setResourcePackage("org.apache.eagle.alert.coordinator.resource,org.apache.eagle.service.metadata.resource");
    swaggerConfig.setScan(true);

    // simple CORS filter
    environment.servlets().addFilter("corsFilter", new SimpleCORSFiler())
        .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");

    // context listener
    environment.servlets().addServletListeners(new CoordinatorListener());
}
 
Example #11
Source File: SwaggerJsonBareService.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/swagger")
@ApiOperation(value = "The swagger definition in JSON", hidden = true)
public Response getListingJsonBare(
        @Context Application app,
        @Context ServletConfig sc,
        @Context HttpHeaders headers,
        @Context UriInfo uriInfo,
        @Context ResourceContext rc) {
    ApiListingResource apiListingResource = rc.getResource(ApiListingResource.class);
    return apiListingResource.getListingJson(app, sc, headers, uriInfo);
}
 
Example #12
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 #13
Source File: RestAPIResourceConfig.java    From datacollector with Apache License 2.0 4 votes vote down vote up
public RestAPIResourceConfig() {
  register(new AbstractBinder() {
    @Override
    protected void configure() {
      bindFactory(PipelineStoreInjector.class).to(PipelineStoreTask.class);
      bindFactory(AclStoreInjector.class).to(AclStoreTask.class);
      bindFactory(StageLibraryInjector.class).to(StageLibraryTask.class);
      bindFactory(PrincipalInjector.class).to(Principal.class);
      bindFactory(URIInjector.class).to(URI.class);
      bindFactory(ConfigurationInjector.class).to(Configuration.class);
      bindFactory(RuntimeInfoInjector.class).to(RuntimeInfo.class);
      bindFactory(BuildInfoInjector.class).to(BuildInfo.class);
      bindFactory(StatsCollectorInjector.class).to(StatsCollector.class);
      bindFactory(StandAndClusterManagerInjector.class).to(Manager.class);
      bindFactory(SupportBundleInjector.class).to(SupportBundleManager.class);
      bindFactory(EventHandlerTaskInjector.class).to(EventHandlerTask.class);
      bindFactory(BlobStoreTaskInjector.class).to(BlobStoreTask.class);
      bindFactory(CredentialStoreTaskInjector.class).to(CredentialStoresTask.class);

      bindFactory(UserGroupManagerInjector.class).to(UserGroupManager.class);
      bindFactory(UsersManagerInjector.class).to(UsersManager.class);
      bindFactory(ActivationInjector.class).to(Activation.class);
    }
  });
  register(new PaginationInfoInjectorBinder());

  register(RolesAnnotationFilter.class);
  register(CsrfProtectionFilter.class);
  register(MultiPartFeature.class);

  //Hooking up Swagger-Core
  register(ApiListingResource.class);
  register(SwaggerSerializers.class);

  register(RestResponseFilter.class);

  //Configure and Initialize Swagger
  BeanConfig beanConfig = new BeanConfig();
  beanConfig.setVersion("1.0.0");
  beanConfig.setBasePath("/rest");
  beanConfig.setResourcePackage(RestAPI.class.getPackage().getName());
  beanConfig.setScan(true);
  beanConfig.setTitle("Data Collector RESTful API");

  Info info = new Info();
  info.setTitle("Data Collector RESTful API");
  info.setDescription("An Enterprise-Grade Approach to Managing Big Data in Motion");
  info.setVersion("1.0.0");
  beanConfig.setInfo(info);
}
 
Example #14
Source File: Swagger2Feature.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
protected void addSwaggerResource(Server server, Bus bus) {
    JAXRSServiceFactoryBean sfb =
            (JAXRSServiceFactoryBean) server.getEndpoint().get(JAXRSServiceFactoryBean.class.getName());

    ServerProviderFactory factory =
            (ServerProviderFactory)server.getEndpoint().get(ServerProviderFactory.class.getName());
    final ApplicationInfo appInfo = DefaultApplicationFactory.createApplicationInfoOrDefault(server,
            factory, sfb, bus, isScan());

    List<Object> swaggerResources = new LinkedList<>();

    if (customizer == null) {
        customizer = new Swagger2Customizer();
    }
    ApiListingResource apiListingResource = new Swagger2ApiListingResource(customizer);
    swaggerResources.add(apiListingResource);

    List<Object> providers = new ArrayList<>();
    providers.add(new SwaggerSerializers());

    if (isRunAsFilter()) {
        providers.add(new SwaggerContainerRequestFilter(appInfo == null ? null : appInfo.getProvider(),
                customizer));
    }

    final Properties swaggerProps = getSwaggerProperties(propertiesLocation, bus);
    final Registration swaggerUiRegistration = getSwaggerUi(bus, swaggerProps, isRunAsFilter());

    if (!isRunAsFilter()) {
        swaggerResources.addAll(swaggerUiRegistration.getResources());
    }

    providers.addAll(swaggerUiRegistration.getProviders());
    sfb.setResourceClassesFromBeans(swaggerResources);

    List<ClassResourceInfo> cris = sfb.getClassResourceInfo();
    if (!isRunAsFilter()) {
        for (ClassResourceInfo cri : cris) {
            if (ApiListingResource.class.isAssignableFrom(cri.getResourceClass())) {
                InjectionUtils.injectContextProxies(cri, apiListingResource);
            }
        }
    }
    customizer.setClassResourceInfos(cris);
    customizer.setDynamicBasePath(dynamicBasePath);

    BeanConfig beanConfig = appInfo == null
            ? new BeanConfig()
            : new ApplicationBeanConfig(appInfo.getProvider());
    initBeanConfig(beanConfig, swaggerProps);

    Swagger swagger = beanConfig.getSwagger();
    if (swagger != null && securityDefinitions != null) {
        swagger.setSecurityDefinitions(securityDefinitions);
    }
    customizer.setBeanConfig(beanConfig);

    providers.add(new ReaderConfigFilter());

    if (beanConfig.isUsePathBasedConfig()) {
        providers.add(new ServletConfigProvider());
    }

    factory.setUserProviders(providers);
}