-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Generate a Rest Client with XML Deserialization and not JSON #2082
Comments
The client is mostly optimized for json. I think it does not yet support xml serialization... |
Hey guys, I'm facing this same issue at the moment as well. I'm running on dotnet core (still only 2.1). While researching my options I took a look at the various csharp client generators in openapi-generator as well, but they don't support XML either. The openapi-generator also don't parse Enums nicely (they come out as string properties), so NSwag is a winner here for me as it generates proper enums. There are some other differences but from what I can tell NSwag should meet our requirements once I switch over the seralisation to XML. I did a few quick hacks on a generated client to see what's involved in adding XML support after generation. In my case I know I won't need to regenerate my client for a while. So I'm weighing up whether I just continue with the XML conversion in my generated client, or whether I start implementing XML support in a fork of NSWag. Unfortunately I'm pretty time-poor right at the minute. At this stage I think I might do both (manually update the client, and start on XML support). But the XML support will be slow (until it becomes a priority :) ). In terms of implementation, I think what would be nice to support both XML and JSON out of the box and use standard Content negotiation to determine which serialisation to use at runtime. The default (preferred) content type could therefore be set to One other thing worth mentioning is the use of
Cheers! |
Just reading #2036. Perhaps an extensible Input/Output formatter style approach similar to ASP.NET Core would be a better approach here. That pattern is widely understood as well. Then custom formatters could be registered via the partial implementation. |
There are settings to change ICollection to Collection... |
Thanks, that will simplify things! Will RTFM and see what else I'm missing :) |
That was not my final answer to this issue... will add more soon 🙂 |
There are many dimensions to this issues:
we need to change the output to
I think/hope this issue is only about 3. and the rest is already implemented...
I think we shouldn't implement this externally (as proposed in #2036) but the generated clients should be completely self-contained and not require external code - #2036 would only be needed for special customizations (e.g. MessagePack serialization which is not directly supported by Swagger) and/or to make the generated clients easier to understand (but still generating a default implementation). What do you think? |
Hi, @RicoSuter , regarding your bullet number 1 i see it as finalized for C# to Swagger. It's the other way that is not done in my head. |
Hey guys, thanks for the replies. @RicoSuter, your points 2 and 3 look good to me - that's what I had to do to hack my generated client to get it to work as a test. I understand and agree that generated clients should be self-contained. I was merely thinking of a change to make it a bit more extensible so that if someone needs some other serialiser, they're free to implement it without having to modify the generator further. So for example, instead of this:
we were to do something like this:
Then we'd just move the "code for JSON" and "code for XML" to be an implementation of the formatter interface. That way, generated clients would have the JSON and XML formatters loaded by default so the out of box experience would "just work" for JSON and XML. I..e they wouldn't require external code. But if someone wanted another formatter for another content type, they could implement their own formatter and load it somewhere using the partial class so it would persist when the client is re-generated. The only problem with this approach is if people need additional attributes for their custom formatter, but I think that's outside of the scope of this (at least there's an entrypoint to have a formatter and they can perform whatever logic they need in there). It's only a little more complex than just adding @emilw, yeah unfortunately I'm integrating with a 3rd party that has implemented their API just like that. They only support XML, but thankfully have an OpenAPI spec (complete with Swagger UI). It's a financial/related institution to do with property transactions here in Australia. I don't know why they decided to implement it like this, but they have! :) In fact, their OpenAPI spec is in YAML, so I have to convert it to JSON because most tooling doesn't play nicely with YAML out of the box. That reminds me, I think NSwag is meant to support YAML but I couldn't get it to work. I'm not terribly fussed about that though and I haven't had time to investigate which is why I haven't raised an issue here yet. Plus there are some other minor manual tweaks I have to make to their YAML to get it to work anyway (a few typos and inaccessible external references). Overall it's pretty good though - certainly far better than not having the spec! |
Hi guys, Sorry for the absence. I haven't forgotten about this as we still have this requirement. It's just a bit lower on our priority list right now. I might have some help soon though. So will let you know when we are able to make a proper start on this. Cheers, |
In our org we have a requirement to use more sophisticated serialization techniques such as msgpack and compression for performance. So I would also love an extensible solution where the client comes with json as default, but then enable you to add options regarding content, very much like AspNetCore does. As it stands now, I would probably generate a client using nswag and then either find a way to create a script that does replaces json with msgpack or hand-code the changes. |
ATM the easiest solution would be to replace this template: |
The final solution would be to
|
Create a PR: #2248 Please review. |
I would like to see support for any serialization/transport type; json, xml, protobuf, message pack... I'm after a swagger client generator that can handle protobuf & json... |
@RicoSuter Is there any news for the open PR? |
Hi, any news? |
I am interfacing with an "external web API server" that returns only xml content-type. I have generated a rest client with NswagStudio but an exception is always thrown because of the response type which is XML and the deserialisation type which is JSON.
Is there any way to generate a client with XML Deserialisation?
The text was updated successfully, but these errors were encountered: