Description
The bug involves this PR
#2626
It works when the page is directly returned by the controller, but if wrapped in a ResponseEntity the generated schema for PagedModel's content
is generic object
instead of the DTO passed as type.
I tracked down the issue to
dd30b9d#diff-aa17a2514af0e0de9a296e748f33bffb9baa551038dcfbf2f959a46bc20764b1R96
where the the block responsible for typing page content is put behind a instanceof check that will fail for ResponseEntity wrapped response, because the pageType gets recognized as SimpleType
unlike what happens when the Page is returned directly, where pageType results of ParameterizedType
.
Steps to reproduce the behavior:
- SpringBoot 3.4
- springdoc-openapi-starter-webmvc-ui 2.8.5
public record UserDto(
String id,
String email,
)
@RestController
public class HelloController {
@GetMapping("/page-simple")
public ResponseEntity<Page<UserDto>> pageSimple() {
return ResponseEntity.ok(pageImpl(new UserDto("someId", "someName")));
}
}
@SpringBootApplication
@EnableSpringDataWebSupport(pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO)
public static class SpringDocTestApp {
}
Expected behavior
current schema
...
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PagedModel"
}
}
}
},
...
"PagedModel": {
"type": "object",
"properties": {
"content": {
"type": "array",
"items": {
"type": "object"
}
...
expected schema
...
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PagedModelUserDto"
}
}
}
},
...
"PagedModelUserDto": {
"type": "object",
"properties": {
"content": {
"type": "array",
"items": {
"$ref": "#/components/schemas/UserDto"
}
...
Issue is not present returning a ResponseEntity<PagedModel>
explicitly
return ResponseEntity.ok(new PagedModel(pageImpl(new UserDto("someId", "someName"))));
but that completely defeats the goal of the VIA_DTO configuration