Description
@fastify/swagger is a Fastify plugin that serves Swagger (OpenAPI v2) or OpenAPI v3 documentation for your API. In its default dynamic mode, the schema is generated automatically from your route schemas, and a static mode is available for an existing Swagger or OpenAPI schema. You register the plugin with Fastify, pass it options, and call the swagger API to get the generated document. The plugin must be registered before your routes, because routes registered earlier will not appear in the docs. This also applies when you load routes with @fastify/autoload. An OpenAPI option produces OpenAPI-compliant output, and the default OpenAPI version is 3.0.3, with 3.1.0 and 3.2.0 also selectable. The README's compatibility table matches plugin versions to Fastify versions, for example version 9.x for Fastify 5.x. Separate plugins such as @fastify/swagger-ui and @scalar/fastify-api-reference serve front-ends based on the generated document.…
Highlights
- OpenAPI v3 or Swagger v2 docs from routes
- Dynamic and static registration modes
- Works with @fastify/autoload
- Pairs with Swagger UI and Scalar viewers
- Migration guide from version 8.x
Ratings & Reviews
No ratings yet
Be the first to rate Fastify Swagger.
People also visit

agent-docs-api-openapi
Agent skill for docs-api-openapi - invoke with $agent-docs-api-openapi
Swagger Inspector Extension
This extension allows the Swagger Inspector to bypass CORS

kadykov/mcp-openapi-schema-explorer
Token-efficient access to OpenAPI/Swagger specs via MCP Resources

fastify-best-practices
Guides development of Fastify Node.js backend servers and REST APIs
Fastify Swagger FAQ
What is @fastify/swagger?
A Fastify plugin that generates and serves Swagger or OpenAPI documentation for your routes.
Which Fastify version do I need?
The README's compatibility table lists the pairs. Plugin version 9.x and later works with Fastify 5.x.
Does the order of registration matter?
Yes. Register @fastify/swagger before your routes, or they will not appear in the generated documentation.
Can it generate OpenAPI 3?
Yes. Provide the openapi option to get OpenAPI-compliant output. The default version is 3.0.3, and 3.1.0 or 3.2.0 can be set.
Which viewers can display the docs?
The README lists @fastify/swagger-ui and @scalar/fastify-api-reference as plugins that serve front-ends for the generated definitions.
What are the best Fastify Swagger alternatives?
Popular alternatives to Fastify Swagger include Swagger Inspector Extension, Graphql Docs and GraphQL-Markdown. See all Fastify Swagger alternatives












