Class: Openapi3Parser::Validators::UnexpectedFields

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi3_parser/validators/unexpected_fields.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(*args, **kwargs) ⇒ Object



11
12
13
# File 'lib/openapi3_parser/validators/unexpected_fields.rb', line 11

def self.call(*args, **kwargs)
  new.call(*args, **kwargs)
end

Instance Method Details

#call(validatable, allowed_fields:, allow_extensions: true, raise_on_invalid: true) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/openapi3_parser/validators/unexpected_fields.rb', line 15

def call(validatable,
         allowed_fields:,
         allow_extensions: true,
         raise_on_invalid: true)
  fields = unexpected_fields(validatable.input,
                             allowed_fields,
                             allow_extensions)
  return if fields.empty?

  if raise_on_invalid
    location_summary = validatable.context.location_summary
    raise Openapi3Parser::Error::UnexpectedFields,
          "Unexpected fields for #{location_summary}: " \
          "#{fields.sentence_join}"
  else
    validatable.add_error(
      "Unexpected fields: #{fields.sentence_join}"
    )
  end
end