spring-boot - 使用 SpringDoc OpenAPI,Double 和其他非原始数字不会被标记为可为空
问题描述
我们将 SpringDoc OpenAPI 与 SpingBoot 2.3 和 WebFlux 一起使用,并在其之上拥有 Swagger UI(更准确地说是 springdoc-openapi-webflux-ui 1.4.8)。
最近,我们注意到无法区分可空/可选数字 (Double) 和原始数字 (double)。
例如下面的类
@With
@Value
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CurrencyBalanceDto {
double balance;
Double hardCapping;
}
产生以下 OpenAPI Schema
"CurrencyBalanceDto": {
"type": "object",
"properties": {
"balance": {
"type": "number",
"format": "double"
},
"hardCapping": {
"type": "number",
"format": "double"
}
}
}
基于https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#schemaNullable,我希望 hardCapping 属性具有"nullable": true
解决方案
提供的链接中的文档引用:
nullable boolean 允许为定义的模式发送空值。默认值为 false。
所以默认情况下,所有字段都不能为空。您需要通过使用注释或使用明确地将字段设置为可@Null
为@Nullable
空@Schema(nullable = true)
推荐阅读
- mysql - 无法使用 mysql docker 容器在 docker-entrypoint-initdb.d 中创建数据库
- python - 关于python中的导入模块
- php - 警告在 php 中遇到的非数字值
- ios - Core Data 在一对多关联中双插入子记录
- python - 如何从文件中将值添加到现有的空值键字典?
- segmentation-fault - 即使访问的地址可访问,是否也可能导致段错误?
- c# - 用于将路由模板与请求路径匹配的正则表达式
- python - 如何使用 pexpect 在多个文件上运行 osm2pgsql?坚持“使用 PBF 解析器”。
- cmake - 在另一个目标中包含一个目标的包含目录
- reactjs - React Router 在页脚上渲染页面