How to use swagger with dropwizard .0.7.0
NickName:Jerry H Ask DateTime:2014-04-26T03:04:00

How to use swagger with dropwizard .0.7.0

I have the latest dropwizard setup. Now I have created a simple API and I am trying to add Swagger on top. There is a Swagger implementation for dropwizard but the sample code is against Yammer dropwizard 0.6.2 which requires addProvider and addResource. The io.dropwizard environment doesn't seem to have this function. Can you please let me know how I can do this under io.dropwizard?

Copyright Notice:Content Author:「Jerry H」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/23301054/how-to-use-swagger-with-dropwizard-0-7-0

Answers
condit 2014-04-25T19:34:33

For Dropwizard 0.7.0 I configure swagger like this:\n\nvoid configureSwagger(Environment environment) {\n environment.jersey().register(new ApiListingResourceJSON());\n environment.jersey().register(new ApiDeclarationProvider());\n environment.jersey().register(new ResourceListingProvider());\n ScannerFactory.setScanner(new DefaultJaxrsScanner());\n ClassReaders.setReader(new DefaultJaxrsApiReader());\n SwaggerConfig config = ConfigFactory.config();\n config.setApiVersion(API_VERSION);\n config.setBasePath(\"..\" + environment.getApplicationContext().getContextPath());\n}\n\n\nEDIT\n\nTo run Swagger UI with Dropwizard clone the repo and copy the dist directory into src/main/resources/swagger/ (customizing as necessary). Then add the asset bundle like this:\n\n@Override\npublic void initialize(Bootstrap<ApplicationConfiguration> bootstrap) {\n bootstrap.addBundle(new AssetsBundle(\"/swagger/\", \"/docs\", \"index.html\"));\n}\n",


fehguy 2015-02-20T00:24:40

There are some changes for Swagger spec 2.0 that you can see here:\n\nhttps://github.com/swagger-api/swagger-core/tree/develop_2.0/samples/java-dropwizard\n\nNamely the configuration is slightly different:\n\n @Override\n public void run(SwaggerSampleConfiguration configuration, Environment environment) {\n environment.jersey().register(new ApiListingResource());\n\n // specific to the sample\n environment.jersey().register(new PetResource());\n environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);\n BeanConfig config = new BeanConfig();\n\n // api specific configuration\n config.setTitle(\"Swagger sample app\");\n config.setVersion(\"1.0.0\");\n config.setResourcePackage(\"com.wordnik.swagger.sample\");\n config.setScan(true);\n }\n",


Matt Stephenson 2016-10-06T13:50:56

Dropwizard 1.0.2, Swagger 1.5.0. Call this from your application's run().\n\nprivate void configureSwagger(Environment environment) {\n BeanConfig magicBean = new BeanConfig();\n magicBean.setVersion(\"0.1\");\n magicBean.setTitle(\"title\");\n magicBean.setBasePath(\"/api\");\n magicBean.setResourcePackage(\"com.me.resources\");\n magicBean.setScan(true);\n environment.jersey().register(new ApiListingResourceJSON());\n environment.jersey().register(new SwaggerSerializers());\n}\n",


More about “How to use swagger with dropwizard .0.7.0” related questions

What Maven Dependencies to use Swagger with DropWizard 0.7.0

I have an existing dropwizard 0.7.0 service which I would like to document using Swagger. I am using the followind dependency for swagger from https://github.com/wordnik/swagger-core/wiki/JavaDrop...

Show Detail

How to use swagger with dropwizard .0.7.0

I have the latest dropwizard setup. Now I have created a simple API and I am trying to add Swagger on top. There is a Swagger implementation for dropwizard but the sample code is against Yammer

Show Detail

Dropwizard 0.7.0 : Testing Hibernate backed resources

I'm developing on Dropwizard 0.7.0 and followed the document and example mentioned in the Dropwizard site In the same I'm using Hibernate for database related operations. My resources are workin...

Show Detail

Using CORS header filter with dropwizard 0.7.0

I am trying to get a dropwizard 0.7.0 (Jersey) REST service to send HTML CORS header like "Access-Control-Allow-Origin". I found various tutorials and also learned about the difference how to do it...

Show Detail

Dropwizard-swagger with Dropwizard 1.3

I am using the dropwizard-swagger dependency with Dropwizard 1.3 as follows &lt;dependency&gt; &lt;groupId&gt;com.smoketurner&lt;/groupId&gt; &lt;artifactId&gt;dropwizard-s...

Show Detail

Swagger UI into dropwizard

I added folder dist from swagger-ui github and provide path to openapi.yaml in index.html url: &quot;/openapi/openapi.yaml&quot; Now I can see UI by the address http://localhost:63342/dropwizard-e...

Show Detail

Swagger UI into dropwizard

I added folder dist from swagger-ui github and provide path to openapi.yaml in index.html url: &quot;/openapi/openapi.yaml&quot; Now I can see UI by the address http://localhost:63342/dropwizard-e...

Show Detail

MarkLogic integration with Dropwizard

I am trying to use MarkLogic DB in Dropwizard application for data persistence. I tried with different versions combinations but still facing issues. Exception in thread "main" java.lang.

Show Detail

Intercepting HTTP response body in DropWizard 0.7.0/Jersey 1.x

I'm building a web service with DropWizard 0.7.0 that produces JavaScript output using a Mustache template. I'd like to minify and obfuscate the generated JavaScript. In Jersey 2.x's manual, I see...

Show Detail

Implementing long polling server using Dropwizard 0.7.0

I'm trying to implement a long polling server using Dropwizard 0.7.0 framework. I've been suggested to use jetty integration. After some googling, I got really confused by things like websockets, j...

Show Detail