Sha256: cc7624090dad5626c2296dffe80405cf6a086b67413f6e5229e11034ab07db87

Contents?: true

Size: 1.39 KB

Versions: 17

Compression:

Stored size: 1.39 KB

Contents

# validate AllOf schema
class OpenAPIParser::SchemaValidator
  class AllOfValidator < Base
    # coerce and validate value
    # @param [Object] value
    # @param [OpenAPIParser::Schemas::Schema] schema
    def coerce_and_validate(value, schema, **_keyword_args)
      # if any schema return error, it's not valida all of value
      remaining_keys               = value.kind_of?(Hash) ? value.keys : []
      nested_additional_properties = false
      schema.all_of.each do |s|
        # We need to store the reference to all of, so we can perform strict check on allowed properties
        _coerced, err = validatable.validate_schema(value, s, :parent_all_of => true)

        if s.type == "object"
          remaining_keys               -= (s.properties || {}).keys
          nested_additional_properties = true if s.additional_properties
        else
          # If this is not allOf having array of objects inside, but e.g. having another anyOf/oneOf nested
          remaining_keys.clear
        end

        return [nil, err] if err
      end

      # If there are nested additionalProperites, we allow not defined extra properties and lean on the specific
      # additionalProperties validation
      if !nested_additional_properties && !remaining_keys.empty?
        return [nil, OpenAPIParser::NotExistPropertyDefinition.new(remaining_keys, schema.object_reference)]
      end

      [value, nil]
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
openapi_parser-0.13.0 lib/openapi_parser/schema_validators/all_of_validator.rb
openapi_parser-0.12.1 lib/openapi_parser/schema_validators/all_of_validator.rb
openapi_parser-0.12.0 lib/openapi_parser/schema_validators/all_of_validator.rb
openapi_parser-0.11.2 lib/openapi_parser/schema_validators/all_of_validator.rb
openapi_parser-0.11.1 lib/openapi_parser/schema_validators/all_of_validator.rb
openapi_parser-0.11.0 lib/openapi_parser/schema_validators/all_of_validator.rb
openapi_parser-0.10.0 lib/openapi_parser/schema_validators/all_of_validator.rb
openapi_parser-0.9.0 lib/openapi_parser/schema_validators/all_of_validator.rb
openapi_parser-0.8.0 lib/openapi_parser/schema_validators/all_of_validator.rb
openapi_parser-0.7.0 lib/openapi_parser/schema_validators/all_of_validator.rb
openapi_parser-0.6.1 lib/openapi_parser/schema_validators/all_of_validator.rb
openapi_parser-0.6.0 lib/openapi_parser/schema_validators/all_of_validator.rb
openapi_parser-0.5.0 lib/openapi_parser/schema_validators/all_of_validator.rb
openapi_parser-0.4.1 lib/openapi_parser/schema_validators/all_of_validator.rb
openapi_parser-0.4.0 lib/openapi_parser/schema_validators/all_of_validator.rb
openapi_parser-0.3.1 lib/openapi_parser/schema_validators/all_of_validator.rb
openapi_parser-0.3.0 lib/openapi_parser/schema_validators/all_of_validator.rb