250x250
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 28 |
29 | 30 | 31 |
Tags
- Python
- PostgreSQL
- Open Source
- 문서
- myBatis
- 설정
- JavaScript
- SpringBoot
- maven
- git
- jpa
- Thymeleaf
- MySQL
- spring
- 오픈소스
- Core Java
- STS
- oracle
- Eclipse
- Tomcat
- AJAX
- ubuntu
- JDBC
- Spring Boot
- Source
- Docker
- Exception
- error
- IntelliJ
- MSSQL
Archives
- Today
- Total
헤르메스 LIFE
[Swagger] API 문서 자동화 설정 본문
728x90
개발환경
Spring Boot 2.7.9
H2 2.1.214
p6spy 1.8.1
slf4j 1.7.36
lombok
devtools
postgresql
참고로
Swagger 의 버전별 call URL이 다릅니다.
2.x 버전 : http://localhost:9090/swagger-ui.html
3.x 버전 : http://localhost:9090/swagger-ui/index.html
Swagger2 2.9.2 버전 설정
build.gradle
// Default : 2.0.0.RELEASE
//implementation 'org.springframework.plugin:spring-plugin-core'
implementation 'org.springframework.plugin:spring-plugin-core:1.2.0.RELEASE'
// Swagger
implementation 'io.springfox:springfox-swagger2:2.9.2'
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
SwaggerConfiguration.java
import java.util.ArrayList;
import java.util.List;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.hateoas.client.LinkDiscoverer;
import org.springframework.hateoas.client.LinkDiscoverers;
import org.springframework.hateoas.mediatype.collectionjson.CollectionJsonLinkDiscoverer;
import org.springframework.plugin.core.SimplePluginRegistry;
import org.springframework.validation.Errors;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket swaggerApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(swaggerInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("octopus.backend"))
.paths(PathSelectors.any())
.build()
.useDefaultResponseMessages(false); // 기본으로 세팅되는 200,401,403,404 메시지를 표시 하지 않음
}
private ApiInfo swaggerInfo() {
return new ApiInfoBuilder()
.title("Octopus API Documentation")
.description("앱 개발시 사용되는 서버 API에 대한 연동 문서입니다")
.license("MIT License")
.licenseUrl("https://hermeslog.tistory.com/")
.version("1.0")
.build();
}
@Bean
public LinkDiscoverers discoverers() {
List<LinkDiscoverer> plugins = new ArrayList<>();
plugins.add(new CollectionJsonLinkDiscoverer());
return new LinkDiscoverers(SimplePluginRegistry.create(plugins));
}
}
Swagger2 3.0.0 버전 설정
build.gradle
// Default : 2.0.0.RELEASE
implementation 'org.springframework.plugin:spring-plugin-core:2.0.0.RELEASE'
implementation 'io.springfox:springfox-boot-starter:3.0.0'
implementation 'io.springfox:springfox-swagger-ui:3.0.0'
SwaggerConfiguration.java
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.Errors;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket swaggerApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(swaggerInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("octopus.backend"))
.paths(PathSelectors.any())
.build()
.useDefaultResponseMessages(false); // 기본으로 세팅되는 200,401,403,404 메시지를 표시 하지 않음
}
private ApiInfo swaggerInfo() {
return new ApiInfoBuilder()
.title("Octopus API Documentation")
.description("앱 개발시 사용되는 서버 API에 대한 연동 문서입니다")
.license("MIT License")
.licenseUrl("https://hermeslog.tistory.com/")
.version("1.0")
.build();
}
// @Bean
// public LinkDiscoverers discoverers() {
// List<LinkDiscoverer> plugins = new ArrayList<>();
// plugins.add(new CollectionJsonLinkDiscoverer());
//
// return new LinkDiscoverers(SimplePluginRegistry.create(plugins));
// }
}
참고
https://kim-jong-hyun.tistory.com/49
https://hermeslog.tistory.com/698
728x90
'Spring Boot Framework' 카테고리의 다른 글
[Spring Boot] HandlerMethodArgumentResolver를 이용한 중복 Source 제거 방법 (0) | 2023.04.04 |
---|---|
[Spring Boot] Jackson 직렬화 문제 (0) | 2023.04.01 |
[JPA] 정렬 Sort (0) | 2023.03.21 |
[JPA] update (Persistence Context) (0) | 2023.03.18 |
[JPA] JPA Data Save, Delete 시 Select 쿼리가 먼저 실행 된다. (1) | 2023.03.12 |