Spaces:
Running
Running
itaru2622 commited on
fix: _replace_ref_with_defs; ensure ref_path is string, because some REST servers use "$ref" as property name of schema. (#1164)
Browse files
src/fastmcp/utilities/openapi.py
CHANGED
|
@@ -1068,15 +1068,16 @@ def _replace_ref_with_defs(
|
|
| 1068 |
"""
|
| 1069 |
schema = info.copy()
|
| 1070 |
if ref_path := schema.get("$ref"):
|
| 1071 |
-
if
|
| 1072 |
-
|
| 1073 |
-
|
| 1074 |
-
|
| 1075 |
-
|
| 1076 |
-
|
| 1077 |
-
|
| 1078 |
-
|
| 1079 |
-
|
|
|
|
| 1080 |
elif properties := schema.get("properties"):
|
| 1081 |
if "$ref" in properties:
|
| 1082 |
schema["properties"] = _replace_ref_with_defs(properties)
|
|
|
|
| 1068 |
"""
|
| 1069 |
schema = info.copy()
|
| 1070 |
if ref_path := schema.get("$ref"):
|
| 1071 |
+
if isinstance(ref_path, str):
|
| 1072 |
+
if ref_path.startswith("#/components/schemas/"):
|
| 1073 |
+
schema_name = ref_path.split("/")[-1]
|
| 1074 |
+
schema["$ref"] = f"#/$defs/{schema_name}"
|
| 1075 |
+
elif not ref_path.startswith("#/"):
|
| 1076 |
+
raise ValueError(
|
| 1077 |
+
f"External or non-local reference not supported: {ref_path}. "
|
| 1078 |
+
f"FastMCP only supports local schema references starting with '#/'. "
|
| 1079 |
+
f"Please include all schema definitions within the OpenAPI document."
|
| 1080 |
+
)
|
| 1081 |
elif properties := schema.get("properties"):
|
| 1082 |
if "$ref" in properties:
|
| 1083 |
schema["properties"] = _replace_ref_with_defs(properties)
|