From 606f8ab116a0cb44b5dce3c484544748fe118944 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Mon, 26 Jun 2023 11:13:21 -0300 Subject: [PATCH] experiments: suggested organization of API parameter definitions --- ...s-tainacan-rest-collections-controller.php | 11 +++++----- .../class-tainacan-rest-items-controller.php | 6 ++++-- .../class-tainacan-collections.php | 20 +++++++++++++++++-- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/classes/api/endpoints/class-tainacan-rest-collections-controller.php b/src/classes/api/endpoints/class-tainacan-rest-collections-controller.php index df7e1a943..bb792ef00 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-collections-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-collections-controller.php @@ -87,11 +87,11 @@ class REST_Collections_Controller extends REST_Controller { 'callback' => array($this, 'update_metadata_section_order'), 'permission_callback' => array($this, 'update_metadata_section_order_permissions_check'), 'args' => [ - 'metadata_section_order' => [ - 'description' => __( 'The order of the metadata section in the collection, an array of objects with integer ID and bool enabled.', 'tainacan' ), + 'collection_id' => [ + 'description' => 'ID da coleção', 'required' => true, - 'validate_callback' => [$this, 'validate_metadata_section_order'] - ] + ], + 'metadata_section_order' => $this->collections_repository->get_map()['metadata_section_order'] ], ), 'schema' => [$this, 'get_schema'], @@ -889,7 +889,8 @@ class REST_Collections_Controller extends REST_Controller { $schema = [ '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'collection', - 'type' => 'object' + 'type' => 'object', + 'tags' => ['collection'], ]; $main_schema = parent::get_repository_schema( $this->collections_repository ); diff --git a/src/classes/api/endpoints/class-tainacan-rest-items-controller.php b/src/classes/api/endpoints/class-tainacan-rest-items-controller.php index 76884c507..d692c962c 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-items-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-items-controller.php @@ -1572,7 +1572,8 @@ class REST_Items_Controller extends REST_Controller { $schema = [ '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'item', - 'type' => 'object' + 'type' => 'object', + 'tags' => ['item'], ]; $main_schema = parent::get_repository_schema( $this->items_repository ); @@ -1592,7 +1593,8 @@ class REST_Items_Controller extends REST_Controller { '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'items', 'type' => 'array', - 'items' => $this->get_schema() + 'items' => $this->get_schema(), + 'tags' => ['item'], ]; return $schema; } diff --git a/src/classes/repositories/class-tainacan-collections.php b/src/classes/repositories/class-tainacan-collections.php index 27db8c830..c734a0cc4 100644 --- a/src/classes/repositories/class-tainacan-collections.php +++ b/src/classes/repositories/class-tainacan-collections.php @@ -134,8 +134,24 @@ class Collections extends Repository { 'metadata_section_order' => [ 'map' => 'meta', 'title' => __( 'Metadata order', 'tainacan' ), - 'type' => ['array', 'object', 'string'], - 'items' => [ 'type' => ['array', 'string', 'integer', 'object'] ], + 'type' => 'array', + 'items' => [ + 'type' => 'object', + "properties" => [ + "id" => [ + "description" => "IDs.", + "type" => "integer", + ], + "enabled" => [ + "description" => "enabled.", + "type" => "boolean", + ], + "metadata_order" => [ + "description" => "metadata_order.", + "type" => "array", + ], + ] + ], 'description' => __( 'The order of the metadata section in the collection', 'tainacan' ), ], 'metadata_order' => [