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.smoketurner
ArtifactId

ArtifactId

dropwizard-swagger
Last Version

Last Version

2.0.12-1
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/smoketurner/dropwizard-swagger/
Source Code Management

Source Code Management

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

Download dropwizard-swagger

How to add to project

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

Dependencies

compile (7)

Group / Artifact Type Version
io.dropwizard : dropwizard-core jar
io.dropwizard : dropwizard-auth jar
io.dropwizard : dropwizard-assets jar
io.dropwizard : dropwizard-views jar
io.dropwizard : dropwizard-views-freemarker jar
org.glassfish.jersey.media : jersey-media-multipart jar 2.31
io.swagger : swagger-jersey2-jaxrs jar 1.6.2

runtime (2)

Group / Artifact Type Version
jakarta.xml.bind : jakarta.xml.bind-api jar 2.3.3
jakarta.activation : jakarta.activation-api jar 1.2.2

test (7)

Group / Artifact Type Version
io.rest-assured : rest-assured jar 4.3.1
io.dropwizard : dropwizard-testing jar
org.junit.jupiter : junit-jupiter jar 5.6.2
org.assertj : assertj-core jar 3.16.1
org.mockito : mockito-core jar 3.5.2
org.openjdk.jmh : jmh-core jar 1.25
org.openjdk.jmh : jmh-generator-annprocess jar 1.25

Project Modules

There are no modules declared in this project.

dropwizard-swagger

Build Status Coverage Status Maven Central GitHub license Become a Patron

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

Current version has been tested with Dropwizard 2.0.0 and Swagger 1.6.0 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.x 1.5.1-M2 v2.1.4-M1
0.7.2 0.8.4 1.5.3 v2.1.2
0.9.x 0.9.x 1.5.9 v2.1.5
1.0.x 1.0.x 1.5.12 v2.2.10
1.1.x 1.1.x 1.5.16 v2.2.10
1.2.x 1.2.x 1.5.18 v3.9.2
1.3.x 1.3.x 1.5.22 v3.23.0
2.0.x 2.0.x 1.6.0 v3.24.3

How to use it

  • Add the Maven dependency (available in Maven Central)
<dependency>
    <groupId>com.smoketurner</groupId>
    <artifactId>dropwizard-swagger</artifactId>
    <version>2.0.0-1</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<YourConfiguration>() {
        @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

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

com.smoketurner

Smoke Turner, LLC

Versions

Version
2.0.12-1
2.0.0-1
1.3.17-1
1.3.12-1
1.3.9-1
1.3.8-1
1.3.7-1
1.3.5-3
1.3.5-2
1.3.5-1
1.3.4-1
1.3.1-1
1.3.0-1
1.2.4-2
1.2.4-1
1.2.3-3
1.2.3-2
1.2.3-1
1.2.2-2
1.2.2-1
1.1.2-1
1.1.1-1
1.1.0-1
1.0.6-1
1.0.5-4
1.0.5-3
1.0.5-2
1.0.5-1
1.0.0-1
1.0.0-rc4-2
1.0.0-rc4-1
1.0.0-rc2-1
1.0.0-rc1-1
0.9.3-3
0.9.3-2
0.9.3-1
0.9.2-3
0.9.2-2
0.9.2-1
0.9.1-1
0.7.2
0.7.1