plexus / yaks

Ruby library for building hypermedia APIs
http://rubygems.org/gems/yaks
MIT License
236 stars 26 forks source link

Implement a linter for Yaks::Resource #99

Open plexus opened 9 years ago

plexus commented 9 years ago

We ran into an interesting case today that was a little tricky to figure out. In the end it turns out we had a nil where we expected a form, causing havoc in the HTML formatter.

Yaks::Format::HTML.new.call(Yaks::Resource.new(forms: [nil]))

Yaks::Resource are quite strict and explicit in their structure. In this case it's an error on the user's side that there's a nil there, but it can be hard to debug (and works fine for most JSON formats).

So the idea would be to have a linter that can run as part of an after_map hook and that throws more descriptive messages.

Yaks.new do
  after_map {|resource, _env| Yaks::Resource::Lint.call(resource) }
end