13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/skooma/keywords/oas_3_1/dialect/additional_properties.rb', line 13
def evaluate(instance, result)
known_property_names = result.sibling(instance, "properties")&.schema_node&.keys || []
known_property_patterns = (result.sibling(instance, "patternProperties")&.schema_node&.keys || [])
.map { |pattern| Regexp.new(pattern) }
forbidden = []
if json.root.enforce_access_modes?
only_key = result.path.include?("responses") ? "writeOnly" : "readOnly"
properties_result = result.sibling(instance, "properties")
instance.each_key do |name|
res = properties_result&.children&.[](instance[name]&.path)&.[]name
forbidden << name if res && annotation_exists?(res, key: only_key)
end
end
annotation = []
error = []
instance.each do |name, item|
if forbidden.include?(name) || !known_property_names.include?(name) && known_property_patterns.none? { |pattern| pattern.match?(name) }
if json.evaluate(item, result).passed?
annotation << name
else
error << name
result.success
end
end
end
return result.annotate(annotation) if error.empty?
result.failure(error)
end
|