Post

[AWS] SpringBoot, Swagger-ui 연동

[AWS] SpringBoot, Swagger-ui 연동

1. build.gradle 의존성 추가

1
2
3
dependencies {
    implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.4'
}

2. application.yml 파일 수정

하단에 해당 부분을 추가하여준다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
springdoc:
  swagger-ui:
    groups-order: DESC
    tags-sorter: alpha
    operations-sorter: method
    disable-swagger-default-url: true
    display-request-duration: true
    defaultModelsExpandDepth: 2
    defaultModelExpandDepth: 2
    path: /swagger-ui/index.html
  api-docs:
    path: /api-docs
  show-actuator: true
  default-consumes-media-type: application/json
  default-produces-media-type: application/json
  writer-with-default-pretty-printer: true
  model-and-view-allowed: true
  paths-to-match:
    - /api/v1/**

3. SwaggerConfig 클래스 생성

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

    @Bean
    public GroupedOpenApi publicApi() {
        return GroupedOpenApi.builder()
                .group("springdoc-public")
                .pathsToMatch("/**")
                .build();
    }

    @Bean
    public OpenAPI openAPI() {
        Info info = new Info()
                .version("v1.0")
                .title("TEST")
                .description("Swagger-ui 테스트입니다.");
        return new OpenAPI()
                .info(info);
    }
}

image

✨ 접속 성공

This post is licensed under CC BY 4.0 by the author.