Sha256: 3eb51c627fac0dcd975a8bb9a177aa39589a2290f8f9a9c4c74b10498cbcd269
Contents?: true
Size: 1.33 KB
Versions: 7
Compression:
Stored size: 1.33 KB
Contents
# frozen_string_literal: true require "openapi3_parser/node_factory/object" module Openapi3Parser module NodeFactory class RequestBody < NodeFactory::Object allow_extensions field "description", input_type: String field "content", factory: :content_factory, required: true field "required", input_type: :boolean, default: false private def build_object(data, context) Node::RequestBody.new(data, context) end def content_factory(context) NodeFactory::Map.new( context, value_factory: NodeFactory::MediaType, validate: ContentValidator ) end class ContentValidator def self.call(*args) new.call(*args) end 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. if validatable.input.size.zero? return validatable.add_error("Expected to have at least 1 item") end validatable.input.keys.each do |key| message = Validators::MediaType.call(key) next unless message context = Context.next_field(validatable.context, key) validatable.add_error(message, context) end end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems