From 5c8f78720699d3b06470cf4f5a2c11508a0dca5f Mon Sep 17 00:00:00 2001 From: Sebastian Arias Date: Mon, 29 Nov 2021 23:02:43 -0500 Subject: [PATCH 1/5] Add reports/ directory to .gitignore file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b6e4761..9ad24b8 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,7 @@ coverage.xml *.py,cover .hypothesis/ .pytest_cache/ +reports/ # Translations *.mo From ddb8291694ef587aaa9be494a2ddf5a469add9fa Mon Sep 17 00:00:00 2001 From: Sebastian Arias Date: Mon, 29 Nov 2021 23:03:18 -0500 Subject: [PATCH 2/5] Add missing __init__ files for integrations test to be run: --- tests/__init__.py | 0 tests/integration/__init__.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/integration/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py new file mode 100644 index 0000000..e69de29 From 2234b93d48b748fcf602fa29738b4757f4e1b010 Mon Sep 17 00:00:00 2001 From: Sebastian Arias Date: Mon, 29 Nov 2021 23:51:19 -0500 Subject: [PATCH 3/5] Update validate function that mutated the schema --- openapi_schema_validator/validators.py | 4 +++- tests/unit/__init__.py | 0 tests/unit/test_shortcut.py | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/unit/__init__.py create mode 100644 tests/unit/test_shortcut.py diff --git a/openapi_schema_validator/validators.py b/openapi_schema_validator/validators.py index 555df89..8ea4b98 100644 --- a/openapi_schema_validator/validators.py +++ b/openapi_schema_validator/validators.py @@ -1,3 +1,4 @@ +import copy from jsonschema import _legacy_validators, _utils, _validators from jsonschema.validators import create @@ -63,7 +64,8 @@ def __init__(self, *args, **kwargs): def iter_errors(self, instance, _schema=None): if _schema is None: - _schema = self.schema + # creates a copy by value from schema to prevent mutation + _schema = copy.deepcopy(self.schema) # append defaults to trigger validator (i.e. nullable) if 'nullable' not in _schema: diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/test_shortcut.py b/tests/unit/test_shortcut.py new file mode 100644 index 0000000..9832489 --- /dev/null +++ b/tests/unit/test_shortcut.py @@ -0,0 +1,22 @@ +from openapi_schema_validator import validate +from unittest import TestCase + + +class ValidateTest(TestCase): + def test_validate_does_not_mutate_schema_adding_nullable_key(self): + schema = { + "type": "object", + 'properties': { + 'email': { + 'type': 'string' + }, + 'enabled': { + 'type': 'boolean', + } + }, + 'example': {'enabled': False, 'email': "foo@bar.com"} + } + + validate({"email": "foo@bar.com"}, schema) + + self.assertTrue("nullable" not in schema["properties"]["email"].keys()) From 13e2833793dc23498c36e43ceced5fea2c2d0b28 Mon Sep 17 00:00:00 2001 From: p1c2u Date: Tue, 28 Dec 2021 11:18:12 +0000 Subject: [PATCH 4/5] deepcopy import fix --- openapi_schema_validator/validators.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openapi_schema_validator/validators.py b/openapi_schema_validator/validators.py index 8ea4b98..8521c64 100644 --- a/openapi_schema_validator/validators.py +++ b/openapi_schema_validator/validators.py @@ -1,4 +1,5 @@ -import copy +from copy import deepcopy + from jsonschema import _legacy_validators, _utils, _validators from jsonschema.validators import create @@ -65,7 +66,7 @@ def __init__(self, *args, **kwargs): def iter_errors(self, instance, _schema=None): if _schema is None: # creates a copy by value from schema to prevent mutation - _schema = copy.deepcopy(self.schema) + _schema = deepcopy(self.schema) # append defaults to trigger validator (i.e. nullable) if 'nullable' not in _schema: From 7ed2ea8cce31cca416849eb91984f83ca46703b5 Mon Sep 17 00:00:00 2001 From: p1c2u Date: Tue, 28 Dec 2021 11:18:50 +0000 Subject: [PATCH 5/5] get rid of init files inside tests --- tests/__init__.py | 0 tests/integration/__init__.py | 0 tests/unit/__init__.py | 0 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/__init__.py delete mode 100644 tests/integration/__init__.py delete mode 100644 tests/unit/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py deleted file mode 100644 index e69de29..0000000