diff --git a/connexion/json_schema.py b/connexion/json_schema.py index f2d67a39b..47b6ab562 100644 --- a/connexion/json_schema.py +++ b/connexion/json_schema.py @@ -128,6 +128,29 @@ def nullable_validation_fn(validator, to_validate, instance, schema): return nullable_validation_fn +def validate_required(validator, required, instance, schema): + if not validator.is_type(instance, "object"): + return + + for prop in required: + if prop not in instance: + properties = schema.get('properties') + if properties is not None: + subschema = properties.get(prop) + if subschema is not None: + if 'readOnly' in validator.VALIDATORS and subschema.get('readOnly'): + continue + if 'writeOnly' in validator.VALIDATORS and subschema.get('writeOnly'): + continue + if 'x-writeOnly' in validator.VALIDATORS and subschema.get('x-writeOnly') is True: + continue + yield ValidationError("%r is a required property" % prop) + + +def validate_readOnly(validator, wo, instance, schema): + yield ValidationError("Property is read-only") + + def validate_writeOnly(validator, wo, instance, schema): yield ValidationError("Property is write-only") @@ -140,6 +163,8 @@ def validate_writeOnly(validator, wo, instance, schema): { "type": NullableTypeValidator, "enum": NullableEnumValidator, + "readOnly": validate_readOnly, + "required": validate_required, }, ) @@ -150,5 +175,6 @@ def validate_writeOnly(validator, wo, instance, schema): "enum": NullableEnumValidator, "writeOnly": validate_writeOnly, "x-writeOnly": validate_writeOnly, + "required": validate_required, }, )