[英]How to add different @Schema descriptions on OpenApi Spring?
[英]Swagger 3 / OpenApi How to add two descriptions to the same status code
我正在嘗試為我的小 api 做一些文檔。 在狀態碼 400 上我可以有 2 種可能的描述時,我應該怎么做? 我想做類似的事情:
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "description",
content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = StudentFullDTO.class))}),
@ApiResponse(responseCode = "400", description = "description" +
"ExceptionResponseObject", content = @Content),
@ApiResponse(responseCode = "400", description = "Odescription",
content = @Content)})
@PatchMapping("/{id}")
public ResponseEntity<StudentFullDTO> patch(@PathVariable String id,
@RequestBody @Valid Map<Object, Object> fields) {
StudentEntity studentEntity = studentEntityService.patchStudentEntity(id, fields);
StudentFullDTO studentFullDTO = modelMapperService.mapObjectToObjectOfEnteredClass(studentEntity, StudentFullDTO.class);
return new ResponseEntity<>(studentFullDTO, HttpStatus.OK);
}
是否可以多次定義相同的狀態?
您需要合並這兩個描述並在同一個@ApiResponse(description = "...")
注釋中指定它們。 這是因為 OpenAPI 規范只允許在每個操作中定義每個 HTTP 狀態代碼一次。
@ApiResponse(responseCode = "400",
description = "Possible reasons: reason 1; reason 2",
content = @Content),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.