Skip to content

Regression: Generated Api Doc does not mark fields as required in Kotlin #3203

@simonhauck

Description

@simonhauck

Describe the bug

After Upgrading our Kotlin project to SpringBoot 4 and updating this library to 3.0.1 we noticed a change in the generated open-api specification.

Fields that are by Kotlin language definition Not-Null are now no longer marked as required. This worked in previous versions.

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using: 4.0.1
  • What modules and versions of springdoc-openapi are you using: 3.0.1
  • What is the actual and the expected result using OpenAPI Description (yml or json)?

Actual openApi.json

{
  "openapi": "3.1.0",
  # ....
  "components": {
    "schemas": {
      "HelloWorld": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string"
          }
        }
      }
    }
  }
}

Expected:

{
  "openapi": "3.1.0",
  # ...
  "components": {
    "schemas": {
      "HelloWorld": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string"
          }
        },
        "required": [
          "message"
        ]
      }
    }
  }
}
  • Provide with a sample code (HelloController) or Test that reproduces the problem
@RestController
@SpringBootApplication
class DemoOpenApiApplication{

	@GetMapping("/hello")
	fun hello(): HelloWorld {
		return HelloWorld("Helo world")
	}
}

data class HelloWorld(
	@field:NotNull val message: String)

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

Expected behavior

Fields that are by Kotlin Language definition not null, should be marked as required

Additional context
A minimal reproducable example can be found here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions