Sha256: 2d7a06af96b8e15e9d1486405e0f3016cfc70f8c53a7ad82ede269485619e139

Contents?: true

Size: 695 Bytes

Versions: 2

Compression:

Stored size: 695 Bytes

Contents

# frozen_string_literal: true

require "openapi3_parser/node_factory/object"

module Openapi3Parser
  module NodeFactories
    class Reference
      include NodeFactory::Object

      field "$ref", input_type: String, required: true

      attr_reader :factory

      def initialize(context, factory)
        super(context)
        @factory = factory
      end

      private

      def build_object(_, context)
        context.resolve_reference do |ref_context|
          resolve_factory(ref_context).node
        end
      end

      def resolve_factory(ref_context)
        return factory.new(ref_context) if factory.is_a?(Class)
        factory.call(ref_context)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
openapi3_parser-0.2.0 lib/openapi3_parser/node_factories/reference.rb
openapi3_parser-0.1.0 lib/openapi3_parser/node_factories/reference.rb