Check these first:
- the route is inside the configured
apiDir - the route is not matched by
ignoreRoutes - if
includeOpenApiRoutesistrue, the handler includes@openapi - for Pages Router, the handler includes
@method
If generation still misses the route, rerun with debug: true in
next.openapi.json to inspect discovery output.
Response inference is selective and best-effort.
It works best when:
- the handler returns typed
NextResponse.json(...) - the handler returns typed
Response.json(...) - the response type can be resolved cleanly by the TypeScript checker
Use explicit @response tags when you need exact component names, custom status
codes, or deterministic output.
Use one of these approaches:
- add
@ignoreto a specific route - add route patterns to
ignoreRoutes - enable
includeOpenApiRoutesand only tag the routes you want exported
Yes.
Set:
routerTypeto"pages"apiDirto your Pages Router API directory@methodon handlers
See ../apps/next-pages-router for a working example.
public/openapi.json is the default because it is convenient for local
inspection and UI integrations.
If you do not want the spec exposed at that path:
- change
outputDir - disable the generated UI with
--ui none - wire your preferred private serving strategy separately
Yes. The generated docs page is just a normal Next.js route. Protect it the same way you protect any other internal route in your application or deployment environment.
Use route-level @auth for operation security requirements, and use
schemaFiles or template content for richer components.securitySchemes
objects such as OAuth details, API key locations, or OpenID Connect metadata.
Check:
- the exported type or schema name matches the JSDoc reference
- the file is under one of the configured
schemaDirpaths - your path aliases are defined in
tsconfig.json - the target is exported from the module you expect
The checker can resolve path aliases in supported scenarios, but explicit route metadata is still the safest option when output needs to be predictable.
The simplest workflow is:
- update routes and schemas
- run
openapi-gen generate - review the spec or
/api-docs - add generation to CI if the spec is part of your release contract
Yes. The output is standard OpenAPI, so it can be consumed by docs platforms, client generators, gateways, and other tooling that accepts OpenAPI files.
Start here: