-
-
Notifications
You must be signed in to change notification settings - Fork 784
Validate required fields based on readOnly & writeOnly #1943
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sampoh0523 has convinced me that there is no need for this function, the argument is that Connexion should tolerate a readOnly field in requests without complaint. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh good point. Why is it important for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is because the same
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please let me amend my first comment here. @sampoh0523 has convinced me that this function should be a no-op. It has to exist and be registered, so the validation function can detect it is validating a request, but this function should never reject an instance. |
||
|
|
||
|
|
||
| def validate_writeOnly(validator, wo, instance, schema): | ||
| yield ValidationError("Property is write-only") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extending the scope here slightly, for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I did not see this before. I do not have strong opinions about |
||
|
|
||
|
|
@@ -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, | ||
| }, | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the prevailing style in this code is to use double quotes (not single quotes) around strings, please consider matching that.