Browse Source

🐛 Fix handling of JSON Schema atributes named "$ref"

pull/14349/head
Sebastián Ramírez 8 months ago
parent
commit
db57570a2b
  1. 12
      fastapi/_compat/v2.py

12
fastapi/_compat/v2.py

@ -262,12 +262,12 @@ def _replace_refs(
new_schema = deepcopy(schema) new_schema = deepcopy(schema)
for key, value in new_schema.items(): for key, value in new_schema.items():
if key == "$ref": if key == "$ref":
ref_name = schema["$ref"].split("/")[-1] value = schema["$ref"]
if ref_name in old_name_to_new_name_map: if isinstance(value, str):
new_name = old_name_to_new_name_map[ref_name] ref_name = schema["$ref"].split("/")[-1]
new_schema["$ref"] = REF_TEMPLATE.format(model=new_name) if ref_name in old_name_to_new_name_map:
else: new_name = old_name_to_new_name_map[ref_name]
new_schema["$ref"] = schema["$ref"] new_schema["$ref"] = REF_TEMPLATE.format(model=new_name)
continue continue
if isinstance(value, dict): if isinstance(value, dict):
new_schema[key] = _replace_refs( new_schema[key] = _replace_refs(

Loading…
Cancel
Save