johnbillion / wp-json-schemas

JSON schemas for WordPress PHP objects and REST API responses
https://www.npmjs.com/package/wp-json-schemas
MIT License
143 stars 8 forks source link

Provide separate REST API schemas for CRUD and by context #40

Open johnbillion opened 3 years ago

johnbillion commented 3 years ago

The REST API schemas provided currently are only valid for reads (GET) and for the view and edit contexts. This has some problems:

Ideally separate schemas would be provided for each of the four request types (CRUD) and each of the three contexts (view, edit, and embed).

What I don't want to do though is maintain a bunch of schemas for each endpoint that are all similar. This needs to either use partials or be automated somehow.

johnbillion commented 3 years ago

Perhaps the entire set of REST API schema files need to be generated from OPTIONS requests to the actual endpoints, and this library provides transformation rules on a per-endpoint basis for adjustments.

johnbillion commented 3 years ago

For naming conventions, the HTTP verbs can't be used because POST can be used for both creating and updating.

johnbillion commented 3 years ago

Actually that might not be true, because to create an entity you POST to the collection endpoint and to update an entity you POST to the single item endpoint, and these have different schemas (although currently the collection schema is just an array of the single schemas).