【问题标题】:Spring WebFlux OpenAPI - override model/schema field nameSpring WebFlux OpenAPI - 覆盖模型/模式字段名称
【发布时间】: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


    【解决方案1】:

    终于找到问题了。我正在使用 kotlin,我们需要添加以下依赖项:

    <dependency>
       <groupId>org.springdoc</groupId>
       <artifactId>springdoc-openapi-kotlin</artifactId>
       <version>1.5.8</version>
    </dependency>
    

    这在https://www.baeldung.com/spring-rest-openapi-documentation 有很好的记录,但我错过了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-11
      • 2021-09-09
      • 2010-10-29
      • 1970-01-01
      • 2019-07-25
      • 2012-05-10
      • 1970-01-01
      相关资源
      最近更新 更多