janbuchar

payload oapi

by janbuchar
APIs & SDKs
v3
^3.0.0
MIT

Overview

Summary generated from the README

Autogenerates an OpenAPI 3.0 or 3.1 specification from a Payload CMS instance, covering collection and global CRUD, auth and preferences endpoints. It is added as a plugin in the Payload config and serves the spec as JSON from an API route. Optional plugins add Scalar, Swagger UI, RapiDoc or Redoc viewers. Requires Payload 3.x.

Features

  • Documents collection and global CRUD endpoints
  • Documents auth endpoints following each collection's auth config
  • Outputs OpenAPI 3.0 or 3.1
  • Filters collections and globals by slug and hides internal collections
  • Documents custom endpoints through custom.openapi
  • adjustGeneratedSpec hook to modify the final spec per request

Use cases

  • Publish API documentation for a Payload backend with a built-in docs UI
  • Generate client SDKs from the spec produced by a Payload instance
  • Expose only selected collections in a public API spec behind a reverse proxy

From the author

An OpenAPI plugin for Payload CMS

Installation

npm i payload-oapi

125

Stars

25

Forks

13

Open Issues

2 months ago

Last Updated

31.7k

Weekly Downloads

v0.3.1

npm Version

188.8 KB

Unpacked Size

4

Dependencies

GitHub stars

125+3 since Sep 6

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

31.3K+20.1K since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 202631,264
Dec 4, 202630,289
Dec 3, 202629,263
Dec 2, 202630,715
Dec 1, 202632,537
Nov 30, 202631,349
Nov 29, 202630,304
Nov 28, 202630,446
Nov 27, 202630,109
Nov 26, 202630,270
Nov 25, 202629,816
Nov 24, 202628,263
Nov 23, 202628,784
Nov 22, 202629,304
Nov 21, 202630,240
Nov 20, 202630,792
Nov 19, 202629,997
Nov 18, 202628,324
Nov 17, 202627,292
Nov 16, 202627,098
Nov 15, 202625,843
Nov 14, 202625,189
Nov 13, 202625,380
Nov 12, 202625,107
Nov 11, 202624,325
Nov 10, 202623,654
Nov 9, 202622,930
Nov 8, 202622,795
Nov 7, 202621,135
Nov 6, 202620,360
Nov 5, 202619,706
Nov 4, 202619,782
Nov 3, 202620,017
Nov 2, 202620,865
Nov 1, 202620,848
Oct 31, 202621,242
Oct 30, 202620,307
Oct 29, 202616,676
Oct 28, 202613,359
Oct 27, 202614,276
Oct 26, 202614,068
Oct 25, 202614,082
Oct 24, 202614,567
Oct 23, 202611,246
Oct 22, 202614,967
Oct 21, 202618,120
Oct 20, 202616,723
Oct 19, 202615,819
Oct 18, 202615,188
Oct 17, 202614,946
Oct 16, 202618,458
Oct 15, 202618,616
Oct 14, 202618,251
Oct 13, 202618,206
Oct 12, 202618,262
Oct 11, 202618,502
Oct 10, 202617,472
Oct 9, 202617,049
Oct 8, 202617,014
Oct 7, 202617,150
Oct 6, 202617,048
Oct 5, 202617,011
Oct 4, 202616,308
Oct 3, 202615,653
Oct 2, 202614,690
Oct 1, 202612,789
Sep 30, 202612,992
Sep 29, 202613,195
Sep 28, 202613,177
Sep 27, 202613,657
Sep 26, 202614,451
Sep 25, 202615,329
Sep 24, 202616,799
Sep 23, 202616,643
Sep 22, 202616,741
Sep 21, 202617,317
Sep 20, 202617,254
Sep 19, 202616,662
Sep 18, 202616,396
Sep 17, 202616,290
Sep 16, 202614,937
Sep 15, 202615,228
Sep 14, 202614,802
Sep 13, 202614,033
Sep 12, 202613,736
Sep 11, 202613,278
Sep 10, 202612,103
Sep 9, 202612,480
Sep 8, 202611,806
Sep 7, 202611,233
Sep 6, 202611,146

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

Health Score

