-
-
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
oneOf support in NSwag.CodeGeneration.CSharp.SwaggerToCSharpClientGenerator #1721
Comments
No this is not supported. What would you expect as c# output for the property? |
Related: RicoSuter/NJsonSchema#13 |
Hi @RSuter, There are two possible approaches I can think of to support oneOf, anyOf & allOf in the generated c#.
In the mean time, the work-around I thought of is something like overriding the calling method in the generated code, pass a custom JsonConverter method to SerializeObject(), where the custom JsonConvertor converts the oneOf part of the json stream ? Please let me know if I can help further. Many thanks Chris Jolly |
Yes, and also there is different output when oneOf is used for inheritance vs. your scenario here.. |
Maybe the simplest solution in this case would be to just generate an object/JToken property... |
Hi @RSuter, Perhaps JToken is the right answer. Sorry, I don't know enough about the inner workings of your code or Newtonsoft to know if that's the right approach... I'd also be interested to know how easy it was to work with the resulting entities after deserialization. |
Hmm, I dont like exposing JToken or Newtonsoft.Json specific stuff (leaky abstraction) so maybe it's better to just expose object, but then the property is completely untyped - i.e. in your case not only string and string[] is allowed but everything... Can you create a new issue in NJsonSchema for this? Because it has to be implemented there (DTO handling is in this library) |
OK - I've created a new issue in NJsonSchema. Please let me know if you want me to copy over the example code from the above description |
|
I didn't read it through, but could it be merged with #2991 ? |
Hello @RSuter,
does NSwag.CodeGeneration.CSharp.SwaggerToCSharpClientGenerator currently support oneOf ? It seems to only convert the first item but ignores the second and following items.
Here is the part of the schema in question:
And here is the generated code:
The text was updated successfully, but these errors were encountered: