繁体   English   中英

Swagger 3 / OpenApi 如何为同一个状态码添加两个描述

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM