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

[REQ] [rust] Support XML objects in requests and responses #5594

Closed
sverch opened this issue Mar 15, 2020 · 6 comments · Fixed by #5660
Closed

[REQ] [rust] Support XML objects in requests and responses #5594

sverch opened this issue Mar 15, 2020 · 6 comments · Fixed by #5660

Comments

@sverch
Copy link

sverch commented Mar 15, 2020

Is your feature request related to a problem? Please describe.

I'm trying to generate a client that works with these AWS OpenAPI specs, but the AWS API is XML based, and the specs there all have XML definitions.

I don't know for sure how to tell whether a generator supports this, but if I understand correctly based on this comment that says "this option indicates whether XML structures can be defined by spec document and honored by the caller", the XMLStructureDefinitions is what says whether a given generator supports XML objects in the requests and responses.

However, it doesn't appear that any clients actually support this feature:

$ git grep "|XMLStructureDefinitions|✓|"
docs/generators/dynamic-html.md:|XMLStructureDefinitions|✓|OAS2,OAS3
docs/generators/html.md:|XMLStructureDefinitions|✓|OAS2,OAS3
docs/generators/html2.md:|XMLStructureDefinitions|✓|OAS2,OAS3
docs/generators/openapi-yaml.md:|XMLStructureDefinitions|✓|OAS2,OAS3
docs/generators/openapi.md:|XMLStructureDefinitions|✓|OAS2,OAS3
docs/generators/spring.md:|XMLStructureDefinitions|✓|OAS2,OAS3

Those are all either documentation or server generators.

Describe the solution you'd like

I would like the generated rust code to support XML based service definitions.

I managed to get the generated code working on a basic level (single call), so here's some idea of what I think is needed for this:

Describe alternatives you've considered

I considered using a different language client, but it doesn't seem like I have another option.

However, I also filed this because I'm not sure if I'm actually understanding this correctly, so any corrections are very welcome!

Additional context

The OpenAPI spec was generated from this AWS service definition using this tool and the resulting specs can be found here.

@auto-labeler
Copy link

auto-labeler bot commented Mar 15, 2020

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@richardwhiuk
Copy link
Contributor

The Rust Server generator (which generates both a client and a server) supports receiving and producing XML.

Can you clarify which AWS API you are looking at - I had a quick look at one - and it looks like it uses JSON:

https://github.com/APIs-guru/openapi-directory/blob/master/APIs/amazonaws.com/AWSMigrationHub/2017-05-31/openapi.yaml#L109-L125

It looks like they've been converted from the source in https://github.com/aws/aws-sdk-js/tree/master/apis which don't look like OpenAPI APIs at all....

@sverch
Copy link
Author

sverch commented Mar 17, 2020

The Rust Server generator (which generates both a client and a server) supports receiving and producing XML.

Ah, I used the rust-server generator and I see it generating code that handles XML. Thanks! I also see that I was looking at the wrong flag to see if a generator supports XML, and the rust client generator claims to support XML: https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/rust.md Maybe just the hyper version supports it? I was using reqwest.

I'm using this API definition: https://github.com/APIs-guru/openapi-directory/blob/master/APIs/amazonaws.com/iam/2010-05-08/openapi.yaml

It looks like they've been converted from the source in https://github.com/aws/aws-sdk-js/tree/master/apis which don't look like OpenAPI APIs at all....

Yeah, part of this is an exercise to see how many differences there are, and see whether it's even possible to auto-generate a functional client from an openapi spec. As far as I know the AWS service definitions aren't a standard thing, so I thought this was worth an attempt.

@sverch
Copy link
Author

sverch commented Mar 17, 2020

Also, thanks for the quick response, and for your patience as I understand this better.

One thing I found is that if I generate the rust-server code when the content types are text/xml, it actually generates the code to handle JSON, but it generates code to handle XML when I change the content type to application/xml. Is that intentional?

You can see from this issue that the returned content type from AWS is text/xml.

@richardwhiuk
Copy link
Contributor

No, there's no particular reason. I've added a fix to the Rust Server generator to handle text/xml the same as application/xml.

Thanks!

@sverch
Copy link
Author

sverch commented Mar 27, 2020

Thank you @richardwhiuk! I'll keep going on this then.

The last thing I'll say is that I think https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/rust.md#wire-format-feature might need to be updated because it says it does have XML support. It might just depend on which library you use though (hyper, reqwest).

In any case, since you mentioned rust-server I'll assume that's more actively maintained anyway and move to using that one.

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

Successfully merging a pull request may close this issue.

2 participants