Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot generate Enums from Dictionary Object #156

Open
ashervb opened this issue Apr 14, 2023 · 2 comments
Open

Cannot generate Enums from Dictionary Object #156

ashervb opened this issue Apr 14, 2023 · 2 comments

Comments

@ashervb
Copy link

ashervb commented Apr 14, 2023

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

@alan-oliv
Copy link
Contributor

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

@ashervb
Copy link
Author

ashervb commented Apr 26, 2023

@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.

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

No branches or pull requests

2 participants