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