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

Do not strip discriminator property in oneOf generation. #268

Merged
merged 4 commits into from
Mar 5, 2024
Merged

Conversation

cjbooms
Copy link
Owner

@cjbooms cjbooms commented Mar 1, 2024

As per title and Issue #258 it does not seem correct to be stripping a declared property from the data classes.

Instead, adopt the same approach as allOf polymorphism and default the discriminator to the correct value

@@ -462,22 +465,8 @@ class JacksonModelGenerator(
extensions: Map<String, Any>,
oneOfInterfaces: Set<SchemaInfo>,
): TypeSpec {
val filteredProperties = if (oneOfInterfaces.size == 1) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the logic in question. I'm not sure of the intent here, but perhaps @pschichtel can weigh in before I revert it

Copy link
Contributor

@pschichtel pschichtel Mar 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the logic is:

if:

  • the super interface' model defines a discriminator field
  • the discriminator mappings map to the current model exactly once

then:

  • remove the discriminator field, since it must always be the same value given by the jackson type info field.

@pschichtel
Copy link
Contributor

I personally think this is a mistake.

@cjbooms cjbooms requested a review from averabaq March 5, 2024 07:46
Copy link
Collaborator

@averabaq averabaq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@cjbooms cjbooms merged commit 61af512 into master Mar 5, 2024
1 check passed
@ulrikandersen ulrikandersen deleted the fix-one-of branch October 18, 2024 12:09
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

Successfully merging this pull request may close these issues.

3 participants