From 05a1c8e40e06cb235e753660c83a973c117c8584 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 9 Nov 2022 10:25:50 +0000 Subject: [PATCH] jsonschemavalidate: Add more fields to output object Will be used later to rewrite error messages in https://github.com/Open-Telecoms-Data/cove-ofds/issues/4 --- CHANGELOG.md | 1 + libcoveofds/jsonschemavalidate.py | 6 ++++++ tests/fixtures/jsonschemavalidate/bad_uuid_1.expected.json | 5 ++++- tests/fixtures/jsonschemavalidate/basic_1.expected.json | 5 ++++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdb37c3..56972a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - JSONSchema validate: - Add format checkers + - Add more fields to output object ## [0.3.0] - 2022-11-08 diff --git a/libcoveofds/jsonschemavalidate.py b/libcoveofds/jsonschemavalidate.py index 2aa8c1b..59d7d30 100644 --- a/libcoveofds/jsonschemavalidate.py +++ b/libcoveofds/jsonschemavalidate.py @@ -30,9 +30,12 @@ def __init__( self._path = json_schema_exceptions_validation_error.path self._schema_path = json_schema_exceptions_validation_error.schema_path self._validator = json_schema_exceptions_validation_error.validator + self._validator_value = json_schema_exceptions_validation_error.validator_value self._data_ids = schema.extract_data_ids_from_data_and_path( json_data, self._path ) + self._context = json_schema_exceptions_validation_error.context + self._instance = json_schema_exceptions_validation_error.instance def json(self): return { @@ -41,4 +44,7 @@ def json(self): "schema_path": list(self._schema_path), "validator": self._validator, "data_ids": self._data_ids, + "validator_value": self._validator_value, + "context": self._context, + "instance": self._instance, } diff --git a/tests/fixtures/jsonschemavalidate/bad_uuid_1.expected.json b/tests/fixtures/jsonschemavalidate/bad_uuid_1.expected.json index 3d1f7b5..85b29e2 100644 --- a/tests/fixtures/jsonschemavalidate/bad_uuid_1.expected.json +++ b/tests/fixtures/jsonschemavalidate/bad_uuid_1.expected.json @@ -17,6 +17,9 @@ "validator": "format", "data_ids": { "network_id": "1" - } + }, + "validator_value": "uuid", + "context": [], + "instance": "1" } ] diff --git a/tests/fixtures/jsonschemavalidate/basic_1.expected.json b/tests/fixtures/jsonschemavalidate/basic_1.expected.json index 4836173..37393df 100644 --- a/tests/fixtures/jsonschemavalidate/basic_1.expected.json +++ b/tests/fixtures/jsonschemavalidate/basic_1.expected.json @@ -23,6 +23,9 @@ "data_ids": { "network_id": "a096d627-72e1-4f9b-b129-951b1737bff4", "node_id": "1" - } + }, + "validator_value": "object", + "context": [], + "instance": "Somewhere, idunno" } ]