Skip to content

Instantly share code, notes, and snippets.

@danielbachhuber
Last active October 12, 2015 23:27
Show Gist options
  • Save danielbachhuber/2a64bb410810369ae78e to your computer and use it in GitHub Desktop.
Save danielbachhuber/2a64bb410810369ae78e to your computer and use it in GitHub Desktop.
JSON Schema in REST API endpoints

Q: What is the purpose of defining the resource with a schema?

  • To have the format of the object documented in a structured manner. Because it's documented in a structured manner, we can automagically create human-readable documentation from it.
  • Closely-coupling structured documentation to the code will help prevent it from getting out of date.
  • We can also use the schema internally to programmatically manipulate the request or response (e.g. validate required parameters, filter response based on context)

Q: Why JSON schema?

  • It is quite graybeard. JSON schema has been around for a long time, and is a well-known standard.
  • We can extend JSON schema base spec to include our own attributes, and publish this extension.
  • There aren't any competing standards that are better.

Q: What needs to be done to finalize our implementation for 4.4?

  • Most pieces related to our schema implementation shouldn't be committed to core for 4.4.
  • However, we have support for schema in the registration, but the implementation takes an arbitrary array/object and spits it out on OPTIONS requests.

Q: What might be done later?

  • Document and publish the ways in which our schema differs from JSON schema draft 4
  • Probably lots of other little things.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment