Sha256: b1385d640b0892abdbfc6ec72ba61442eae8dd7ecbdd69feb40faa200bb6ab57

Contents?: true

Size: 975 Bytes

Versions: 25

Compression:

Stored size: 975 Bytes

Contents

require 'json-schema/attribute'

module JSON
  class Schema
    class PropertiesOptionalAttribute < Attribute
      def self.validate(current_schema, data, fragments, processor, validator, options = {})
        return unless data.is_a?(Hash)

        schema = current_schema.schema
        schema['properties'].each do |property, property_schema|
          property = property.to_s

          if !property_schema['optional'] && !data.key?(property)
            message = "The property '#{build_fragment(fragments)}' did not contain a required property of '#{property}'"
            validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
          end

          if data.has_key?(property)
            expected_schema = JSON::Schema.new(property_schema, current_schema.uri, validator)
            expected_schema.validate(data[property], fragments + [property], processor, options)
          end
        end
      end
    end
  end
end

Version data entries

25 entries across 24 versions & 4 rubygems

Version Path
json-schema-5.1.0 lib/json-schema/attributes/properties_optional.rb
json-schema-ouidou-2.9.1 lib/json-schema/attributes/properties_optional.rb
json-schema-ouidou-2.9.0 lib/json-schema/attributes/properties_optional.rb
json-schema-5.0.1 lib/json-schema/attributes/properties_optional.rb
json-schema-5.0.0 lib/json-schema/attributes/properties_optional.rb
json-schema-4.3.1 lib/json-schema/attributes/properties_optional.rb
json-schema-4.3.0 lib/json-schema/attributes/properties_optional.rb
json-schema-4.2.0 lib/json-schema/attributes/properties_optional.rb
json-schema-4.1.1 lib/json-schema/attributes/properties_optional.rb
json-schema-4.1.0 lib/json-schema/attributes/properties_optional.rb
json-schema-4.0.0 lib/json-schema/attributes/properties_optional.rb
json-schema-3.0.0 lib/json-schema/attributes/properties_optional.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/bundler/gems/json-schema-2253a5ee6679/lib/json-schema/attributes/properties_optional.rb
mountapi-0.11.1 vendor/json-schema/lib/json-schema/attributes/properties_optional.rb
json-schema-2.8.1 lib/json-schema/attributes/properties_optional.rb
json-schema-2.8.0 lib/json-schema/attributes/properties_optional.rb
json-schema-2.7.0 lib/json-schema/attributes/properties_optional.rb
json-schema-2.6.2 lib/json-schema/attributes/properties_optional.rb
json-schema-2.6.1 lib/json-schema/attributes/properties_optional.rb
json-schema-2.6.0 lib/json-schema/attributes/properties_optional.rb