Skip to content

Support multi-file OpenAPI spec files #26

Open
@jpierson-at-riis

Description

@jpierson-at-riis

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions