Skip to content
Snippets Groups Projects
Verified Commit fb1f78d8 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

ENH: json schema exporter: Removed "ID, " from reference enums.

parent ce21eb96
No related branches found
No related tags found
2 merge requests!89ENH: JsonSchemaExporter accepts do_not_create parameter.,!85more jsonschema export
Pipeline #43494 failed
......@@ -239,7 +239,7 @@ class JsonSchemaExporter:
vals = []
for val in possible_values:
if val.name:
vals.append(f"{val.id}, {val.name}")
vals.append(f"{val.name}")
else:
vals.append(f"{val.id}")
......
......@@ -337,11 +337,11 @@ def test_rt_with_references():
assert "oneOf" not in props["RefProp"]
example = {
"RefProp": "101, otherB"
"RefProp": "otherB"
}
validate(example, schema)
example = {
"RefProp": "23, I don't exist"
"RefProp": "I don't exist"
}
with raises(ValidationError):
# Wrong enum value
......@@ -372,8 +372,8 @@ def test_rt_with_references():
assert "enum" in props["RefProp"]["oneOf"][enum_index]
assert isinstance(props["RefProp"]["oneOf"][enum_index]["enum"], list)
assert len(props["RefProp"]["oneOf"][enum_index]["enum"]) == 3
assert "100, otherA" in props["RefProp"]["oneOf"][enum_index]["enum"]
assert "101, otherB" in props["RefProp"]["oneOf"][enum_index]["enum"]
assert "otherA" in props["RefProp"]["oneOf"][enum_index]["enum"]
assert "otherB" in props["RefProp"]["oneOf"][enum_index]["enum"]
assert "102" in props["RefProp"]["oneOf"][enum_index]["enum"]
# the other element of oneOf is the OtherType object
assert props["RefProp"]["oneOf"][1 - enum_index]["type"] == "object"
......@@ -395,7 +395,7 @@ def test_rt_with_references():
validate(example, schema)
example = {
"RefProp": "101, otherB",
"RefProp": "otherB",
"OtherTextProp": "something"
}
validate(example, schema)
......@@ -423,17 +423,17 @@ def test_rt_with_references():
assert "description" not in items
example = {
"RefProp": "101, otherB"
"RefProp": "otherB"
}
with raises(ValidationError):
# Should be list but isn't
validate(example, schema)
example = {
"RefProp": ["101, otherB"]
"RefProp": ["otherB"]
}
validate(example, schema)
example = {
"RefProp": ["101, otherB", "102", "104, referencing"]
"RefProp": ["otherB", "102", "referencing"]
}
validate(example, schema)
......@@ -461,8 +461,8 @@ def test_rt_with_references():
assert "enum" in items["oneOf"][enum_index]
assert isinstance(items["oneOf"][enum_index]["enum"], list)
assert len(items["oneOf"][enum_index]["enum"]) == 3
assert "100, otherA" in items["oneOf"][enum_index]["enum"]
assert "101, otherB" in items["oneOf"][enum_index]["enum"]
assert "otherA" in items["oneOf"][enum_index]["enum"]
assert "otherB" in items["oneOf"][enum_index]["enum"]
assert "102" in items["oneOf"][enum_index]["enum"]
other_type = items["oneOf"][1 - enum_index]
assert other_type["type"] == "object"
......@@ -472,7 +472,7 @@ def test_rt_with_references():
assert "IntegerProp" in other_type["required"]
example = {
"RefProp": ["101, otherB", "102", "104, referencing"]
"RefProp": ["otherB", "102", "referencing"]
}
with raises(ValidationError):
# Wrong value in enum
......@@ -488,7 +488,7 @@ def test_rt_with_references():
# we have additional_properties=False which propagates to subschemas
validate(example, schema)
example = {
"RefProp": [{"IntegerProp": 12}, "101, otherB"]
"RefProp": [{"IntegerProp": 12}, "otherB"]
}
validate(example, schema)
......@@ -506,7 +506,7 @@ def test_rt_with_references():
enum_index = 1 - enum_index
assert len(ref_ref["oneOf"][enum_index]["enum"]) == 2
assert "103" in ref_ref["oneOf"][enum_index]["enum"]
assert "104, referencing" in ref_ref["oneOf"][enum_index]["enum"]
assert "referencing" in ref_ref["oneOf"][enum_index]["enum"]
assert ref_ref["oneOf"][1 - enum_index]["type"] == "object"
assert "OtherType" in ref_ref["oneOf"][1 - enum_index]["properties"]
assert ref_ref["oneOf"][1 - enum_index]["properties"]["OtherType"]["type"] == "array"
......@@ -520,8 +520,8 @@ def test_rt_with_references():
assert "enum" in items["oneOf"][enum_index]
assert isinstance(items["oneOf"][enum_index]["enum"], list)
assert len(items["oneOf"][enum_index]["enum"]) == 3
assert "100, otherA" in items["oneOf"][enum_index]["enum"]
assert "101, otherB" in items["oneOf"][enum_index]["enum"]
assert "otherA" in items["oneOf"][enum_index]["enum"]
assert "otherB" in items["oneOf"][enum_index]["enum"]
assert "102" in items["oneOf"][enum_index]["enum"]
other_type = items["oneOf"][1 - enum_index]
assert other_type["type"] == "object"
......@@ -532,7 +532,7 @@ def test_rt_with_references():
example = {
"RefRefProp": {
"OtherType": [
"100, otherA",
"otherA",
{"IntegerProp": 12}
]
}
......@@ -638,7 +638,7 @@ RT2:
"title": "Existing entries",
"enum": [
"103",
"104, referencing"
"referencing"
]
},
{
......@@ -684,7 +684,7 @@ RT2:
"description": "some description",
"enum": [
"103",
"104, referencing"
"referencing"
]
}
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment