API document만들기

dalBeen·2023년 9월 27일
0

스프링

목록 보기
4/14

프론트 개발자와 백엔드 개발자끼리 공유하는 문서

tool

  • Swagger
  • ReDoc
  • GitBook

등 있음

Swagger사용방법에 대해서 설명하겠음

Swagger

  1. 디펜던시 추가
implementation 'io.springfox:springfox-boot-starter:3.0.0'
implementation 'io.springfox:springfox-swagger-ui:3.0.0'
  1. SwaggerConfig생성
@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() {
       String description = "Welcome Log Company";
       return new ApiInfoBuilder()
       .title("SWAGGER TEST")
       .description(description)
       .version("1.0")
       .build();
 }
  • @EnableSwagger2

    • Swagger2 버전을 활성화 하겠다
  • Docket

    • Swagger 설정할 수 있게 도와주는 클래스
    • APi자체에 대한 정보는 컨트롤러에서 작성
  • select()

    • ApiSelectorBuilder를 생성하여 apis()와 paths()를 사용할 수 있게 해준다.
  • paths()

    • apis()로 선택되어진 API중 특정 path 조건에 맞는 API들을 다시 필터링하여 문서화한다.
    • PathSelectors.any()로 설정하면 패키지 안에 모든 API를 한 번에 볼 수 있다.
  • apiInfo()

    • 제목, 설명 등 문서에 대한 정보들을 설정하기 위해 호출한다.

해당 API에 대한 자세한 설명

	@ApiOperation("선택한 날짜의 모든 일기 데이터 가져오기")
    @GetMapping("/read/diary")
    public List<Diary> readDiary(@RequestParam @DateTimeFormat(iso=DateTimeFormat.ISO.DATE)@ApiParam(value = "yyyy-MM-dd",example = "2020-02-02") LocalDate date){
        List<Diary> diary = diaryService.getDiary(date);
        return diary;
    }

이외 더자세한 내용
swagger2

profile
깊게 공부해보자

0개의 댓글