class Schemacop::V3::ReferenceNode

Public Class Methods

allowed_options() click to toggle source
Calls superclass method Schemacop::V3::Node::allowed_options
# File lib/schemacop/v3/reference_node.rb, line 4
def self.allowed_options
  super + %i[path]
end
create(path, **options, &block) click to toggle source
Calls superclass method Schemacop::V3::Node::create
# File lib/schemacop/v3/reference_node.rb, line 8
def self.create(path, **options, &block)
  options[:path] = path
  super(**options, &block)
end

Public Instance Methods

_validate(data, result:) click to toggle source
Calls superclass method Schemacop::V3::Node#_validate
# File lib/schemacop/v3/reference_node.rb, line 21
def _validate(data, result:)
  super_data = super
  return if super_data.nil?

  # Lookup schema #
  node = target
  fail "Schema #{@path.to_s.inspect} not found." unless node

  # Validate schema #
  node._validate(super_data, result: result)
end
as_json() click to toggle source
# File lib/schemacop/v3/reference_node.rb, line 13
def as_json
  if context.swagger_json?
    process_json([], '$ref': "#/components/schemas/#{@path}")
  else
    process_json([], '$ref': "#/definitions/#{@path}")
  end
end
cast(data) click to toggle source
# File lib/schemacop/v3/reference_node.rb, line 37
def cast(data)
  data = default if data.nil?
  return target.cast(data)
end
target() click to toggle source
# File lib/schemacop/v3/reference_node.rb, line 33
def target
  schemas[@path] || Schemacop.context.schemas[@path] || GlobalContext.schema_for(@path)
end
used_external_schemas() click to toggle source
# File lib/schemacop/v3/reference_node.rb, line 42
def used_external_schemas
  target_children_schema = target.used_external_schemas

  if schemas.include?(@path)
    return target_children_schema
  else
    return [@path] + target_children_schema
  end
end

Protected Instance Methods

init() click to toggle source
# File lib/schemacop/v3/reference_node.rb, line 54
def init
  @path = options.delete(:path)
end