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

Support multi-file OpenAPI spec files #26

Open
jpierson-at-riis opened this issue Jan 5, 2024 · 3 comments
Open

Support multi-file OpenAPI spec files #26

jpierson-at-riis opened this issue Jan 5, 2024 · 3 comments

Comments

@jpierson-at-riis
Copy link

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.

@astahmer
Copy link
Owner

makes sense, feel free to send a PR

@jpierson-at-riis
Copy link
Author

Currently I'm using openapi-flattener to preprocess the spec file but it's not quite ideal as it seems to also be flattening the separate schema's themselves which make up the spec. I'll see what I can do as far as contributing a PR.

@jpierson-at-riis
Copy link
Author

I still haven't had time to return to this issue. I'm hoping that I will in the next few months 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