maximseshuk

payload plugin openapi

by maximseshuk
APIs & SDKs
v4
^4.0.0-beta.4
^4.0.0-beta.4 · prerelease
MIT

Overview

Summary generated from the README

Builds an OpenAPI document from the sanitized Payload config, covering collections, globals, auth, versions, uploads, jobs and endpoints of official plugins. It plugs in through the plugins array and serves the spec plus an interactive Scalar or Swagger UI page. Requires Payload 4.0.0-beta.4 or later, Next.js 16.4 or later and Node.js 24.22.1 or later. Sends opt-out anonymous telemetry.

Features

  • Generates the spec automatically from collections, globals, auth, versions, uploads and jobs
  • Serves interactive docs with Scalar, Swagger UI, or both on different paths
  • Document custom endpoints and refine field schemas through the custom.openapi key
  • Filters which entities and operations appear in the spec
  • Marks operations as public or secured by probing access functions
  • Writes the spec to disk with the openapi:generate CLI command

Use cases

  • Publish interactive API reference docs for a Payload REST API
  • Generate a spec file in CI for schema diffs or client code generation
  • Document custom endpoints and plugin routes in a single OpenAPI document

From the author

Payload plugin that generates OpenAPI 3.0/3.1/3.2 docs, with Scalar or Swagger UI

Installation

npm i @seshuk/payload-plugin-openapi

18

Stars

1

Forks

6

Open Issues

1 weeks ago

Last Updated

1.5k

Weekly Downloads

v0.2.3

npm Version

469.1 KB

Unpacked Size

1

Dependencies

GitHub stars

18+4 since Sep 6

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 202618
Dec 4, 202618
Dec 3, 202618
Dec 2, 202618
Dec 1, 202618
Nov 30, 202618
Nov 29, 202618
Nov 28, 202618
Nov 27, 202618
Nov 26, 202618
Nov 25, 202618
Nov 24, 202618
Nov 23, 202618
Nov 22, 202618
Nov 21, 202618
Nov 20, 202618
Nov 19, 202618
Nov 18, 202618
Nov 17, 202618
Nov 16, 202618
Nov 15, 202618
Nov 14, 202618
Nov 13, 202618
Nov 12, 202618
Nov 11, 202618
Nov 10, 202618
Nov 9, 202618
Nov 8, 202618
Nov 7, 202618
Nov 6, 202618
Nov 5, 202618
Nov 4, 202618
Nov 3, 202618
Nov 2, 202618
Nov 1, 202618
Oct 31, 202618
Oct 30, 202618
Oct 29, 202618
Oct 28, 202618
Oct 27, 202618
Oct 26, 202618
Oct 25, 202618
Oct 24, 202618
Oct 23, 202618
Oct 22, 202618
Oct 21, 202618
Oct 20, 202618
Oct 19, 202618
Oct 18, 202618
Oct 17, 202618
Oct 16, 202618
Oct 15, 202618
Oct 14, 202617
Oct 13, 202617
Oct 12, 202617
Oct 11, 202617
Oct 10, 202615
Oct 9, 202614
Oct 8, 202614
Oct 7, 202614
Oct 6, 202614
Oct 5, 202614
Oct 4, 202614
Oct 3, 202614
Oct 2, 202614
Oct 1, 202614
Sep 30, 202614
Sep 29, 202614
Sep 28, 202614
Sep 27, 202614
Sep 26, 202614
Sep 25, 202614
Sep 24, 202614
Sep 23, 202614
Sep 22, 202614
Sep 21, 202614
Sep 20, 202614
Sep 19, 202614
Sep 18, 202614
Sep 17, 202614
Sep 16, 202614
Sep 15, 202614
Sep 14, 202614
Sep 13, 202614
Sep 12, 202614
Sep 11, 202614
Sep 10, 202614
Sep 9, 202614
Sep 8, 202614
Sep 7, 202614
Sep 6, 202614
npm weekly downloads

