Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Java support for application/xml #5962

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

Merged
wing328 merged 15 commits into swagger-api:master from mobreza:3870-java-application-xml
Jul 11, 2017

Conversation

@mobreza
Copy link
Contributor

@mobreza mobreza commented Jun 30, 2017
edited
Loading

PR checklist

  • Read the contribution guidelines.
  • Ran the shell/batch script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates)
  • Filed the PR against the correct branch: master for non-breaking changes and 2.3.0 branch for breaking (non-backward compatible) changes.

Description of the PR

I needed application/xml support in a Java client as in #3870. Thought the best way was to add a new withXml flag and then generate the Java clients accordingly. All Java clients need work, I focused only on the resttemplate library.

withXml is respected as one of the configOptions for Java clients in the maven plugin:

<configOptions>
	<withXml>true</withXml>
	...

I've updated the CodegenModel and CodegenProperty to include Swagger XML options.

Notes

This is the raw work log of my changes and can be squashed and rebased as necessary. Let me know.

nwertzberger reacted with thumbs up emoji
@mobreza mobreza changed the title (削除) WIP: Java client support for application/xml (削除ここまで) (追記) Java client support for application/xml (追記ここまで) Jun 30, 2017
@mobreza mobreza changed the title (削除) Java client support for application/xml (削除ここまで) (追記) Java support for application/xml (追記ここまで) Jun 30, 2017
Copy link
Contributor Author

mobreza commented Jun 30, 2017

-l spring is fairly well supported in this code.

mobreza added 14 commits July 1, 2017 00:28
@mobreza mobreza force-pushed the 3870-java-application-xml branch from 4f65265 to 1024ba0 Compare June 30, 2017 22:30
Copy link
Contributor Author

mobreza commented Jun 30, 2017

It's possible that the withXml flag is automagically set when there's a single API call definition that only uses application/xml as Content-Type in a POST or as Accept header in a GET.

Copy link

@mobreza Thanks for submitting this PR! This solves for a need my team is facing. 👍
@wing328 I believe this will solve #6005 that I submitted. The approach is very similar to what I was planning on doing, except that his work is way more thorough. I will try to pull this down and test it against my use cases within the next few days.

If I may provide one bit of feedback, I would question whether it's appropriate to add a new config option withXml when there's already an option for useJaxbAnnotations. Can we reuse useJaxbAnnotations here, or is it meant to represent something entirely different? Along those lines, I'm not sure we need a flag for this at all. Is there a downside to removing the config option and always generating the XML annotations?

Copy link

I cloned @mobreza's fork and built the 3870-java-application-xml branch locally. I tested it against all of my team's use cases, and everything worked correctly. I look forward to seeing this PR merged and released. Thanks!

Copy link
Contributor

wing328 commented Jul 10, 2017

Can we reuse useJaxbAnnotations here, or is it meant to represent something entirely different?

Very good feedback. Either is fine with me. Looking at the bigger picture, I would prefer "withXML" as it can be used in other non-java generators as well (e.g. Ruby, which has one outstanding request/feedback to support XML payload in Ruby API client)

I'm not sure we need a flag for this at all. Is there a downside to removing the config option and always generating the XML annotations?

Previously there were feedbacks to avoid unnecessary dependencies included in the auto-generated code so I prefer supporting XML via an option as it will require additional dependency "jackson-dataformat-xml" (which is not needed if the use case is JSON-only)

Copy link
Contributor Author

mobreza commented Jul 10, 2017

@wing328 we could consider folding useJaxbAnnotations into the new withXml flag.

Copy link
Contributor

wing328 commented Jul 10, 2017

@wing328 we could consider folding useJaxbAnnotations into the new withXml flag.

Yup, you're reading my mind. We'll do it in the 2.3.0 branch (containing breaking changes) to consolidate all other XML flags (if any) into withXML. I'll open a ticket for tracking later.

Copy link
Contributor

wing328 commented Jul 10, 2017

@packleader thanks for testing the changes. I'll run some tests tomorrow locally and merge th PR accordingly.

Copy link

Can we reuse useJaxbAnnotations here, or is it meant to represent something entirely different?

Very good feedback. Either is fine with me. Looking at the bigger picture, I would prefer "withXML" as it can be used in other non-java generators as well (e.g. Ruby, which has one outstanding request/feedback to support XML payload in Ruby API client)

I'm fine either way as well. If we intend for withXml to be used across languages, should it moved directly under <configuration> instead of <configOptions>? I may be mistaken, but I interpret <configOptions> as language- or library-specific options. Also, we might want to update the documentation and example at swagger-codegen-maven-plugin/README.md

I'm not sure we need a flag for this at all. Is there a downside to removing the config option and always generating the XML annotations?

Previously there were feedbacks to avoid unnecessary dependencies included in the auto-generated code so I prefer supporting XML via an option as it will require additional dependency "jackson-dataformat-xml" (which is not needed if the use case is JSON-only)

That's a good point; we don't want dependency bloat. I'm sure this is a dumb question, but what is the value in using @JacksonXmlProperty instead of just @XmlElement? The latter is part of core Java, so it doesn't require any additional dependencies.

Copy link
Contributor Author

mobreza commented Jul 10, 2017

@wing328 See above about:

It's possible that the withXml flag is automagically set when there's a single API call definition that only uses application/xml as Content-Type in a POST or as Accept header in a GET.

Also let me know if you need me to rebase, squash or clean up the code in the branch.

Copy link
Contributor Author

mobreza commented Jul 10, 2017

@wing328 Also, we could aways generate the javax.xml annotations and the @Jackson* annotations. Annotations apparently don't trip the ClassNotFound exception at runtime. We could also declare the dependencies as "provided" in pom.xml.

@wing328 wing328 merged commit 5d32edd into swagger-api:master Jul 11, 2017
Copy link
Contributor

wing328 commented Jul 11, 2017

FYI. Updated CircleCI to cover resttemplate-withXml via 898ead1

Copy link
Contributor

wing328 commented Jul 11, 2017

Minor enhancement/fix to gradle file: #6020 (merged into master)

Copy link
Contributor Author

mobreza commented Jul 11, 2017

@wing328 will the 2.2.3-SNAPSHOT be available on Sonatype soon?

Copy link
Contributor

wing328 commented Jul 11, 2017

@mobreza yes, after the build (https://travis-ci.org/swagger-api/swagger-codegen/builds/2524139110 completes, the snapshot version will be published to Sonatype.

Copy link
Contributor

wing328 commented Jul 11, 2017

I'm fine either way as well. If we intend for withXml to be used across languages, should it moved directly under instead of ?

@packleader at the moment, I think it should be a generator-specified option as not all generators supports XML payload via the withXML option.

Also, we might want to update the documentation and example at swagger-codegen-maven-plugin/README.md

Please feel free to submit a PR to improve the plug-in's README

Copy link
Contributor

wing328 commented Jul 17, 2017

Created #6084 to replace useJaxbAnnotations with withXml

Copy link

Hi, XML support is only generated via Spring rest template? What if you want to use a Jersey or RestEasy client? It's too hard to add a @Provider for xml/application configuration in the generated client?

Copy link

@nalmeida84 Even though the PR specifically references RestTemplate, the fix that he submitted applies to all of the libraries. I have personally tested with Jersey2 and can confirm that it works correctly.

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

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

v2.2.3

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /