Skip to content

Conversation

@daniel-kullmann
Copy link
Contributor

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
Contributor 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
Contributor 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
Contributor Author

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

@daniel-kullmann
Copy link
Contributor 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"
              ]
            }
          }
        }
      }

@daniel-kullmann
Copy link
Contributor Author

Any progress on this?

Copy link
Contributor

@deekshas8 deekshas8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution @daniel-kullmann. With the tests and changelog in place, this is now ready to be merged. 🚀

enum: ["'One'", "'Two'"]
}
})
).toEqual("('One' | 'Two')[]");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽

@deekshas8 deekshas8 merged commit f17ca59 into SAP:main Nov 20, 2025
16 checks passed
@davidkna-sap
Copy link
Member

Thanks for the contribution @daniel-kullmann!

@ZhongpinWang
Copy link
Contributor

Hi @daniel-kullmann ,

We have released Cloud SDK v4.2.0 with your contribution! Thanks again for this PR.

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.

4 participants