Let's say I have a users
resource, with two properties: name
and email
as specified by a users
JSON Schema document, which right now looks like this:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string"
}
},
"required": [
"name",
"email"
]
}
My requirements state that we need to be able to change the schema, e.g. to add a property such as phoneNumber
, and do so via HTTP in a RESTful way. That is, I need to be able to update the JSON Schema definition of the users
resource to look like this:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"phoneNumber": {
"type": "string"
}
},
"required": [
"name",
"email",
"phoneNumber"
]
}
Now, clients of the API can create new users that have the additional phoneNumber
property (where previously I would have gotten a schema validation error).
I am puzzling over how to do this. One way I can imagine doing it is by creating a "meta-resource" called resources
. This resource might have some properties, for example: path
and schema
. The schema
property would be a full JSON Schema object. To update the users
resource, then, I could maybe POST to resources
with an HTTP request body like:
{
"path": "users",
"schema": { ...JSON Schema object goes here... }
}
Is this a reasonable implementation? If not, why not? Alternative ideas? Any pitfalls I should watch out for? Any articles/blogs on this topic that I should read? (I haven't been able to Google successfully for this).