1.5K+1.2K since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 20261,472
Dec 4, 20261,472
Dec 3, 20261,450
Dec 2, 20261,515
Dec 1, 20261,511
Nov 30, 20261,529
Nov 29, 20261,409
Nov 28, 20261,470
Nov 27, 20261,404
Nov 26, 20261,317
Nov 25, 20261,053
Nov 24, 20261,044
Nov 23, 20261,018
Nov 22, 2026986
Nov 21, 2026865
Nov 20, 2026811
Nov 19, 2026769
Nov 18, 2026857
Nov 17, 2026858
Nov 16, 2026876
Nov 15, 2026821
Nov 14, 2026796
Nov 13, 2026724
Nov 12, 2026762
Nov 11, 2026785
Nov 10, 2026789
Nov 9, 2026785
Nov 8, 2026988
Nov 7, 20261,015
Nov 6, 20261,051
Nov 5, 20261,040
Nov 4, 20261,045
Nov 3, 20261,042
Nov 2, 20261,047
Nov 1, 2026936
Oct 31, 2026939
Oct 30, 2026924
Oct 29, 2026721
Oct 28, 2026503
Oct 27, 2026525
Oct 26, 2026514
Oct 25, 2026583
Oct 24, 2026719
Oct 23, 2026595
Oct 22, 2026771
Oct 21, 2026940
Oct 20, 2026952
Oct 19, 20261,079
Oct 18, 20261,092
Oct 17, 20261,522
Oct 16, 20261,735
Oct 15, 20261,732
Oct 14, 20261,639
Oct 13, 20261,620
Oct 12, 20261,486
Oct 11, 20261,377
Oct 10, 2026728
Oct 9, 2026665
Oct 8, 2026633
Oct 7, 2026655
Oct 6, 2026640
Oct 5, 2026636
Oct 4, 2026644
Oct 3, 2026699
Oct 2, 2026705
Oct 1, 2026641
Sep 30, 2026669
Sep 29, 2026658
Sep 28, 2026666
Sep 27, 2026761
Sep 26, 2026720
Sep 25, 2026691
Sep 24, 2026747
Sep 23, 2026740
Sep 22, 2026761
Sep 21, 2026758
Sep 20, 2026640
Sep 19, 2026586
Sep 18, 2026620
Sep 17, 2026593
Sep 16, 2026598
Sep 15, 2026596
Sep 14, 2026602
Sep 13, 2026588
Sep 12, 2026587
Sep 11, 2026490
Sep 10, 2026445
Sep 9, 2026379
Sep 8, 2026367
Sep 7, 2026354
Sep 6, 2026315

Each point is npm's rolling 7-day download count.

Health Score

