- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 springdoc-openapi 来记录我的 REST API。错误对象返回错误,该对象具有 errorCode
和 message
。我使用 @Schema
注释来记录示例。但是,对于不同的错误,我需要不同的示例。有什么办法吗?
我的代码示例:
@PostMapping(consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
@Operation(summary = "Get new license or retrieve previously issued one for this userId.", tags = "License Endpoint", description = "Licensing operations.",
responses = {
@ApiResponse(
responseCode = "200",
description = "New license or previously issued license for this user, if request was called multiple times.",
content = {@Content(schema = @Schema(implementation = LicenseResponse.class))}
),
@ApiResponse(responseCode = "400",
description = "License can not be retrieved because of either expired bundle or requested bundleId does not exist.",
//I need different example for this error
content = {@Content(schema = @Schema(implementation = LicenseErrorResponse.class))
}
),
@ApiResponse(responseCode = "500",
description = "Internal Error",
//And different example for this error
content = {@Content(schema = @Schema(implementation = LicenseErrorResponse.class))
}
)
}
)
@LoggedIO(input = INFO, result = INFO)
public ResponseEntity<Object> newLicense(@Valid @RequestBody LicenseRequest licenseRequest) {
//content not interesting
}
import javax.validation.constraints.NotBlank;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class LicenseErrorResponse {
// I need different examples for different error in controller.
@Schema(example = "UNKNOWN_BUNDLE_ID", required = true)
private final LicenseErrorCode licenseErrorCode;
@Schema(example = "Bundle doesn't exist, bundleId=com.unknown.id")
private final String message;
@JsonCreator
public LicenseErrorResponse(
@NotBlank @JsonProperty(value = "errorCode") final LicenseErrorCode licenseErrorCode,
@NotBlank @JsonProperty(value = "message") final String message) {
this.licenseErrorCode = licenseErrorCode;
this.message = message;
}
public enum LicenseErrorCode {
EXPIRED_BUNDLE, UNKNOWN_BUNDLE_ID, OTHER
}
}
最佳答案
一种方法是您可以定义一个字符串作为示例
public static final String exampleInternalError = "{\r\n"
+ " \"licenseErrorCode\": 500,\r\n"
+ " \"message\": \"Internal Error\"\r\n" + "}";
same用于显示示例
@ApiResponse(responseCode = "500",
description = "Internal Error",
//And different example for this error
content = @Content(schema = @Schema(implementation = LicenseErrorResponse.class),
examples = @ExampleObject(description = "Internal Error", value = exampleInternalError)))
关于java - springdoc-openapi 不同的例子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61045499/
我正在尝试用 Springdoc 替换手动维护的 swagger 文件。目前,我们使用 ReDoc渲染文件,因为他们支持 discriminator . 是否有直接的方法来替换/取代嵌入式 swagg
我已经在我的 Java 项目的 pom 文件中使用以下工件安装了 swagger-ui: org.springdoc springdoc-openapi-ui
有两种方法可以将 OpenAPI 3 添加到 Spring Boot 项目。 > org.springdoc springdoc-openapi-ui https://www.dariawan.com
我正在尝试为我的 API 中的所有端点添加一个默认错误模型,以获取一些错误代码。 我通过阅读以下问题找到了部分解决方案: Springfox -> Springdoc: How to expose a
我正在使用 Springdoc (1.4.8) 来记录我们的 Rest API。 99% 的调用使用 OAuth2 Bearer Token 进行保护,所以我想像这样默认添加它: new OpenAP
我正在使用具有以下依赖项的 SpringBoot org.springdoc springdoc-openapi-ui 1.5.12
我正在使用 SpringDoc 并尝试以编程方式向 OpenApi 添加模式,但没有成功。 @Bean public OpenAPI customOpenAPI() { Schema
我使用 springdoc-openapi 来记录我的 REST API。错误对象返回错误,该对象具有 errorCode 和 message。我使用 @Schema 注释来记录示例。但是,对于不同的
我有一个 Spring Boot (kotlin) 项目,我使用 springdoc-openapi 来生成 OpenApi 3 规范。我的数据模型如下所示: open class Animal da
我正在尝试使用gradle依赖项来使用springdoc-openapi-ui。 马文 org.springdoc springdoc-openapi-ui 1
我有一个 Spring boot Gradle 项目,我想获取它的 OpenAPI 规范 YAML 文件。 据我了解官方swagger-core不支持 Spring boot 项目,所以我找到了 sp
如何更改 swagger-ui 的布局? 对于布局选项,您可以使用 swagger-ui 配置选项。这是什么意思? 例如: springdoc.swagger-ui.layout=BaseLayout
我正在尝试在多模块 gradle 项目中使用 Springdoc,但我无法使其工作。 有人已经做过类似的事情了吗? 我的 Gradle 项目结构如下所示: 我的项目 申请 模块1 接口(interfa
网络上没有关于如何使用 springdocs-openapi 库 (1.5.7) 获得以下输出的好例子。我希望获得以下输出: [ "A", "B", "C" ] 这是基于提供的示例的代码。 @Op
网络上没有关于如何使用 springdocs-openapi 库 (1.5.7) 获得以下输出的好例子。我希望获得以下输出: [ "A", "B", "C" ] 这是基于提供的示例的代码。 @Op
我有以下 Controller 代码: public abstract class BaseController { @Operation @GetMapping
我有一个现有的 Spring 4 API,并已成功集成 springdoc-openapi 以在 JSON/YAML 中生成 OpenAPI 3 规范,还使用 springdoc-openapi
我有以下SecurityScheme使用 springdoc-openapi 为 java SpringBoot RESTful 应用程序定义: @Bean public OpenAP
我正在尝试使用 spring boot 和 GraalVM Native Image 创建一个示例应用程序,但是一旦我添加了 Springdoc 的依赖项,生成的可执行文件就不再工作了,原因如下:
我正在运行 springdoc-openapi-maven-plugin,具有以下(标准)配置: org.springdoc spri
我是一名优秀的程序员,十分优秀!