-
Notifications
You must be signed in to change notification settings - Fork 147
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
Too many cases generated when oneOf discriminator has explicit mappings #297
Comments
JanC
changed the title
Too many cases generated when discriminator has an explicit mapping
Too many cases generated when oneOf discriminator explicit mappings
Jan 25, 2022
JanC
changed the title
Too many cases generated when oneOf discriminator explicit mappings
Too many cases generated when oneOf discriminator has explicit mappings
Jan 25, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I noticed that when I set an explicit mappings to a
discriminator
, the default mapping remain in the generated code when decoding.Given this spec
The generated
SingeAnimal.swift
containsSwagGen/Specs/TestSpec/generated/Swift/Sources/Models/SingleAnimal.swift
Lines 16 to 25 in 2b3140b
As you can see, the switch on the
discriminator
value contains both the explicit mappingscat
dog
,woof
values but also what seems to be the implicit mappings by the name of the referenceCat
andDog
.Since I supply explicit mappings, I would expect only the explicit ones to be present:
I think that if we detect an explicit mapping for a type, we should remove the implicit one in CodeFormatter.swift#L216
So just adding
mapping.removeValue(forKey: reference.name)
here would work:@yonaskolb any thoughts? If you agree with the approach, I can open a PR.
I used the specs.yaml from the repo but for reference I put the relevant part here:
The text was updated successfully, but these errors were encountered: