Skip to content

Error No models file found after upgrading to v1 #66

Closed
@jamesnw

Description

@jamesnw
Contributor

I upgraded from 0.5.3 to 1.0.6, and ran-

openapi-rq -i src/client-gen/openapi.yml -c axios -o src/client

It starts generating, and outputs-

Then, it throws an Error at

throw new Error("No models file found");

✨ Creating Axios client
✨ Running Prettier
✨ Done! Your client is located in: /Users/devpath/src/client/requests
file:///Users/devpath/node_modules/@7nohe/openapi-react-query-codegen/dist/createImports.mjs:17
        throw new Error("No models file found");
              ^

Error: No models file found
    at createImports (file:///Users/devpath/node_modules/@7nohe/openapi-react-query-codegen/dist/createImports.mjs:17:15)
    at createSourceFile (file:///Users/devpath/node_modules/@7nohe/openapi-react-query-codegen/dist/createSource.mjs:18:21)
    at async createSource (file:///Users/devpath/node_modules/@7nohe/openapi-react-query-codegen/dist/createSource.mjs:47:71)
    at async generate (file:///Users/devpath/node_modules/@7nohe/openapi-react-query-codegen/dist/generate.mjs:37:20)

Node.js v18.16.0

I confirmed there is not a models.ts on disk, or in the response of project.getSourceFiles().

Did I miss a migration step somewhere? Thanks!

Activity

seriouslag

seriouslag commented on Apr 15, 2024

@seriouslag
Collaborator

Hey @jamesnw, I'm sorry you're having trouble.
This can happen when an invalid OpenAPI spec file is used.

Please validate you are using a structurally valid OpenAPI file, you can validate the file in the web using a site like https://editor.swagger.io/ or a cli tool like redocly-cli (which has more features)

If you are still facing the issue after validation and fixing any errors, please provide a minimal OpenAPI spec file in a gist or attach here, your node/npm version and typescript version and I will gladly look into it.

seriouslag

seriouslag commented on Apr 15, 2024

@seriouslag
Collaborator

@jamesnw A fellow Hoosier programmer :)

jamesnw

jamesnw commented on Apr 15, 2024

@jamesnw
ContributorAuthor

@jamesnw A fellow Hoosier programmer :)

👋

I think I figured out the issue.

  1. If the OpenApi does not have a .components.schemas or .components.parameters, openapi-ts does not create any Models- see https://github.com/hey-api/openapi-ts/blob/a9a87831876cc93d41ae4ac529a462d8812fc2b5/packages/openapi-ts/src/openApi/v3/parser/getModels.ts#L10
  2. If there are no Models, openapi-ts does not create a model.ts file. https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/utils/write/index.ts#L36
  3. If there is no model.ts file, this package throws an error-
    throw new Error("No models file found");

So, it appears to me that openapi-react-query-codegen expects there to be components or parameters, but openapi-ts does not. Would it be possible to throw a No models found error only if there are components or parameters defined?

seriouslag

seriouslag commented on Apr 15, 2024

@seriouslag
Collaborator

@jamesnw A fellow Hoosier programmer :)

👋

I think I figured out the issue.

  1. If the OpenApi does not have a .components.schemas or .components.parameters, openapi-ts does not create any Models- see https://github.com/hey-api/openapi-ts/blob/a9a87831876cc93d41ae4ac529a462d8812fc2b5/packages/openapi-ts/src/openApi/v3/parser/getModels.ts#L10
  2. If there are no Models, openapi-ts does not create a model.ts file. https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/utils/write/index.ts#L36
  3. If there is no model.ts file, this package throws an error-
    throw new Error("No models file found");

So, it appears to me that openapi-react-query-codegen expects there to be components or parameters, but openapi-ts does not. Would it be possible to throw a No models found error only if there are components or parameters defined?

Yeah, that makes sense.
Thank you for looking into that, a PR would be great if you have time.
It is very rare for me to see a spec file with no components these days, but they exist.
Logging a warning there instead of throwing would be good.

jamesnw

jamesnw commented on Apr 15, 2024

@jamesnw
ContributorAuthor

Yeah, that makes sense.
Thank you for looking into that, a PR would be great if you have time.
It is very rare for me to see a spec file with components these days, but they exist.
Logging a warning there instead of throwing would be good.

PR open at #67. Thanks!

seriouslag

seriouslag commented on Apr 20, 2024

@seriouslag
Collaborator

Released a test version with this patch under: @seriouslag/openapi-react-query-codegen@next
Until we merge the patches into this repo 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @jamesnw@seriouslag

      Issue actions

        Error `No models file found` after upgrading to v1 · Issue #66 · 7nohe/openapi-react-query-codegen