Search in sources :

Example 16 with BeanConfig

use of io.swagger.jaxrs.config.BeanConfig in project camel by apache.

the class RestSwaggerReaderModelBookOrderTest 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("Camel User store");
    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("\"description\" : \"The order returned\""));
    assertTrue(json.contains("\"BookOrder\""));
    assertTrue(json.contains("\"LineItem\""));
    assertTrue(json.contains("\"$ref\" : \"#/definitions/BookOrder\""));
    assertTrue(json.contains("\"$ref\" : \"#/definitions/LineItem\""));
    assertTrue(json.contains("\"x-className\""));
    assertTrue(json.contains("\"format\" : \"org.apache.camel.swagger.BookOrder\""));
    assertTrue(json.contains("\"format\" : \"org.apache.camel.swagger.LineItem\""));
    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 17 with BeanConfig

use of io.swagger.jaxrs.config.BeanConfig in project camel by apache.

the class RestSwaggerReaderPropertyPlaceholderTest 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();
    RestSwaggerSupport support = new RestSwaggerSupport();
    List<RestDefinition> rests = support.getRestDefinitions(context.getName());
    Swagger swagger = reader.read(rests, 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\""));
    assertTrue(json.contains("\"/hello/bye\""));
    assertTrue(json.contains("\"summary\" : \"To update the greeting message\""));
    assertTrue(json.contains("\"/hello/bye/{name}\""));
    assertTrue(json.contains("\"/hello/hi/{name}\""));
    assertFalse(json.contains("{foo}"));
    assertFalse(json.contains("{bar}"));
    context.stop();
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig) RestDefinition(org.apache.camel.model.rest.RestDefinition) DefaultClassResolver(org.apache.camel.impl.DefaultClassResolver) Swagger(io.swagger.models.Swagger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 18 with BeanConfig

use of io.swagger.jaxrs.config.BeanConfig in project pinot by linkedin.

the class AdminApiApplication method setupSwagger.

private void setupSwagger(HttpServer httpServer) {
    BeanConfig beanConfig = new BeanConfig();
    beanConfig.setTitle("Pinot Server API");
    beanConfig.setDescription("APIs for accessing Pinot server information");
    beanConfig.setContact("https://github.com/linkedin/pinot");
    beanConfig.setVersion("1.0");
    beanConfig.setSchemes(new String[] { "http" });
    beanConfig.setBasePath(baseUri.getPath());
    beanConfig.setResourcePackage(RESOURCE_PACKAGE);
    beanConfig.setScan(true);
    CLStaticHttpHandler staticHttpHandler = new CLStaticHttpHandler(AdminApiApplication.class.getClassLoader(), "/api/");
    // map both /api and /help to swagger docs. /api because it looks nice. /help for backward compatibility
    httpServer.getServerConfiguration().addHttpHandler(staticHttpHandler, "/api");
    httpServer.getServerConfiguration().addHttpHandler(staticHttpHandler, "/help");
    URL swaggerDistLocation = AdminApiApplication.class.getClassLoader().getResource("META-INF/resources/webjars/swagger-ui/2.2.2/");
    CLStaticHttpHandler swaggerDist = new CLStaticHttpHandler(new URLClassLoader(new URL[] { swaggerDistLocation }));
    httpServer.getServerConfiguration().addHttpHandler(swaggerDist, "/swaggerui-dist/");
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig) CLStaticHttpHandler(org.glassfish.grizzly.http.server.CLStaticHttpHandler) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL)

Example 19 with BeanConfig

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

the class SwaggerContextServiceTest method initMock.

@BeforeMethod
void initMock() {
    servletContext1 = mock(ServletContext.class);
    servletConfig1 = mock(ServletConfig.class);
    servletContext2 = mock(ServletContext.class);
    servletConfig2 = mock(ServletConfig.class);
    jaxrsScanner = new DefaultJaxrsScanner();
    BeanConfig bc = new BeanConfig();
    bc.setDescription("Bean Config test 1");
    beanConfigScanner1 = bc;
    bc = new BeanConfig();
    bc.setDescription("Bean Config test 2");
    beanConfigScanner2 = bc;
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig) DefaultJaxrsScanner(io.swagger.jaxrs.config.DefaultJaxrsScanner) ServletConfig(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext) BeforeMethod(org.testng.annotations.BeforeMethod)

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