From 04740be50ff57ba974b8fb810275eb49c8df6bbc Mon Sep 17 00:00:00 2001 From: albie Date: Wed, 28 Jan 2026 15:30:58 +0000 Subject: [PATCH] fix(curve): oneOf and tests --- schemas/curve.json | 88 +++++++++++++++++++++++++++++++------------ tests/__init__.py | 7 ++-- tests/test_schemas.py | 8 +++- 3 files changed, 73 insertions(+), 30 deletions(-) diff --git a/schemas/curve.json b/schemas/curve.json index 76a9cca2..29ae734b 100644 --- a/schemas/curve.json +++ b/schemas/curve.json @@ -47,8 +47,23 @@ "description": "The reference item for the value. (x-axis)", "type": "string", "enum": [ - "o_n", "1w", "1m", "3m", "6m", "9m", "12m", "15m", "18m", - "21m", "24m", "27m", "30m", "33m", "36m", "60m", "120m" + "o_n", + "1w", + "1m", + "3m", + "6m", + "9m", + "12m", + "15m", + "18m", + "21m", + "24m", + "27m", + "30m", + "33m", + "36m", + "60m", + "120m" ] }, "value": { @@ -63,7 +78,10 @@ ] } }, - "required": ["reference", "value"] + "required": [ + "reference", + "value" + ] } }, "version_id": { @@ -71,32 +89,54 @@ "type": "string" } }, - "required": ["id", "date", "values"], + "required": [ + "id", + "date", + "values" + ], "additionalProperties": true, - "if": { - "properties": { "type": { "const": "risk_rating" } }, - "required": ["type"] - }, - "then": { - "properties": { - "values": { - "items": { - "properties": { - "value": { "type": "string" } + "oneOf": [ + { + "required": [ + "type" + ], + "properties": { + "type": { + "const": "risk_rating" + }, + "values": { + "items": { + "properties": { + "value": { + "type": "string" + } + } } } } - } - }, - "else": { - "properties": { - "values": { - "items": { - "properties": { - "value": { "type": "number" } + }, + { + "not": { + "required": [ + "type" + ], + "properties": { + "type": { + "const": "risk_rating" + } + } + }, + "properties": { + "values": { + "items": { + "properties": { + "value": { + "type": "number" + } + } } } } } - } -} + ] +} \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py index 4d05193d..9dd9bc39 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -4,7 +4,6 @@ import requests from string import ascii_lowercase, digits - HOME = os.path.join(os.path.dirname(__file__), "..") SCHEMAS_DIR = os.path.join(HOME, "schemas") DOCS_DIR = os.path.join(HOME, "documentation", "properties") @@ -150,7 +149,7 @@ def check_schema_fields(schema_dir, schema_name): errs.extend((prop, r) for r in required if r not in spec) else: try: - (url, ref_prop_path) = spec["$ref"].split("#") + url, ref_prop_path = spec["$ref"].split("#") except ValueError as exc: raise ValueError( f"{spec} is not an appropriate format. Should be {{url}}#/{{property_path}}" @@ -160,7 +159,7 @@ def check_schema_fields(schema_dir, schema_name): prop_path_tuple = ref_prop_path.split("/") if len(prop_path_tuple) == 3: - (start, base, ref_prop_name) = prop_path_tuple + start, base, ref_prop_name = prop_path_tuple assert start == "", "Referenced property path must begin with /" assert ( base == "properties" @@ -168,7 +167,7 @@ def check_schema_fields(schema_dir, schema_name): ref_properties = resp.json()[base] elif len(prop_path_tuple) == 2: - (start, ref_prop_name) = prop_path_tuple + start, ref_prop_name = prop_path_tuple assert start == "", "Referenced property path must begin with /" assert url.endswith( "common.json" diff --git a/tests/test_schemas.py b/tests/test_schemas.py index 11638a90..bcc87409 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -313,7 +313,9 @@ def test_unknown_curve_type(self): self.validator.validate(instance=unknown_curve) unknown_curve["values"] = [{"reference": "1m", "value": "AAA"}] - with pytest.raises(ValidationError, match="is not of type 'number'"): + with pytest.raises( + ValidationError, match="is not valid under any of the given schemas" + ): self.validator.validate(instance=unknown_curve) def test_invalid_mixed_value_types(self): @@ -328,7 +330,9 @@ def test_invalid_mixed_value_types(self): {"reference": "6m", "value": 0.02}, ], } - with pytest.raises(ValidationError, match="is not of type 'number'"): + with pytest.raises( + ValidationError, match="is not valid under any of the given schemas" + ): self.validator.validate(instance=invalid_mixed_curve)