With hash randomisation enabled, the key order of the definitions namespace can change between runs. The typical solution to that kind of problem is to sort the keys when calling json.dump, but that doesn't work for ordered=True as sorting when dumping to JSON would also lose the definition order for properties.
The technique I am currently using is to sort the definitions before dumping to JSON:
schema = MyDocument().get_schema(ordered=True)
schema["definitions"] = OrderedDict(sorted(schema["definitions"].items()))
with open(schema_file, "w") as f:
json.dump(schema, f, indent=4)
Would it be reasonable to make sorting the subschema definitions and putting them in an OrderedDict instance the default behaviour for both get_schema and get_definitions_and_schema when ordered=True?
With hash randomisation enabled, the key order of the definitions namespace can change between runs. The typical solution to that kind of problem is to sort the keys when calling
json.dump
, but that doesn't work forordered=True
as sorting when dumping to JSON would also lose the definition order for properties.The technique I am currently using is to sort the definitions before dumping to JSON:
Would it be reasonable to make sorting the subschema definitions and putting them in an OrderedDict instance the default behaviour for both
get_schema
andget_definitions_and_schema
whenordered=True
?