From 1efbfdb24c4c24f9b3898c5eeef2ade964233bbd Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 24 Aug 2024 22:34:02 +0100 Subject: [PATCH] Add schemas for patterns from the pattern directory. --- packages/wp-types/index.ts | 44 +++++++++++ packages/wp-types/readme.md | 2 +- readme.md | 2 +- schema.json | 8 ++ .../pattern-directory-patterns.json | 19 +++++ .../rest-api/pattern-directory-pattern.json | 73 +++++++++++++++++++ tests/output/block-pattern-categories.php | 9 --- tests/output/block-patterns.php | 12 +++ 8 files changed, 158 insertions(+), 11 deletions(-) create mode 100644 schemas/rest-api/collections/pattern-directory-patterns.json create mode 100644 schemas/rest-api/pattern-directory-pattern.json delete mode 100644 tests/output/block-pattern-categories.php diff --git a/packages/wp-types/index.ts b/packages/wp-types/index.ts index 30386a0..3e95846 100644 --- a/packages/wp-types/index.ts +++ b/packages/wp-types/index.ts @@ -166,6 +166,10 @@ export type WP_REST_API_Page = WP_REST_API_Partial_Post_Common & * A collection of page objects in a REST API context. */ export type WP_REST_API_Pages = WP_REST_API_Page[]; +/** + * A collection of patterns from the pattern directory in a REST API context. + */ +export type WP_REST_API_Pattern_Directory_Patterns = WP_REST_API_Pattern_Directory_Pattern[]; /** * A post object in a REST API context. */ @@ -295,6 +299,8 @@ export interface WP { Navigation_Menus: WP_REST_API_Navigation_Menus; Page: WP_REST_API_Page; Pages: WP_REST_API_Pages; + Pattern_Directory_Pattern: WP_REST_API_Pattern_Directory_Pattern; + Pattern_Directory_Patterns: WP_REST_API_Pattern_Directory_Patterns; Post: WP_REST_API_Post; Posts: WP_REST_API_Posts; Rendered_Block: WP_REST_API_Rendered_Block; @@ -3364,6 +3370,44 @@ interface WP_REST_API_Partial_Post_Excerpt { protected: boolean; }; } +/** + * A pattern from the pattern directory in a REST API context. + */ +export interface WP_REST_API_Pattern_Directory_Pattern { + /** + * The pattern ID. + */ + id: number; + /** + * The pattern title, in human readable format. + */ + title: string; + /** + * The pattern content. + */ + content: string; + /** + * The pattern category slugs. + */ + categories: string[]; + /** + * The pattern keywords. + */ + keywords: string[]; + /** + * The pattern detailed description. + */ + description: string; + /** + * The pattern viewport width for inserter preview. + */ + viewport_width: number; + /** + * Block types that the pattern is intended to be used with. + */ + block_types?: string[]; + [k: string]: unknown; +} /** * A rendered dynamic block in a REST API context. Only accessible with the 'edit' context. */ diff --git a/packages/wp-types/readme.md b/packages/wp-types/readme.md index 8582490..c1a5ba7 100644 --- a/packages/wp-types/readme.md +++ b/packages/wp-types/readme.md @@ -87,7 +87,7 @@ Route | Schema /wp/v2/pages/{parent}/autosaves/{id} | Todo /wp/v2/pages/{parent}/revisions | `WP_REST_API_Revisions` /wp/v2/pages/{parent}/revisions/{id} | `WP_REST_API_Revision` -/wp/v2/pattern-directory/patterns | Todo +/wp/v2/pattern-directory/patterns | `WP_REST_API_Pattern_Directory_Patterns` /wp/v2/plugins | Todo /wp/v2/plugins/{plugin} | Todo /wp/v2/posts | `WP_REST_API_Posts` diff --git a/readme.md b/readme.md index 705c173..1c58ce9 100644 --- a/readme.md +++ b/readme.md @@ -91,7 +91,7 @@ Route | Schema /wp/v2/pages/{parent}/autosaves/{id} | Todo /wp/v2/pages/{parent}/revisions | `WP_REST_API_Revisions` /wp/v2/pages/{parent}/revisions/{id} | `WP_REST_API_Revision` -/wp/v2/pattern-directory/patterns | Todo +/wp/v2/pattern-directory/patterns | `WP_REST_API_Pattern_Directory_Patterns` /wp/v2/plugins | Todo /wp/v2/plugins/{plugin} | Todo /wp/v2/posts | `WP_REST_API_Posts` diff --git a/schema.json b/schema.json index d05e642..6361200 100644 --- a/schema.json +++ b/schema.json @@ -185,6 +185,12 @@ "Pages": { "$ref": "schemas/rest-api/collections/pages.json" }, + "Pattern_Directory_Pattern": { + "$ref": "schemas/rest-api/pattern-directory-pattern.json" + }, + "Pattern_Directory_Patterns": { + "$ref": "schemas/rest-api/collections/pattern-directory-patterns.json" + }, "Post": { "$ref": "schemas/rest-api/post.json" }, @@ -287,6 +293,8 @@ "Navigation_Menus", "Page", "Pages", + "Pattern_Directory_Pattern", + "Pattern_Directory_Patterns", "Post", "Posts", "Rendered_Block", diff --git a/schemas/rest-api/collections/pattern-directory-patterns.json b/schemas/rest-api/collections/pattern-directory-patterns.json new file mode 100644 index 0000000..b5483ef --- /dev/null +++ b/schemas/rest-api/collections/pattern-directory-patterns.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/hyper-schema", + "$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/rest-api/collections/pattern-directory-patterns.json", + "title": "WP_REST_API_Pattern_Directory_Patterns", + "description": "A collection of patterns from the pattern directory in a REST API context.", + "type": "array", + "items": { + "$ref": "../pattern-directory-pattern.json" + }, + "links": [ + { + "rel": "self", + "href": "/wp/v2/pattern-directory/patterns", + "targetSchema": { + "$ref": "#" + } + } + ] +} diff --git a/schemas/rest-api/pattern-directory-pattern.json b/schemas/rest-api/pattern-directory-pattern.json new file mode 100644 index 0000000..8866dfa --- /dev/null +++ b/schemas/rest-api/pattern-directory-pattern.json @@ -0,0 +1,73 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/hyper-schema", + "$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/rest-api/pattern-directory-pattern.json", + "title": "WP_REST_API_Pattern_Directory_Pattern", + "description": "A pattern from the pattern directory in a REST API context.", + "type": "object", + "readOnly": true, + "required": [ + "id", + "title", + "content", + "categories", + "keywords", + "description", + "viewport_width" + ], + "properties": { + "id": { + "description": "The pattern ID.", + "type": "integer" + }, + "title": { + "description": "The pattern title, in human readable format.", + "type": "string" + }, + "content": { + "description": "The pattern content.", + "contentMediaType": "text/html", + "type": "string" + }, + "categories": { + "description": "The pattern category slugs.", + "type": "array", + "items": { + "type": "string" + } + }, + "keywords": { + "description": "The pattern keywords.", + "type": "array", + "items": { + "type": "string" + } + }, + "description": { + "description": "The pattern detailed description.", + "type": "string" + }, + "viewport_width": { + "description": "The pattern viewport width for inserter preview.", + "type": "integer" + }, + "block_types": { + "description": "Block types that the pattern is intended to be used with.", + "type": "array", + "items": { + "type": "string" + } + } + }, + "links": [ + { + "rel": "collection", + "href": "/wp/v2/pattern-directory/patterns", + "targetSchema": { + "type": "array", + "items": { + "$ref": "#" + } + } + } + ] +} diff --git a/tests/output/block-pattern-categories.php b/tests/output/block-pattern-categories.php deleted file mode 100644 index 53a2f29..0000000 --- a/tests/output/block-pattern-categories.php +++ /dev/null @@ -1,9 +0,0 @@ -