Skip to content

Commit

Permalink
Schemas for menus and menu locations.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbillion committed Aug 12, 2024
1 parent 56c97cb commit 832b54d
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 8 deletions.
8 changes: 4 additions & 4 deletions packages/wp-types/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ Route | Schema
/wp/v2/menu-items/{id} | `WP_REST_API_Menu_Item`
/wp/v2/menu-items/{id}/autosaves | Todo
/wp/v2/menu-items/{parent}/autosaves/{id} | Todo
/wp/v2/menu-locations | Todo
/wp/v2/menu-locations/{location} | Todo
/wp/v2/menus | Todo
/wp/v2/menus/{id} | Todo
/wp/v2/menu-locations | `WP_REST_API_Menu_Locations`
/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/{id}/autosaves | Todo
Expand Down
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ Route | Schema
/wp/v2/menu-items/{id} | `WP_REST_API_Menu_Item`
/wp/v2/menu-items/{id}/autosaves | Todo
/wp/v2/menu-items/{parent}/autosaves/{id} | Todo
/wp/v2/menu-locations | Todo
/wp/v2/menu-locations/{location} | Todo
/wp/v2/menus | Todo
/wp/v2/menus/{id} | Todo
/wp/v2/menu-locations | `WP_REST_API_Menu_Locations`
/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/{id}/autosaves | Todo
Expand Down
16 changes: 16 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@
"Menu_Items": {
"$ref": "schemas/rest-api/collections/menu-items.json"
},
"Menu_Location": {
"$ref": "schemas/rest-api/menu-location.json"
},
"Menu_Locations": {
"$ref": "schemas/rest-api/collections/menu-locations.json"
},
"Menu": {
"$ref": "schemas/rest-api/menu.json"
},
"Menus": {
"$ref": "schemas/rest-api/collections/menus.json"
},
"Error": {
"$ref": "schemas/rest-api/error.json"
}
Expand Down Expand Up @@ -271,6 +283,10 @@
"Application_Passwords",
"Menu_Item",
"Menu_Items",
"Menu_Location",
"Menu_Locations",
"Menu",
"Menus",
"Error"
],
"additionalProperties": false
Expand Down
10 changes: 10 additions & 0 deletions schemas/rest-api/collections/menu-locations.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/menu-locations.json",
"title": "WP_REST_API_Menu_Locations",
"description": "A collection of menu locations in a REST API context.",
"type": "object",
"additionalProperties": {
"$ref": "../menu-location.json"
}
}
10 changes: 10 additions & 0 deletions schemas/rest-api/collections/menus.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/menus.json",
"title": "WP_REST_API_Menus",
"description": "A collection of menus in a REST API context.",
"type": "array",
"items": {
"$ref": "../menu.json"
}
}
59 changes: 59 additions & 0 deletions schemas/rest-api/menu-location.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"$schema": "http://json-schema.org/draft-07/hyper-schema#",
"$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/rest-api/menu-location.json",
"title": "WP_REST_API_Menu_Location",
"description": "A menu location in a REST API context.",
"type": "object",
"required": [
"name",
"description",
"menu",
"_links"
],
"properties": {
"name": {
"description": "The name of the menu location.",
"type": "string",
"readOnly": true
},
"description": {
"description": "The description of the menu location.",
"type": "string",
"readOnly": true
},
"menu": {
"description": "The ID of the assigned menu.",
"type": "integer",
"readOnly": true
},
"_links": {
"$ref": "properties/object-links.json"
}
},
"links": [
{
"rel": "self",
"href": "/wp/v2/menu-locations/{name}",
"hrefSchema": {
"properties": {
"name": {
"$ref": "#/properties/name"
}
}
},
"targetSchema": {
"$ref": "#"
}
},
{
"rel": "collection",
"href": "/wp/v2/menu-locations",
"targetSchema": {
"type": "array",
"items": {
"$ref": "#"
}
}
}
]
}
100 changes: 100 additions & 0 deletions schemas/rest-api/menu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"$schema": "http://json-schema.org/draft-07/hyper-schema#",
"$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/rest-api/menu.json",
"title": "WP_REST_API_Menu",
"description": "A menu in a REST API context.",
"type": "object",
"required": [
"id",
"description",
"name",
"slug",
"meta",
"locations",
"auto_add",
"_links"
],
"properties": {
"id": {
"description": "Unique identifier for the term.",
"type": "integer",
"readOnly": true
},
"description": {
"description": "HTML description of the term.",
"type": "string"
},
"name": {
"description": "HTML title for the term.",
"type": "string"
},
"slug": {
"description": "An alphanumeric identifier for the term unique to its type.",
"type": "string"
},
"meta": {
"description": "Meta fields.",
"oneOf": [
{
"$ref": "../../schema.json#/definitions/EmptyArray"
},
{
"type": "object"
}
]
},
"locations": {
"description": "The locations assigned to the menu.",
"type": "array",
"items": {
"type": "string"
}
},
"auto_add": {
"description": "Whether to automatically add top level pages to this menu.",
"type": "boolean"
},
"_links": {
"$ref": "properties/object-links.json"
},
"_embedded": {
"description": "The embedded representation of relations. Only present when the '_embed' query parameter is set.",
"type": "object",
"required": [
"wp:menu-location"
],
"properties": {
"wp:menu-location": {
"description": "The menu locations.",
"type": "array"
}
}
}
},
"links": [
{
"rel": "self",
"href": "/wp/v2/menus/{id}",
"hrefSchema": {
"properties": {
"id": {
"$ref": "#/properties/id"
}
}
},
"targetSchema": {
"$ref": "#"
}
},
{
"rel": "collection",
"href": "/wp/v2/menus",
"targetSchema": {
"type": "array",
"items": {
"$ref": "#"
}
}
}
]
}

0 comments on commit 832b54d

Please sign in to comment.