mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-22 13:34:17 +02:00
fix: handle non-string $ref values in experimental OpenAPI parser (#1217)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
parent
d6bd800d88
commit
bde9515ced
2 changed files with 13 additions and 9 deletions
|
|
@ -146,6 +146,9 @@ class OpenAPIParser(
|
|||
"""Resolves a reference to its target definition."""
|
||||
if isinstance(item, self.reference_cls):
|
||||
ref_str = item.ref
|
||||
# Ensure ref_str is a string before calling startswith()
|
||||
if not isinstance(ref_str, str):
|
||||
return item
|
||||
try:
|
||||
if not ref_str.startswith("#/"):
|
||||
raise ValueError(
|
||||
|
|
|
|||
|
|
@ -93,15 +93,16 @@ def _replace_ref_with_defs(
|
|||
"""
|
||||
schema = info.copy()
|
||||
if ref_path := schema.get("$ref"):
|
||||
if ref_path.startswith("#/components/schemas/"):
|
||||
schema_name = ref_path.split("/")[-1]
|
||||
schema["$ref"] = f"#/$defs/{schema_name}"
|
||||
elif not ref_path.startswith("#/"):
|
||||
raise ValueError(
|
||||
f"External or non-local reference not supported: {ref_path}. "
|
||||
f"FastMCP only supports local schema references starting with '#/'. "
|
||||
f"Please include all schema definitions within the OpenAPI document."
|
||||
)
|
||||
if isinstance(ref_path, str):
|
||||
if ref_path.startswith("#/components/schemas/"):
|
||||
schema_name = ref_path.split("/")[-1]
|
||||
schema["$ref"] = f"#/$defs/{schema_name}"
|
||||
elif not ref_path.startswith("#/"):
|
||||
raise ValueError(
|
||||
f"External or non-local reference not supported: {ref_path}. "
|
||||
f"FastMCP only supports local schema references starting with '#/'. "
|
||||
f"Please include all schema definitions within the OpenAPI document."
|
||||
)
|
||||
elif properties := schema.get("properties"):
|
||||
if "$ref" in properties:
|
||||
schema["properties"] = _replace_ref_with_defs(properties)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue