ylahav

payload schema export

by ylahav
APIs & SDKs
v3
^3.0.0
MIT

Overview

Summary generated from the README

Adds a REST endpoint that returns a JSON description of the sanitized Payload config, including collections, globals, fields, relations, select options, locales and every built-in and custom route. Access is controlled by a configurable rule, and an admin page summarises the schema and downloads it. A JSON Schema of the format is bundled for validation and reader generation. Works with Payload 3.

Features

  • Serves the site schema at a configurable endpoint path under the API route
  • Describes collections, globals, fields, relations, labels and locales
  • Lists built-in and custom REST routes with operation names and custom metadata
  • Admin page with sidebar link to view the summary and download schema.json
  • Configurable access function, defaulting to any signed-in user
  • Ships a JSON Schema of the output format with a versioned schema

Use cases

  • Generate typed clients or models in non-TypeScript languages such as Dart from a Payload site
  • Build schema-driven editors or tools that read the data model without the Payload config
  • Document custom REST endpoints alongside built-in routes for API consumers

From the author

Serves a JSON description of a Payload CMS site (collections, fields, relations, locales and REST routes) for typed clients, code generators and schema-driven editors in any language.

Installation

npm i @yairl/payload-schema-export

0

Stars

0

Forks

0

Open Issues

Today

Last Updated

0

Weekly Downloads

v0.1.0

npm Version

95.4 KB

Unpacked Size

0

Dependencies

GitHub stars

Trends appear after 7 days of data. Daily snapshots have not started yet.

npm weekly downloads

Trends appear after 7 days of data. Daily snapshots have not started yet.

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

Health Score

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

README

@yairl/payload-schema-export

A Payload 3 plugin that describes your site as JSON: collections, globals, fields, relations, select options, labels, locales, and every REST route, built-in and custom. Clients, code generators and schema-driven tools in any language read that one file instead of your Payload config.

  • GET /api/_schema serves it, behind your own access rule.
  • An API schema page in the admin summarises it and downloads schema.json.
  • schema.schema.json in this package is the format as a JSON Schema, for validating the file or generating a reader for it.
// payload.config.ts
import { schemaExport } from '@yairl/payload-schema-export'

export default buildConfig({
  // ...
  plugins: [
    schemaExport({
      // Default: any signed-in user. The schema is a map of your data model.
      access: ({ req }) => Boolean(req.user?.roles?.includes('admin')),
    }),
  ],
})
pnpm add @yairl/payload-schema-export
pnpm payload generate:importmap   # so the admin page and sidebar link are found

Options

OptionDefault
path'/_schema'Under your API route: GET /api/_schema
accessany signed-in user({ req }) => boolean, used by the endpoint and the admin page
adminView{ path: '/schema', showInSidebar: true }The admin page; false for the endpoint alone
enabledtrueTurn the plugin off without removing it

What's in the file

{
  "schemaVersion": 1,
  "adminUserCollection": "users",
  "idType": "text",                       // or "number" (Postgres, SQLite)
  "localization": { "defaultLocale": "he", "locales": [{ "code": "he", "rtl": true }, …] },
  "api": {
    "basePath": "/api",
    "authorizationScheme": "JWT",         // Authorization: JWT <token>
    "cookieName": "payload-token",
    "routes": [{ "method": "get", "path": "/api/public-catalog" }, …],
    "graphQL": false
  },
  "collections": [{
    "slug": "posts",
    "drafts": true,
    "routes": [
      { "method": "get", "path": "/api/posts", "operation": "find" },
      { "method": "post", "path": "/api/posts/:id/publish" }   // custom: no operation
    ],
    "fields": [
      { "name": "title", "type": "text", "required": true, "localized": true },
      { "name": "author", "type": "relationship", "relationTo": "users" },
      …
    ]
  }],
  "globals": […]
}

SPEC.md describes every key. In short:

  • It describes the sanitized config, so fields Payload adds (auth, upload, timestamps, _status for drafts) are there, because the API returns them.

  • Nothing executable crosses. Function defaults and admin conditions become flags (hasDynamicDefault, admin.conditional); clients leave those to the server.

  • Routes are the site's real route table, read from the config. Built-in ones carry Payload's operation name (find, login, getFile…). Custom ones carry their endpoint's custom object when it's plain JSON, which is the place to describe a custom route's request and response:

    endpoints: [{
      path: '/public-catalog',
      method: 'get',
      handler,
      custom: { description: 'Active exercises, no auth', response: { docs: 'Exercise[]' } },
    }]
    

Versioning

Adding keys doesn't change schemaVersion, so readers must ignore keys they don't know. The version goes up only for a change an existing reader would have to handle: a key removed, renamed, or changing type.

Clients

  • Dart / Flutter: payload_flutter: generated models (payload_dart_gen), a REST client, and a schema-driven editor app.

Built one for another language? Open an issue and it goes on this list.

Development

pnpm install
pnpm test          # builds real sanitized configs and checks the output
pnpm build         # dist/ and schema.schema.json
pnpm fixture       # test/fixtures/schema.json, a sample for client tests
pnpm publish       # runs typecheck, tests and build first

License

MIT

Similar plugins