Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Swagger Cheatsheet

Swagger and Spring

Add the following dependencies to your pom.xml

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.5.0</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.5.0</version>
    <scope>compile</scope>
</dependency>

Add the following @Configuration class

@Configuration
@EnableSwagger2
public class SwaggerConfig {

	@Bean
	public Docket api(){
		return new Docket(DocumentationType.SWAGGER_2)
				.select()
				.apis(RequestHandlerSelectors.any())
				.paths(PathSelectors.any())
				.build()
				.apiInfo(apiInfo());
	}

		private ApiInfo apiInfo() {
			return new ApiInfoBuilder()
					.title("API Title")
					.description("Description of API Documentation")
					.version("0.0.1")
					.build();
		}

}

Further References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.