Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: add coverage for line 211 in convert.py
  • Loading branch information
MagnusS0 committed Apr 21, 2025
commit dae803533864f3d6876f883d79b79fa15594f353
25 changes: 25 additions & 0 deletions tests/test_openapi_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,28 @@ def test_request_body_handling(complex_fastapi_app: FastAPI):
assert "create_order" in operation_map
assert operation_map["create_order"]["path"] == "/orders"
assert operation_map["create_order"]["method"] == "post"


def test_missing_type_handling(complex_fastapi_app: FastAPI):
openapi_schema = get_openapi(
title=complex_fastapi_app.title,
version=complex_fastapi_app.version,
openapi_version=complex_fastapi_app.openapi_version,
description=complex_fastapi_app.description,
routes=complex_fastapi_app.routes,
)

# Remove the type field from the product_id schema
params = openapi_schema["paths"]["/products/{product_id}"]["get"]["parameters"]
for param in params:
if param.get("name") == "product_id" and "schema" in param:
param["schema"].pop("type", None)
break

tools, operation_map = convert_openapi_to_mcp_tools(openapi_schema)

get_product_tool = next(tool for tool in tools if tool.name == "get_product")
get_product_props = get_product_tool.inputSchema["properties"]

assert "product_id" in get_product_props
assert get_product_props["product_id"].get("type") == "string" # Default type applied