Skip to content
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

[BUG] using xml:wrapped:false does not generate the correct annotation #2417

Closed
tom-mayer opened this issue Mar 15, 2019 · 10 comments · Fixed by #18870
Closed

[BUG] using xml:wrapped:false does not generate the correct annotation #2417

tom-mayer opened this issue Mar 15, 2019 · 10 comments · Fixed by #18870

Comments

@tom-mayer
Copy link

Hey,

in the documentation https://swagger.io/docs/specification/data-models/representing-xml/ here it says that you can represent unwrapped lists in xml with using the xml:wrapped:false in the openapi yaml. I am using the JavaSpring generator. The xml:atttribute:[true|false] and xml:name seem to work fine, generating the correct @JacksonXmlProperty values.

However using xml:wrapped:false does not change the generated model. Jackson-Xml uses wrapping by default, so if this is set, a @JacksonXmlElementWrapper(useWrapping = false) should be rendered over the property to make xmls like that parsable.

Looking at the pojo.mustache @JacksonXmlElementWrapper is also not in there. Should be around line 27.

My question is, is this really a bug / not yet done or do I just miss something.

@thiko
Copy link

thiko commented Feb 6, 2020

Any news here? :-/
@tom-mayer could you find a workaround (beside adding the annotation manually)?

Thanks!

@tom-mayer
Copy link
Author

Hey @thiko . No couldn't find a good workaround here. We were in the lucky spot that we could change the API to return wrapped lists,... but that was not a very satisfying solution and for sure not applicable if you don't own the API,.. even then it's not really a preferable solution.

Cheers

@thiko
Copy link

thiko commented Feb 11, 2020

hi @tom-mayer, thanks for your response!
great that you were able/allowed to change the API. Unfortunately, thats not possible for us. The "calling system" is fix and we really need to serve the expected output.
Our current workaround is: generating the model, copy the files to another place, add the custom annotations, deactivate the model creation, delete the generated files and work with the customized "copies". Sounds stupid and.. well.. it is! ;-)

@mutyasaisrikar
Copy link

mutyasaisrikar commented Nov 16, 2022

Unfortunately, I am also facing the same issue with the Open API generator. Is there a planned fix for this?

@siimp
Copy link

siimp commented Nov 20, 2022

Same here, it seems that one of my deserialization does not work properly because of this bug. Looking forward to this fix also.

A little googeling shows that swagger codegen has JacksonXmlElementWrapper annotation generation https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/JavaSpring/pojo.mustache#L50
but openapi tools does not https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache#L48

Currently workaround for me was to override two mustache files JavaSpring/model.mustache and JavaSpring/pojo.mustache to add wrapper import and JacksonXmlElementWrapper annotation too these files respectively.

@chschu
Copy link
Contributor

chschu commented Aug 21, 2023

If you're interested, I can provide a Pull Request that generates the wrapper annotations for the JavaSpring generator and fixes some other issues in the same area.

@UnleashSpirit
Copy link
Contributor

If you're interested, I can provide a Pull Request that generates the wrapper annotations for the JavaSpring generator and fixes some other issues in the same area.

Hi, this topic is a bit old but i'm very interested

@Philzen
Copy link
Contributor

Philzen commented Apr 11, 2024

If you're interested, I can provide a Pull Request that generates the wrapper annotations for the JavaSpring generator and fixes some other issues in the same area.

@chschu that'd be dope and highly appreciated 🙏

That would probably solve #5078 and #5764 as well.

@chschu
Copy link
Contributor

chschu commented Apr 15, 2024

I created PR #18392 containing my changes. It's still a draft, because I'd really like to have some tests for that.

The branch in my fork is based on the v7.4.0 tag, but it should apply to master cleanly.

Any feedback, improvements and additional contributions (tests?) are highly welcome!

@chschu
Copy link
Contributor

chschu commented Apr 15, 2024

There are a couple of mustache templates that generate Jackson XML annotations in generators other than JavaSpring. These should probably be fixed as well.

Both #5078 and #5764 would require a similar fix in src/main/resources/Java/jackson_annotations.mustache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants