Sha256: f8a21ce98c48bd22d5707fd8d2632545ad8fe48730f65fef87349086a6eb68b9

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module JSI
  module Schema::Validation::Ref
    # @private
    # @param throw_result [Boolean] if a $ref is present, whether to throw the result being built after
    #   validating the $ref, bypassing subsequent keyword validation
    def internal_validate_ref(result_builder, throw_result: false)
      if keyword?('$ref')
        value = schema_content['$ref']

        if value.respond_to?(:to_str)
          schema_ref = jsi_memoize(:ref) { Schema::Ref.new(value, self) }

          if result_builder.visited_refs.include?(schema_ref)
            result_builder.schema_error('self-referential schema structure', '$ref')
          else
            ref_result = schema_ref.deref_schema.internal_validate_instance(
              result_builder.instance_ptr,
              result_builder.instance_document,
              validate_only: result_builder.validate_only,
              visited_refs: result_builder.visited_refs + [schema_ref],
            )
            result_builder.validate(
              ref_result.valid?,
              'instance is not valid against the schema referenced by `$ref` value',
              keyword: '$ref',
              results: [ref_result],
            )
            if throw_result
              throw(:jsi_validation_result, result_builder.result)
            end
          end
        else
          result_builder.schema_error("`$ref` is not a string", '$ref')
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jsi-0.7.0 lib/jsi/schema/validation/ref.rb