gpt4 book ai didi

java - Swagger 和 Springfox 更改不同状态代码的示例响应

转载 作者:行者123 更新时间:2023-12-05 04:44:38 25 4
gpt4 key购买 nike

我有一个特定的 DTO,我正在使用它作为 Swagger 文档的示例返回。如果我有成功的 201 代码,我该如何更改示例?

招摇的示例响应:

Example responses in swagger

我使用注释“@ApiModelProperty”来描述我的对象,但找不到如何更改不同响应代码示例的方法。在我的代码中,我不想显示错误列表,因为它是一个可选属性,并且只有在生成非 201 代码时才可用。

想法?

最佳答案

您可以使用如下几个注释来完成此操作:

import io.swagger.v3.oas.annotations.media.ExampleObject;

@Operation(summary = "Your summary")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Your description",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = YourModel.class),
examples = [@ExampleObject(value = "{\"timestamp\": 1581552186590, \"status\": 404, \"error\": \"Not Found\", \"message\": \"Error message\", \"requestId\": \"62bcf95d\"}")]) })})

关于java - Swagger 和 Springfox 更改不同状态代码的示例响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69320147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com