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

Geschlossen
#3,399 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
66/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Bereich
api

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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
Vorherrschende Sprache
Java
Sterne
3.7k
Forks
605
Ø Merge
4 T. 18 Std.
Gemergte PRs (30 T.)
21

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus springdoc/springdoc-openapi

Alle Issues in springdoc/springdoc-openapi

Ähnliche Issues

Weitere Issues zu Java

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.