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

Chiusa
#3,399 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 9 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
66/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java, kotlin, spring-boot
Ambito
api

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Java
Stelle
3.7k
Fork
605
Merge medio
9g 11h
PR unite (30g)
14

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di springdoc/springdoc-openapi

Tutte le issue di springdoc/springdoc-openapi

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.