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] [C#] Deserialize JSON empty array associated with additionalProperties #7418

Open
wondergarance opened this issue Sep 15, 2020 · 2 comments

Comments

@wondergarance
Copy link

wondergarance commented Sep 15, 2020

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

I use openapi-generator 4.3.1 to generate a C# client from a yaml file (OpenAPI V3) with additionalProperties inside. A Dictionary<Tkey, Tvalue> is created with an ojbect as Tvalue.
eg:
yml:

debug-item-bean:
        tokens:
          type: object
          description: tokens
          additionalProperties:
            type: object
            description: debug-item-bean tokens dictionary
            properties:
              key:
                type: string
              value:
                type: array
                items:
                  type: string

C#:
Dictionary<string, DebugItemBeanTokens>

If the response of the endpoint has "tokens": [], I recevie an error:
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Tokens' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
So I should modify
Dictionary<string, DebugItemBeanTokens>
to
Dictionary<string, List<string>>

Describe the solution you'd like

I want to have an option to control empty arrays [] in openapi-generator, for class created from additionalProperties.

Has this issues done in the version 5.0.0?

@wing328
Copy link
Member

wing328 commented Sep 17, 2020

We just added better support for additional properties via #7396. Please give the latest master a try.

@wondergarance
Copy link
Author

wondergarance commented Sep 28, 2020

Thanks for your response.

I download the version 5.0.0-beta2 and generate the code, I always have the same error:
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Model.FilterValue' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
...

I compared Filter.cs and FilterValue.cs between 2 versions (4.3.1 and 5.0.0-beta2), they are the same.
Forthemore I can't find 5.0.0-beta3

I also download the lastest project and build it, when I run the command
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i ...
There is nothing changed, I get the same c# objects.

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

No branches or pull requests

2 participants