OpenAPITools / OpenAPITools/openapi-generator

[REQ] [C#] Deserialize JSON empty array associated with additionalProperties

Open
#7,418 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the OpenAPI V3 YAML example with the C# generator and an endpoint response where tokens is []. Inspect the generated Dictionary<string, DebugItemBeanTokens> handling for additionalProperties and compare behavior in version 5.0.0. Done means an explicit option controls empty-array deserialization for these generated classes, with the resulting behavior documented or covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
api, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.