typed-openapi
typed-openapi copied to clipboard
Support multi-file OpenAPI spec files
The OpenAPI spec allows for portions of the spec to be split out to separate files which are referenced from the main spec. When attempting to run typed-openapi
CLI on a project that had this setup I encountered the following error which prevented the typed zod schema from being created.
> npx typed-openapi .\main.yaml -r 'zod'
C:\Users\myuser\AppData\Local\npm-cache\_npx\82013c35a310ca1e\node_modules\typed-openapi\dist\cli.cjs:124
return t.reference(refInfo.normalized);
^
TypeError: Cannot read properties of undefined (reading 'normalized')
at getTs (C:\Users\myuser\AppData\Local\npm-cache\_npx\82013c35a310ca1e\node_modules\typed-openapi\dist\cli.cjs:124:34)
at openApiSchemaToTs (C:\Users\pvjpierson\AppData\Local\npm-cache\_npx\82013c35a310ca1e\node_modules\typed-openapi\dist\cli.cjs:227:16)
at getTs (C:\Users\myuser\AppData\Local\npm-cache\_npx\82013c35a310ca1e\node_modules\typed-openapi\dist\cli.cjs:181:27)
at openApiSchemaToTs (C:\Users\pvjpierson\AppData\Local\npm-cache\_npx\82013c35a310ca1e\node_modules\typed-openapi\dist\cli.cjs:227:16)
at C:\Users\myuser\AppData\Local\npm-cache\_npx\82013c35a310ca1e\node_modules\typed-openapi\dist\cli.cjs:211:26
at Array.map (<anonymous>)
at getTs (C:\Users\myuser\AppData\Local\npm-cache\_npx\82013c35a310ca1e\node_modules\typed-openapi\dist\cli.cjs:210:43)
at openApiSchemaToTs (C:\Users\pvjpierson\AppData\Local\npm-cache\_npx\82013c35a310ca1e\node_modules\typed-openapi\dist\cli.cjs:227:16)
at C:\Users\myuser\AppData\Local\npm-cache\_npx\82013c35a310ca1e\node_modules\typed-openapi\dist\cli.cjs:806:25
at Array.forEach (<anonymous>)
Node.js v18.12.0
After some trial and error I was able to discover that if I just manually merged the spec files together into one file that the schema was able to be generated and the CLI tool ran as expected. It would be great if multi file specs using references could be supported so that this tool could be used directly on these valid spec files without having to manually tinker with them before running this tool.