[wp-trac] [WordPress Trac] #44287: REST API: Declare user capability to perform actions using JSON Hyper Schema `targetSchema`

WordPress Trac noreply at wordpress.org
Tue Jun 5 15:11:33 UTC 2018


#44287: REST API: Declare user capability to perform actions using JSON Hyper
Schema `targetSchema`
------------------------------------------+-----------------------
 Reporter:  danielbachhuber               |       Owner:  (none)
     Type:  enhancement                   |      Status:  new
 Priority:  normal                        |   Milestone:  4.9.8
Component:  Role/Capability               |     Version:
 Severity:  normal                        |  Resolution:
 Keywords:  needs-patch needs-unit-tests  |     Focuses:  rest-api
------------------------------------------+-----------------------

Comment (by TimothyBlynJacobs):

 So the simplest version of this is using `add_link()` directly in the
 controllers and adding all the information inline. For example.

 {{{#!php
 $response->add_link( 'https://api.w.org/action-sticky', $self, array(
         'title'        => __( 'The current user can sticky this post.' ),
         'targetSchema' => array(
                 'type'       => 'object',
                 'properties' => array(
                         'sticky' => array(
                                 'type' => 'boolean',
                         ),
                 ),
         ),
 ) );
 }}}

 A concern here is that we would be duplicating information for every item
 in collection responses. We can alleviate this by adding the bulk of the
 link details to the schema document for the resource. For example.

 {{{#!php
 // In ::get_item_schema()
 $schema['links'][] = array(
         'rel'          => 'https://api.w.org/action-sticky',
         'title'        => __( 'The current user can sticky this post.' ),
         'href'         => rest_url( '/wp/v2/posts/{id}' ),
         'targetSchema' => array(
                 'type'       => 'object',
                 'properties' => array(
                         'sticky' => array(
                                 'type' => 'boolean',
                         ),
                 ),
         ),
 );
 }}}

 Then, the response size will be considerably smaller.

 {{{#!php
 $response->add_link( 'https://api.w.org/action-sticky', $self );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44287#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list