@readyapi/fastify-api-reference
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

Readyapi Fastify API Reference Plugin

Version Downloads License Discord

This plugin provides an easy way to render a beautiful API reference based on a OpenAPI/Swagger file with Fastify.

Screenshot of an API Reference

Installation

npm install @readyapi/fastify-api-reference

And then register it with Fastify:

await fastify.register(require('@readyapi/fastify-api-reference'), {
  routePrefix: '/reference',
})

Usage

If you have a OpenAPI/Swagger file already, you can pass an URL to the plugin:

// Render an API reference for a given OpenAPI/Swagger spec URL
fastify.register(require('@readyapi/fastify-api-reference'), {
  routePrefix: '/reference',
  configuration: {
    title: 'Our API Reference',
    spec: {
      url: '/openapi.json',
    },
  },
})

With the @fastify/swagger you can even generate your Swagger spec from the registered routes and directly pass it to the plugin:

await fastify.register(require('@readyapi/fastify-api-reference'), {
  routePrefix: '/reference',
  configuration: {
    spec: {
      content: () => fastify.swagger(),
    },
  },
})

Actually, we’re picking it up automatically, so this would be enough:

await fastify.register(require('@readyapi/fastify-api-reference'), {
  routePrefix: '/reference',
})

Or, if you just have a static OpenAPI spec, you can directly pass it, too:

await fastify.register(require('@readyapi/fastify-api-reference'), {
  routePrefix: '/reference',
  configuration: {
    spec: {
      content: { … }
    },
  },
})

The fastify plugin takes our universal configuration object, read more about configuration in the core package README.

Themes

By default, we’re using a custom Fastify theme and it’s beautiful. But you can choose one of our other themes, too:

await fastify.register(require('@readyapi/fastify-api-reference'), {
  routePrefix: '/reference',
  configuration: {
    theme: 'purple',
  },
})

Dependencies (1)

Dev Dependencies (12)

Package Sidebar

Install

npm i @readyapi/fastify-api-reference

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

21.7 kB

Total Files

13

Last publish

Collaborators

  • nextlinux