Dropwizard Swagger support

A simple way to document your REST APIs in DropWizard using Swagger

License

License

Categories

Categories

DropWizard Container Microservices Swagger Program Interface REST Frameworks
GroupId

GroupId

com.github.jasonfry89
ArtifactId

ArtifactId

dropwizard-swagger
Last Version

Last Version

1.2.4
Release Date

Release Date

Type

Type

jar
Description

Description

Dropwizard Swagger support
A simple way to document your REST APIs in DropWizard using Swagger
Project URL

Project URL

https://github.com/jasonfry89/dropwizard-swagger/
Source Code Management

Source Code Management

http://github.com/jasonfry89/dropwizard-swagger

Download dropwizard-swagger

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.jasonfry89/dropwizard-swagger/ -->
<dependency>
    <groupId>com.github.jasonfry89</groupId>
    <artifactId>dropwizard-swagger</artifactId>
    <version>1.2.4</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.jasonfry89/dropwizard-swagger/
implementation 'com.github.jasonfry89:dropwizard-swagger:1.2.4'
// https://jarcasting.com/artifacts/com.github.jasonfry89/dropwizard-swagger/
implementation ("com.github.jasonfry89:dropwizard-swagger:1.2.4")
'com.github.jasonfry89:dropwizard-swagger:jar:1.2.4'
<dependency org="com.github.jasonfry89" name="dropwizard-swagger" rev="1.2.4">
  <artifact name="dropwizard-swagger" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.jasonfry89', module='dropwizard-swagger', version='1.2.4')
)
libraryDependencies += "com.github.jasonfry89" % "dropwizard-swagger" % "1.2.4"
[com.github.jasonfry89/dropwizard-swagger "1.2.4"]

Dependencies

compile (6)

Group / Artifact Type Version
io.dropwizard : dropwizard-core jar 1.2.2
io.dropwizard : dropwizard-assets jar 1.2.2
io.dropwizard : dropwizard-views jar 1.2.2
io.dropwizard : dropwizard-views-freemarker jar 1.2.2
io.swagger : swagger-jersey2-jaxrs jar 1.5.19
xml-apis : xml-apis jar 1.4.01

test (5)

Group / Artifact Type Version
junit : junit jar 4.11
com.jayway.restassured : rest-assured jar 1.7.2
org.seleniumhq.selenium.client-drivers : selenium-java-client-driver jar 1.0.2
org.seleniumhq.selenium : selenium-java jar 2.53.0
org.apache.httpcomponents : httpclient jar 4.3.2

Project Modules

There are no modules declared in this project.

dropwizard-swagger

a Dropwizard bundle that serves Swagger UI static content and loads Swagger endpoints. Swagger UI static content is taken from https://github.com/wordnik/swagger-ui

Current version has been tested with Dropwizard 0.8.0 and Swagger 1.5.1-M2 which supports Swagger 2 spec!

Note: if you come from previous versions there have been some changes in the way the bundle is configured, see details below.

License

http://www.apache.org/licenses/LICENSE-2.0

Version matrix

dropwizard-swagger Dropwizard Swagger API Swagger UI
 < 0.5        |   0.7.x  |   1.3.2   |    ?
   0.5.x      |   0.7.x  |   1.3.12  | v2.1.4-M1
   0.6.x      |   0.8.0  |   1.3.12  | v2.1.4-M1
   0.7.x      |   0.8.0  |   1.5.1-M2| v2.1.4-M1

How to use it

  • Add the Maven dependency (available in Maven Central)

      <dependency>
          <groupId>io.federecio</groupId>
          <artifactId>dropwizard-swagger</artifactId>
          <version>0.7.0</version>
      </dependency>
    
  • Add the following to your Configuration class:

      public class YourConfiguration extends Configuration {
      ...
          @JsonProperty("swagger")
          public SwaggerBundleConfiguration swaggerBundleConfiguration;
    
  • Add the following your configuration yaml (this is the minimal configuration you need):

      prop1: value1
      prop2: value2
      ...
      # the only required property is resourcePackage, for more config options see below
      swagger:
        resourcePackage: <a comma separated string of the packages that contain your @Api annotated resources>
    
  • In your Application class:

      @Override
      public void initialize(Bootstrap<YourConfiguration> bootstrap) {
          ...
          bootstrap.addBundle(new SwaggerBundle<TestConfiguration>() {
              @Override
              protected SwaggerBundleConfiguration getSwaggerBundleConfiguration(YourConfiguration configuration) {
                  return configuration.swaggerBundleConfiguration;
              }
          });
          ...
      }
    
  • As usual, add Swagger annotations to your resource classes and methods

  • Open a browser and hit http://localhost:<your_port>/swagger

Sample Application

Take a look at this sample application that shows how to integrate DropWizard and Swagger: dropwizard-swagger-sample-app

Additional Swagger configuration

To see all the properties that can be used to customize Swagger see SwaggerBundleConfiguration.java

A note on Swagger 2

Host and port do not seem to be needed for Swagger 2 to work properly as it uses relative URLs. At the moment I haven't run through all the scenarios so some adjustments might be needed, please open a bug if you encounter any problems.

Contributors

Versions

Version
1.2.4
1.2.3
1.2.2
1.2.1
1.2.0
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0