Opened 9 months ago
Last modified 3 months ago
#64168 new defect (bug)
Inaccurate JSON schema for template-parts endpoint
| Reported by: | johnbillion | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | REST API | Version: | 5.8 |
| Severity: | normal | Keywords: | good-first-bug has-patch has-unit-tests |
| Cc: | Focuses: |
Description
The schema provided by the wp/v2/template-parts REST API endpoint has some inaccuracies:
- The
originproperty can benullas well as a string. This property maps directly toWP_Block_Template::originwhich isstring|null. - The
modifiedproperty can befalseas well as a date-time string.
Both of these properties can be seen with null/false values by performing an authenticated request to /wp/v2/template-parts on a freshly installed vanilla WordPress site.
Any updates will need unit test coverage.
Here's an untested update to the modified property to replace its type and format.
'oneOf' => array( array( 'type' => 'string', 'format' => 'date-time' ), array( 'type' => 'boolean', 'enum' => array( false ), ) ),
Attachments (1)
Change History (3)
This ticket was mentioned in PR #10441 on WordPress/wordpress-develop by @nimeshatxecurify.
9 months ago
#1
- Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed
@
4 months ago
Refreshed patch for current trunk (r609f25f). Schema fix for origin (string|null) and modified (oneOf string|false) with 3 unit tests. All 51 template controller tests pass.
This ticket was mentioned in PR #11699 on WordPress/wordpress-develop by @motylanogha.
3 months ago
#2
WP_REST_Templates_Controller::prepare_item_for_response() can return:
origin: nullfor templates that do not come from a customizer/theme/plugin sourcemodified: falsefor templates whose modified timestamp cannot be resolved
The schema declared origin as string and modified as string/date-time, so both responses failed schema validation under strict-mode REST clients.
This PR widens the schema to match the runtime behavior:
originbecomes[ string, null ]modifiedbecomes aoneOfof date-time string orfalse
Tests cover:
- The
originschema acceptsnull - The
modifiedschema accepts both date-time string andfalse - A theme template returns
nullfororiginagainst the new schema
Complements GH-10441.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Fix as suggested by John