vega / ts-json-schema-generator

Generate JSON schema from your Typescript sources
MIT License
1.45k stars 193 forks source link

UnknownNodeError on Template Literal Type #1041

Open hackerhailee opened 2 years ago

hackerhailee commented 2 years ago

Great library here!

It's been working great for my use cases, with one exception. I'm getting an UnknownNodeError any time there is a template literal type.

For example:

export type Products = 'Product' | 'SaaS' | 'App' | 'API' | 'Marketplace' | 'Directory'
export type APIs = 'Trigger' | 'Search' | 'Action'
export type ProductAPIs = `${Products} ${APIs}`

Generates this error:

/Users/hailee/Projects/apis.dev/node_modules/ts-json-schema-generator/dist/src/ChainNodeParser.js:41
        throw new UnknownNodeError_1.UnknownNodeError(node, context.getReference());
        ^

UnknownNodeError: Unknown node " `${Products} ${APIs}`
    at ChainNodeParser.getNodeParser (/Users/hailee/Projects/apis.dev/node_modules/ts-json-schema-generator/dist/src/ChainNodeParser.js:41:15)
    at ChainNodeParser.createType (/Users/hailee/Projects/apis.dev/node_modules/ts-json-schema-generator/dist/src/ChainNodeParser.js:28:25)
    at TypeAliasNodeParser.createType (/Users/hailee/Projects/apis.dev/node_modules/ts-json-schema-generator/dist/src/NodeParser/TypeAliasNodeParser.js:36:43)
    at AnnotatedNodeParser.createType (/Users/hailee/Projects/apis.dev/node_modules/ts-json-schema-generator/dist/src/NodeParser/AnnotatedNodeParser.js:22:47)
    at ExposeNodeParser.createType (/Users/hailee/Projects/apis.dev/node_modules/ts-json-schema-generator/dist/src/ExposeNodeParser.js:22:45)
    at CircularReferenceNodeParser.createType (/Users/hailee/Projects/apis.dev/node_modules/ts-json-schema-generator/dist/src/CircularReferenceNodeParser.js:21:43)
    at ChainNodeParser.createType (/Users/hailee/Projects/apis.dev/node_modules/ts-json-schema-generator/dist/src/ChainNodeParser.js:28:54)
    at TopRefNodeParser.createType (/Users/hailee/Projects/apis.dev/node_modules/ts-json-schema-generator/dist/src/TopRefNodeParser.js:12:47)
    at /Users/hailee/Projects/apis.dev/node_modules/ts-json-schema-generator/dist/src/SchemaGenerator.js:30:36
    at Array.map (<anonymous>) {

Any ideas?

domoritz commented 2 years ago

I think template literal types didn't exist since recently. You could send a pull request to add a new template literal type node parser.