Skip to content

Commit

Permalink
Add schemas for patterns from the pattern directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbillion committed Aug 24, 2024
1 parent 52107eb commit 1efbfdb
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 11 deletions.
44 changes: 44 additions & 0 deletions packages/wp-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/wp-types/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
8 changes: 8 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -287,6 +293,8 @@
"Navigation_Menus",
"Page",
"Pages",
"Pattern_Directory_Pattern",
"Pattern_Directory_Patterns",
"Post",
"Posts",
"Rendered_Block",
Expand Down
19 changes: 19 additions & 0 deletions schemas/rest-api/collections/pattern-directory-patterns.json
Original file line number Diff line number Diff line change
@@ -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": "#"
}
}
]
}
73 changes: 73 additions & 0 deletions schemas/rest-api/pattern-directory-pattern.json
Original file line number Diff line number Diff line change
@@ -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": "#"
}
}
}
]
}
9 changes: 0 additions & 9 deletions tests/output/block-pattern-categories.php

This file was deleted.

12 changes: 12 additions & 0 deletions tests/output/block-patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@

namespace WPJsonSchemas;

$data = get_rest_response( 'GET', '/wp/v2/block-patterns/categories' );

save_rest_array( [
$data,
], 'block-pattern-categories' );

$data = get_rest_response( 'GET', '/wp/v2/block-patterns/patterns' );

save_rest_array( [
$data,
], 'block-patterns' );

$data = get_rest_response( 'GET', '/wp/v2/pattern-directory/patterns' );

save_rest_array( [
$data,
], 'pattern-directory-patterns' );

0 comments on commit 1efbfdb

Please sign in to comment.