Browse Source

Update v2.py

Fixed AttributeError: 'dict' object has no attribute 'split' #14344
this issue
pull/14346/head
Amit Moralwar 8 months ago
committed by GitHub
parent
commit
f5381e9f93
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 13
      fastapi/_compat/v2.py

13
fastapi/_compat/v2.py

@ -262,7 +262,18 @@ def _replace_refs(
new_schema = deepcopy(schema)
for key, value in new_schema.items():
if key == "$ref":
ref_name = schema["$ref"].split("/")[-1]
#ref_name = schema["$ref"].split("/")[-1]
ref_name = schema["$ref"]
if isinstance(ref_value, str):
# Normal case
ref_name = ref_value.split("/")[-1]
elif isinstance(ref_value, dict):
# Handle dict case
ref_name = ref_value.get("title") or "unknown_ref"
else:
# Unexpected type
ref_name = "invalid_ref"
if ref_name in old_name_to_new_name_map:
new_name = old_name_to_new_name_map[ref_name]
new_schema["$ref"] = REF_TEMPLATE.format(model=new_name)

Loading…
Cancel
Save