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 WordPress 6.6 #69

Merged
merged 9 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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@

/composer.lock
/package-lock.json
/tests/hyper-schema/index.js
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
"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.5.0",
"roots/wordpress-full": "6.6-RC3",
"wp-cli/core-command": "^2",
"wp-cli/db-command": "^2",
"wp-cli/language-command": "^2",
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"scripts": {
"version": "cd packages/wp-types && npm version $(node -p -e \"require('../../package.json').version\") && git add .",
"build-wp-types": "json2ts -i schema.json -o packages/wp-types/index.ts --style.trailingComma=all --style.useTabs && cat packages/wp-types/append.ts >> packages/wp-types/index.ts",
"build-hyper-schema-types": "json2ts -i tests/hyper-schema/hyper-schema.json -o tests/hyper-schema/index.ts --style.trailingComma=all --style.useTabs",
"test-wp-types": "tsc packages/wp-types/tests/test.ts --noEmit --strict",
"validate": "ajv compile --strict --strict-schema=false -c ajv-formats -m tests/hyper-schema/hyper-schema.json -s schema.json -r \"schemas/**/*.json\""
"validate": "ajv compile --strict --strict-schema=false -c ajv-formats -m tests/external-schemas/hyper-schema.json -s schema.json -r \"schemas/**/*.json\""
}
}
248 changes: 248 additions & 0 deletions packages/wp-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ export type WP_REST_API_Date_Time = string;
* A collection of comment objects in a REST API context.
*/
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 @@ -138,6 +150,12 @@ export interface WP {
REST_API: {
Comment: WP_REST_API_Comment;
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 @@ -984,6 +1002,7 @@ export interface WP_Post_Type_Labels {
item_link_description: string;
menu_name: string;
name_admin_bar: string;
template_name?: string;
}
/**
* Post type capabilities.
Expand Down Expand Up @@ -1723,6 +1742,7 @@ export interface WP_Taxonomy_Labels {
item_link_description: string;
menu_name: string;
name_admin_bar: string;
template_name: string;
}
/**
* Taxonomy capabilities.
Expand Down Expand Up @@ -1884,6 +1904,193 @@ export interface WP_REST_API_Object_Links {
[k: string]: unknown;
}[];
}
/**
* A font collection object in a REST API context.
*/
export interface WP_REST_API_Font_Collection {
/**
* Unique identifier for the font collection.
*/
slug: string;
/**
* The name for the font collection.
*/
name: string;
/**
* The description for the font collection.
*/
description: string;
/**
* The font families for the font collection.
*/
font_families: {
font_family_settings: WP_Font_Family_Settings;
categories?: string[];
}[];
/**
* The categories for the font collection.
*/
categories: {
name: string;
slug: string;
}[];
_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 Expand Up @@ -1957,6 +2164,10 @@ export interface WP_REST_API_Post {
* A field used for ordering posts.
*/
menu_order?: number;
/**
* An array of the class names for the post container element.
*/
class_list: string[];
/**
* The title for the post.
*/
Expand Down Expand Up @@ -2202,6 +2413,10 @@ export interface WP_REST_API_Attachment {
* Slug automatically generated from the attachment title. Only present when using the 'edit' context and the post type is public.
*/
generated_slug?: string;
/**
* An array of the class names for the post container element.
*/
class_list: string[];
/**
* The title for the attachment.
*/
Expand Down Expand Up @@ -2339,6 +2554,23 @@ export interface WP_REST_API_Block {
*/
protected: boolean;
};
/**
* The excerpt for the block.
*/
excerpt?: {
/**
* Excerpt for the block, as it exists in the database. Only present when using the 'edit' context.
*/
raw?: string;
/**
* HTML content for the post excerpt, transformed for display.
*/
rendered: string;
/**
* Whether the content is protected with a password.
*/
protected: boolean;
};
wp_pattern_sync_status: "" | "partial" | "unsynced";
/**
* Pattern categories.
Expand Down Expand Up @@ -3279,6 +3511,22 @@ export interface WP_REST_API_Type {
* REST route's namespace for the post type.
*/
rest_namespace: string;
/**
* The block template associated with the post type.
*/
template?: (
| [string]
| [
string,
{
[k: string]: unknown;
},
]
)[];
/**
* The template lock associated with the post type, or false if none.
*/
template_lock?: "all" | "insert" | false;
/**
* The visibility settings for the post type. Only present when using the 'edit' context.
*/
Expand Down
18 changes: 9 additions & 9 deletions packages/wp-types/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This package provides well-documented TypeScript definitions that describe the s
* WordPress REST API responses such as from `/wp/v2/posts` and `/wp/v2/users`
* Various property types and allowed values of both

The definitions were last updated for WordPress 6.5.
The definitions were last updated for WordPress 6.6.

## What's included?

Expand Down 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 | Todo
/wp/v2/wp/v2/font-collections/{slug} | Todo
/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 Expand Up @@ -181,12 +181,12 @@ npm install wp-types --save-dev
This package is versioned so that you can specify both the schema version and the WordPress branch version in a way that's compatible with semantic versioning. Given version `x.y.z`:

* The major version number (`x`) indicates the schema version number, currently `3`
* The minor version number (`y`) indicates the WordPress branch version number without its decimal place, eg. `65` for WordPress 6.5
* The minor version number (`y`) indicates the WordPress branch version number without its decimal place, eg. `66` for WordPress 6.6
* The patch version number (`z`) indicates the schema patch version number

Examples:

* `~3.65.0` - Schema version 3 for WordPress 6.5
* `~3.66.0` - Schema version 3 for WordPress 6.6
* `~3.60.0` - Schema version 3 for WordPress 6.0
* `~3.57.0` - Schema version 3 for WordPress 5.7
* `^3.0.0` - Schema version 3 for the latest WordPress version
Expand Down
Loading
Loading