반응형 Spring22 [Spring] Springdoc Swagger 그룹, 정렬, 카테고리 접기 springdoc을 이용한 swagger의 정렬하는 방법과 첫화면에서 카테고리 접는 방법을 알아보겠습니다. 해당 기능은 springdoc의 설정으로 간단하게 처리할수 있습니다 spring-doc: swagger-ui: tags-sorter: alpha operations-sorter : method doc-expansion : none 위와 같이 tags 정렬을 이름순으로 하고 operation 정렬을 method로 doc-expansion은 기본 펼침으로 되어 있지만 none으로 설정하여 카테고리가 접힌상태로 로드되도록 설정할 수 있습니다. 카테고리가 접힌상태라 하더라도 api 숫자가 많으면 스크롤이 많이 늘어날텐데요. 이문제를 해결하기 위해 group 기능을 사용할 수 있습니다 아래코드를 spring.. 2023. 3. 21. [Spring] Springdoc swagger에서 글로벌 header를 설정하는 방법 현재 Springdoc을 이용한 swagger를 사용하고 있는데요. 프로젝트를 진행하다보니 글로벌 header를 설정하는 기능이 필요했습니다 일반적으로 header를 파라미터로 받으면 swagger에 생성되는데요. 아래코드처럼 구현하면 됩니다 @Operation(description = "test") @PostMapping("/test") public void userLogout(@RequestHeader("headerParam1") String headerParam1) throws Exception { log.info(headerParam1); } 대부분의 메서드에 해당 파라미터가 필요하다면 일일이 넣어주는것은 불편한 일입니다. 그래서 swagger config에 아래 코드를 추가해 주면 간단하게 글로.. 2023. 3. 10. [Spring] Springdoc을 이용한 Swagger 적용 SpringBoot 3 버전을 사용하면서 이전에 사용했던 swaggerFox를 사용시 에러가 발생하여 Springdoc을 이용하여 Swagger를 구성했습니다 우선 아래처럼 의존성 추가를 해줍니다 dependencies { implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' } 그런다음 yaml 파일에 swagger 주소를 추가합니다 springdoc: swagger-ui: path: /swagger-ui.html 이제 swagger config 파일을 생성합니다 기존에 swaggerfox를 이용할때는 아래처럼 설정했지만 springdoc을 이용할때는 조금 다르니 참고해주시기 바랍니다 @EnableSwagger2 @Config.. 2023. 3. 2. [Spring] MapStruct를 이용한 DTO <-> Entity 사용시 조인관계 매핑 기본적은 MapStruct 설정은 이전글 https://apere.tistory.com/10 을 참고해주세요 이번글에서는 아래처럼 Member와 Team Entity가 관계를 가질경우 MemberDTO에서 Member로 변환시 간단하게 구현하는 방법입니다 public class Team { @Id @GeneratedValue @Column(name = "team_id") private Long id; @Column(name = "team_name") private String teamName; @JsonIgnore @OneToMany(fetch = FetchType.LAZY, mappedBy = "team") private List members = new ArrayList(); } public clas.. 2023. 3. 1. 이전 1 2 3 4 5 6 다음 반응형