Class: OpenAPIParser::SchemaValidator::AllOfValidator
- Defined in:
- lib/openapi_parser/schema_validator/all_of_validator.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#coerce_and_validate(value, schema, **keyword_args) ⇒ Object
coerce and validate value.
Methods inherited from Base
#initialize, #validate_discriminator_schema
Constructor Details
This class inherits a constructor from OpenAPIParser::SchemaValidator::Base
Instance Method Details
#coerce_and_validate(value, schema, **keyword_args) ⇒ Object
coerce and validate value
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/openapi_parser/schema_validator/all_of_validator.rb', line 7 def coerce_and_validate(value, schema, **keyword_args) if value.nil? && schema.nullable return [value, nil] end # 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, parent_discriminator_schemas: keyword_args[:parent_discriminator_schemas] ) 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 |