deathbob / halidator

Small library for validating hal+json
18 stars 3 forks source link

Getting "_links does not exist" when no _links are returned #4

Open kleinjm opened 6 years ago

kleinjm commented 6 years ago

According to the hal spec, _links are optional

Please let me know if this is expected behavior. If so, I'm afraid I can't use this gem.

deathbob commented 6 years ago

True it's not part of the spec but IMHO you just have regular json and don't need HAL specific validation if there's no _links attribute.

From the readme https://github.com/deathbob/halidator

The default validator is a pure ruby implementation that is slightly more strict than the spec http://tools.ietf.org/html/draft-kelly-json-hal-03. (Specifically, the default validator requires you to have a self link ...

You can try the json-schema validator built in, that might pass where the default hal validator fails

puts "Valid = #{Halidator.new(string, :json_schema).valid?}"
puts "Valid = #{Halidator.new(json, :json_schema).valid?}"