15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/openapi3_parser/validators/required_fields.rb', line 15
def call(validatable,
required_fields:,
raise_on_invalid: true)
input = validatable.input
missing_fields = required_fields.select { |name| input[name].nil? }
return if missing_fields.empty?
if raise_on_invalid
location_summary = validatable.context.location_summary
raise Openapi3Parser::Error::MissingFields,
"Missing required fields for " \
"#{location_summary}: #{missing_fields.sentence_join}"
else
validatable.add_error(
"Missing required fields: #{missing_fields.sentence_join}"
)
end
end
|