Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add schemas for font family and font face REST API endpoints #71

Merged
merged 5 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The WordPress REST API response doesn't fully adhere to the JSON schema spec, so
- Start by copying an existing file such as `post.php` which is for `/wp/v2/posts`
- The command should perform one or more REST API requests to the endpoint and pass the responses to the `save_rest_array()` function which saves them as JSON during the tests
* Run `composer run test` to validate and test the schemas.
* Run `npm run build-wp-types` and check the output of `packages/wp-types/index.ts`.
* Check the output of `packages/wp-types/index.ts`.
* Add documentation for the schema in both `readme.md` and `packages/wp-types/readme.md`.

## Creating a PHP object schema
Expand All @@ -69,7 +69,7 @@ The schema for a PHP object is created using the docblocks from its class proper
- Start by copying an existing file such as `error.php`
- The file should pass an array of one or more objects of this type to the `save_object_array()` function which saves it as JSON during the tests
* Run `composer run test` to validate and test the schemas.
* Run `npm run build-wp-types` and check the output of `packages/wp-types/index.ts`.
* Check the output of `packages/wp-types/index.ts`.
* Add documentation for the schema in both `readme.md` and `packages/wp-types/readme.md`.

## Updating schemas for a new WordPress release
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"require-dev": {
"ext-sqlite3": "*",
"ext-pdo_sqlite": "*",
"ergebnis/json-printer": "^3.5",
"johnbillion/args": "1.7.0",
"roots/wordpress-core-installer": "^1.0.0",
"roots/wordpress-full": "6.6-RC3",
Expand Down
235 changes: 167 additions & 68 deletions packages/wp-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ export type WP_REST_API_Comments = WP_REST_API_Comment[];
* A collection of font collection objects in a REST API context.
*/
export type WP_REST_API_Font_Collections = WP_REST_API_Font_Collection[];
/**
* A collection of font family objects in a REST API context.
*/
export type WP_REST_API_Font_Families = WP_REST_API_Font_Family[];
/**
* A collection of font face objects in a REST API context.
*/
export type WP_REST_API_Font_Faces = WP_REST_API_Font_Face[];
/**
* A collection of post objects in a REST API context.
*/
Expand Down Expand Up @@ -144,6 +152,10 @@ export interface WP {
Comments: WP_REST_API_Comments;
Font_Collection: WP_REST_API_Font_Collection;
Font_Collections: WP_REST_API_Font_Collections;
Font_Family: WP_REST_API_Font_Family;
Font_Families: WP_REST_API_Font_Families;
Font_Face: WP_REST_API_Font_Face;
Font_Faces: WP_REST_API_Font_Faces;
Post: WP_REST_API_Post;
Posts: WP_REST_API_Posts;
Page: WP_REST_API_Page;
Expand Down Expand Up @@ -1912,74 +1924,7 @@ export interface WP_REST_API_Font_Collection {
* The font families for the font collection.
*/
font_families: {
font_family_settings: {
name: string;
fontFamily: string;
slug: string;
fontFace?: {
/**
* URL to a preview image of the font.
*/
preview?: string;
/**
* CSS font-family value.
*/
fontFamily: string;
/**
* CSS font-style value.
*/
fontStyle?: string;
/**
* List of available font weights, separated by a space.
*/
fontWeight?: string | number;
/**
* CSS font-display value.
*/
fontDisplay?: "auto" | "block" | "fallback" | "swap" | "optional";
/**
* Paths or URLs to the font files.
*/
src: string | string[];
/**
* CSS font-stretch value.
*/
fontStretch?: string;
/**
* CSS ascent-override value.
*/
ascentOverride?: string;
/**
* CSS descent-override value.
*/
descentOverride?: string;
/**
* CSS font-variant value.
*/
fontVariant?: string;
/**
* CSS font-feature-settings value.
*/
fontFeatureSettings?: string;
/**
* CSS font-variation-settings value.
*/
fontVariationSettings?: string;
/**
* CSS line-gap-override value.
*/
lineGapOverride?: string;
/**
* CSS size-adjust value.
*/
sizeAdjust?: string;
/**
* CSS unicode-range value.
*/
unicodeRange?: string;
}[];
preview?: string;
};
font_family_settings: WP_Font_Family_Settings;
categories?: string[];
}[];
/**
Expand All @@ -1992,6 +1937,160 @@ export interface WP_REST_API_Font_Collection {
_links: WP_REST_API_Object_Links;
[k: string]: unknown;
}
/**
* Font family settings.
*/
export interface WP_Font_Family_Settings {
name: string;
fontFamily: string;
slug: string;
fontFace?: WP_Font_Face[];
preview?: string;
}
/**
* A font face.
*/
export interface WP_Font_Face {
/**
* URL to a preview image of the font.
*/
preview?: string;
/**
* CSS font-family value.
*/
fontFamily: string;
/**
* CSS font-style value.
*/
fontStyle?: string;
/**
* List of available font weights, separated by a space.
*/
fontWeight?: string | number;
/**
* CSS font-display value.
*/
fontDisplay?: "auto" | "block" | "fallback" | "swap" | "optional";
/**
* Paths or URLs to the font files.
*/
src: string | string[];
/**
* CSS font-stretch value.
*/
fontStretch?: string;
/**
* CSS ascent-override value.
*/
ascentOverride?: string;
/**
* CSS descent-override value.
*/
descentOverride?: string;
/**
* CSS font-variant value.
*/
fontVariant?: string;
/**
* CSS font-feature-settings value.
*/
fontFeatureSettings?: string;
/**
* CSS font-variation-settings value.
*/
fontVariationSettings?: string;
/**
* CSS line-gap-override value.
*/
lineGapOverride?: string;
/**
* CSS size-adjust value.
*/
sizeAdjust?: string;
/**
* CSS unicode-range value.
*/
unicodeRange?: string;
}
/**
* A font family object in a REST API context.
*/
export interface WP_REST_API_Font_Family {
/**
* Unique identifier for the font family.
*/
id: number;
/**
* Version of the theme.json schema used for the typography settings.
*/
theme_json_version: number;
/**
* The IDs of the child font faces in the font family.
*/
font_faces: number[];
font_family_settings: WP_Font_Family_Settings;
_links: WP_REST_API_Object_Links;
/**
* The embedded representation of relations. Only present when the '_embed' query parameter is set.
*/
_embedded?: {
/**
* The associated font faces.
*/
font_faces?: unknown[];
[k: string]: unknown;
};
[k: string]: unknown;
}
/**
* A font face object in a REST API context.
*/
export interface WP_REST_API_Font_Face {
/**
* Unique identifier for the font face.
*/
id: number;
/**
* Version of the theme.json schema used for the typography settings.
*/
theme_json_version: number;
/**
* The ID for the parent font family of the font face.
*/
parent: number;
/**
* font-face declaration in theme.json format.
*/
font_face_settings: {
/**
* Unique identifier for the font family.
*/
id?: number;
/**
* Version of the theme.json schema used for the typography settings.
*/
theme_json_version?: number;
/**
* The IDs of the child font faces in the font family.
*/
font_faces?: number[];
font_family_settings?: WP_Font_Family_Settings;
_links?: WP_REST_API_Object_Links;
/**
* The embedded representation of relations. Only present when the '_embed' query parameter is set.
*/
_embedded?: {
/**
* The associated font faces.
*/
font_faces?: unknown[];
[k: string]: unknown;
};
[k: string]: unknown;
};
_links: WP_REST_API_Object_Links;
[k: string]: unknown;
}
/**
* A post object in a REST API context.
*/
Expand Down
12 changes: 6 additions & 6 deletions packages/wp-types/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ Route | Schema
/wp/v2/categories/{id} | `WP_REST_API_Category`
/wp/v2/comments | `WP_REST_API_Comments`
/wp/v2/comments/{id} | `WP_REST_API_Comment`
/wp/v2/wp/v2/font-collections | `WP_REST_API_Font_Collections`
/wp/v2/wp/v2/font-collections/{slug} | `WP_REST_API_Font_Collection`
/wp/v2/wp/v2/font-families | Todo
/wp/v2/wp/v2/font-families/{id}/ | Todo
/wp/v2/wp/v2/font-families/{id}/font-faces | Todo
/wp/v2/wp/v2/font-families/{id}/font-faces/{id} | Todo
/wp/v2/font-collections | `WP_REST_API_Font_Collections`
/wp/v2/font-collections/{slug} | `WP_REST_API_Font_Collection`
/wp/v2/font-families | `WP_REST_API_Font_Families`
/wp/v2/font-families/{id}/ | `WP_REST_API_Font_Family`
/wp/v2/font-families/{parent}/font-faces | `WP_REST_API_Font_Faces`
/wp/v2/font-families/{parent}/font-faces/{id} | `WP_REST_API_Font_Face`
/wp/v2/global-styles/{id} | Todo
/wp/v2/global-styles/{parent}/revisions | Todo
/wp/v2/global-styles/{parent}/revisions/{id} | Todo
Expand Down
12 changes: 6 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ Route | Schema
/wp/v2/categories/{id} | `WP_REST_API_Category`
/wp/v2/comments | `WP_REST_API_Comments`
/wp/v2/comments/{id} | `WP_REST_API_Comment`
/wp/v2/wp/v2/font-collections | `WP_REST_API_Font_Collections`
/wp/v2/wp/v2/font-collections/{slug} | `WP_REST_API_Font_Collection`
/wp/v2/wp/v2/font-families | Todo
/wp/v2/wp/v2/font-families/{id}/ | Todo
/wp/v2/wp/v2/font-families/{id}/font-faces | Todo
/wp/v2/wp/v2/font-families/{id}/font-faces/{id} | Todo
/wp/v2/font-collections | `WP_REST_API_Font_Collections`
/wp/v2/font-collections/{slug} | `WP_REST_API_Font_Collection`
/wp/v2/font-families | `WP_REST_API_Font_Families`
/wp/v2/font-families/{id}/ | `WP_REST_API_Font_Family`
/wp/v2/font-families/{parent}/font-faces | `WP_REST_API_Font_Faces`
/wp/v2/font-families/{parent}/font-faces/{id} | `WP_REST_API_Font_Face`
/wp/v2/global-styles/{id} | Todo
/wp/v2/global-styles/{parent}/revisions | Todo
/wp/v2/global-styles/{parent}/revisions/{id} | Todo
Expand Down
16 changes: 16 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@
"Font_Collections": {
"$ref": "schemas/rest-api/collections/font-collections.json"
},
"Font_Family": {
"$ref": "schemas/rest-api/font-family.json"
},
"Font_Families": {
"$ref": "schemas/rest-api/collections/font-families.json"
},
"Font_Face": {
"$ref": "schemas/rest-api/font-face.json"
},
"Font_Faces": {
"$ref": "schemas/rest-api/collections/font-faces.json"
},
"Post": {
"$ref": "schemas/rest-api/post.json"
},
Expand Down Expand Up @@ -209,6 +221,10 @@
"Comments",
"Font_Collection",
"Font_Collections",
"Font_Family",
"Font_Families",
"Font_Face",
"Font_Faces",
"Post",
"Posts",
"Page",
Expand Down
10 changes: 10 additions & 0 deletions schemas/rest-api/collections/font-faces.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "http://json-schema.org/draft-07/hyper-schema#",
"$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/rest-api/collections/font-faces.json",
"title": "WP_REST_API_Font_Faces",
"description": "A collection of font face objects in a REST API context.",
"type": "array",
"items": {
"$ref": "../font-face.json"
}
}
19 changes: 19 additions & 0 deletions schemas/rest-api/collections/font-families.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "http://json-schema.org/draft-07/hyper-schema#",
"$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/rest-api/collections/font-families.json",
"title": "WP_REST_API_Font_Families",
"description": "A collection of font family objects in a REST API context.",
"type": "array",
"items": {
"$ref": "../font-family.json"
},
"links": [
{
"rel": "self",
"href": "/wp/v2/font-families",
"targetSchema": {
"$ref": "#"
}
}
]
}
Loading
Loading