Closed
Description
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
✨ 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 commentedon Apr 15, 2024
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 commentedon Apr 15, 2024
@jamesnw A fellow Hoosier programmer :)
jamesnw commentedon Apr 15, 2024
👋
I think I figured out the issue.
.components.schemas
or.components.parameters
,openapi-ts
does not create anyModels
- see https://github.com/hey-api/openapi-ts/blob/a9a87831876cc93d41ae4ac529a462d8812fc2b5/packages/openapi-ts/src/openApi/v3/parser/getModels.ts#L10openapi-ts
does not create amodel.ts
file. https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/utils/write/index.ts#L36model.ts
file, this package throws an error-openapi-react-query-codegen/src/createImports.mts
Line 23 in 4e27e41
So, it appears to me that
openapi-react-query-codegen
expects there to be components or parameters, butopenapi-ts
does not. Would it be possible to throw aNo models found
error only if there are components or parameters defined?seriouslag commentedon Apr 15, 2024
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 commentedon Apr 15, 2024
PR open at #67. Thanks!
seriouslag commentedon Apr 20, 2024
Released a test version with this patch under: @seriouslag/openapi-react-query-codegen@next
Until we merge the patches into this repo 😀