View config schema: generate from JSON - #12854
Draft
oandregal wants to merge 2 commits into
Draft
Conversation
…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>
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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