70/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1254944928-root.svg)](https://payloaddirectory.dev/plugins/1254944928-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1254944928-root"><img src="https://payloaddirectory.dev/badge/1254944928-root.svg" alt="Payload Directory"></a>
Updated Nov 26, 2026Created May 31, 2026Published Oct 8, 2026

README

OpenAPI Plugin for Payload

OpenAPI Plugin for Payload

Generate an OpenAPI 3.0/3.1/3.2 specification from your Payload config and serve it with Scalar or Swagger UI.

GitHub release npm version npm downloads CI Documentation license Ko-fi

Features

  • Full spec from your config — collections, globals, auth, versions, uploads, jobs, and the endpoints of official Payload plugins are documented with zero annotation. See the endpoint list.
  • Interactive docs included — mount Scalar or Swagger UI, or both on different paths.
  • Native metadata — document custom endpoints and refine field schemas through Payload's own custom.openapi key. No wrapper, no separate registry.
  • Precise filtering — choose exactly which entities and operations end up in the spec.
  • Security marking — every operation is marked public or secured by probing your access functions, with per-entity and document-wide overrides.
  • Localized — descriptions resolve through your Payload i18n, and the UI ships translations for 44 locales.
  • File generation — write the spec to disk with payload openapi:generate for CI, schema diffs, or client codegen.
  • One option for the spec version — serve OpenAPI 3.0, 3.1, or 3.2 from the same config.

Quick start

Requires Payload 4.0.0-beta.4 or later, Next.js 16.4 or later and Node.js 24.22.1 or later. On Payload 3, use @seshuk/payload-plugin-openapi@0.

Install

npm install @seshuk/payload-plugin-openapi@beta

v1 is in beta under the beta npm tag, and Payload 4 is published under beta.

Configure

Add the plugin to your Payload config, plus a docs UI renderer:

import { openapi, scalar } from '@seshuk/payload-plugin-openapi'
import { buildConfig } from 'payload'

export default buildConfig({
  plugins: [
    openapi({
      info: {
        title: 'My API',
        version: '1.0.0',
      },
    }),
    scalar(),
  ],
})

Two endpoints are now live, both relative to your API route (/api by default):

  • GET /api/openapi.json — the generated OpenAPI document
  • GET /api/docs — the interactive API reference

info.title and info.version are required; the plugin throws at boot without them. Prefer Swagger UI? Swap scalar() for swaggerUi(), or mount both on different paths.

The document is built lazily from the fully sanitized config, so collections, fields, and endpoints added by other plugins are picked up regardless of plugin order.

Add filters to control what is exposed, interactiveAuth for a login dialog in the docs UI, extensions for anything the generator doesn't produce on its own — see the configuration reference.

Upgrading from 0.x

v1 renames a few options. The plugin throws at boot when it finds an old name.

// 0.x
openapi({
  metadata: { title, version },
  specEndpoint: '/spec.json',
  interactiveAuth: { endpoint: '/login' },
  securityWhen: ({ slug }) => (slug === 'feed' ? true : undefined),
  filters: { excludeWhen: ({ path }) => path.includes('/internal/') },
})
scalar({ specEndpoint: '/api/spec.json' })

// v1
openapi({
  info: { title, version },
  path: '/spec.json',
  interactiveAuth: { path: '/login' },
  security: ({ slug }) => (slug === 'feed' ? 'public' : undefined),
  filters: { excludeOperations: [({ path }) => path.includes('/internal/')] },
})
scalar() // follows the openapi() path; use specURL for another URL

// 0.x
custom: { openapi: { security: { read: true, create: false } } }

// v1
custom: { openapi: { security: { read: 'public', create: 'secured' } } }

The spec no longer reads servers from the Host header. It uses serverURL, the new servers option, or hosts you list in trustedHosts. An extension transform that throws now fails the request. The spec and docs page are open by default. Add access to openapi() and scalar() to make them private. See Upgrading from 0.x.

Documentation

Full docs are at https://payload-plugin-openapi.seshuk.im/:

Official plugins

When you install an official Payload plugin, the spec documents the REST endpoints it mounts: @payloadcms/plugin-ecommerce, plugin-stripe, plugin-mcp, plugin-seo, plugin-search, plugin-multi-tenant, plugin-import-export and storage-r2. There is nothing to configure. Filter them with excludeOperations: [{ plugin: '@payloadcms/plugin-stripe' }] or { kind: 'plugin' }. See Official plugins.

For plugin authors

If you maintain a Payload plugin, attach a custom.openapi Operation Object to the endpoints you add and they show up in the generated spec — no dependency on this package, and nothing for your users to wire up. The same key works on fields. If this plugin isn't installed, the metadata is inert. See For plugin authors.

Telemetry

The plugin sends an anonymous, opt-out usage report once per day: plugin, Payload, and Node versions plus which features are enabled. It never sends secrets, IPs, keys, URLs, paths, hostnames, collection names, or anything from your spec. A one-time notice prints on first run.

Opt out with telemetry: false, DO_NOT_TRACK=1, or OPENAPI_TELEMETRY_DISABLED=1 (also disabled automatically in CI and when payload.config.telemetry is false). See Telemetry for the full list of what is and isn't collected.

Support

Bug reports, feature requests, and questions go to GitHub Issues. For Payload itself, see the Payload docs and Discord.

License

MIT — see LICENSE.

Credits

Built by Maxim Seshuk for the Payload community.

If this plugin saves you time, you can buy me a coffee ☕

Similar plugins