diff --git a/packages/wp-types/index.ts b/packages/wp-types/index.ts index 747f522..312b306 100644 --- a/packages/wp-types/index.ts +++ b/packages/wp-types/index.ts @@ -128,6 +128,14 @@ 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 navigation menu object in a REST API context. + */ +export type WP_REST_API_Navigation_Menu = WP_REST_API_Partial_Post_Common; +/** + * A collection of navigation menu objects in a REST API context. + */ +export type WP_REST_API_Navigation_Menus = WP_REST_API_Navigation_Menu[]; /** * A collection of media attachment objects in a REST API context. */ @@ -236,6 +244,8 @@ export interface WP { Posts: WP_REST_API_Posts; Page: WP_REST_API_Page; Pages: WP_REST_API_Pages; + Navigation_Menu: WP_REST_API_Navigation_Menu; + Navigation_Menus: WP_REST_API_Navigation_Menus; Attachment: WP_REST_API_Attachment; Attachments: WP_REST_API_Attachments; Block: WP_REST_API_Block; diff --git a/packages/wp-types/readme.md b/packages/wp-types/readme.md index 1be89b0..91c205f 100644 --- a/packages/wp-types/readme.md +++ b/packages/wp-types/readme.md @@ -75,8 +75,8 @@ Route | Schema /wp/v2/menu-locations/{location} | `WP_REST_API_Menu_Location` /wp/v2/menus | `WP_REST_API_Menus` /wp/v2/menus/{id} | `WP_REST_API_Menu` -/wp/v2/navigation | Todo -/wp/v2/navigation/{id} | Todo +/wp/v2/navigation | `WP_REST_API_Navigation_Menus` +/wp/v2/navigation/{id} | `WP_REST_API_Navigation_Menu` /wp/v2/navigation/{id}/autosaves | Todo /wp/v2/navigation/{parent}/autosaves/{id} | Todo /wp/v2/navigation/{parent}/revisions | Todo diff --git a/readme.md b/readme.md index 8b2ed32..8f472de 100644 --- a/readme.md +++ b/readme.md @@ -79,8 +79,8 @@ Route | Schema /wp/v2/menu-locations/{location} | `WP_REST_API_Menu_Location` /wp/v2/menus | `WP_REST_API_Menus` /wp/v2/menus/{id} | `WP_REST_API_Menu` -/wp/v2/navigation | Todo -/wp/v2/navigation/{id} | Todo +/wp/v2/navigation | `WP_REST_API_Navigation_Menus` +/wp/v2/navigation/{id} | `WP_REST_API_Navigation_Menu` /wp/v2/navigation/{id}/autosaves | Todo /wp/v2/navigation/{parent}/autosaves/{id} | Todo /wp/v2/navigation/{parent}/revisions | Todo diff --git a/schema.json b/schema.json index cac97d3..27f4f82 100644 --- a/schema.json +++ b/schema.json @@ -110,6 +110,12 @@ "Pages": { "$ref": "schemas/rest-api/collections/pages.json" }, + "Navigation_Menu": { + "$ref": "schemas/rest-api/navigation-menu.json" + }, + "Navigation_Menus": { + "$ref": "schemas/rest-api/collections/navigation.json" + }, "Attachment": { "$ref": "schemas/rest-api/attachment.json" }, @@ -247,6 +253,8 @@ "Posts", "Page", "Pages", + "Navigation_Menu", + "Navigation_Menus", "Attachment", "Attachments", "Block_Directory_Item", diff --git a/schemas/rest-api/collections/navigation.json b/schemas/rest-api/collections/navigation.json new file mode 100644 index 0000000..bdf7027 --- /dev/null +++ b/schemas/rest-api/collections/navigation.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/navigation.json", + "title": "WP_REST_API_Navigation_Menus", + "description": "A collection of navigation menu objects in a REST API context.", + "type": "array", + "items": { + "$ref": "../navigation-menu.json" + }, + "links": [ + { + "rel": "self", + "href": "/wp/v2/navigation", + "targetSchema": { + "$ref": "#" + } + } + ] +} diff --git a/schemas/rest-api/navigation-menu.json b/schemas/rest-api/navigation-menu.json new file mode 100644 index 0000000..07be229 --- /dev/null +++ b/schemas/rest-api/navigation-menu.json @@ -0,0 +1,55 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/hyper-schema", + "$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/rest-api/navigation-menu.json", + "title": "WP_REST_API_Navigation_Menu", + "description": "A navigation menu object in a REST API context.", + "type": "object", + "allOf": [ + { + "$ref": "partials/post/common.json" + } + ], + "links": [ + { + "rel": "self", + "href": "/wp/v2/navigation/{id}", + "hrefSchema": { + "properties": { + "id": { + "$ref": "partials/post/common.json#/properties/id" + } + } + }, + "targetSchema": { + "$ref": "#" + } + }, + { + "rel": "collection", + "href": "/wp/v2/navigation", + "targetSchema": { + "type": "array", + "items": { + "$ref": "#" + } + } + }, + { + "rel": "version-history", + "href": "/wp/v2/navigation/{id}/revisions", + "hrefSchema": { + "properties": { + "id": { + "$ref": "partials/post/common.json#/properties/id" + } + } + }, + "targetSchema": { + "type": "array", + "items": { + "$ref": "#" + } + } + } + ] +} diff --git a/tests/output/post.php b/tests/output/post.php index a2b6571..1281c4f 100644 --- a/tests/output/post.php +++ b/tests/output/post.php @@ -21,6 +21,13 @@ 'post_status' => 'publish', ] ); +wp_insert_post( [ + 'post_type' => 'wp_navigation', + 'post_title' => 'Navigation', + 'post_content' => '', + 'post_status' => 'publish', +] ); + $posts = get_posts( [ 'posts_per_page' => -1, 'post_status' => 'any', @@ -31,7 +38,7 @@ save_object_array( $posts, 'post' ); -foreach ( [ 'posts', 'pages', 'blocks' ] as $type ) { +foreach ( [ 'posts', 'pages', 'blocks', 'navigation' ] as $type ) { $view_data = get_rest_response( 'GET', "/wp/v2/{$type}", [ 'context' => 'view', 'per_page' => 100,