bcherny/json-schema-to-typescript

Unnamed enums in array items throw

Joshua-Schecker opened this issue · 1 comments

I would like use the tsEnumNames property when defining the items property of an array of enum values; however it fails.
If it's not a supported use case, then it would be nice to put this in the documentation.

Example schema:

{
  "type": "object",
  "properties": {
    "foo": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": ["BAR", "BAZ"],
        "enumNames": ["bar", "baz"],
        "tsEnumNames": ["BAR", "BAZ"]
      }
    },
    "title": "foo"
  }
}

results in the following error:

  TypeError: Cannot read properties of undefined (reading 'endsWith')
      at /Users/<username>/Library/Application Support/fnm/node-versions/v18.12.1/installation/lib/node_modules/json-schema-to-typescript/dist/src/generator.js:161:29
      at generateRawType (/Users/<username>/Library/Application Support/fnm/node-versions/v18.12.1/installation/lib/node_modules/json-schema-to-typescript/dist/src/generator.js:162:15)
      at generateTypeUnmemoized (/Users/<username>/Library/Application Support/fnm/node-versions/v18.12.1/installation/lib/node_modules/json-schema-to-typescript/dist/src/generator.js:143:16)
      at memoized (/Users/<username>/Library/Application Support/fnm/node-versions/v18.12.1/installation/lib/node_modules/json-schema-to-typescript/node_modules/lodash/lodash.js:10620:27)
      at /Users/<username>/Library/Application Support/fnm/node-versions/v18.12.1/installation/lib/node_modules/json-schema-to-typescript/dist/src/generator.js:273:72
      at Array.map (<anonymous>)
      at generateInterface (/Users/<username>/Library/Application Support/fnm/node-versions/v18.12.1/installation/lib/node_modules/json-schema-to-typescript/dist/src/generator.js:271:14)
      at generateStandaloneInterface (/Users/<username>/Library/Application Support/fnm/node-versions/v18.12.1/installation/lib/node_modules/json-schema-to-typescript/dist/src/generator.js:309:9)
      at declareNamedInterfaces (/Users/<username>/Library/Application Support/fnm/node-versions/v18.12.1/installation/lib/node_modules/json-schema-to-typescript/dist/src/generator.js:71:21)
      at generate (/Users/<username>/Library/Application Support/fnm/node-versions/v18.12.1/installation/lib/node_modules/json-schema-to-typescript/dist/src/generator.js:22:9)
]

Published

+ json-schema-to-typescript@13.0.2