Skip to content
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

Don't return 400 when read-only property is provided #1655

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions connexion/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,34 +121,6 @@ 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, ro, instance, schema):
yield ValidationError("Property is read-only")


def validate_writeOnly(validator, wo, instance, schema):
yield ValidationError("Property is write-only")

Expand All @@ -161,8 +133,6 @@ def validate_writeOnly(validator, wo, instance, schema):
{
"type": NullableTypeValidator,
"enum": NullableEnumValidator,
"required": validate_required,
"readOnly": validate_readOnly,
},
)

Expand All @@ -171,7 +141,6 @@ def validate_writeOnly(validator, wo, instance, schema):
{
"type": NullableTypeValidator,
"enum": NullableEnumValidator,
"required": validate_required,
"writeOnly": validate_writeOnly,
"x-writeOnly": validate_writeOnly,
},
Expand Down
2 changes: 0 additions & 2 deletions tests/fixtures/json_validation/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ components:
type: object
required:
- name
- user_id
- password
properties:
user_id:
type: integer
Expand Down
4 changes: 1 addition & 3 deletions tests/test_json_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ def test_readonly(json_validation_spec_dir, spec, app_class):
)
app_client = app.test_client()

headers = {"content-type": "application/json"}

res = app_client.get("/v1.0/user")
assert res.status_code == 200
assert res.json().get("user_id") == 7
Expand All @@ -76,7 +74,7 @@ def test_readonly(json_validation_spec_dir, spec, app_class):
"/v1.0/user",
json={"user_id": 9, "name": "max"},
)
assert res.status_code == 400
assert res.status_code == 200


def test_writeonly(json_validation_spec_dir, spec, app_class):
Expand Down