Skip to content

[JAVA] [SPRING] [PKMST] [MICRONAUT] XML wireformat: Fix Jackson useWrapping=false, JAXB+Jackson namespaces#18870

Merged
wing328 merged 26 commits intoOpenAPITools:masterfrom
Philzen:bugfix/JavaSpring-Jackson-XML-Annotations
Jun 15, 2024
Merged

[JAVA] [SPRING] [PKMST] [MICRONAUT] XML wireformat: Fix Jackson useWrapping=false, JAXB+Jackson namespaces#18870
wing328 merged 26 commits intoOpenAPITools:masterfrom
Philzen:bugfix/JavaSpring-Jackson-XML-Annotations

Conversation

@Philzen
Copy link
Contributor

@Philzen Philzen commented Jun 6, 2024

Closes #2417
Closes #3223
Closes #5078
Closes #18869

Replaces #18392

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (For Windows users, please run the script in Git BASH)
    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.
  • File the PR against the correct branch: master (upcoming 7.6.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@Philzen Philzen force-pushed the bugfix/JavaSpring-Jackson-XML-Annotations branch from 61b59ba to 5728693 Compare June 6, 2024 06:57
@Philzen Philzen changed the title Bugfix/java spring jackson xml annotations [JAVA] [SPRING] Bugfix/java spring jackson xml annotations Jun 6, 2024
@Philzen Philzen self-assigned this Jun 6, 2024
@Philzen Philzen added Client: Java Server: Java Server: Spring java Pull requests that update Java code Issue: Bug Wireformat: XML XML formatted API capabilities labels Jun 6, 2024
@Philzen Philzen changed the title [JAVA] [SPRING] Bugfix/java spring jackson xml annotations [JAVA] [SPRING] [PKMST] Bugfix/java spring jackson xml annotations Jun 6, 2024
@Philzen Philzen changed the title [JAVA] [SPRING] [PKMST] Bugfix/java spring jackson xml annotations [JAVA] [SPRING] [PKMST] [MICRONAUT] XML wireformat: Fix Jackson useWrapping=false, JAXB+Jackson namespaces Jun 6, 2024
@Philzen Philzen force-pushed the bugfix/JavaSpring-Jackson-XML-Annotations branch 2 times, most recently from 8e293d4 to f444467 Compare June 6, 2024 10:20
@Philzen
Copy link
Contributor Author

Philzen commented Jun 6, 2024

Hey @chschu! Sorry for this being held up for so long... i've now finally got around to open this PR.

Following our discussions, could you briefly review this and see if you have anything to add? Would be looking forward to your feedback, and otherwise these fixes finally hitting the 7.7 release :)

@Philzen Philzen force-pushed the bugfix/JavaSpring-Jackson-XML-Annotations branch from f444467 to d5bcb30 Compare June 6, 2024 11:05
@Philzen Philzen force-pushed the bugfix/JavaSpring-Jackson-XML-Annotations branch 4 times, most recently from 3ef690c to 2fca7c7 Compare June 6, 2024 14:41
@Philzen Philzen marked this pull request as ready for review June 7, 2024 13:04
@Philzen Philzen added this to the 7.7.0 milestone Jun 11, 2024
@Philzen
Copy link
Contributor Author

Philzen commented Jun 13, 2024

@wing328 if you have some time at the weekend i'd highly appreciate this PR going into v7.7 if possible.

I haven't heard back from @chschu which is co-author of this fix (which actually kickstarted my contributions here as it pointed me into the right direction), but from our discussion over at #18392 they seemed already pretty satisfied at the time.

@Philzen Philzen force-pushed the bugfix/JavaSpring-Jackson-XML-Annotations branch from 2fca7c7 to 16a725b Compare June 13, 2024 22:58
chschu and others added 6 commits June 14, 2024 01:30
* generate JAXB annotations for attributes and elements

* generate wrapper annotations (JAXB and Jackson)

* use XML config from items for annotations of containers
…tter if enabled

This is in line with the way the class annotations in `xmlAnnotations.mustache`
are rendered – which only renders the `@Jackson`… xml annotations if
additionalProperty jackson is true.

Also reorder annotation attributes in the following order:
- localName/name
- namespace (optional)
- isAttribute/useWrapping (optional)
Philzen added 20 commits June 14, 2024 01:35
This was slightly inspired by @jzrebiec via PR OpenAPITools#5371.

Wrapping is the default since Jackson 2.1 – so explicitly rendering
this will:
- make generated model work out-of-the-box in Jackson 2.0 for instance
- ensure the models still work if the local `XmlWrapper` was
  configured with `useXmlWrapper(false)`
This makes discovery & cross-navigation in IDE easier.
Brings the SpringCodegen in line with other Java Codegen's
May look a bit more complex, but cuts out a lot of repetitiveness.
Also reorders annotation attributes in the following order:
- localName/name
- namespace (optional)
- isAttribute/useWrapping (optional)
Was not referenced anywhere in java-helidon resources folder
@Philzen Philzen force-pushed the bugfix/JavaSpring-Jackson-XML-Annotations branch from 16a725b to 26be7d5 Compare June 13, 2024 23:36
@wing328 wing328 merged commit 642b1a3 into OpenAPITools:master Jun 15, 2024
@wing328
Copy link
Member

wing328 commented Jun 15, 2024

thanks for the PR, which has been merged.

@martin-mfg
Copy link
Contributor

Hi @Philzen, it seems this PR broke the java-camel samples.

openapi-generator\samples\server\petstore\java-camel> mvn clean verify

results in several failed tests.

Coud you have a look at this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment