Skip to content

Instantly share code, notes, and snippets.

@shabbirdwd53
Created July 24, 2022 07:50
Show Gist options
  • Save shabbirdwd53/622adfc4e142680e2b7dbc2aac6e5419 to your computer and use it in GitHub Desktop.
Save shabbirdwd53/622adfc4e142680e2b7dbc2aac6e5419 to your computer and use it in GitHub Desktop.

API Documentation with Swagger

You can imlement API Documentation in 4 easy steps

Step 1

Add the below dependency in your Spring boot project in POM.xml file

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <version>3.0.0</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>3.0.0</version>
</dependency>

Step 2

Add EnableSwagger2 annotation in your SPring Boot main Java File

@SpringBootApplication
@EnableSwagger2
public class SpringBootDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringBootDemoApplication.class, args);
    }

}

Step 3

Create a Springfox Configuration Class

@Configuration
public class SpringFoxConfig {

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

Step 4

Add the Configuration in application.properties for Springfox

spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER

Run Locally

Start the Spring boot application and go to below URL fro your API Documentation

  http://localhost:8080/swagger-ui/
@Name-Is-Vinee7
Copy link

can you do api documentation for spring boot version - 3.2.0 please if you do it will be really helpful for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment