Property type "null" is missing if Kotlin property name does not equal OpenAPI property name

已关闭
#3,399 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 9 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
66/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
api

调研方向

Start by reproducing the issue with the supplied Kotlin Request model and inspect the generated OpenAPI schema for its three properties. Trace how schema generation handles Kotlin nullability and the @JsonProperty name. Done means the type: "null" output is consistent for properties whether or not their JSON names match their Kotlin names.

由索引模型根据 Issue 内容生成。

描述

Describe the bug

  • A nullable Kotlin property gets type: "null" when the @JsonProperty name equals the Kotlin property name, but not if the names are different.

To Reproduce

  • springdoc-openapi-starter-webmvc-ui 3.2.0
  • Spring Boot 4.1.2
  • Kotlin 2.3.21 with JDK 21
  • com.fasterxml.jackson.core:jackson-core:2.21.7
  • tools.jackson.core:jackson-core:3.1.7
import com.fasterxml.jackson.annotation.JsonProperty
import io.swagger.v3.oas.annotations.media.Schema
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RestController

@SpringBootApplication
class SpringdocBugApplication

fun main(args: Array<String>) {
  runApplication<SpringdocBugApplication>(*args)
}

data class Request(
  @get:Schema(description = "JSON name == property name -> schema contains type \"null\"")
  val myproperty1: String? = null,

  @get:JsonProperty("myproperty2_suffix")
  @get:Schema(description = "JSON name != property name -> no \"null\" type in schema")
  val myproperty2: String? = null,

  @get:Schema(
    nullable = false,
    description = "JSON name == property name and \"nullable = false\" -> schema contains type \"null\""
  )
  val myproperty3: String? = null,
)

@RestController
class Controller {
  @PostMapping("/test")
  fun test(@RequestBody r: Request) = Unit
}

Resulting OpenAPI spec:

openapi: 3.1.0
# ...
components:
  schemas:
    Request:
      type: object
      properties:
        myproperty1:
          type:
          - string
          - "null"
          description: JSON name == property name -> schema contains type "null"
        myproperty3:
          type:
          - string
          - "null"
          description: JSON name == property name and "nullable = false" -> schema
            contains type "null"
        myproperty2_suffix:
          type: string
          description: JSON name != property name -> no "null" type in schema

Expected behavior

  • Type "null" should be assigned consistently for all properties, not depending on Kotlin property name
主要语言
Java
星标
3.7k
派生
605
平均合并
9 天 11 小时
30 天内合并 PR
14

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

springdoc/springdoc-openapi 的其他 Issue

查看 springdoc/springdoc-openapi 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。