OpenAPITools / OpenAPITools/openapi-generator

[BUG][CSharp] type array uniqueItems uses invalid type

Open
#22,247 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

In the generichost CSharp generator, if there's a response that is of the type array and contains the property "uniqueItems": true, the generated file will use Set<T> (which is non-existent) instead of a valid type such as HashSet<T>.

openapi-generator version

7.16.0

OpenAPI declaration file content or url
{
  "openapi": "3.0.1",
  "info": {
    "title": "CSharp Code Generation Error Test",
    "description": "This API is made with the purpose of replicating the csharp code generation issue with openapi-generators.",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "paths": {
    "/api/test": {
      "get": {
        "summary": "Test endpoint",
        "description": "This is a test endpoint to replicate the csharp code generation issue with openapi-generators",
        "responses": {
          "200": {
            "description": "Successful Request",
            "content": {
              "application/json": {
                "schema": {
                  "uniqueItems": true,
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Test"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Test": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "type": {
            "type": "string"
          },
          "label": {
            "type": "string"
          }
        }
      }
	}
  }
}
Generation Details
npx --yes @openapitools/openapi-generator-cli generate -i ./test.json -g csharp -o test --additional-properties=library=generichost,apiName=TestApi,packageName=TestApi,useSourceGeneration=true,sourceFolder=.,targetFramework=net9.0
Steps to reproduce
  • Generate a CSharp project with the provided schema above.
Related issues/PRs

None that I could find.

Suggest a fix

Provide specific C# compatible types when uniqueItems is specified, such as HashSet

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

Run the provided npx openapi-generator command with the supplied OpenAPI declaration and inspect the generated CSharp generichost output for the response array. Trace how uniqueItems is mapped to its collection type, then verify that the generated project uses a valid C# type and compiles successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
56/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.