Added more missing args and types

This commit is contained in:
Mike Jolley 2017-01-26 20:33:39 +00:00
parent b727c61da7
commit 82d7fe6e73
14 changed files with 228 additions and 23 deletions

View File

@ -45,7 +45,9 @@ abstract class WC_REST_Terms_Controller extends WC_REST_Controller {
'permission_callback' => array( $this, 'create_item_permissions_check' ),
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
'name' => array(
'required' => true,
'type' => 'string',
'description' => __( 'Name for the resource.', 'woocommerce' ),
'required' => true,
),
) ),
),
@ -53,6 +55,12 @@ abstract class WC_REST_Terms_Controller extends WC_REST_Controller {
));
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -74,6 +82,7 @@ abstract class WC_REST_Terms_Controller extends WC_REST_Controller {
'args' => array(
'force' => array(
'default' => false,
'type' => 'boolean',
'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
),
),
@ -687,16 +696,22 @@ abstract class WC_REST_Terms_Controller extends WC_REST_Controller {
$params['context']['default'] = 'view';
$params['exclude'] = array(
'description' => __( 'Ensure result set excludes specific ids.', 'woocommerce' ),
'type' => 'array',
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
'description' => __( 'Ensure result set excludes specific ids.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
);
$params['include'] = array(
'description' => __( 'Limit result set to specific ids.', 'woocommerce' ),
'type' => 'array',
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
'description' => __( 'Limit result set to specific ids.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
);
if ( ! $taxonomy->hierarchical ) {
$params['offset'] = array(

View File

@ -67,7 +67,9 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
'permission_callback' => array( $this, 'create_item_permissions_check' ),
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
'code' => array(
'required' => true,
'description' => __( 'Coupon code.', 'woocommerce' ),
'required' => true,
'type' => 'string',
),
) ),
),
@ -448,11 +450,17 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
'product_ids' => array(
'description' => __( "List of product ID's the coupon can be used on.", 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'context' => array( 'view', 'edit' ),
),
'exclude_product_ids' => array(
'description' => __( "List of product ID's the coupon cannot be used on.", 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'context' => array( 'view', 'edit' ),
),
'usage_limit' => array(
@ -479,11 +487,17 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
'product_categories' => array(
'description' => __( "List of category ID's the coupon applies to.", 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'context' => array( 'view', 'edit' ),
),
'excluded_product_categories' => array(
'description' => __( "List of category ID's the coupon does not apply to.", 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'context' => array( 'view', 'edit' ),
),
'exclude_sale_items' => array(
@ -505,11 +519,17 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
'email_restrictions' => array(
'description' => __( 'List of email addresses that can use this coupon.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'string',
),
'context' => array( 'view', 'edit' ),
),
'used_by' => array(
'description' => __( 'List of user IDs who have used the coupon.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'context' => array( 'view', 'edit' ),
'readonly' => true,
),

View File

@ -41,6 +41,12 @@ class WC_REST_Customer_Downloads_Controller extends WC_REST_Controller {
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
'args' => array(
'customer_id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),

View File

@ -54,12 +54,18 @@ class WC_REST_Customers_Controller extends WC_REST_Controller {
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
'email' => array(
'required' => true,
'type' => 'string',
'description' => __( 'New user email address.', 'woocommerce' ),
),
'username' => array(
'required' => 'no' === get_option( 'woocommerce_registration_generate_username', 'yes' ),
'description' => __( 'New user username.', 'woocommerce' ),
'type' => 'string',
),
'password' => array(
'required' => 'no' === get_option( 'woocommerce_registration_generate_password', 'no' ),
'description' => __( 'New user password.', 'woocommerce' ),
'type' => 'string',
),
) ),
),
@ -97,7 +103,11 @@ class WC_REST_Customers_Controller extends WC_REST_Controller {
'type' => 'boolean',
'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
),
'reassign' => array(),
'reassign' => array(
'default' => 0,
'type' => 'integer',
'description' => __( 'ID to reassign posts to.', 'woocommerce' ),
),
),
),
'schema' => array( $this, 'get_public_item_schema' ),

View File

@ -48,6 +48,12 @@ class WC_REST_Order_Notes_Controller extends WC_REST_Controller {
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
'args' => array(
'order_id' => array(
'description' => __( 'The order ID.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
@ -60,7 +66,9 @@ class WC_REST_Order_Notes_Controller extends WC_REST_Controller {
'permission_callback' => array( $this, 'create_item_permissions_check' ),
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
'note' => array(
'required' => true,
'type' => 'string',
'description' => __( 'Order note content.', 'woocommerce' ),
'required' => true,
),
) ),
),
@ -73,6 +81,10 @@ class WC_REST_Order_Notes_Controller extends WC_REST_Controller {
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
'order_id' => array(
'description' => __( 'The order ID.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,

View File

@ -64,6 +64,12 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
'args' => array(
'order_id' => array(
'description' => __( 'The order ID.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
@ -81,6 +87,10 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'order_id' => array(
'description' => __( 'The order ID.', 'woocommerce' ),
'type' => 'integer',
),
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
@ -104,7 +114,6 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
'type' => 'boolean',
'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
),
'reassign' => array(),
),
),
'schema' => array( $this, 'get_public_item_schema' ),

View File

@ -107,7 +107,6 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'boolean',
'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
),
'reassign' => array(),
),
),
'schema' => array( $this, 'get_public_item_schema' ),

View File

@ -36,6 +36,95 @@ class WC_REST_Product_Attribute_Terms_Controller extends WC_REST_Terms_Controlle
*/
protected $rest_base = 'products/attributes/(?P<attribute_id>[\d]+)/terms';
/**
* Register the routes for terms.
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
'args' => array(
'attribute_id' => array(
'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'args' => $this->get_collection_params(),
),
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( $this, 'create_item' ),
'permission_callback' => array( $this, 'create_item_permissions_check' ),
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
'name' => array(
'type' => 'string',
'description' => __( 'Name for the resource.', 'woocommerce' ),
'required' => true,
),
) ),
),
'schema' => array( $this, 'get_public_item_schema' ),
));
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
'attribute_id' => array(
'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
'permission_callback' => array( $this, 'get_item_permissions_check' ),
'args' => array(
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
),
),
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'update_item' ),
'permission_callback' => array( $this, 'update_item_permissions_check' ),
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
),
array(
'methods' => WP_REST_Server::DELETABLE,
'callback' => array( $this, 'delete_item' ),
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
'args' => array(
'force' => array(
'default' => false,
'type' => 'boolean',
'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
),
),
),
'schema' => array( $this, 'get_public_item_schema' ),
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
'args' => array(
'attribute_id' => array(
'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'batch_items' ),
'permission_callback' => array( $this, 'batch_items_permissions_check' ),
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
),
'schema' => array( $this, 'get_public_batch_schema' ),
) );
}
/**
* Prepare a single product attribute term output for response.
*

View File

@ -60,7 +60,9 @@ class WC_REST_Product_Attributes_Controller extends WC_REST_Controller {
'permission_callback' => array( $this, 'create_item_permissions_check' ),
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
'name' => array(
'required' => true,
'description' => __( 'Name for the resource.', 'woocommerce' ),
'type' => 'string',
'required' => true,
),
) ),
),

View File

@ -41,6 +41,16 @@ class WC_REST_Product_Reviews_Controller extends WC_REST_Controller {
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
'args' => array(
'product_id' => array(
'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
'type' => 'integer',
),
'id' => array(
'description' => __( 'Unique identifier for the variation.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
@ -53,13 +63,19 @@ class WC_REST_Product_Reviews_Controller extends WC_REST_Controller {
'permission_callback' => array( $this, 'create_item_permissions_check' ),
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
'review' => array(
'required' => true,
'required' => true,
'type' => 'string',
'description' => __( 'Review content.', 'woocommerce' ),
),
'name' => array(
'required' => true,
'required' => true,
'type' => 'string',
'description' => __( 'Name of the reviewer.', 'woocommerce' ),
),
'email' => array(
'required' => true,
'required' => true,
'type' => 'string',
'description' => __( 'Email of the reviewer.', 'woocommerce' ),
),
) ),
),
@ -68,6 +84,10 @@ class WC_REST_Product_Reviews_Controller extends WC_REST_Controller {
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'product_id' => array(
'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
'type' => 'integer',
),
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
@ -103,6 +123,12 @@ class WC_REST_Product_Reviews_Controller extends WC_REST_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
'args' => array(
'product_id' => array(
'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'batch_items' ),

View File

@ -111,7 +111,6 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Products_Controller
'type' => 'boolean',
'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
),
'reassign' => array(),
),
),
'schema' => array( $this, 'get_public_item_schema' ),

View File

@ -2049,17 +2049,26 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
'related_ids' => array(
'description' => __( 'List of related products IDs.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'upsell_ids' => array(
'description' => __( 'List of up-sell products IDs.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'context' => array( 'view', 'edit' ),
),
'cross_sell_ids' => array(
'description' => __( 'List of cross-sell products IDs.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'context' => array( 'view', 'edit' ),
),
'parent_id' => array(
@ -2539,6 +2548,9 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
'grouped_products' => array(
'description' => __( 'List of grouped products ID.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'context' => array( 'view', 'edit' ),
'readonly' => true,
),

View File

@ -351,6 +351,9 @@ class WC_REST_Report_Sales_Controller extends WC_REST_Controller {
'totals' => array(
'description' => __( 'Totals.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'array',
),
'context' => array( 'view' ),
'readonly' => true,
),

View File

@ -519,10 +519,13 @@ class WC_REST_Settings_Options_Controller extends WC_REST_Controller {
'readonly' => true,
),
'options' => array(
'description' => __( 'Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'readonly' => true,
'description' => __( 'Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'array',
),
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
),
);