use of io.swagger.jaxrs.config.BeanConfig in project fru-paqx-parent by dellemc-symphony.
the class JerseyConfig method configureSwagger.
private void configureSwagger() {
// Springfox UI isn't compatible with Jersey.
// So we use swagger-jersey to generate JSON,
// springfox swagger-ui to display it,
// and application property springfox.documentation.swagger.v2.path to integrate them.
// See details in: http://stackoverflow.com/a/42228055
register(ApiListingResource.class);
register(SwaggerSerializers.class);
BeanConfig config = new BeanConfig();
config.setConfigId("fru-paqx");
config.setTitle("FRU PAQX");
config.setVersion("v1");
config.setSchemes(new String[] { "http", "https" });
config.setBasePath("/fru/api");
config.setResourcePackage("com.dell.cpsd.paqx.fru.rest");
config.setPrettyPrint(true);
config.setScan(true);
}
use of io.swagger.jaxrs.config.BeanConfig in project cxf by apache.
the class Swagger2Feature method addSwaggerResource.
@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());
ApplicationInfo appInfo = null;
if (!isScan()) {
appInfo = factory.getApplicationProvider();
if (appInfo == null) {
Set<Class<?>> serviceClasses = new HashSet<>();
for (ClassResourceInfo cri : sfb.getClassResourceInfo()) {
serviceClasses.add(cri.getServiceClass());
}
appInfo = new ApplicationInfo(new DefaultApplication(serviceClasses), bus);
server.getEndpoint().put(Application.class.getName(), appInfo);
}
}
List<Object> swaggerResources = new LinkedList<>();
if (customizer == null) {
customizer = new Swagger2Customizer();
}
ApiListingResource apiListingResource = new Swagger2ApiListingResource(customizer);
swaggerResources.add(apiListingResource);
List<Object> providers = new ArrayList<>();
if (isRunAsFilter()) {
providers.add(new SwaggerContainerRequestFilter(appInfo == null ? null : appInfo.getProvider(), customizer));
}
final Properties swaggerProps = getSwaggerProperties(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);
}
use of io.swagger.jaxrs.config.BeanConfig in project metacat by Netflix.
the class ApiConfig method swaggerBeanConfig.
/**
* Swagger configuration.
*
* @param config The application configuration abstraction
* @return Swagger bean configuration
*/
@Bean
public BeanConfig swaggerBeanConfig(final Config config) {
final BeanConfig beanConfig = new BeanConfig();
// TODO: put this back and remove hard coding
// beanConfig.setVersion(config.getMetacatVersion());
beanConfig.setVersion("1.1.0");
beanConfig.setBasePath("/mds");
beanConfig.setResourcePackage("com.netflix.metacat");
beanConfig.setScan(true);
return beanConfig;
}
use of io.swagger.jaxrs.config.BeanConfig in project camel by apache.
the class RestSwaggerReaderApiDocsTest method testReaderRead.
@Test
public void testReaderRead() throws Exception {
BeanConfig config = new BeanConfig();
config.setHost("localhost:8080");
config.setSchemes(new String[] { "http" });
config.setBasePath("/api");
RestSwaggerReader reader = new RestSwaggerReader();
Swagger swagger = reader.read(context.getRestDefinitions(), null, config, context.getName(), new DefaultClassResolver());
assertNotNull(swagger);
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
String json = mapper.writeValueAsString(swagger);
log.info(json);
assertTrue(json.contains("\"host\" : \"localhost:8080\""));
assertTrue(json.contains("\"basePath\" : \"/api\""));
assertFalse(json.contains("\"/hello/bye\""));
assertFalse(json.contains("\"summary\" : \"To update the greeting message\""));
assertFalse(json.contains("\"/hello/bye/{name}\""));
assertTrue(json.contains("\"/hello/hi/{name}\""));
context.stop();
}
use of io.swagger.jaxrs.config.BeanConfig in project camel by apache.
the class RestSwaggerReaderDayOfWeekTest method testReaderRead.
@Test
public void testReaderRead() throws Exception {
BeanConfig config = new BeanConfig();
config.setHost("localhost:8080");
config.setSchemes(new String[] { "http" });
config.setBasePath("/api");
config.setTitle("Day");
config.setLicense("Apache 2.0");
config.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html");
RestSwaggerReader reader = new RestSwaggerReader();
Swagger swagger = reader.read(context.getRestDefinitions(), null, config, context.getName(), new DefaultClassResolver());
assertNotNull(swagger);
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
String json = mapper.writeValueAsString(swagger);
log.info(json);
assertTrue(json.contains("\"host\" : \"localhost:8080\""));
assertTrue(json.contains("\"default\" : \"friday\""));
assertTrue(json.contains("\"enum\" : [ \"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\" ]"));
assertTrue(json.contains("\"$ref\" : \"#/definitions/DayResponse\""));
assertTrue(json.contains("\"format\" : \"org.apache.camel.swagger.DayResponse\""));
assertTrue(json.contains("\"X-Rate-Limit-Limit\" : {"));
assertTrue(json.contains("\"description\" : \"The number of allowed requests in the current period\""));
context.stop();
}
Aggregations