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

クローズ
#3,399 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 9 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
66/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java, kotlin, spring-boot
領域
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時間
マージ済み PR(30日)
14

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

springdoc/springdoc-openapi のほかの issue

springdoc/springdoc-openapi の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。