76/100Excellent

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/618796772-root.svg)](https://payloaddirectory.dev/plugins/618796772-root)
HTML
<a href="https://payloaddirectory.dev/plugins/618796772-root"><img src="https://payloaddirectory.dev/badge/618796772-root.svg" alt="Payload Directory"></a>
Updated Oct 3, 2026Created Mar 25, 2023Published Oct 3, 2026

README

Payload OpenAPI Plugin

npm version

Autogenerate an OpenAPI specification from your Payload CMS instance and use it for documentation or to generate client SDKs.

Roadmap

  • Complete description of collection CRUD endpoints
  • Complete description of globals CRUD endpoints
  • Integrated Swagger UI and Rapidoc
  • Authentication endpoints and specification
  • Preferences endpoints
  • Support Payload CMS 3.x
  • Support generating both OpenAPI 3.0 and 3.1
  • Collection and global filtering
  • Custom endpoints

Installation

You can install the plugin using your preferred package manager:

  • pnpm add payload-oapi
  • npm install payload-oapi
  • yarn add payload-oapi

Setup

1. Add the OpenAPI core plugin

To add the OpenAPI specification endpoint to your Payload app, simply import the openapi plugin and add it to your payload configuration:

import { openapi } from 'payload-oapi'

buildConfig({
  plugins: [
    openapi({ openapiVersion: '3.0', metadata: { title: 'Dev API', version: '0.0.1' } }),
  ],
  // ...
})

2. Add a documentation UI plugin (optional)

To provide a user interface for your API documentation, you can add one of the following plugins:

Example usage:

import { openapi, scalar, swaggerUI, rapidoc, redoc } from 'payload-oapi'

// Choose one documentation UI plugins as needed
buildConfig({
  plugins: [
    openapi(/* ... */),
    // Uncomment the UI you want to use:
    scalar({ /* ...options */ }),
    // swaggerUI({ /* ...options */ }),
    // rapidoc({ /* ...options */ }),
    // redoc({ /* ...options */ }),
  ],
  // ...
})

3. Filter collections and globals (optional)

Control which collections and globals appear in the OpenAPI spec using the filters option:

  • includeCollections / excludeCollections — filter collections by slug
  • includeGlobals / excludeGlobals — filter globals by slug
  • hideInternalCollections — exclude payload-* collections

Example:

openapi({
  openapiVersion: '3.0',
  metadata: { title: 'Dev API', version: '0.0.1' },
  filters: {
    includeCollections: ['posts', 'categories'],
    excludeGlobals: ['footer'],
    hideInternalCollections: true,
  },
})

4. Override the API base path (optional)

Generated operation paths are prefixed with your Payload routes.api setting. Set apiBasePath if clients reach the API under a different prefix, e.g. behind a reverse proxy:

openapi({
  openapiVersion: '3.0',
  metadata: { title: 'Dev API', version: '0.0.1' },
  apiBasePath: '/public-api',
})

5. Document your own endpoints (optional)

Payload endpoints — on a collection, a global or the config root — are documented when they carry an OpenAPI operation under custom.openapi. Anything you do not set is filled in for you (tags, operationId, summary, and a security requirement, since the generator cannot inspect a custom handler's access control):

import type { CustomEndpointDocumentation } from 'payload-oapi'

const Pets: CollectionConfig = {
  slug: 'pets',
  endpoints: [
    {
      path: '/by-status/:status',
      method: 'get',
      handler: myHandler,
      custom: {
        openapi: {
          summary: 'List pets by status',
          security: [],
          parameters: [{ in: 'path', name: 'status', required: true, schema: { type: 'string' } }],
          responses: {
            200: {
              description: 'Pets with the requested status',
              content: {
                'application/json': {
                  schema: { type: 'array', items: { $ref: '#/components/schemas/Pet' } },
                },
              },
            },
          },
        } satisfies CustomEndpointDocumentation,
      },
    },
  ],
  // ...
}

Write these in OpenAPI 3.1 syntax whatever openapiVersion you configured — a 3.0 spec is down-converted on the way out. $ref pointers to generated components work as shown; to add schemas of your own, declare them through Payload's typescript.schema and reference them the same way.

6. Adjust the finished document (optional)

adjustGeneratedSpec gets the last word on the spec. Use it for anything the plugin does not model — paths Payload does not serve, extra components, or removing a generated operation that you'd like to exclude from the spec:

openapi({
  metadata: { title: 'Dev API', version: '0.0.1' },
  adjustGeneratedSpec: (spec, req) => {
    spec.paths['/external/health'] = {
      get: { summary: 'Health check', responses: { 200: { description: 'ok' } } },
    }

    delete spec.paths['/api/posts'].post
  },
})
  • it always receives a 3.1 document, even with openapiVersion: '3.0' — write 3.1 syntax and it is down-converted afterwards, exactly like custom.openapi
  • mutate the argument or return a replacement; it may be async
  • it runs per request and gets req, so the spec can depend on the locale or the current user
  • $ref targets are already resolved, so generated components can be reused by pointer

Component names derive from labels.singular, so they are not a stable contract — a collection you declare yourself gets Post, while the same slug can yield Posts elsewhere. Copy a $ref the generator produced instead of assembling one:

adjustGeneratedSpec: spec => {
  const posts = spec.paths['/api/posts'].get.responses['200'] // { $ref: '…/PostListResponse' }

  spec.paths['/external/latest'] = { get: { responses: { 200: posts } } }
}

Auth endpoints

Collections with auth get their login, logout, refresh, verification and password-reset operations documented automatically, following that collection's auth config — disableLocalStrategy drops the password operations, loginWithUsername decides whether the login body takes an email or a username, maxLoginAttempts: 0 drops /unlock, and verify adds /verify/{id}.

Usage

Unless you configured it otherwise, your spec will be accessible via https://your-payload.com/api/openapi.json. If you added a documentation UI, that will be accessible via https://your-payload.com/api/docs (this is also configurable).

Similar plugins