【发布时间】:2021-05-11 10:16:02
【问题描述】:
我正在使用 Spring boot + webflux + r2dbc 来实现一个 REST API Server。
为模型生成的架构复制了具有不同定义(名称、限制等)的相同字段。
我的模特:
data class Extension(
@Column("number")
@JsonProperty("number", required = true)
@Pattern(regexp = "^[0-9]{6,}\$")
@Schema(description = "The number", example = "12345007100")
val number: String,
@Column("tenant_id")
@JsonProperty("tenant_id", required = true)
@Pattern(regexp = "^[0-9]{5}\$")
@Schema(name = "tenant_id", description = "The ID of the Tenant", example = "12345")
val tenantId: String,
)
路由器
@Bean
fun extensionsRoutes(): RouterFunction<ServerResponse> {
return SpringdocRouteBuilder.route()
.GET(
path("/extensions").and(accept(MediaType.APPLICATION_JSON)),
handler::getAll
) { ops ->
ops
.tag(tag)
.operationId("operation id")
.summary("summary")
.description("description")
.response(
responseBuilder()
.responseCode("200")
.description("The list of all Extensions")
.implementationArray(Extension::class.java)
)
}
为Extension 模型生成的 OpenAPI 架构
Extension:
required:
- number
type: object
properties:
number:
pattern: "^[0-9]{6,}$"
type: string
description: The number
example: "12345007100"
tenant_id:
pattern: "^[0-9]{5}$"
type: string
description: The ID of the Tenant to which the Extension belongs
writeOnly: true
example: "12345"
tenantId:
type: string
我有两个字段:tenant_id 和tenantId,但这是模型中的同一个字段。另请注意,tenantId 的定义忽略了架构属性(如 required 和 pattern 属性)。
我缺少一些注释?似乎我缺少一些注释来指示该字段已在定义中的 springdoc 库。
【问题讨论】:
标签: spring-boot spring-webflux springdoc-openapi-ui