oapi-codegen
oapi-codegen copied to clipboard
fix: #1530 use discriminator with several mappings for one schema
I've decided I'll give it a try but as long as fixing ValueByDiscriminator seems pretty straightforward, it requires some more changes to support proper generation of FromX and MergeX methods.
Let's assume our Dog has breeds [ beagle, poodle ]. It will produce a code:
func (t *Pet) FromDog(v Dog) error {
v.Breed = "beagle"
v.Breed = "poodle"
b, err := json.Marshal(v)
t.union = b
return err
}
which seems fair if you're not planning to use it, but it compiles only if we specify our breed as required.
I am not fully aware of the intentions behind setting the mapping field in these methods, so I'm not sure if resigning from setting the field is the solution here.
Another pair of 👀 would be much appreciated. Cheers!