Skip to content

Instantly share code, notes, and snippets.

@michaellihs
Last active January 23, 2021 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaellihs/31112346a6c65be0e4379756d0652108 to your computer and use it in GitHub Desktop.
Save michaellihs/31112346a6c65be0e4379756d0652108 to your computer and use it in GitHub Desktop.
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