lib/jddf/schema.rb
# Check that the schema represents a correct JDDF schema.
#
# To make it convenient to construct and verify a schema, this function
# returns +self+ if the schema is correct.
#
# @raise [ArgumentError] if the schema is incorrect
#
# @return [Schema] self
Check that the schema represents a correct JDDF schema.
To make it convenient to construct and verify a schema, this function
returns +self+ if the schema is correct.
Check that the schema represents a correct JDDF schema . To make it convenient to construct and verify a schema this function returns + self + if the schema is correct .
def verify(root = self, is_root = true)
      if definitions
        raise ArgumentError, 'non-root definitions' unless is_root
        definitions.values.each { |schema| schema.verify(root, false) }
      end
      empty = true
      if ref
        empty = false
        unless root.definitions&.keys&.include?(ref)
          raise ArgumentError, 'reference to non-existent definition'
        end
      end
      if type
        raise ArgumentError, 'invalid form' unless empty
        empty = false
      end
      if enum
        raise ArgumentError, 'invalid form' unless empty
        empty = false
      end
      if elements
        raise ArgumentError, 'invalid form' unless empty
        empty = false
        elements.verify(root, false)
      end
      if properties || optional_properties
        raise ArgumentError, 'invalid form' unless empty
        empty = false
        properties&.values&.each { |schema| schema.verify(root, false) }
        optional_properties&.values&.each { |schema| schema.verify(root, false) }
      end
      if values
        raise ArgumentError, 'invalid form' unless empty
        empty = false
        values.verify(root, false)
      end
      if properties && optional_properties
        unless (properties.keys & optional_properties.keys).empty?
          raise ArgumentError, 'properties and optional_properties share key'
        end
      end
      if discriminator
        raise ArgumentError, 'invalid form' unless empty
        discriminator.mapping.values.each do |schema|
          schema.verify(root, false)
          unless schema.form == :properties
            raise ArgumentError, 'mapping value not of properties form'
          end
          if schema&.properties&.include?(discriminator.tag) ||
             schema&.optional_properties&.include?(discriminator.tag)
            raise ArgumentError, 'tag appears in mapping properties'
          end
        end
      end
      self
    end
def verify ( root = self , is_root = true ) if definitions raise ArgumentError , 'non-root definitions' unless is_root definitions . values . each { | schema | schema . verify ( root , false ) } end empty = true if ref empty = false unless root . definitions &. keys &. include? ( ref ) raise ArgumentError , 'reference to non-existent definition' end end if type raise ArgumentError , 'invalid form' unless empty empty = false end if enum raise ArgumentError , 'invalid form' unless empty empty = false end if elements raise ArgumentError , 'invalid form' unless empty empty = false elements . verify ( root , false ) end if properties || optional_properties raise ArgumentError , 'invalid form' unless empty empty = false properties &. values &. each { | schema | schema . verify ( root , false ) } optional_properties &. values &. each { | schema | schema . verify ( root , false ) } end if values raise ArgumentError , 'invalid form' unless empty empty = false values . verify ( root , false ) end if properties && optional_properties unless ( properties . keys & optional_properties . keys ) . empty? raise ArgumentError , 'properties and optional_properties share key' end end if discriminator raise ArgumentError , 'invalid form' unless empty discriminator . mapping . values . each do | schema | schema . verify ( root , false ) unless schema . form == :properties raise ArgumentError , 'mapping value not of properties form' end if schema &. properties &. include? ( discriminator . tag ) || schema &. optional_properties &. include? ( discriminator . tag ) raise ArgumentError , 'tag appears in mapping properties' end end end self end
Check that the schema represents a correct JDDF schema.
Check that the schema represents a correct JDDF schema .
None
Schema
[ArgumentError] if the schema is incorrect
[ ArgumentError ] if the schema is incorrect
root
<not_specific>
is_root
<not_specific>