Closed SaadBazaz closed 10 months ago
There are several reasons why this might happen. I would start with making sure that you are using the latest version of Next REST Framework. v3.4.6
adds an option to display logs for debugging purposes, so running npx next-rest-framework generate --debug=true
should give you the logs of the next build
command that is run under the hood. The default timeout is 60 seconds, so if building your Next.js application takes more than that, then you can increase the timeout with the --timeout=<your_timeout_ms>
option. If based on the debugging logs, it looks like the next build
step actually succeeds but the command still gets stuck, then there's a problem somewhere else. In order for the generate
command to work you need to have atleast one docs handler (docsRouteHandler
/docsApiRouteHandler
) that defines your configuration for NRF. Additionally, all paths that that you would like to be included in the OpenAPI spec should be defined with the routeHandler
/apiRouteHandler
functions and allowed by the docs config (by default all paths are allowed). If this won't solve your issue, I would like to know more details about your application structure for deeper analysis.
Sounds good. Will use the verbose logs.
When generating OpenAPI spec, can we avoid building the entire app and just build the API folder somehow? Here's something which looks similar: https://github.com/vercel/next.js/discussions/51891
Perhaps using some fancy logic we can reduce the time it takes to generate NRF routes.
Sounds good. Will use the verbose logs.
Possible Improvement
When generating OpenAPI spec, can we avoid building the entire app and just build the API folder somehow? Here's something which looks similar: vercel/next.js#51891
Perhaps using some fancy logic we can reduce the time it takes to generate NRF routes.
Thanks, something like that seems promising for improving the performance and is definitely worth looking into. Getting back to your original issue, I'm interested if you were able able to use the debug logs to find out what could be the issue for the generation to get stuck and if this issue is still relevant.
It was most likely due to long / failed build.
I use
npx next-rest-framework generate
to generate the openapi.json file on the fly, so I can typecheck my RTK Query APIs on each build.This used to work fine before, but now it just gets stuck indefinitely here:
Until it times out.
When it does complete, it generates an empty openapi.json file, as shown below: