flyvictor / fortune

A framework for prototyping hypermedia APIs.
http://fortunejs.com
MIT License
4 stars 18 forks source link

Schema validation #121

Open EugeneKostrikov opened 9 years ago

EugeneKostrikov commented 9 years ago

There's nothing to warn about misconfiguration and typos. One of the most annoying examples - wrong reference name that doesn't show up until you try to create compound resource.

app.resource('user', {
  addresses: [{ref: 'addresses'}]  //This will throw an error as there's no 'addresses' resource
});
app.resource('address', {
   user: {ref: 'user'}
});
EugeneKostrikov commented 9 years ago

One other thing to validate is when some reference field is used by two "inverse" fields.

app.resource('user', {
  addresses: [{ref: 'address', inverse: 'user'}],
  estate: [{ref: 'address', inverse: 'user'}]
});

app.resource('address', {
   user: {ref: 'user', inverse: 'addresses'}
})

The same applies to the case when single reference is used from two different resources:

app.resource('user', {
  address: {ref: 'address', inverse: 'user'}
});
app.resource('address', {
  user: {ref: 'address' inverse: 'address'}
});
app.resource('pet', {
  user: {ref: 'user', inverse: 'address'}
})