diff options
Diffstat (limited to 'config/initializers/json_validator_patch.rb')
-rw-r--r-- | config/initializers/json_validator_patch.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/config/initializers/json_validator_patch.rb b/config/initializers/json_validator_patch.rb new file mode 100644 index 00000000000..cb4158045ee --- /dev/null +++ b/config/initializers/json_validator_patch.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +# This patches https://github.com/ruby-json-schema/json-schema/blob/765e6d8fdbfdaca1a42fa743f4621e757f9f6a03/lib/json-schema/validator.rb +# to address https://github.com/ruby-json-schema/json-schema/issues/148. +require 'json-schema' + +module JSON + class Validator + def initialize_data(data) + if @options[:parse_data] + if @options[:json] + data = self.class.parse(data) + elsif @options[:uri] + json_uri = Util::URI.normalized_uri(data) + data = self.class.parse(custom_open(json_uri)) + elsif data.is_a?(String) + begin + data = self.class.parse(data) + rescue JSON::Schema::JsonParseError + # Silently discard the error - use the data as-is + end + end + end + + JSON::Schema.stringify(data) + end + end +end |