Skip to content

feat(plugin-swagger): add OpenAPI runtime mode for Fastify#1408

Draft
jpina1-godaddy wants to merge 4 commits into
mainfrom
feat/swagger-openapi-mode-main
Draft

feat(plugin-swagger): add OpenAPI runtime mode for Fastify#1408
jpina1-godaddy wants to merge 4 commits into
mainfrom
feat/swagger-openapi-mode-main

Conversation

@jpina1-godaddy

Copy link
Copy Markdown
Contributor

Summary

  • Adds a swagger.openapi config option to @gasket/plugin-swagger that enables runtime route introspection via @fastify/swagger, removing the need for a static definition file.
  • The plugin's fastify hook now uses timing: { first: true } so @fastify/swagger is always registered before any route-defining plugins, ensuring all routes are automatically discovered without any extra configuration by consumers.
  • When swagger.openapi is set: the build step is skipped, and Express warns and exits early (OpenAPI mode is Fastify-only).
  • Corrects README config name drift: uiConfiguiOptions, apiDocsapiDocsRoute.

Test plan

  • Verify existing swagger (static file) mode still works for both Fastify and Express apps
  • Verify swagger.openapi mode shows all routes in Swagger UI without any after timing declarations in route plugins
  • Confirm build hook is skipped when swagger.openapi is set
  • Confirm Express logs a warning and skips setup when swagger.openapi is set
  • Run unit tests: npx vitest run in packages/gasket-plugin-swagger

Made with Cursor

Adds a `swagger.openapi` config option to `@gasket/plugin-swagger` that
enables runtime route introspection via `@fastify/swagger` instead of
loading a static definition file. When set, the build step is skipped,
Express warns and exits early, and the Fastify hook registers
`@fastify/swagger` in openapi mode with `timing: { first: true }` so
routes are always discovered regardless of registration order.

Made-with: Cursor
@jpina1-godaddy jpina1-godaddy requested a review from a team as a code owner April 8, 2026 21:20
@changeset-bot

changeset-bot Bot commented Apr 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9dedc2c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@gasket/plugin-swagger Patch
@gasket/preset-api Patch
generate-docs-index Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

…nfig

Introduces swagger.mode ('static'|'introspect') and swagger.spec to
make the distinction between static file serving and Fastify route
introspection explicit and configurable. Defaults to 'static' for full
backward compatibility with existing apps.

- configure hook defaults mode to 'static'
- build hook skips file generation only in introspect mode
- fastify hook auto-detects spec format from content in both modes
- warns when swagger.spec is set without mode: 'introspect'
- warns when swagger.jsdoc is set with mode: 'introspect'
- warns when mode: 'introspect' is used with Express

Made-with: Cursor
@jpina1-godaddy jpina1-godaddy marked this pull request as draft April 14, 2026 20:10
- Replace mode/spec config with a single swagger.introspect object that
  enables @fastify/swagger route introspection. Format (OpenAPI 3.x vs
  Swagger 2.0) is auto-detected from the object's keys.
- Add swagger.introspect.routes with include/exclude prefix arrays to
  filter which Fastify routes appear in the generated spec. The routes
  property is stripped before being passed to @fastify/swagger.
- Improve static Fastify path: auto-detect openapi vs swagger key from
  the loaded spec file instead of always using swagger.
- Guard against invalid introspect values with a clear error message.
- Warn when include/exclude prefix entries are missing a leading slash.
- Log a warning when swagger.introspect is used with Express.
- Add 13 new tests covering introspect.routes filtering, routes stripping,
  transform function correctness, and input validation.
- Fix trailing comma lint error and invalid JSDoc tag warning.

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant