Summary
I am wondering if we could add an opt-in flag (require_properties_presence or a shorter name) to also require presence of properties declared in properties (even if not in required)?
Default behavior should stay unchanged and spec-compliant.
Why this is useful
For contract/feature tests, we need to detect missing or accidental field removals inAPI responses.
Today, this requires custom recursive checks on top of openapi-schema-validator.
Environment
- openapi-schema-validator:
0.6.3
- jsonschema:
4.25.1
- Python:
3.12.3
- OpenAPI version used:
3.0.3
- OS:
Ubuntu 24.04.2 LTS (Linux)
Minimal reproduction
from openapi_schema_validator import validate, OAS30Validator
schema = {
"type": "object",
"properties": {
"id": {"type": "string"},
"nickname": {"type": "string"},
},
"required": ["id"],
}
instance = {"id": "42"} # nickname missing
validate(instance, schema, cls=OAS30Validator) # currently valid
Observed
Validation succeeds because nickname is optional.
Expected (opt-in only)
With a new flag enabled, validation should fail and report missing declared properties.
Proposed API
Example:
validate(..., require_properties_presence=False) # (default False)
Thanks for your time