Repository: cxf Updated Branches: refs/heads/master 4ff4d39b0 -> e31cf1c5d
CXF-6046: Enhance SwaggerFeature to support JAX-RS annotations. Added customized Swagger UI. Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/49c35937 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/49c35937 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/49c35937 Branch: refs/heads/master Commit: 49c35937c3a0813ed4ccf34dd03fd5fa2f41b86c Parents: e2ad037 Author: reta <[email protected]> Authored: Wed Nov 12 13:37:12 2014 -0500 Committer: reta <[email protected]> Committed: Wed Nov 12 13:37:12 2014 -0500 ---------------------------------------------------------------------- .../samples/jax_rs/description_swagger/pom.xml | 117 ++++++++++++------- .../webjars/swagger-ui/2.0.24/index.html | 60 ++++++++++ .../cxf/jaxrs/swagger/SwaggerFeature.java | 6 +- 3 files changed, 137 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/49c35937/distribution/src/main/release/samples/jax_rs/description_swagger/pom.xml ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger/pom.xml b/distribution/src/main/release/samples/jax_rs/description_swagger/pom.xml index fa49ef0..0faab16 100644 --- a/distribution/src/main/release/samples/jax_rs/description_swagger/pom.xml +++ b/distribution/src/main/release/samples/jax_rs/description_swagger/pom.xml @@ -39,42 +39,73 @@ <id>server</id> <build> <defaultGoal>test</defaultGoal> - <plugins> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>exec-maven-plugin</artifactId> - <executions> - <execution> - <phase>test</phase> - <goals> - <goal>java</goal> - </goals> - <configuration> - <mainClass>demo.jaxrs.swagger.server.Server</mainClass> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - </profiles> - + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <executions> + <execution> + <phase>test</phase> + <goals> + <goal>java</goal> + </goals> + <configuration> + <mainClass>demo.jaxrs.swagger.server.Server</mainClass> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <version>2.9</version> + <executions> + <execution> + <phase>generate-resources</phase> + <goals> + <goal>unpack</goal> + </goals> + <configuration> + <artifactItems> + <artifactItem> + <groupId>org.webjars</groupId> + <artifactId>swagger-ui</artifactId> + <version>2.0.24</version> + <overWrite>true</overWrite> + <outputDirectory>${project.build.directory}/classes</outputDirectory> + <excludes>**/index.html</excludes> + </artifactItem> + </artifactItems> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + <dependencies> - <dependency> + <dependency> <groupId>com.wordnik</groupId> - <artifactId>swagger-jaxrs_2.10</artifactId> - <exclusions> - <exclusion> - <groupId>javax.ws.rs</groupId> + <artifactId>swagger-jaxrs_2.10</artifactId> + <exclusions> + <exclusion> + <groupId>javax.ws.rs</groupId> <artifactId>jsr311-api</artifactId> - </exclusion> - </exclusions> + </exclusion> + </exclusions> </dependency> <dependency> - <groupId>org.webjars</groupId> - <artifactId>swagger-ui</artifactId> - <version>2.0.24</version> + <groupId>org.webjars</groupId> + <artifactId>swagger-ui</artifactId> + <version>2.0.24</version> + <scope>provided</scope> </dependency> <dependency> <groupId>javassist</groupId> @@ -82,15 +113,15 @@ <version>3.12.1.GA</version> </dependency> <dependency> - <groupId>com.fasterxml.jackson.jaxrs</groupId> - <artifactId>jackson-jaxrs-json-provider</artifactId> - <version>2.2.2</version> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-core</artifactId> - <version>2.2.2</version> - </dependency> + <groupId>com.fasterxml.jackson.jaxrs</groupId> + <artifactId>jackson-jaxrs-json-provider</artifactId> + <version>2.2.2</version> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-core</artifactId> + <version>2.2.2</version> + </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> @@ -125,8 +156,8 @@ <artifactId>javax.ws.rs-api</artifactId> </dependency> <dependency> - <groupId>org.eclipse.jetty</groupId> - <artifactId>jetty-webapp</artifactId> - </dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-webapp</artifactId> + </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/cxf/blob/49c35937/distribution/src/main/release/samples/jax_rs/description_swagger/src/main/resources/META-INF/resources/webjars/swagger-ui/2.0.24/index.html ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger/src/main/resources/META-INF/resources/webjars/swagger-ui/2.0.24/index.html b/distribution/src/main/release/samples/jax_rs/description_swagger/src/main/resources/META-INF/resources/webjars/swagger-ui/2.0.24/index.html new file mode 100644 index 0000000..5d18b8b --- /dev/null +++ b/distribution/src/main/release/samples/jax_rs/description_swagger/src/main/resources/META-INF/resources/webjars/swagger-ui/2.0.24/index.html @@ -0,0 +1,60 @@ +<!DOCTYPE html> +<html> +<head> + <title>Swagger UI</title> + <link href='css/reset.css' media='screen' rel='stylesheet' type='text/css'/> + <link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/> + <link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/> + <link href='css/screen.css' media='print' rel='stylesheet' type='text/css'/> + <script type="text/javascript" src="lib/shred.bundle.js"></script> + <script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script> + <script src='lib/jquery.slideto.min.js' type='text/javascript'></script> + <script src='lib/jquery.wiggle.min.js' type='text/javascript'></script> + <script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script> + <script src='lib/handlebars-1.0.0.js' type='text/javascript'></script> + <script src='lib/underscore-min.js' type='text/javascript'></script> + <script src='lib/backbone-min.js' type='text/javascript'></script> + <script src='lib/swagger.js' type='text/javascript'></script> + <script src='swagger-ui.js' type='text/javascript'></script> + <script src='lib/highlight.7.3.pack.js' type='text/javascript'></script> + + <!-- enabling this will enable oauth2 implicit scope support --> + <script src='lib/swagger-oauth.js' type='text/javascript'></script> + + <script type="text/javascript"> + $(function () { + window.swaggerUi = new SwaggerUi({ + url: "http://localhost:9000/api-docs", + dom_id: "swagger-ui-container", + supportedSubmitMethods: ['get', 'post', 'put', 'delete'], + onComplete: function(swaggerApi, swaggerUi){ + log("Loaded SwaggerUI"); + $('pre code').each(function(i, e) { + hljs.highlightBlock(e) + }); + }, + onFailure: function(data) { + log("Unable to Load SwaggerUI"); + }, + docExpansion: "none", + sorter : "alpha" + }); + + $('#input_apiKey').change(function() { + var key = $('#input_apiKey')[0].value; + log("key: " + key); + if(key && key.trim() != "") { + log("added key " + key); + window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "query")); + } + }) + window.swaggerUi.load(); + }); + </script> +</head> + +<body class="swagger-section"> +<div id="message-bar" class="swagger-ui-wrap"> </div> +<div id="swagger-ui-container" class="swagger-ui-wrap"></div> +</body> +</html> http://git-wip-us.apache.org/repos/asf/cxf/blob/49c35937/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerFeature.java ---------------------------------------------------------------------- diff --git a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerFeature.java b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerFeature.java index 7f62906..3630415 100644 --- a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerFeature.java +++ b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerFeature.java @@ -33,9 +33,9 @@ public class SwaggerFeature extends AbstractFeature { private String resourcePackage; private String version = "1.0.0"; private String basePath; - private String title = "Rest sample app"; - private String description = "This is a app."; - private String contact = "[email protected]"; + private String title = "Sample REST Application"; + private String description = "The Application"; + private String contact = "[email protected]"; private String license = "Apache 2.0 License"; private String licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0.html"; private boolean scan = true;
