-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[Typescript-Node] Incorrect serialization of subclasses in generated code #100
Comments
Where are The subclass case is interesting. The spec requires the described behavior (i.e. send the sub class) in the case of a It looks like the serializer just does not take into account |
@TiFu sorry, my mistake.. I boiled this spec down from a larger one, and I seemed to have left parts out. Let me fix. |
@TiFu fixed. |
Thanks! Why does But this shows another issue: I think this might also happen if the The root cause for this seems to be the handling of |
@TiFu PricePointRestriction is the base class. So this is in the generated client, so at this point oneOf/allOf/anyOf aren't really things. The classes have already been generated outwith their given properties, inheritance tree, and the discriminator values, etc. So I actually think this is correct for handling the subclassed case. At this point in the process I believe we are looking at regular old polymorphic objects with the discriminator for a little help. |
Thanks for the clarification. Let's ignore the I'm torn on what the correct behavior in this case is. There are basically two options:
IMO 2. feels messy and is bad design. The endpoint includes knowledge about subclasses which might not yet exist (imagine if you add another type of restriction), so adding a new subclass of I guess there's a reason why |
I mean, yes the server would need to know about both types and use the discriminator possibly, but such is inheritance. In our business domain, EntityRestriction is more specific. Really a better name would be "EntityPricePointRestriction", which is a specific type of PricePointRestriction that adds on an entityId and entityType. If we went with #1 (the current behavior) that would essentially eliminate the ability to use polymorphism in an Swagger 2.0 spec... which really isn't great. If my understanding of OpenAPI 3.0 is correct, you could use "anyOf" (provided the serializer supported it) rather than inheritance. I don't really see a good reason to disallow the inheritance though. |
Oh okay. I see your point now. Sorry for being so slow xD. |
Description
When using a generated client, serialization only looks at the referenced type when serializing properties of the object. If you are using inheritance, you will lose properties of the subclasses when you serialize.
Openapi-codegen version
3.0.0
Swagger declaration file content or url
Command line used for generation
java -jar .\openapi-generator-cli.jar generate -i /path/to/swagger.yaml -l typescript-node -o /path/to/target/directory
Steps to reproduce
With the generated code, run the following:
If you step into the updatePricePoint call to where it goes to serialize the list of restrictions, you'll notice that entityId and entityType get left off the serialized object, so that when it is sent onto the server, it is invalid.
The text was updated successfully, but these errors were encountered: