Class: Openapi3Parser::NodeFactory::RequestBody::ContentValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi3_parser/node_factory/request_body.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(*args) ⇒ Object



28
29
30
# File 'lib/openapi3_parser/node_factory/request_body.rb', line 28

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

Instance Method Details

#call(validatable) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/openapi3_parser/node_factory/request_body.rb', line 32

def call(validatable)
  # This validation isn't actually mentioned in the spec, but it
  # doesn't seem to make sense if this is an empty hash.
  return validatable.add_error("Expected to have at least 1 item") if validatable.input.empty?

  validatable.input.each_key do |key|
    message = Validators::MediaType.call(key)
    next unless message

    context = Context.next_field(validatable.context, key)
    validatable.add_error(message, context)
  end
end