Skip to content

Any? is generated with type of null in 3.0.3 #3273

@petergphillips

Description

@petergphillips

Describe the bug
After the upgrade from springdoc 3.0.2 to 3.0.3 we've noticed that

  val anyName: Any? = null,

gets generated as

          "anyName" : {
            "type" : "null"
          }

This causes problems with the openapi generator as it then thinks that the type can only be null and tries to generate a Null type etc.

Under springdoc 3.0.2 the same code generated:

          "anyName" : { }

To Reproduce

  • What version of spring-boot you are using? 4.0.5
  • What version of kotlin are you using? 2.3.20
  • What modules and versions of springdoc-openapi are you using? 3.0.3
  • What is the actual and the expected result using OpenAPI Description (yml or json)? See above for actual and also the generated code in 3.0.2. I would expect the type not to just be "null".
  • Provide with a sample code (HelloController) or Test that reproduces the problem
@RestController
class IssuesController {
  @GetMapping("/")
  fun greet(greeting: Greeting): String = greeting.anyName?.toString() ?: "Hello World"
}

data class Greeting(
  val anyName: Any? = null,
)

Expected behavior
Note that if the field is defined as

  val stringName: String? = null,

then the generated code is

            "type" : [ "string", "null" ]

I think it is therefore because Any doesn't have a type and therefore null just gets inserted instead. I guess one option is to remove the null if it is the only type found?

Additional context
Looks to be a side effect of #3256.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions