-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support schemas validation in additionalProperties + remove additionalProperties logic from allof #167
support schemas validation in additionalProperties + remove additionalProperties logic from allof #167
Conversation
…lProperties logic from allof
@epaillous |
@sasamuku These changes is breaking the I am not sure about the original issue described here, and you are probably missing some specs to cover the scenario. If you have a request body schema like this:
and you're passing a correct object with all fields, you will still receive a
That is happening because the |
@n-shay can you explain why we would need a parent_all_of ? From https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/#allof I see that:
My understanding from this sentence is that the validation should be something like |
@MrChoclate In simple cases, the validation of each schema under To specify inheritance between schemas, you would use As long as you don't use Here are the example models: ModelA:
allOf:
- "$ref": "#/components/schemas/ModelB"
- type: object
properties:
field_a:
type: string
additionalProperties: false
ModelB:
allOf:
- "$ref": "#/components/schemas/ModelB"
- type: object
properties:
field_b:
type: string
additionalProperties: false
ModelC:
type: object
properties:
field_c:
type: string
additionalProperties: false First run of the schema validation will cascade all the way down to That is the reason why we need to monitor the That being said, we don't pass upwards which properties were found/validated and which remained but that's another issue. I've implemented the validation in a forked repo that we're using: all_of_validator.rb and object_validator.rb. |
@n-shay I understand your use case, but according to json-schema it is explicitly said that using allOf + additionalProperties is restricting the schema and that we should rather use unevaluatedProperties to specify "inheritance" |
@MrChoclate Only in OAS3.1, the schema object was made to fully support json-schema. unevaluatedProperties is not supported by OAS3.0 and this project was never updated to OAS3.1 (See #152) |
Hi @sasamuku when do you plan to release a new version with this fix please? 😃 |
Description
For now, when passing schemas like :
there is no error triggered on value like :
because the gem does not support validating schemas inside
additionalProperties
field. This PR intends to support this behaviour.While implementing this PR, some specs in
all_of_validator_spec
were failing (or not failing) because of some combination of subschemas in allOf havingadditionalProperties
to false. But according to OpenApi specification, "allOf takes an array of object definitions that are validated independently but together compose a single object.", meaning validating allOf schemas should be equivalent to validating each schema one by one. So there is no reason to checkremainingKeys
inAllOfValidator
object.Let me know if you need anything else 😇