Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unevaluated* in 2019-09 #6

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion json_skooma.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "zeitwerk", "~> 2.6"
spec.add_runtime_dependency "hana", "~> 1.3"
spec.add_runtime_dependency "regexp_parser", "~> 2.0"
spec.add_runtime_dependency "uri-idna", "~> 0.1"
spec.add_runtime_dependency "uri-idna", "~> 0.2"
end
2 changes: 1 addition & 1 deletion lib/json_skooma/dialects/draft201909.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def call(registry, assert_formats: false)
Keywords::Draft201909::Items,
Keywords::Draft201909::AdditionalItems,
Keywords::Draft201909::UnevaluatedItems,
Keywords::Draft201909::UnevaluatedProperties,
Keywords::Applicator::Contains,
Keywords::Applicator::Properties,
Keywords::Applicator::PatternProperties,
Keywords::Applicator::AdditionalProperties,
Keywords::Unevaluated::UnevaluatedProperties,
Keywords::Applicator::PropertyNames
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class UnevaluatedItems < Base
self.depends_on = %w[
items additionalItems
if then else allOf anyOf oneOf not
$ref $dynamicRef
$ref $dynamicRef $recursiveRef
]

LOOKUP_KEYWORDS = %w[items additionalItems unevaluatedItems].freeze
Expand Down
45 changes: 45 additions & 0 deletions lib/json_skooma/keywords/draft_2019_09/unevaluated_properties.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

module JSONSkooma
module Keywords
module Draft201909
class UnevaluatedProperties < Base
self.key = "unevaluatedProperties"
self.instance_types = %w[object]
self.value_schema = :schema
self.depends_on = %w[
properties patternProperties additionalProperties
if then else dependentSchemas allOf anyOf oneOf not
$ref $dynamicRef $recursiveRef
]

LOOKUP_KEYWORDS = %w[properties patternProperties additionalProperties unevaluatedProperties].freeze

def evaluate(instance, result)
evaluated_names = Set.new
result.parent.collect_annotations(instance, keys: LOOKUP_KEYWORDS) do |node|
evaluated_names += node.annotation
end

annotation = []
error = []
instance.each do |name, item|
next if evaluated_names.include?(name)

if json.evaluate(item, result).passed?
annotation << name
else
error << name
# reset to success for the next iteration
result.success
end
end

return result.failure(error) if error.any?

result.annotate(annotation)
end
end
end
end
end
3 changes: 2 additions & 1 deletion lib/json_skooma/validators/idn_hostname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module JSONSkooma
module Validators
class IdnHostname < Base
def call(data)
URI::IDNA.register(ulabel: data.value)
register_opts = data.value.ascii_only? ? {alabel: data.value} : {ulabel: data.value}
URI::IDNA.register(**register_opts)
rescue URI::IDNA::Error => e
raise FormatError, "#{data} is not a valid IDN hostname: #{e.message}"
end
Expand Down