def valid?
      unvalidated_fields = @data.keys.dup
      for property_key, schema_class in self.class.properties
        property_value = @data[property_key]
        if !self.class.validate_property_value(
            property_value, schema_class.data)
          return false
        end
        if property_value == nil && schema_class.data['required'] != true
          # Value was omitted, but not required. Still valid. Skip dependency
          # checks.
          next
        end

        # Verify property dependencies
        property_dependencies = self.class.property_dependencies[property_key]
        case property_dependencies
        when String, Array
          property_dependencies = [property_dependencies].flatten
          for dependency_key in property_dependencies
            dependency_value = @data[dependency_key]
            return false if dependency_value == nil
          end
        when Class
          if property_dependencies.ancestors.include?(Instance)
            dependency_instance = property_dependencies.new(property_value)
            return false unless dependency_instance.valid?
          else
            raise TypeError,
              "Expected schema Class, got #{property_dependencies.class}."
          end
        end
      end
      if self.class.additional_properties_schema == nil
        # No additional properties allowed
        return false unless unvalidated_fields.empty?
      elsif self.class.additional_properties_schema != EMPTY_SCHEMA
        # Validate all remaining fields against this schema
        for property_key in unvalidated_fields
          property_value = @data[property_key]
          if !self.class.additional_properties_schema.validate_property_value(
              property_value, self.class.additional_properties_schema.data)
            return false
          end
        end
      end
      if self.class.superclass && self.class.superclass != Instance &&
          self.class.ancestors.first != Instance
        # The spec actually only defined the 'extends' semantics as children
        # must also validate aainst the parent.
        return false unless self.class.superclass.new(@data).valid?
      end
      return true
    end
def valid?
      unvalidated_fields = @data.keys.dup
      for property_key, schema_class in self.class.properties
        property_value = @data[property_key]
        if !self.class.validate_property_value(
            property_value, schema_class.data)
          return false
        end
        if property_value == nil && schema_class.data['required'] != true
          # Value was omitted, but not required. Still valid. Skip dependency
          # checks.
          next
        end

        # Verify property dependencies
        property_dependencies = self.class.property_dependencies[property_key]
        case property_dependencies
        when String, Array
          property_dependencies = [property_dependencies].flatten
          for dependency_key in property_dependencies
            dependency_value = @data[dependency_key]
            return false if dependency_value == nil
          end
        when Class
          if property_dependencies.ancestors.include?(Instance)
            dependency_instance = property_dependencies.new(property_value)
            return false unless dependency_instance.valid?
          else
            raise TypeError,
              "Expected schema Class, got #{property_dependencies.class}."
          end
        end
      end
      if self.class.additional_properties_schema == nil
        # No additional properties allowed
        return false unless unvalidated_fields.empty?
      elsif self.class.additional_properties_schema != EMPTY_SCHEMA
        # Validate all remaining fields against this schema
        for property_key in unvalidated_fields
          property_value = @data[property_key]
          if !self.class.additional_properties_schema.validate_property_value(
              property_value, self.class.additional_properties_schema.data)
            return false
          end
        end
      end
      if self.class.superclass && self.class.superclass != Instance &&
          self.class.ancestors.first != Instance
        # The spec actually only defined the 'extends' semantics as children
        # must also validate aainst the parent.
        return false unless self.class.superclass.new(@data).valid?
      end
      return true
    end
Validates the parsed data against the schema.