fabien0102 / openapi-codegen

A tool for generating code base on an OpenAPI schema.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot generate Enums from Dictionary Object

ashervb opened this issue · 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

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

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