objection-rest icon indicating copy to clipboard operation
objection-rest copied to clipboard

thoughts about json-schema and json-reference

Open kapouer opened this issue 10 years ago • 0 comments

Hi,

I'm trying to expose how JSON Schema JSON Reference could be useful and should be the default output.

For example, let's say we have /api/pets/66.json returning { id: "66", name: "didi", owner_id: 77 } (non-populated) { id: "66", name: "didi", owner: { id: 77, surname: "John" }} (eager-loaded)

/api/owners/77.json returning { id: 77, surname: "John" }

JSON Schema and Reference do two things:

  • it tells "id" is actually a url or can be resolved to one,
  • it explains how to use references

Let's see how the json are rewritten:

/api/pets/66.json returning { id: "66", name: "didi", owner: {$ref: "owners/77"} } (non-populated) { id: "66", name: "didi", owner: {id: "owners/77", surname: "John"}} (eager-loaded)

/api/owners/77.json returning { id: 77, surname: "John" }

One to many relations could be written as { id: 77, surname: "John", pets: { $ref: "pets?owner_id=77" } } or even populated partially { id: 77, surname: "John", pets: [{ $ref: "pets/66" }] } or, populated completely { id: 77, surname: "John", pets: [{ id: "pets/66", name: "didi", owner: { $ref: '#' } }] }

All id being resolved relative to the url used to get the current object. What do you think ?

kapouer avatar Sep 10 '15 11:09 kapouer