GET /vegetables
{
"item_count": 120,
"items": [
{"name": "squash"},
{"name": "broccoli"},
{"name": "asparagus"}
]
}
GET /vegetables
{
"item_count": 120,
"vegetables": [
{"name": "squash"},
{"name": "broccoli"},
{"name": "asparagus"}
]
}
--
You received this message because you are subscribed to a topic in the Google Groups "JSON Schema" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/json-schema/n9Ox8jIPfBk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to json-schema...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"car": { "type": "string", "maxLength": 20 },
"juicer": { "type": "string", "maxLength": 20 }
},
"dependencies": {
"car": {
"type": "object",
"properties": {
"numPassengers": { "type": "integer", "minimum": 1 }
},
"required": ["numPassengers"]
},
"juicer": {
"type": "object",
"properties": {
"kind": { "type": "string", "enum": ["press", "centrifugal"] }
},
"required": ["kind"]
}
}
}
GET /vegetables
GET /cheeses
GET /vegetables/12
{
"id": 12,
"name": "lettuce",
"color": "green",
"plant": "march",
"harvest": "june"
}
GET /cheeses/34
{
"id": 34,
"name": "camembert",
"region": "Normandy, France"
}
GET /cheeses
{
"total_count": 10,
"data": [
{"id": 34, "name": "camembert", "region": "Normandy, France"},
{"id": 35, "name": "maasdam", "region": "Netherlands"},
{"id": 36, "name": "laguiole", "region": "Aveyron, France"}
]
}
That being the case, I know I have two options (there may be more than that):1. Instead of having one "collection" resource, I have two: a vegetables collection and a cheeses collection2. I include the individual resource schema for both cheese and vegetable in the collection schema and use oneOf to show that they're both permissible.This is where I feel that I might be missing something, because this seems like it must be a reasonably common scenario, but I'm running into a pitfall with each of those options:1. If I do this, I drastically increase the work required to modify a collection schema (since now I have to change a bunch of individualized collection resources) and I risk future developers of the API changing a collection for a particular resource type and losing the benefit of having a consistent collection response.2. This requires either the full duplication of the individual resource schema in a new place, or it requires some kind of "include" feature, so as to say "items in the data array must match one of the following external schema."It could be that my life would be easier if I change my collection resource from using a unified (polymorphic) data to one that uses, say, a cheeses property to hold an array of individual cheese resources, but I'd still need to be able to reference an external schema, which I haven't quite wrapped my head around yet.I feel like I must be missing something!
--
That being the case, I know I have two options (there may be more than that):1. Instead of having one "collection" resource, I have two: a vegetables collection and a cheeses collection2. I include the individual resource schema for both cheese and vegetable in the collection schema and use oneOf to show that they're both permissible.This is where I feel that I might be missing something, because this seems like it must be a reasonably common scenario, but I'm running into a pitfall with each of those options:1. If I do this, I drastically increase the work required to modify a collection schema (since now I have to change a bunch of individualized collection resources) and I risk future developers of the API changing a collection for a particular resource type and losing the benefit of having a consistent collection response.
2. This requires either the full duplication of the individual resource schema in a new place, or it requires some kind of "include" feature, so as to say "items in the data array must match one of the following external schema."
--