nitro icon indicating copy to clipboard operation
nitro copied to clipboard

OpenAPI, Scalar, and Swagger routes are not found

Open miloofcroton opened this issue 9 months ago • 3 comments

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


miloofcroton avatar Mar 09 '25 17:03 miloofcroton

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',
      },
    },
  },
});

miloofcroton avatar Mar 09 '25 17:03 miloofcroton

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

kricsleo avatar May 03 '25 15:05 kricsleo

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.

Image

There is a mention for "object on the root level" but if they are different, they should be in different parts of the docs

guesant avatar Jun 02 '25 18:06 guesant