From a371a32cf5d6e0838b711c17f02832ccc076a1a0 Mon Sep 17 00:00:00 2001 From: Chris Tubbs Date: Fri, 4 Aug 2023 20:28:36 +0000 Subject: [PATCH] Removed errant print statements added documentation to explain how the BINARY_TYPE regex works --- .../specification/test_deserialization.py | 3 --- .../evaluation_service/forms/json.py | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/python/lib/evaluations/dmod/test/specification/test_deserialization.py b/python/lib/evaluations/dmod/test/specification/test_deserialization.py index de6b0a17c..84d60fdf2 100644 --- a/python/lib/evaluations/dmod/test/specification/test_deserialization.py +++ b/python/lib/evaluations/dmod/test/specification/test_deserialization.py @@ -50,9 +50,6 @@ def test_multitemplate(self): self.assertEqual(single_instance, pure_template_instance) def test_evaluation_deserialization(self): - from pprint import pprint - - pprint(dir(specification.EvaluationSpecification)) normal_specification = self.template_manager.get_template( specification_type=specification.EvaluationSpecification, name="no-template" diff --git a/python/services/evaluationservice/dmod/evaluationservice/evaluation_service/forms/json.py b/python/services/evaluationservice/dmod/evaluationservice/evaluation_service/forms/json.py index 8c55e7778..8ae8822f2 100644 --- a/python/services/evaluationservice/dmod/evaluationservice/evaluation_service/forms/json.py +++ b/python/services/evaluationservice/dmod/evaluationservice/evaluation_service/forms/json.py @@ -23,6 +23,29 @@ ) """ A regular expression that finds all type definitions that are strings formatted as bytes + +Catches on: + +- `{"type": "string", "format": "binary"}, ` +- `, {"type": "string", "format": "binary"} + +Both cases must be handled for replacement/removal logic. A simple find and replace for +'{"type": "string", "format": "binary"}' could/would result in errant commas, causing the json to fail deserialization + +The first will catch when it is at the beginning of a list. If it's at the beginning of the list, the following +comma and whitespace need to be removed to make the next object the first in the list. + +The second will catch when it is not the first of the list. In this case, it will need to remove the previous comma +and any following whitespace. If there are further elements in the list, they will collapse and the comma that +would have proceeded this string definition will follow the previous element. + +Examples: + >>> at_beginning = '{"types": [{"type": "string", "format": "binary}, {"type": "number"}, {"type": "string"}]}' + >>> not_at_beginning = '{"types": [{"type": "string"}, {"type": "string", "format": "binary}, {"type": "number"}]}' + >>> BINARY_TYPES.sub("", at_beginning) + '{"types": [{"type": "number"}, {"type": "string"}]}' + >>> BINARY_TYPES.sub("", not_at_beginning) + '{"types": [{"type": "string"}, {"type": "number"}]}' """ def get_editor_friendly_model_schema(model: typing.Type[BaseModel]) -> typing.Optional[dict]: