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.
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-export0
Stars
0
Forks
0
Open Issues
Today
Last Updated
0
Weekly Downloads
v0.1.0
npm Version
95.4 KB
Unpacked Size
0
Dependencies
Trends appear after 7 days of data. Daily snapshots have not started yet.
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
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1434479081-root)<a href="https://payloaddirectory.dev/plugins/1434479081-root"><img src="https://payloaddirectory.dev/badge/1434479081-root.svg" alt="Payload Directory"></a>README
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.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
| Option | Default | |
|---|---|---|
path | '/_schema' | Under your API route: GET /api/_schema |
access | any 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 |
enabled | true | Turn the plugin off without removing it |
{
"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[]' } },
}]
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.
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.
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
MIT
openapi
Generate OpenAPI 3 documents from your Payload config, including collection, global and custom endpoints
48299/wk142v1
payload oapi
Generate an OpenAPI spec from your Payload config with optional documentation UIs
8710.8k/wk125v3
payload plugin openapi
Generate an OpenAPI 3.0, 3.1 or 3.2 spec from your Payload config and serve it with Scalar or Swagger UI
77459/wk18v4
payload operations
Typed custom operations for Payload CMS using the native Payload REST SDK
589/wk2v3
swagger
Generate OpenAPI 3 docs from your Payload config and serve them through Swagger UI
48122/wk142v1
query
Typesafe query filters and field selection for Payload's REST and internal APIs
438/wk142v1