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

Allow for multiple overridden types at once #24

Closed
CarstenWickner opened this issue Feb 17, 2020 · 4 comments · Fixed by #35
Closed

Allow for multiple overridden types at once #24

CarstenWickner opened this issue Feb 17, 2020 · 4 comments · Fixed by #35
Assignees
Labels
enhancement New feature or request

Comments

@CarstenWickner
Copy link
Member

CarstenWickner commented Feb 17, 2020

There is already a way to override a given property's type by way of:

  • SchemaGeneratorConfigPart.withTargetTypeOverrideResolver()

However, that only allows for one-to-one replacements -- e.g. replacing all occurrences of an interface with a single implementation that may contain more/different properties.

But what about those cases, where an interface is implemented by multiple types -- e.g. a Pet being either a Cat or a Dog?

The generator (and its configuration) should therefore be extended to:

  1. allow for (multiple) subtypes to be identified,
  2. in case of multiple of those subtypes, they should be included separately via anyOf (since oneOf would require them to be mutually exclusive).
@CarstenWickner CarstenWickner added the enhancement New feature or request label Feb 17, 2020
@CarstenWickner CarstenWickner self-assigned this Mar 2, 2020
@CarstenWickner CarstenWickner linked a pull request Mar 2, 2020 that will close this issue
@CarstenWickner
Copy link
Member Author

CarstenWickner commented Mar 2, 2020

PR #35 introduces the subtype resolution in general – including identified/applicable ones in an "anyOf" block with (for now) one known limitation:

For non-generic subtypes, this should be good to go.

@CarstenWickner
Copy link
Member Author

The above has been released in v4.4.0.

@JanLabrie
Copy link
Contributor

I experienced a problem trying to implement the
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT) strategy.
Details are in the attached document:
SchemaGenerationIssueDetails.pdf

@CarstenWickner
Copy link
Member Author

The reason for the infinite loop is, that the createStandardDefinition() method assumes that you will change the returned definition afterwards and therefore excludes it from the "definitions" stack, which are only visited once.

In your given example, you don't change the returned standard definition but rather want to simply include it and by-pass your own CustomDefinitionProvider. I hadn't considered that before until I encountered the same infinite loop. Therefore, in the linked pull request #35 I introduced a new createStandardDefinitionReference() method for when you do not intend to change that returned definition.

Using createStandardDefinitionReference() should avoid the infinite loop. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

2 participants