Search in sources :

Example 11 with BeanConfig

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);
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig)

Example 12 with BeanConfig

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);
}
Also used : ServerProviderFactory(org.apache.cxf.jaxrs.provider.ServerProviderFactory) ApplicationInfo(org.apache.cxf.jaxrs.model.ApplicationInfo) ApiListingResource(io.swagger.jaxrs.listing.ApiListingResource) ArrayList(java.util.ArrayList) Properties(java.util.Properties) JAXRSServiceFactoryBean(org.apache.cxf.jaxrs.JAXRSServiceFactoryBean) Swagger(io.swagger.models.Swagger) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) BeanConfig(io.swagger.jaxrs.config.BeanConfig) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) LinkedList(java.util.LinkedList) Application(javax.ws.rs.core.Application)

Example 13 with BeanConfig

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;
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig) Bean(org.springframework.context.annotation.Bean)

Example 14 with 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();
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig) DefaultClassResolver(org.apache.camel.impl.DefaultClassResolver) Swagger(io.swagger.models.Swagger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 15 with BeanConfig

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();
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig) DefaultClassResolver(org.apache.camel.impl.DefaultClassResolver) Swagger(io.swagger.models.Swagger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

BeanConfig (io.swagger.jaxrs.config.BeanConfig)19 Swagger (io.swagger.models.Swagger)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 DefaultClassResolver (org.apache.camel.impl.DefaultClassResolver)7 Test (org.junit.Test)7 Test (org.testng.annotations.Test)3 SplitResourceImpl (com.splitresourcesTestImpl.SplitResourceImpl)1 RootResource (com.subresourcesTest.RootResource)1 DefaultJaxrsScanner (io.swagger.jaxrs.config.DefaultJaxrsScanner)1 ApiListingResource (io.swagger.jaxrs.listing.ApiListingResource)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 FilterInfo (io.undertow.servlet.api.FilterInfo)1 ServletInfo (io.undertow.servlet.api.ServletInfo)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1