简体   繁体   English

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

[英]Swagger 3 / OpenApi How to add two descriptions to the same status code

I am trying to do some documentation to my small api.我正在尝试为我的小 api 做一些文档。 What should I do in situation when on status code 400 I can have 2 possible descriptions?在状态码 400 上我可以有 2 种可能的描述时,我应该怎么做? I would like to do something like:我想做类似的事情:

@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);
}

Is it possible to define the same status multiple times?是否可以多次定义相同的状态?

You'll need to merge the two descriptions and specify them within the same @ApiResponse(description = "...") annotation.您需要合并这两个描述并在同一个@ApiResponse(description = "...")注释中指定它们。 This is because OpenAPI Specification only allows defining each HTTP status code once per operation.这是因为 OpenAPI 规范只允许在每个操作中定义每个 HTTP 状态代码一次。

@ApiResponse(responseCode = "400",
    description = "Possible reasons: reason 1; reason 2",
    content = @Content),

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 OpenApi Spring 上添加不同的@Schema 描述? - How to add different @Schema descriptions on OpenApi Spring? java spring openApi:swagger请求返回状态码403 - java spring openApi : swagger request returns status code 403 从 OpenAPI 规范生成代码,包括示例和描述 - Generate code from OpenAPI spec including examples and descriptions 如何在openApi / springfox-swagger2中为不同的状态代码定义不同的响应模型 - How to define different response models for different status codes in openApi / springfox-swagger2 OpenAPI/Swagger 构建具有多个相同键的对象 - OpenAPI/Swagger building objects with multiple same keys 如果添加带有 WebMvcConfigurationSupport 的转换器,Swagger OpenAPI 3 不会显示在 springboot 2 上 - Swagger OpenAPI 3 not display on springboot 2 if add Converter with a WebMvcConfigurationSupport OpenAPI Generator / Swagger Codegen:如何在生成所有文件后添加函数 - OpenAPI Generator / Swagger Codegen: How to add a function after all files have been generated 如何使用 springdoc-openapi-maven-plugin 和 swagger-codegen-maven-plugin 生成客户端代码? - How to generate client code using springdoc-openapi-maven-plugin and swagger-codegen-maven-plugin? 如何在 Gradle for OpenAPI 3.0 中使用 Swagger Codegen? - How to use Swagger Codegen in Gradle for OpenAPI 3.0? 如何使用 OpenAPI 3 Swagger 注释指定列表 - How to specify a list using OpenAPI 3 Swagger annotations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM