3.65.0 • Published 1 month ago

wp-json-schemas v3.65.0

Weekly downloads
21
License
MIT
Repository
github
Last release
1 month ago

npm.io npm.io npm.io

WordPress JSON Schemas

This package provides well-documented JSON schemas that describe the shape of:

  • WordPress core PHP objects such as WP_Post, WP_Term, and WP_User
  • WordPress REST API responses such as those from /wp/v2/posts, /wp/v2/categories, and /wp/v2/users
  • Various property types and values of both

The schemas in this library are used to generate the WordPress TypeScript definitions provided by the wp-types package.

The schemas were last updated for WordPress 6.5.

What's included?

PHP Object Schemas

  • WP_Post
  • WP_Term
  • WP_User
  • WP_Comment
  • WP_Error
  • WP_Query
  • WP_Block
  • WP_Block_Type
  • WP_Block_Template
  • WP_Site
  • WP_Locale
  • WP_Taxonomy
  • WP_Post_Type
  • WP_Role
  • WP_Network
  • WP_Screen

REST API Response Schemas

RouteSchema
/wp/v2/block-directory/searchWP_REST_API_Block_Directory_Items
/wp/v2/block-patterns/categoriesWP_REST_API_Block_Pattern_Categories
/wp/v2/block-patterns/patternsWP_REST_API_Block_Patterns
/wp/v2/block-renderer/{name}WP_REST_API_Rendered_Block
/wp/v2/block-typesWP_REST_API_Block_Types
/wp/v2/block-types/{namespace}WP_REST_API_Block_Type
/wp/v2/block-types/{namespace}/{name}WP_REST_API_Block_Type
/wp/v2/blocksWP_REST_API_Blocks
/wp/v2/blocks/{id}WP_REST_API_Block
/wp/v2/blocks/{id}/autosavesTodo
/wp/v2/blocks/{parent}/autosaves/{id}Todo
/wp/v2/blocks/{parent}/revisionsWP_REST_API_Revisions
/wp/v2/blocks/{parent}/revisions/{id}WP_REST_API_Revision
/wp/v2/categoriesWP_REST_API_Categories
/wp/v2/categories/{id}WP_REST_API_Category
/wp/v2/commentsWP_REST_API_Comments
/wp/v2/comments/{id}WP_REST_API_Comment
/wp/v2/wp/v2/font-collectionsTodo
/wp/v2/wp/v2/font-collections/{slug}Todo
/wp/v2/wp/v2/font-familiesTodo
/wp/v2/wp/v2/font-families/{id}/Todo
/wp/v2/wp/v2/font-families/{id}/font-facesTodo
/wp/v2/wp/v2/font-families/{id}/font-faces/{id}Todo
/wp/v2/global-styles/{id}Todo
/wp/v2/global-styles/{parent}/revisionsTodo
/wp/v2/global-styles/{parent}/revisions/{id}Todo
/wp/v2/global-styles/themes/{stylesheet}/variationsTodo
/wp/v2/global-styles/themes/{stylesheet}Todo
/wp/v2/mediaWP_REST_API_Attachments
/wp/v2/media/{id}WP_REST_API_Attachment
/wp/v2/media/{id}/editTodo
/wp/v2/media/{id}/post-processTodo
/wp/v2/menu-itemsTodo
/wp/v2/menu-items/{id}Todo
/wp/v2/menu-items/{id}/autosavesTodo
/wp/v2/menu-items/{parent}/autosaves/{id}Todo
/wp/v2/menu-locationsTodo
/wp/v2/menu-locations/{location}Todo
/wp/v2/menusTodo
/wp/v2/menus/{id}Todo
/wp/v2/navigationTodo
/wp/v2/navigation/{id}Todo
/wp/v2/navigation/{id}/autosavesTodo
/wp/v2/navigation/{parent}/autosaves/{id}Todo
/wp/v2/navigation/{parent}/revisionsTodo
/wp/v2/navigation/{parent}/revisions/{id}Todo
/wp/v2/pagesWP_REST_API_Pages
/wp/v2/pages/{id}WP_REST_API_Page
/wp/v2/pages/{id}/autosavesTodo
/wp/v2/pages/{parent}/autosaves/{id}Todo
/wp/v2/pages/{parent}/revisionsWP_REST_API_Revisions
/wp/v2/pages/{parent}/revisions/{id}WP_REST_API_Revision
/wp/v2/pattern-directory/patternsTodo
/wp/v2/pluginsTodo
/wp/v2/plugins/{plugin}Todo
/wp/v2/postsWP_REST_API_Posts
/wp/v2/posts/{id}WP_REST_API_Post
/wp/v2/posts/{id}/autosavesTodo
/wp/v2/posts/{parent}/autosaves/{id}Todo
/wp/v2/posts/{parent}/revisionsWP_REST_API_Revisions
/wp/v2/posts/{parent}/revisions/{id}WP_REST_API_Revision
/wp/v2/searchWP_REST_API_Search_Results
/wp/v2/settingsWP_REST_API_Settings
/wp/v2/sidebarsTodo
/wp/v2/sidebars/{id}Todo
/wp/v2/statusesWP_REST_API_Statuses
/wp/v2/statuses/{status}WP_REST_API_Status
/wp/v2/tagsWP_REST_API_Tags
/wp/v2/tags/{id}WP_REST_API_Tag
/wp/v2/taxonomiesWP_REST_API_Taxonomies
/wp/v2/taxonomies/{taxonomy}WP_REST_API_Taxonomy
/wp/v2/templatesTodo
/wp/v2/templates/{id}Todo
/wp/v2/templates/{id}/autosavesTodo
/wp/v2/templates/{parent}/autosaves/{id}Todo
/wp/v2/templates/{parent}/revisionsTodo
/wp/v2/templates/{parent}/revisions/{id}Todo
/wp/v2/templates/lookupTodo
/wp/v2/template-partsTodo
/wp/v2/template-parts/{id}Todo
/wp/v2/template-parts/{id}/autosavesTodo
/wp/v2/template-parts/{parent}/autosaves/{id}Todo
/wp/v2/template-parts/{parent}/revisionsTodo
/wp/v2/template-parts/{parent}/revisions/{id}Todo
/wp/v2/template-parts/lookupTodo
/wp/v2/themesTodo
/wp/v2/themes/{stylesheet}Todo
/wp/v2/typesWP_REST_API_Types
/wp/v2/types/{type}WP_REST_API_Type
/wp/v2/usersWP_REST_API_Users
/wp/v2/users/({id}|me)WP_REST_API_User
/wp/v2/users/({id}|me)/application-passwordsWP_REST_API_Application_Passwords
/wp/v2/users/({id}|me)/application-passwords/{uuid}WP_REST_API_Application_Password
/wp/v2/users/({id}|me)/application-passwords/introspectWP_REST_API_Application_Password
/wp/v2/widget-typesTodo
/wp/v2/widget-types/{id}Todo
/wp/v2/widget-types/{id}/encodeTodo
/wp/v2/widget-types/{id}/renderTodo
/wp/v2/widgetsTodo
/wp/v2/widgets/{id}Todo
/wp/v2/wp_pattern_categoryTodo
/wp/v2/wp_pattern_category/{id}Todo
Any REST API errorWP_REST_API_Error

The REST API schemas use JSON Hyper-Schema.

Property Schemas

Schemas are provided for various properties:

  • WP_Error_Data
  • WP_Error_Messages
  • WP_Post_Type_Caps
  • WP_Post_Type_Labels
  • WP_Post_Type_Rewrite
  • WP_Taxonomy_Caps
  • WP_Taxonomy_Labels
  • WP_Taxonomy_Rewrite
  • WP_User_Cap_Name
  • WP_User_Caps
  • WP_User_Data

Enums

Enums are provided for various values:

  • WP_Comment_Status_Name
  • WP_Comment_Type_Name
  • WP_Post_Comment_Status_Name
  • WP_Post_Format_Name
  • WP_Post_Status_Name
  • WP_Post_Type_Name
  • WP_Taxonomy_Name
  • WP_User_Role_Name
  • WP_HTTP_Status_Code

Installation

npm install wp-json-schemas

Versioning

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 patch version number (z) indicates the schema patch version number

Examples:

  • ~3.65.0 - Schema version 3 for WordPress 6.5
  • ~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

Usage

Usage depends on what you're doing with the schemas. You could use them for validation or just for understanding the shape of an object.

If you're using TypeScript, check out the TypeScript definitions provided by the wp-types package.

FAQs

When do these schemas apply?

The PHP object schemas apply whenever a supported PHP object is encoded to JSON. For example:

printf(
	'let wpPost = %s;',
	wp_json_encode( get_post() )
);

The REST API object schemas apply to the response to a REST API request. For example:

const api = wp.apiFetch( {
	path: '/wp/v2/categories/'
} );

The schemas also apply outside of an HTTP request, for example if you're saving data as a JSON file and reading it in a Node application.

Why are there different schemas for PHP objects and REST API responses?

An object in a REST API response is not the same as its corresponding object in PHP, in fact they are substantially different.

Schemas are available via an OPTIONS request to the REST API endpoints, but the schemas do not adhere strictly to the JSON Schema standard. Here's an article by Timothy B. Jacobs with more info.

Are these schemas automatically generated from WordPress core?

No. I started down that path (using wp-parser-lib) but realised it's quicker to generate them manually and then copy most of the documentation from core, especially as I'm adding extra documentation and schemas for properties when I can.

How do I know the schemas are accurate?

They're all tested against actual output from WordPress core.

Tests

To run the tests:

  • nvm use
  • npm install
  • composer install
  • composer test

License

MIT

3.65.0

1 month ago

3.64.0

6 months ago

3.63.0

7 months ago

3.62.4

1 year ago

3.62.3

1 year ago

3.62.2

1 year ago

3.62.1

1 year ago

3.62.0

1 year ago

3.61.0

1 year ago

3.60.1

1 year ago

3.60.0

2 years ago

3.59.1

2 years ago

3.59.0

2 years ago

3.58.0

2 years ago

3.57.0

2 years ago

3.0.0

2 years ago

2.12.0

3 years ago

2.11.0

3 years ago

2.10.0

3 years ago

2.9.0

3 years ago

2.7.0

3 years ago

2.5.2

3 years ago

2.6.0

3 years ago

2.8.0

3 years ago

2.5.3

3 years ago

2.3.0

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.5.0

3 years ago

2.4.0

3 years ago

2.5.1

3 years ago

2.1.0

3 years ago

2.0.0

3 years ago

1.9.0

3 years ago

1.8.1

3 years ago

1.8.0

3 years ago

1.7.0

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago