Search in sources :

Example 1 with BeanConfig

use of io.swagger.jaxrs.config.BeanConfig in project swagger-core by swagger-api.

the class ApiListingJSONTest method initializeTest.

@Test(description = "test Swagger initialization from BeanConfig")
public void initializeTest() {
    final BeanConfig bc = new BeanConfig();
    bc.setTitle("Petstore Sample API");
    bc.setHost("petstore.swagger.io");
    bc.setBasePath("/api");
    bc.setScan(true);
    final ApiListingJSON listing = new ApiListingJSON();
    // Initializing by Swagger object
    ApiListingJSON.init(new Swagger());
    // Reading configuration and scanning resources
    listing.scan(null);
    final Swagger sw = ApiListingJSON.swagger;
    Assert.assertNotNull(sw);
    Assert.assertEquals(sw.getInfo().getTitle(), "Petstore Sample API");
    Assert.assertEquals(sw.getHost(), "petstore.swagger.io");
    Assert.assertEquals(sw.getBasePath(), "/api");
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig) Swagger(io.swagger.models.Swagger) Test(org.testng.annotations.Test)

Example 2 with BeanConfig

use of io.swagger.jaxrs.config.BeanConfig in project swagger-core by swagger-api.

the class BeanConfigTest method testBeanConfigOnlyScansResourcesAnnoatedWithPaths.

@Test
public void testBeanConfigOnlyScansResourcesAnnoatedWithPaths() throws Exception {
    BeanConfig bc = new BeanConfig();
    bc.setResourcePackage("com.subresourcesTest");
    Set<Class<?>> classes = bc.classes();
    assertEquals(classes.size(), 1, "BeanConfig should only pick up the root resource because it has a @Path annotation at the class level");
    assertTrue(classes.contains(RootResource.class));
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig) RootResource(com.subresourcesTest.RootResource) Test(org.testng.annotations.Test)

Example 3 with BeanConfig

use of io.swagger.jaxrs.config.BeanConfig in project swagger-core by swagger-api.

the class BeanConfigTest method testBeanConfigScansSplitResourcesAnnoatedWithPathAndApi.

@Test
public void testBeanConfigScansSplitResourcesAnnoatedWithPathAndApi() throws Exception {
    BeanConfig bc = new BeanConfig();
    bc.setResourcePackage("com.splitresourcesTestImpl");
    Set<Class<?>> classes = bc.classes();
    assertEquals(classes.size(), 1, "BeanConfig should pick up implementations annotated with @Api that have a superinterface with @Path");
    assertTrue(classes.contains(SplitResourceImpl.class));
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig) SplitResourceImpl(com.splitresourcesTestImpl.SplitResourceImpl) Test(org.testng.annotations.Test)

Example 4 with BeanConfig

use of io.swagger.jaxrs.config.BeanConfig in project swagger-core by swagger-api.

the class BeanConfigTest method createBeanConfig.

private BeanConfig createBeanConfig(String rp) {
    BeanConfig bc = new BeanConfig();
    bc.setResourcePackage(rp);
    bc.setSchemes(new String[] { "http", "https" });
    bc.setHost("petstore.swagger.io");
    bc.setBasePath("/api");
    bc.setTitle("Petstore Sample API");
    bc.setDescription("A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification");
    bc.setTermsOfServiceUrl("http://swagger.io/terms/");
    bc.setContact("Swagger API Team");
    bc.setLicense("MIT");
    bc.setLicenseUrl("http://github.com/gruntjs/grunt/blob/master/LICENSE-MIT");
    bc.setScan(true);
    return bc;
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig)

Example 5 with BeanConfig

use of io.swagger.jaxrs.config.BeanConfig in project Gaffer by gchq.

the class ApplicationConfig method setupBeanConfig.

protected void setupBeanConfig() {
    BeanConfig beanConfig = new BeanConfig();
    String baseUrl = System.getProperty(SystemProperty.BASE_URL, SystemProperty.BASE_URL_DEFAULT);
    if (!baseUrl.startsWith("/")) {
        baseUrl = "/" + baseUrl;
    }
    beanConfig.setBasePath(baseUrl);
    beanConfig.setVersion(System.getProperty(SystemProperty.VERSION, SystemProperty.CORE_VERSION));
    beanConfig.setResourcePackage(System.getProperty(SystemProperty.SERVICES_PACKAGE_PREFIX, SystemProperty.SERVICES_PACKAGE_PREFIX_DEFAULT));
    beanConfig.setScan(true);
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig)

Aggregations

BeanConfig (io.swagger.jaxrs.config.BeanConfig)31 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 ApiListingResource (io.swagger.jaxrs.listing.ApiListingResource)2 SplitResourceImpl (com.splitresourcesTestImpl.SplitResourceImpl)1 RootResource (com.subresourcesTest.RootResource)1 SwaggerResource (gov.ca.cwds.rest.resources.SwaggerResource)1 TokenResource (gov.ca.cwds.rest.resources.TokenResource)1 AssetsBundle (io.dropwizard.assets.AssetsBundle)1 DefaultJaxrsScanner (io.swagger.jaxrs.config.DefaultJaxrsScanner)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 ServletInfo (io.undertow.servlet.api.ServletInfo)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1