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

Đã đóng
#3,399 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 9 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
66/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java, kotlin, spring-boot
Lĩnh vực
api

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Java
Star
3.7k
Fork
605
Merge trung bình
9 ngày 11 giờ
Pull request đã merge (30 ngày)
14

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của springdoc/springdoc-openapi

Tất cả issue của springdoc/springdoc-openapi

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.