Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong schema generation with PagedModel generated VIA_DTO and wrapped in ResponseEntity #2933

Closed
Gianpiero-3di opened this issue Mar 6, 2025 · 0 comments

Comments

@Gianpiero-3di
Copy link

Gianpiero-3di commented Mar 6, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant