diff options
Diffstat (limited to 'app/validators/json_schema_validator.rb')
-rw-r--r-- | app/validators/json_schema_validator.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/app/validators/json_schema_validator.rb b/app/validators/json_schema_validator.rb index f8c1727035c..fee4a00cec5 100644 --- a/app/validators/json_schema_validator.rb +++ b/app/validators/json_schema_validator.rb @@ -12,6 +12,7 @@ class JsonSchemaValidator < ActiveModel::EachValidator FILENAME_ALLOWED = /\A[a-z0-9_-]*\Z/.freeze FilenameError = Class.new(StandardError) + JSON_VALIDATOR_MAX_DRAFT_VERSION = 4 def initialize(options) raise ArgumentError, "Expected 'filename' as an argument" unless options[:filename] @@ -29,10 +30,18 @@ class JsonSchemaValidator < ActiveModel::EachValidator private def valid_schema?(value) - JSON::Validator.validate(schema_path, value) + if draft_version > JSON_VALIDATOR_MAX_DRAFT_VERSION + JSONSchemer.schema(Pathname.new(schema_path)).valid?(value) + else + JSON::Validator.validate(schema_path, value) + end end def schema_path Rails.root.join('app', 'validators', 'json_schemas', "#{options[:filename]}.json").to_s end + + def draft_version + options[:draft] || JSON_VALIDATOR_MAX_DRAFT_VERSION + end end |