openapi-codegen icon indicating copy to clipboard operation
openapi-codegen copied to clipboard

Cannot generate Enums from Dictionary Object

Open ashervb opened this issue 1 year ago • 2 comments

The useEnum option is a great addition! Super happy that got in. Trying it out I ran into an edge case when generating enums from a Dict object. Given the schema:

{
      "Test": {
        "additionalProperties": {
          "properties": {
            "test": {
              "enum": [
                "A",
                "B"
              ],
              "type": "string"
            }
          },
          "required": [
            "test"
          ],
          "type": "object"
        },
        "properties": {},
        "type": "object"
      }
}

With useEnums: false:

export type Test = {
  [key: string]: {
    test: 'A' | 'B'
  }
}

With useEnums: true:

export type Test = {
  [key: string]: {
    test: undefinedTest
  }
}

with a regular object

   "Test": {
          "properties": {
            "test": {
              "enum": [
                "A",
                "B"
              ],
              "type": "string"
            }
          },
          "required": [
            "test"
          ],
          "type": "object"
      }
export enum TestTest {
  A = 'A',
  B = 'B',
}

export type Test = {
  test: TestTest
}

Was also able to duplicate the same behavior when using allOf which makes me think #157 is related

ashervb avatar Apr 14 '23 00:04 ashervb

Hi @ashervb, thanks for reporting it can you provide me the allOf schema that you were able to simulate the same behavior?

alan-oliv avatar Apr 25 '23 05:04 alan-oliv

@alan-oliv Hello! Unfortunately I didn't document the issue at the time and of course now I'm unable to reproduce it :upside_down_face: . Will keep investigating though.

ashervb avatar Apr 26 '23 18:04 ashervb