Description
Describe the bug
When creating multiple nested DTOs with the same name only one is created in the OpenAPI spec.
Example:
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController
@RestController
class FooController {
@GetMapping("/v1/foo")
fun foo1(): Foo1Res {
TODO()
}
@GetMapping("/v2/foo")
fun foo2(): Foo2Res {
TODO()
}
}
data class Foo1Res(
val foo: FooInner,
) {
data class FooInner(
val bar: String,
)
}
data class Foo2Res(
val foo: FooInner,
) {
data class FooInner(
val somethingElse: Int,
)
}
Spec generated:
{
// ...
"components": {
"schemas": {
"Foo2Res": {
"type": "object",
"properties": {
"foo": {
"$ref": "#/components/schemas/FooInner"
}
},
"required": [
"foo"
]
},
"FooInner": {
"type": "object",
"properties": {
"somethingElse": {
"type": "integer",
"format": "int32"
}
},
"required": [
"somethingElse"
]
},
"Foo1Res": {
"type": "object",
"properties": {
"foo": {
"$ref": "#/components/schemas/FooInner"
}
},
"required": [
"foo"
]
}
}
}
}
To Reproduce
Steps to reproduce the behavior:
-
What version of spring-boot you are using?
3.4.5 -
What modules and versions of springdoc-openapi are you using?
I can reproduce in a minimal SpringBoot app created from Spring initializr. Only adding Spring Weba and Springdoc openapi
Tested with springdoc openapi 2.8.8 -
What is the actual and the expected result using OpenAPI Description (yml or json)?
The generated spec should either have those objects in line or provide separate names.
Currently the wrong FooInner is used leading to incorrect an API spec -
Provide with a sample code (HelloController) or Test that reproduces the problem
See above