OpenAPI, Scalar, and Swagger routes are not found
Environment
I've tried setting custom routes and using the default routes, and I simply cannot find the page that hosts the OpenAPI spec or the swagger or scalar UI. Help?
Reproduction
See here for example: https://stackblitz.com/edit/github-l8fjbbyh
Describe the bug
I believe this is the file that is checking the config and creating the routes: https://github.com/nitrojs/nitro/blob/v2/src/core/config/resolvers/open-api.ts
As far as I can tell, no handler is being created.
Additional context
No response
Logs
Ok, I figured it out. I read the file that I linked a little more carefully, and I saw this at the top:
if (!options.experimental.openAPI) {
return;
}
So, you have to add openAPI: true AND add the openAPI: NitroOpenAPIConfig in the nitro config. The docs don't make this very obvious. I thought it was one or the other.
My config now:
export default defineNitroConfig({
srcDir: 'app',
compatibilityDate: '2024-12-16',
experimental: {
openAPI: true,
},
openAPI: {
// production: 'runtime',
meta: {
title: 'My Awesome Project',
description: 'This might become the next big thing.',
version: '1.0',
},
route: '/_docs/openapi.json',
ui: {
scalar: {
route: '/_docs/scalar',
theme: 'purple',
},
swagger: {
route: '/_docs/swagger',
},
},
},
});
I think the Nitro docs already make it clear that you should enable this experimental feature manually, right? 🤔
Enable /_scalar, /_swagger and /_openapi.json endpoints.
Default: false
I think the Nitro docs already make it clear that you should enable this experimental feature manually, right? 🤔
Enable /_scalar, /_swagger and /_openapi.json endpoints. Default: false
Unfortunately, no. There is no other section for the root level openApi config. It's not clear that the docs are talking about different properties.
There is a mention for "object on the root level" but if they are different, they should be in different parts of the docs