Skip to content

Commit

Permalink
First version of schema for filter repository. #290.
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuswetah committed Oct 4, 2019
1 parent 589c946 commit 274df74
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
35 changes: 32 additions & 3 deletions src/api/endpoints/class-tainacan-rest-filters-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function register_routes() {
'permission_callback' => array($this, 'create_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE)
),
'schema' => [$this, 'get_schema']
));
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base, array(
array(
Expand All @@ -57,7 +58,8 @@ public function register_routes() {
'callback' => array($this, 'create_item'),
'permission_callback' => array($this, 'create_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE)
)
),
'schema' => [$this, 'get_schema']
));
register_rest_route($this->namespace, '/' . $this->rest_base, array(
array(
Expand All @@ -71,7 +73,8 @@ public function register_routes() {
'callback' => array($this, 'create_item'),
'permission_callback' => array($this, 'create_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE)
)
),
'schema' => [$this, 'get_schema']
));
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<filter_id>[\d]+)', array(
array(
Expand All @@ -96,7 +99,8 @@ public function register_routes() {
'callback' => array($this, 'get_item'),
'permission_callback' => array($this, 'get_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE)
)
),
'schema' => [$this, 'get_schema']
));
}

Expand Down Expand Up @@ -509,5 +513,30 @@ public function get_wp_query_params() {

return $query_params;
}

function get_schema() {
$schema = [
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'filter',
'type' => 'object'
];

$main_schema = parent::get_repository_schema( $this->filter_repository );
$permissions_schema = parent::get_permissions_schema();

// $collection_scheme = parent::get_repository_schema( $this->collection_repository );
// $metadatum_scheme = parent::get_repository_schema( $this->metadatum_repository );

$schema['properties'] = array_merge(
parent::get_base_properties_schema(),
$main_schema,
$permissions_schema
// $collection_scheme,
// $metadatum_scheme
);

return $schema;

}
}
?>
5 changes: 0 additions & 5 deletions src/api/endpoints/class-tainacan-rest-metadata-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public function register_routes() {
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE),
),
'schema' => [$this, 'get_schema']

)
);
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base,
Expand Down Expand Up @@ -603,10 +602,6 @@ function get_schema() {
// $item_scheme = parent::get_repository_schema( $this->item_repository );
// $collection_scheme = parent::get_repository_schema( $this->collection_repository );

// transformation done in $this->prepare_item_for_response()
$main_schema['moderators'] = $main_schema['moderators_ids'];
$main_schema['moderators']['contex'] = 'edit';

$schema['properties'] = array_merge(
parent::get_base_properties_schema(),
$main_schema,
Expand Down
2 changes: 1 addition & 1 deletion src/classes/repositories/class-tainacan-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected function _get_map() {
'map' => 'meta',
'title' => __( 'Type', 'tainacan' ),
'type' => 'string',
'description' => __( 'The filter type', 'tainacan' ),
'description' => __( 'The filter type class name, such as filter_type: Tainacan\Filter_Types\Checkbox', 'tainacan' ),
'validation' => ''
],
'collection_id' => [
Expand Down
2 changes: 1 addition & 1 deletion src/classes/repositories/class-tainacan-metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function _get_map() {
'map' => 'meta',
'title' => __( 'Type', 'tainacan' ),
'type' => 'string',
'description' => __( 'The metadata type', 'tainacan' ),
'description' => __( 'The metadata type class name, such as Tainacan\Metadata_Types\Core_Title', 'tainacan' ),
'on_error' => __( 'Metadata type is empty', 'tainacan' ),
'validation' => v::stringType()->notEmpty(),
],
Expand Down

0 comments on commit 274df74

Please sign in to comment.