springdoc openapi ui 를 이용한 RequestBody placeHolder 설정

RequestBody placeHolder 를 설정하는 방법

  1. dependency

    1
    
     implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0'
    
  2. annotation 설정

  • NovelController.java ```java import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody;

@RestController @RequestMapping(“/api/v1/novels”) public class NovelController {

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@Operation(summary = "get list of novels in showcase", description =
	"""
		showcaseTypeIds is null: all novels in showcase
		showcaseTypeIds is not null: novels matching with the showcaseTypeIds
		""",
	requestBody = @RequestBody(
		description = "List of showcase type IDs",
		content = @Content(schema = @Schema(implementation = HomeBestNovelsRequest.class))
	)
)
@PostMapping("/home-best")
public ResponseEntity<Object> getBestNovels(@RequestBody HomeBestNovelsRequest requestBody) {
	List<Long> showcaseTypeIds = requestBody.getShowcaseTypeIds();
	Map<String, List<NovelDto>> novels = novelService.getNovelsByShowcaseTypes(showcaseTypeIds);
	return ResponseEntityBuilder.build("Successfully retrieved home best novels", HttpStatus.OK, novels);
} } ```
  • HomeBestNovelsRequest.java
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    
    public class HomeBestNovelsRequest {
    
      @Schema(description = "List of showcase type IDs", example = "[1, 2]")
      private List<Long> showcaseTypeIds;
    
      public List<Long> getShowcaseTypeIds() {
          return showcaseTypeIds;
      }
    
      public void setShowcaseTypeIds(List<Long> showcaseTypeIds) {
          this.showcaseTypeIds = showcaseTypeIds;
      }
    }
    

comments powered by Disqus