fix:To fix the issue of missing reference to body parameter (#15443)

Co-authored-by: crazywoola <427733928@qq.com>
This commit is contained in:
Lick-liu 2025-03-11 16:16:53 +08:00 committed by GitHub
parent 6d172498d1
commit 41bf8d925f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -179,6 +179,18 @@ class ApiTool(Tool):
for content_type in self.api_bundle.openapi["requestBody"]["content"]:
headers["Content-Type"] = content_type
body_schema = self.api_bundle.openapi["requestBody"]["content"][content_type]["schema"]
# handle ref schema
if "$ref" in body_schema:
ref_path = body_schema["$ref"].split("/")
ref_name = ref_path[-1]
if (
"components" in self.api_bundle.openapi
and "schemas" in self.api_bundle.openapi["components"]
):
if ref_name in self.api_bundle.openapi["components"]["schemas"]:
body_schema = self.api_bundle.openapi["components"]["schemas"][ref_name]
required = body_schema.get("required", [])
properties = body_schema.get("properties", {})
for name, property in properties.items():
@ -186,6 +198,8 @@ class ApiTool(Tool):
if property.get("format") == "binary":
f = parameters[name]
files.append((name, (f.filename, download(f), f.mime_type)))
elif "$ref" in property:
body[name] = parameters[name]
else:
# convert type
body[name] = self._convert_body_property_type(property, parameters[name])