itaru2622 commited on
Commit
241bcdf
·
unverified ·
1 Parent(s): 96dfc72

fix: _replace_ref_with_defs; ensure ref_path is string, because some REST servers use "$ref" as property name of schema. (#1164)

Browse files
Files changed (1) hide show
  1. src/fastmcp/utilities/openapi.py +10 -9
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 ref_path.startswith("#/components/schemas/"):
1072
- schema_name = ref_path.split("/")[-1]
1073
- schema["$ref"] = f"#/$defs/{schema_name}"
1074
- elif not ref_path.startswith("#/"):
1075
- raise ValueError(
1076
- f"External or non-local reference not supported: {ref_path}. "
1077
- f"FastMCP only supports local schema references starting with '#/'. "
1078
- f"Please include all schema definitions within the OpenAPI document."
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)