"git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "ca1f1c8685a1f8a16bd578a83239d46e1c9a9f7b"
Unverified Commit cd0935dd authored by Matt's avatar Matt Committed by GitHub
Browse files

Make tool JSON schemas consistent (#31756)

Make the order of array items consistent using sorted()
parent 82486e59
......@@ -80,7 +80,7 @@ def _parse_type_hint(hint: str) -> Dict:
return_dict = subtypes[0]
elif all(isinstance(subtype["type"], str) for subtype in subtypes):
# A union of basic types can be expressed as a list in the schema
return_dict = {"type": [subtype["type"] for subtype in subtypes]}
return_dict = {"type": sorted([subtype["type"] for subtype in subtypes])}
else:
# A union of more complex types requires "anyOf"
return_dict = {"anyOf": subtypes}
......
......@@ -137,7 +137,7 @@ class JsonSchemaGeneratorTest(unittest.TestCase):
"properties": {
"x": {
"type": "array",
"items": {"type": "array", "items": {"type": ["string", "integer"]}},
"items": {"type": "array", "items": {"type": ["integer", "string"]}},
"description": "The input",
}
},
......@@ -455,13 +455,13 @@ class JsonSchemaGeneratorTest(unittest.TestCase):
},
"y": {
"type": "array",
"items": {"type": ["string", "integer"]},
"items": {"type": ["integer", "string"]},
"nullable": True,
"description": "The second input. It's a big list with a single-line description.",
},
"z": {
"type": "array",
"prefixItems": [{"type": ["string", "integer"]}, {"type": "string"}],
"prefixItems": [{"type": ["integer", "string"]}, {"type": "string"}],
"description": "The third input. It's some kind of tuple with a default arg.",
},
},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment