diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-09 21:09:43 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-09 21:09:43 +0000 |
commit | 03d56c8af04d2982aff573b78f08192b07107c5b (patch) | |
tree | 6c9d2a9ffe63565d074a41397f06be0d22f9a8f4 /app/validators | |
parent | 9b09561f47159655d05171b4bee980c669859864 (diff) | |
download | gitlab-ce-03d56c8af04d2982aff573b78f08192b07107c5b.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/validators')
-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 |