Sha256: 0bb0f4acb00d309a2a425149a0034c358f75d348227b097201b0e508b958f712

Contents?: true

Size: 1.46 KB

Versions: 7

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

require "openapi3_parser/node_factory/object"

module Openapi3Parser
  module NodeFactory
    class Response < NodeFactory::Object
      allow_extensions
      field "description", input_type: String, required: true
      field "headers", factory: :headers_factory
      field "content", factory: :content_factory
      field "links", factory: :links_factory

      private

      def build_object(data, context)
        Node::Response.new(data, context)
      end

      def headers_factory(context)
        factory = NodeFactory::OptionalReference.new(NodeFactory::Header)
        NodeFactory::Map.new(context, value_factory: factory)
      end

      def content_factory(context)
        NodeFactory::Map.new(
          context,
          validate: method(:validate_content),
          value_factory: NodeFactory::MediaType
        )
      end

      def links_factory(context)
        factory = NodeFactory::OptionalReference.new(NodeFactory::Link)
        NodeFactory::Map.new(
          context,
          validate: Validation::InputValidator.new(Validators::ComponentKeys),
          value_factory: factory
        )
      end

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

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

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
openapi3_parser-0.9.2 lib/openapi3_parser/node_factory/response.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/openapi3_parser-0.9.1/lib/openapi3_parser/node_factory/response.rb
openapi3_parser-0.9.1 lib/openapi3_parser/node_factory/response.rb
openapi3_parser-0.9.0 lib/openapi3_parser/node_factory/response.rb
openapi3_parser-0.8.2 lib/openapi3_parser/node_factory/response.rb
openapi3_parser-0.8.1 lib/openapi3_parser/node_factory/response.rb
openapi3_parser-0.8.0 lib/openapi3_parser/node_factory/response.rb