Sha256: 641a3419b33d3be24515814f27f103bc433133084c9bc27e4a1d2d867506c086
Contents?: true
Size: 1.2 KB
Versions: 66
Compression:
Stored size: 1.2 KB
Contents
require 'json-schema' module Marty private class PgEnumAttribute < JSON::Schema::Attribute def self.validate(curr_schema, data, frag, pro, validator, opt={}) values = nil path = '#/' + frag.join('/') begin cs = curr_schema.schema["pg_enum"] enum = cs.constantize values = enum::VALUES rescue => e msg = "The property '#{path}': '#{cs}' is not a pg_enum class" validation_error(pro, msg, frag, curr_schema, self, opt[:record_errors]) end if values && !values.include?(data) msg = "The property '#{path}' value '#{data}' not contained in #{enum}" validation_error(pro, msg, frag, curr_schema, self, opt[:record_errors]) end end end class JsonSchema < JSON::Schema::Draft4 RAW_URI = "http://json-schema.org/marty-draft/schema#" def initialize super @attributes["pg_enum"] = PgEnumAttribute @formats["date-time"] = JSON::Schema::DateTimeFormat @formats["date"] = JSON::Schema::DateFormat @uri = JSON::Util::URI.parse(RAW_URI) @names = ["marty-draft", RAW_URI] end JSON::Validator.register_validator(self.new) end end
Version data entries
66 entries across 66 versions & 1 rubygems