-
Notifications
You must be signed in to change notification settings - Fork 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
SubClass annotations are missing from the base class #2449
Comments
@yaelah thanks for the detailed above. Would you have cycle to contribute a fix? Here is a good starting point: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/Java/model.mustache |
Similar ticket: #1253 |
I have a fix for this. What is the process for submitting patches? I have never submitted anything to this project before. |
… base class. Added a children property to CodegenModel and write out the necessary annotations.
Please refer to https://github.com/swagger-api/swagger-codegen/blob/master/CONTRIBUTING.md for contributing guidelines. If you need help, just reply to let us know. |
…from the base class." This reverts commit ff0cefe.
… base class. Added a children property to CodegenModel and write out the necessary annotations.
Thanks for noticing my wrong email. |
… base class. Added a children property to CodegenModel and write out the necessary annotations.
…from the base class." This reverts commit ff0cefe.
… base class. Added a children property to CodegenModel and write out the necessary annotations.
Hi guys, |
@wing328 Do you know anything about progress on this? |
I believe @yaelah has fixed the issue in his branch but didn't have time to submit a PR yet. Can you test his fix via https://github.com/yaelah/swagger-codegen to see if it resolves the issue for you? If the fix works, I can cherry-pick the commits to submit a PR for the fix. |
I modified @yaelah post to work on the latest master branch. I have been using this for a while now, hope it helps. One issue I did notice is that it won't apply to sub-sub classes. Update: the sub-sub class issue has now been fixed in my latest pr commit. |
@szakrewsky I added a comment to the PR #4085. Please take a look when you've time. |
+1 |
How is the discriminator value determined for the name property of the But if a discriminator property value for a sub class is not the name of the class, but another string, how can that be determined? This may need to be addressed in a new issue, but simply wanted to raise it here to see if anyone has ideas. My idea is to add a codegen vendor extension that can be used to state the discriminator value in a subclass - maybe
|
@jeff9finger I have seen a similar issue. The spec (http://swagger.io/specification/) for the discriminator field says
And since the class name is the schema name its all good. |
Using the classname is a good default (in fact, it looks to be the only thing that makes sense). But in some cases, the discriminator value needs to be something other than the class name. I have used a vendor extension "x-discriminator-value" on each subclass. This value contains the value from the enumeration defined for that subclass. Changed the template to handle that value if it exists (otherwise, use name as before). This works perfectly for my. I'd like to see it in the master branch so I don't have to have my own templates.... Anyone else having this issue? |
Isn't this fixed by #4085? |
I think so. |
… class (swagger-api#4085) * petstore up to latest * Issue swagger-api#2449 SubClass annotations are missing from the base class * include child in all its super types
In order for jackson ObjectMapper to deserialize correctly a base class to its subclasses, we need to include annotations defining all expected subclasses in the parent class.
The codegen currently does not generate those annotations.
For this example YAML:
definitions:
Base:
type: object
discriminator: disc
properties:
disc:
type: string
required:
- disc
SubClass:
allOf:
- $ref: '#/definitions/Base'
required:
- field
properties:
field:
type: string
Jackson expects these annotations to be produced, but they are not:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "disc")
@JsonSubTypes({ @type(value = SubClass.class, name = "SubClass") })
public class Base {
}
The text was updated successfully, but these errors were encountered: