Search in sources :

Example 21 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 22 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)

Example 23 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 24 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 25 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)

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