Sha256: 57e79828d07d2edc615a8293e3156d8beef8d3b3bbeeb979715d1dbd4303228d

Contents?: true

Size: 1.03 KB

Versions: 14

Compression:

Stored size: 1.03 KB

Contents

module JSON
  class Schema
    class PropertiesOptionalAttribute < Attribute
      def self.validate(current_schema, data, fragments, processor, validator, options = {})
        if data.is_a?(Hash)
          current_schema.schema['properties'].each do |property,property_schema|
            if ((property_schema['optional'].nil? || property_schema['optional'] == false) && !data.has_key?(property.to_s) && !data.has_key?(property.to_sym))
              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.to_s) || data.has_key?(property.to_sym)
              schema = JSON::Schema.new(property_schema,current_schema.uri,validator)
              fragments << property
              schema.validate(data[property],fragments,processor,options)
              fragments.pop
            end
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
json-schema-2.2.5 lib/json-schema/attributes/properties_optional.rb
json-schema-2.2.4 lib/json-schema/attributes/properties_optional.rb
json-schema-2.2.3 lib/json-schema/attributes/properties_optional.rb
json-schema-2.2.2 lib/json-schema/attributes/properties_optional.rb
json-schema-2.2.1 lib/json-schema/attributes/properties_optional.rb
json-schema-2.2.0 lib/json-schema/attributes/properties_optional.rb
json-schema-2.1.9 lib/json-schema/attributes/properties_optional.rb
json-schema-2.1.8 lib/json-schema/attributes/properties_optional.rb
json-schema-2.1.7 lib/json-schema/attributes/properties_optional.rb
json-schema-2.1.6 lib/json-schema/attributes/properties_optional.rb
json-schema-2.1.5 lib/json-schema/attributes/properties_optional.rb
json-schema-2.1.4 lib/json-schema/attributes/properties_optional.rb
json-schema-2.1.3 lib/json-schema/attributes/properties_optional.rb
json-schema-2.1.2 lib/json-schema/attributes/properties_optional.rb