Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.

Conversation

@danielbachhuber
Copy link
Member

See #1222

@danielbachhuber danielbachhuber added this to the 2.0 Beta 2 milestone May 19, 2015
@danielbachhuber danielbachhuber self-assigned this May 19, 2015
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repeat declaration of schema isn't great. Better ideas?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we register the schema on the route rather than each endpoint?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this:

register_rest_route( 'wp/v2', '/posts', array(
   array( ... )
), false, array( 'schema' => $schema ) );

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not add more parameters to register_rest_route. Can we just add it to the existing route stuff?

register_rest_route( 'wp/v2', '/comments', array(
    array(
        'methods'   => WP_REST_Server::READABLE,
        ...
    ),
    array(
        'methods'  => WP_REST_Server::CREATABLE,
        ...
    ),
    'schema' => ...
) );

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Similar to meta queries with relation mixed with the indexed arrays)

@danielbachhuber
Copy link
Member Author

@joehoyle Would love your input on this. The abstraction seems a bit messy at the moment.

@danielbachhuber
Copy link
Member Author

Response looks a bit like this right now:

{
  "request_args": {
    "GET": {
      "page": {
        "description": "Current page of the collection.",
        "type": "integer",
        "default": 1,
        "sanitize_callback": "absint"
      },
      "per_page": {
        "description": "Maximum number of items to be returned in result set.",
        "type": "integer",
        "default": 10,
        "sanitize_callback": "absint"
      },
      "search": {
        "description": "Limit results to those matching a string.",
        "type": "string",
        "sanitize_callback": "sanitize_text_field"
      },
      "context": {
        "default": "view",
        "description": "Change the response format based on request context.",
        "enum": [
          "view",
          "edit"
        ],
        "sanitize_callback": "sanitize_key",
        "type": "string"
      },
      "order": {
        "default": "asc",
        "description": "Order sort attribute ascending or descending.",
        "enum": [
          "asc",
          "desc"
        ],
        "sanitize_callback": "sanitize_key",
        "type": "string"
      },
      "orderby": {
        "default": "name",
        "description": "Sort collection by object attribute.",
        "enum": [
          "id",
          "name",
          "registered_date"
        ],
        "sanitize_callback": "sanitize_key",
        "type": "string"
      }
    },
    "POST": {
      "capabilities": [],
      "description": [],
      "email": {
        "required": true
      },
      "first_name": [],
      "last_name": [],
      "name": [],
      "nickname": [],
      "roles": [],
      "slug": [],
      "username": {
        "required": true
      },
      "password": {
        "required": true
      }
    }
  },
  "schema": {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "user",
    "type": "object",
    "properties": {
      "avatar_url": {
        "description": "Avatar URL for the object.",
        "type": "string",
        "format": "uri",
        "context": [
          "embed",
          "view",
          "edit"
        ],
        "readonly": true
      },
      "capabilities": {
        "description": "All capabilities assigned to the user.",
        "type": "object",
        "context": [
          "view",
          "edit"
        ]
      },
      "description": {
        "description": "Description of the object.",
        "type": "string",
        "context": [
          "embed",
          "view",
          "edit"
        ]
      },
      "email": {
        "description": "The email address for the object.",
        "type": "string",
        "format": "email",
        "context": [
          "view",
          "edit"
        ],
        "required": true
      },
      "extra_capabilities": {
        "description": "Any extra capabilities assigned to the user.",
        "type": "object",
        "context": [
          "edit"
        ],
        "readonly": true
      },
      "first_name": {
        "description": "First name for the object.",
        "type": "string",
        "context": [
          "embed",
          "view",
          "edit"
        ]
      },
      "id": {
        "description": "Unique identifier for the object.",
        "type": "integer",
        "context": [
          "embed",
          "view",
          "edit"
        ],
        "readonly": true
      },
      "last_name": {
        "description": "Last name for the object.",
        "type": "string",
        "context": [
          "embed",
          "view",
          "edit"
        ]
      },
      "link": {
        "description": "Author URL to the object.",
        "type": "string",
        "format": "uri",
        "context": [
          "embed",
          "view",
          "edit"
        ],
        "readonly": true
      },
      "name": {
        "description": "Display name for the object.",
        "type": "string",
        "context": [
          "embed",
          "view",
          "edit"
        ]
      },
      "nickname": {
        "description": "The nickname for the object.",
        "type": "string",
        "context": [
          "embed",
          "view",
          "edit"
        ]
      },
      "registered_date": {
        "description": "Registration date for the user.",
        "type": "date-time",
        "context": [
          "view",
          "edit"
        ],
        "readonly": true
      },
      "roles": {
        "description": "Roles assigned to the user.",
        "type": "array",
        "context": [
          "view",
          "edit"
        ]
      },
      "slug": {
        "description": "An alphanumeric identifier for the object unique to its type.",
        "type": "string",
        "context": [
          "embed",
          "view",
          "edit"
        ]
      },
      "url": {
        "description": "URL of the object.",
        "type": "string",
        "format": "uri",
        "context": [
          "embed",
          "view",
          "edit"
        ],
        "readonly": true
      },
      "username": {
        "description": "Login name for the user.",
        "type": "string",
        "context": [
          "edit"
        ],
        "required": true
      }
    }
  }
}

@danielbachhuber
Copy link
Member Author

@joehoyle Could you weigh in on this? Thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this cast to an object? Pretty much everything else return an array / ArrayAccess

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I want to make sure it's always an object, even when empty. Otherwise it will be an array when empty.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. Derp. I guess it was empty at one point, and then I changed my code.

@joehoyle
Copy link
Member

Implementation is ok I think - though don't like the repeated schema so much - as I think there should only be one schema per route.

By using GET / POST what do we do when someone uses WP_REST_Server::UPDATABLE as that technically supports PUT and POST I believe.

@rmccue
Copy link
Member

rmccue commented May 24, 2015

So, question: if you don't already know how to form the URL, how do you get the schema for it? For example, posts/{id}; how do I get the schema for that? Kind of annoying.

(Working with a few others on porting the dotcom console and noticed this one.)

@danielbachhuber
Copy link
Member Author

Some discussion in Slack.

Consensus is to chuck everything into the index, as well as return it for OPTIONS on the endpoint.

rmccue added 6 commits May 28, 2015 17:01
@rmccue
Copy link
Member

rmccue commented May 28, 2015

Splitting the index part out to #1305 so we can ship this sucker.

@WP-API/amigos #reviewmerge

@rachelbaker
Copy link
Member

Punting to b3 to get passing tests.

@rachelbaker rachelbaker modified the milestones: 2.0 Beta 3, 2.0 Beta 2 May 28, 2015
@rmccue
Copy link
Member

rmccue commented May 28, 2015

Punting to b3 to get passing tests.

(Also, because as pointed out, this really only affects user endpoints, and we should probably tackle them all.)

@rachelbaker
Copy link
Member

@danielbachhuber,

I believe this has been taken care of in #1415

@danielbachhuber
Copy link
Member Author

This has since been addressed.

@danielbachhuber danielbachhuber removed this from the 2.0 Beta 3 milestone Nov 30, 2015
@danielbachhuber danielbachhuber deleted the 1222-user-options-body branch January 11, 2016 14:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants