Skip to content

Vect0rPro/dropwizard-swagger

Repository files navigation

Dropwizard Swagger Integration

Apache License V2.0 Maven Central

A Dropwizard bundle that serves Swagger UI static content and loads Swagger endpoints.

Current version has been tested with Dropwizard 2.1.12 and Swagger 2.2.2 which supports OpenApi 3.0 specifications

Requirements

  • Dropwizard 2.1.12
  • Swagger API 2.2.2
  • Swagger UI 5.27.0

Usage

  • Add the Maven dependency (available in Maven Central)
<dependency>
    <groupId>in.vectorpro.dropwizard</groupId>
    <artifactId>dropwizard-swagger</artifactId>
    <version>2.1.12-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 @OpenAPIDefinition annotated resources>

  # Configure page title or code snippet targets as needed
  swaggerViewConfiguration:
    pageTitle: "API Documentation"
    # Default value of code snippet targets is always provided by the bundle
    # Include supported snippet targets as per link provided below if modification to default value is required
    codeSnippetTargets:
      - java_okhttp
      - python_requests

Supported code snippet targets: link

  • 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

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

About

Dropwizard Swagger 2.x and OpenAPI 3.x Integration

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •