-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Fix XML annotations on model properties (JavaSpring) #18392
Fix XML annotations on model properties (JavaSpring) #18392
Conversation
* generate JAXB annotations for attributes and elements * generate wrapper annotations (JAXB and Jackson) * use XML config from items for annotations of containers
0879303
to
e588bdb
Compare
Shouldn't the changes be done to modules/openapi-generator/src/main/resources/JavaSpring/xmlAnnotation.mustache? Looking at that file, i believe it would also be cleaner to include it as well at line 217 ... or even better, remove it from there completely – in my tests with Jackson it was totally sufficient to have the annotation on the field rather than the getter. |
@Philzen: Thanks for having a look. The Having the annotations on either the field or the getter doesn't make much of a difference in my experience as well. I had some issues with conflicting annotations on getters and fields in the past, so they should probably be all in one place. As the |
Of course, you're right, i missed that bit.
I know of at least one edge case that can feel like kind of a footshot: when you have a public variable that has a different name than its getter (e.g.
Thanks looking into the file history and providing this commit as context! However the link does not work this way in markdown, leaving the working one here for reference: 69a4a65 |
@chschu Happy to report i was able to whip up a basic test: Philzen@df55a9d I would like to add some refactoring, then also fix the default Java generators and finally add some more tests that also cover the JAXB-related annotation aspects before assembling everything into a joint PR. Kindly allow me some more time to finalize that. If you have any suggestions which aspects should be covered as part of the test as well i'd be more than happy to hear them in the meanwhile. |
Note to self: Also add dedicated tests whether |
Looks like this PR could also close #9371 |
@Philzen Nice, thank you for the test! I'm really looking forward to the joint PR. I think the test could also check if the @JacksonXmlProperty(localName = "Tag")
@JacksonXmlElementWrapper(localName = "tag") The property has an explicit XML wrapper name of "tag" (line 91 in the yaml), and an an XML element name of "Tag" (line 60 in the yaml). The wrapper could also be changed to something like "TagList" to distinguish it from the item. Maybe @JacksonXmlProperty(isAttribute = true, localName = "name") Are the JAXB annotations ( |
@chschu Thanks for your valuable feedback!
Done: Philzen@837a0a7
Done: Philzen@2db2b7b
Done: Philzen@a0afca5 If OK with you, i shall open a new PR when as soon as i'm happy with the branch, as i cannot push to your repo. Before that, i still have a couple of things to review:
|
@Philzen That's more than OK with me. Thank you for the effort you put into fixing this! Once your PR is ready, I'll close this one. |
Closing this in favor of #18870 (which includes your commit) |
This PR fixes the annotations generated by the
JavaSpring
generator when usingwithXml: true
. It is related to #2417, #5078 and #5764.@XmlAttribute
and@JacksonXmlProperty
using the property's XML configuration.@XmlElement
and@JacksonXmlProperty
using the property's XML configuration.@XmlElement
and@JacksonXmlProperty
using the container items' XML configuration.wrapped: true
in its XML configuration, the generator will additionally produce@XmlElementWrapper
and@JacksonXmlElementWrapper
using the container's XML configuration.wrapped: true
in its XML configuration, the generator will additionally produce@JacksonXmlElementWrapper(useWrapping = false)
. IIRC, different Jackson versions behave differently if the annotation is not presentPR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming 7.1.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)