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

@JsonUnwrapped is ignored when PolymorphicConverter is enabled #2640

Closed
ghost opened this issue Jul 8, 2024 · 2 comments
Closed

@JsonUnwrapped is ignored when PolymorphicConverter is enabled #2640

ghost opened this issue Jul 8, 2024 · 2 comments

Comments

@ghost
Copy link

ghost commented Jul 8, 2024

Describe the bug

After upgrading to version 2.6.0 of springdoc-openapi we have found that properties included via @JsonUnwrapped aren’t present in the generated model schema.

We assume that the PolymorphicModelConverter causes the problem, since if we disable the polymorphic converter, the generated model looks like expected.

To Reproduce

  • Spring-Boot: v3.3.1
  • Spring Doc OpenAPI Packages:
    • springdoc-openapi-starter-webmvc-ui v2.6.0
  • Create a model including properties annotated with @JsonUnwrapped
  • set springdoc.model-converters.polymorphic-converter.enabled=true

The model generated by the example project doesn't include the properties of the @JsonUnwrapped annotated property:

{
  "schemas": {
    "RootModel": {
      "type": "object",
      "properties": {
        "rootProperty": {
          "type": "integer",
          "format": "int32"
        }
      }
    }
  }
}

Example project: springdoc-json-unwrapped-ignored.zip

Expected behavior

The expected schema should include all properties including those of the unwrapped property:

{
  "schemas": {
    "RootModel": {
      "type": "object",
      "properties": {
        "rootProperty": {
          "type": "integer",
          "format": "int32"
        },
        "unwrappedProperty": {
          "type": "integer",
          "format": "int32"
        }
      }
    }
  }
}
@EvaristeGalois11
Copy link
Contributor

This is caused by the fix for #2597

Disabling the polymorphic converter is a possibility, but another less intrusive solution is to manually specify the classes that contains @JsonUnwrapped fields in the SpringDocUtils#addParentType method. This way the polymorphic converter should still work fine.

For example taking as a reference your attached project @andreasbannachdmde this is how it's done :

@SpringBootApplication
public class SpringdocJsonUnwrappedIgnoredApplication {

    public static void main(String[] args) {
        SpringDocUtils.getConfig().addParentType(RootModel.class.getSimpleName());
        SpringApplication.run(SpringdocJsonUnwrappedIgnoredApplication.class, args);
    }

}

@ThomHurks
Copy link

A project that I'm working on is affected by this bug as well. We use @JsonUnwrapped quite a lot to have less code duplication between DTOs, and this breaks our openapi specs with 2.6.0. I tried the SpringDocUtils.getConfig().addParentType() workaround, but strangely it did not work in our project. For now I've reverted to SpringDoc version 2.5.0 and that one works fine. I did notice that the description fields have also disappeared from DTO openapi specs (the ones that are gathered by therapi from the JavaDoc in the DTOs) but that is likely a different bug; that also worked fine in pre 2.x versions of SpringDoc. Regardless, thanks for working on this project, we really like using it ❤️

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

2 participants