Validation - npolar/api.npolar.no GitHub Wiki
Given invalid data, the API should respond with HTTP status 422 "Unprocessable Entity".
To make this happen, inject a model with a #valid?
method into the storage object.
storage = Npolar::Storage::Couch.new("my_db")
storage.model = MyModel.new # Should implement :valid? and :errors
run Npolar::Api::Core.new(nil, { :storage => storage })
JSON Schema
Npolar::Validation::MultiJsonSchemaValidator provides JSON schema validation using multiple schemas
require "hashie"
class MyModel < Hashie::Mash
include Npolar::Validation::MultiJsonSchemaValidator
def schemas
["model.json"]
end
end