Skip to content

Conversation

@daniel-kullmann
Copy link

Without this change an array of enums will result in e.g.:

export type Model1 = {
values: 'A' | 'B' | 'C'[];
} & Record<string, any>;

which means the value can be either "A", "B", or "C"[], which is wrong.

Without this change an array of enums will result in e.g.:

export type Model1 = {
  values: 'A' | 'B' | 'C'[];
} & Record<string, any>;

which means the value can be either "A", "B", or "C"[], which is wrong.
@cla-assistant
Copy link

cla-assistant bot commented Nov 14, 2025

CLA assistant check
All committers have signed the CLA.

@daniel-kullmann
Copy link
Author

I tested this with the following API json:

{
  "openapi": "3.0.3",
  "info": {
    "version": "1.0.0",
    "title": "Api",
    "description": "API"
  },
  "components": {
    "schemas": {
      "Model1": {
        "type": "object",
        "required": ["values"],
        "properties": {
          "values": {
            "type": "array",
            "items": {
              "type": "string",
              "uniqueItems": true,
              "minItems": 0,
              "enum": [
                "A",
                "B",
                "C"
              ]
            }
          }
        }
      }
    }
  },
  "paths": {
    "/values": {
      "get": {
        "summary": "",
        "operationId": "getValues",
        "responses": {
          "200": {
            "description": "A list of all values",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Model1"
                }
              }
            }
          }
        }
      }
    }
  }
}

@ZhongpinWang
Copy link
Contributor

Hi @daniel-kullmann ,

Thanks for your contribution! We really appreciate it.

One thing is confusing me a bit. In your json object, I see uniqueItems is set to true. Then it should go into Set<${type} instead?

Overall seems like a valid fix. @deekshas8 WDYT?

@daniel-kullmann
Copy link
Author

daniel-kullmann commented Nov 14, 2025

Hi @ZhongpinWang I agree, but for some reason, the value of uniqueItems is not present in the code that I changed. Maybe that is another bug?

Regardless of that, if uniqueItemsis false, the generated code should still be correct. I agree that this might be an edge case (non-unique list of enums), but it can happen.

@daniel-kullmann
Copy link
Author

I have created a repo to reproduce the problem: https://github.com/daniel-kullmann/openapi-generator-bug

@daniel-kullmann
Copy link
Author

Ah, uniqueItemsshould be one level higher, next to type: "array"

      "Model1": {
        "type": "object",
        "required": ["values"],
        "properties": {
          "values": {
            "type": "array",
            "uniqueItems": true,
            "items": {
              "type": "string",
              "minItems": 0,
              "enum": [
                "A",
                "B",
                "C"
              ]
            }
          }
        }
      }

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants