-
Notifications
You must be signed in to change notification settings - Fork 6k
[csharp] Support arrays of arrays for properties and models #7400
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
Conversation
Previous implementation assumed specification only supports polymorphic associations (via discrimator), although the code didn't seem to be setup correctly for that in the first place. That is, the parent object must define the discriminator (see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#models-with-polymorphism-support), so NOT HAS parent AND HAS discriminator doesn't make sense. From a C# perspective, base classes should have the method marked virtual and derived classes should override the method. This supports both composition and polymorphic definitions.
Unprefixed Configuration property access leads to ambiguous references when spec defines a Configuration model.
Previous implementation didn't support multiple levels of array with array items as OpenAPI spec supports. This means an object defined as type: array with items = type: array|items=double (which is common in GIS) would not be possible. This implementation assumes generics in the nested type definitions, so the above would generate List<List<double?>> for model parent types as well as property type declarations.
I can confirm our library now compiles with this on Linux via mono and also the created tests do pass. |
For my Swagger based API I am trying to generate a C# client for, it has a root type for "Configuration", and I noticed that even with this branch you've committed the code still fails to build. Can you review the enclosed json file that I am trying to generate against please? The checkin you made did a great job of cleaning up where you need to use Client.Configuration, but in ConfigurationApi.cs that get's generated you also need to use Model.Configuration at times to resolve the ambiguity in the other direction. However, I am left with a ton of "The parameter name "Type" is a duplicate about 116 times in the project. ? |
Update, it looks like the json uses a parameter called "Type" over and over... "parameters": [ |
@theason I've looked at the swagger definition you shared. The reason you're getting Here's an example:
The allOf includes one schema defining
This also contains a property defined as
To check, I've also compiled the Java generator. It doesn't seem to have a similar issue with compilation because there are no constructors enforcing the required arguments. It also doesn't appear to me that it handles the What are your expectations for when your model defines type in two different models, both as discriminators? Since I don't know what the correct behavior should be, and your spec doesn't match how I've seen discriminators done elsewhere, you may want to open a new issue for this. To address your issue with
|
Thank you so much for reviewing my problem! Unfortunately, this is a REST API that I am trying to consume from a 3rd party product I have no control over. I had a hunch that their system didn't quite conform to the OpenAPI standard. I won't call them out by name here; suffice to say they are a multibillion dollar organization that I have almost no sway over (but if you search the json for a URL you'll find it). It would seem that auto-generating a client for this API isn't a possibility given the disconnected decisions they made. |
@wing328 will it go into the next release 2.4.0 or only 3.0.0? |
Ups, I can now see the milestone v2.4.0, please ignore. |
* master: (133 commits) add a link to ebook (polish version) Add R namespace file (swagger-api#7467) Add Spring Petstore samples (async, java8-localdatetime) to CircleCI (swagger-api#7468) Revised core team members Ada code generator corrected: "=>" instead of "->". Fixes swagger-api#7450 (swagger-api#7456) Fixes issue swagger-api#7177 (SpringCodeGen dateLibrary "java8-localdatetime" option is ignored). (swagger-api#7178) Issue-7438 Fix that prevents generating interfaces when interfaceOnly is false. (swagger-api#7439) swagger-api#7093 - Add maven wrapper (swagger-api#7356) [csharp] Support arrays of arrays for properties and models (swagger-api#7400) [csharp] Fix ToJson to work with composition and polymorphism (swagger-api#7399) [csharp] Reference this.Configuration in client api template (swagger-api#7394) [JAX-RS][Spec] Removes throws Exception. (swagger-api#7437) Use supportsES6 flag in ts compilation for language typescript-angular (swagger-api#7408) Fix 7457: [Ada] wrong order for generated structures in *-models.ads (swagger-api#7462) Fix 7459: [Ada] wrong JSON in POST operations (swagger-api#7460) [erlang-client] Erlang request utils (swagger-api#7257) reenable pushing snapshot to maven repo Create CODE_OF_CONDUCT.md comment out update to docker image deleted unnecessary notes (swagger-api#7454) ...
…api#7400) * [csharp] Support composition on toJson Previous implementation assumed specification only supports polymorphic associations (via discrimator), although the code didn't seem to be setup correctly for that in the first place. That is, the parent object must define the discriminator (see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#models-with-polymorphism-support), so NOT HAS parent AND HAS discriminator doesn't make sense. From a C# perspective, base classes should have the method marked virtual and derived classes should override the method. This supports both composition and polymorphic definitions. * [csharp] this.Configuration in api template Unprefixed Configuration property access leads to ambiguous references when spec defines a Configuration model. * [csharp] Models/properties support nested arrays Previous implementation didn't support multiple levels of array with array items as OpenAPI spec supports. This means an object defined as type: array with items = type: array|items=double (which is common in GIS) would not be possible. This implementation assumes generics in the nested type definitions, so the above would generate List<List<double?>> for model parent types as well as property type declarations. * [csharp] Regenerate integration test sample * [csharp] Set "Client" case sensitive as reserved * [csharp] Regenerate security sample * [csharp] Regenerate samples
I'm consuming JSON from a third party, and I receive the same error for Configuration and for OperatingSystem (C# and PowerShell clients). By using this PR and making new builds, I fix the Configuration issue, but the OperatingSystem ambiguous reference remains. Should this be part of this issue, a new issue, or is there another way to solve it? |
I think that issue is related to a current feature request for fully qualified models. The issue in this pr fix was a conflict with a property in the API class. OperatingSystem would be a conflict with imports, so just a little different. You could workaround this by passing You could also look into extending the templates. I think OperatingSystem is under System, and that may be difficult to work around without fully qualified model names. |
PR checklist
./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). Windows batch files can be found in.\bin\windows\
.3.0.0
branch for changes related to OpenAPI spec 3.0. Default:master
.Description of the PR
Previous implementation didn't support multiple levels of array with
array items as OpenAPI spec supports. This means an object defined as
type: array with items = type: array|items=double (which is common in
GIS) would not be possible.
This implementation assumes generics in the nested type definitions, so
the above would generate List<List<double?>> for model parent types as
well as property type declarations.
This should resolve multiple issues as presented in #7218:
ToJson
method wasn't working for both composition and polymorphismConfiguration
references in api.template weren't fully qualified, causing conflicts with user definedConfiguration
modelsAs part of this change, I've also removed the case-sensitive comparison for reserved word evaluation. User has a
Break
model which was being renamed toModelBreak
. This shouldn't be necessary in C#, especially because we can escape reserved words in C# 3.x+ by preceding the reserved word with an@
. I haven't done this in this commit since it seems that all generated examples with reserved words use the title cased representation, but this should be a simple fix if it is required for parameter names./cc @mandrean
@wing328 I've opened this PR so @karussell might evaluate all fixes in one. It may be easier to merge this and close the other two.