codememo

swagger ui와 함께 @RequestParam 주석 메서드 사용

tipmemo 2023. 4. 3. 21:32
반응형

swagger ui와 함께 @RequestParam 주석 메서드 사용

사용하고 있다Springfox라이브러리를 사용하여 REST 서비스 설명서를 생성하고 이를 Swagger UI에 표시합니다.저는 Springfox 설명서의 지침을 따랐습니다.

1개의 컨트롤러가 있으며, 이 컨트롤러는 쿼리 문자열의 파라미터를 사용하며 메서드는 다음과 같이 매핑됩니다.

@ApiOperation(value = "")
@RequestMapping(method = GET, value = "/customcollection/{id}/data")
public Iterable<CustomeType> getData(@ApiParam(value = "The identifier of the time series.") 
    @PathVariable String id,
    @ApiParam(name = "startDate", value = "start date", defaultValue = "")
    @RequestParam("startDate") String startDate,
    @ApiParam(name = "endDate", value = "end date", defaultValue = "")
    @RequestParam("endDate") String endDate)

swagger-ui의 결과 매퍼는 다음과 같이 표시됩니다.

GET /customcollection/{id}/data{?startDate,endDate}

파라미터가 UI에 올바르게 표시됩니다.

그러나 [Try it Out]를 클릭하면 요청 URL의 형식이 잘못되었습니다.

http://localhost:8080/customlection/1/data{?startDate,endDate}?startDate=1&endDate=2

어떻게 고칠 수 있을까요?

이것은 회선으로 인해 발생하였습니다.

 enableUrlTemplating(true)

Docket예를 들어 복사하고 삭제하는 것을 잊은 Configuration입니다.

이 라인을 제거하면 모든 것이 예상대로 작동합니다.

언급URL : https://stackoverflow.com/questions/33377388/using-requestparam-annotated-method-with-swagger-ui

반응형