Browse Source

Openapi schema gen preserve order of field remap

During field remapping stage of openapi schema generation the order of
iteration is not consistent across runs. This leads to non-deterministic
schema generation

Preserve the order of this iteration across runs by sorting by the
"new_name", i.e. the value inserted in this mapping
pull/14409/head
Matt Hill 8 months ago
parent
commit
29daf934a4
  1. 5
      fastapi/_compat/v2.py

5
fastapi/_compat/v2.py

@ -302,7 +302,10 @@ def _remap_definitions_and_field_mappings(
Dict[str, Any],
]:
old_name_to_new_name_map = {}
for field_key, schema in field_mapping.items():
for field_key, schema in sorted(
field_mapping.items(),
key=lambda x: model_name_map.get(x[0][0].type_),
):
model = field_key[0].type_
if model not in model_name_map:
continue

Loading…
Cancel
Save