Skip to content

View config schema: generate from JSON - #12854

Draft
oandregal wants to merge 2 commits into
WordPress:trunkfrom
oandregal:update/view-config-schema-from-json
Draft

View config schema: generate from JSON#12854
oandregal wants to merge 2 commits into
WordPress:trunkfrom
oandregal:update/view-config-schema-from-json

Conversation

@oandregal

Copy link
Copy Markdown
Member

Backports WordPress/gutenberg#81168

What

Generates the view config schema from a JSON.

Why

Having a central schema enables us to generate several artifacts at once: handbook documentation and rest api schema.

How

  • Introduce a view-config.json JSON Schema.
  • Introduce a script to generate the corresponding PHP schema.
  • Update the REST Endpoint to use the generated PHP schema.

oandregal and others added 2 commits August 5, 2026 09:52
…SON Schema.

The `/wp/v2/view-config` endpoint schema is now loaded from a generated
PHP file, `wp-includes/rest-api/view-config-schema.php`, which mirrors
the canonical JSON Schema at `schemas/json/view-config.json` in the
Gutenberg repository (regenerated there via
`node tools/docs/gen-view-config-schema-php.mjs`). This makes the JSON
Schema the single source of truth for the endpoint schema, so the two
can no longer drift structurally.

Property descriptions are exported wrapped in `__()` calls so they
remain translatable. The hand-written schema builder methods in
`WP_REST_View_Config_Controller` (get_view_base_schema,
get_column_style_schema, get_table_layout_schema,
get_list_layout_schema, get_grid_layout_schema,
get_combined_layout_schema, get_form_layout_schema,
get_form_field_schema, get_form_schema) are removed, and
`get_item_schema()` now requires the generated file. A test asserts
that every top-level schema property carries a description.

See the Gutenberg PR: WordPress/gutenberg#81168.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The canonical JSON Schema for the /wp/v2/view-config endpoint and its
PHP generator now live in wordpress-develop, at
tools/rest-api/view-config.json and
tools/rest-api/gen-view-config-schema-php.mjs, so the committed
src/wp-includes/rest-api/view-config-schema.php can be regenerated
in-repo with `npm run view-config-schema:generate` (or
`node tools/rest-api/gen-view-config-schema-php.mjs`).

A `--check` mode (`npm run view-config-schema:check`, also wired
into `grunt precommit:php` as `verify:view-config-schema`) fails
when the committed PHP file drifts from the JSON Schema. Only the
generated file's header instructions change; the schema array is
untouched. Docblock references to the Gutenberg repository in the
controller and its tests are updated accordingly.

Reference WordPress/gutenberg#81168.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant