mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-27 15:51:33 +02:00
Fix parameter location enum handling in OpenAPI parser
Fixes issue where ParameterLocation enum values from openapi_pydantic were not properly converted to strings, causing validation errors. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
c79665c76e
commit
f566e9a60f
2 changed files with 31 additions and 2 deletions
|
|
@ -302,11 +302,15 @@ class OpenAPIParser(
|
|||
|
||||
# Extract parameter info - handle both 3.0 and 3.1 parameter models
|
||||
param_in = parameter.param_in # Both use param_in
|
||||
param_location = self._convert_to_parameter_location(param_in)
|
||||
# Handle enum or string parameter locations
|
||||
param_in_str = (
|
||||
param_in.value if hasattr(param_in, "value") else param_in
|
||||
)
|
||||
param_location = self._convert_to_parameter_location(param_in_str)
|
||||
param_schema_obj = parameter.param_schema # Both use param_schema
|
||||
|
||||
# Skip duplicate parameters (same name and location)
|
||||
param_key = (parameter.name, param_in)
|
||||
param_key = (parameter.name, param_in_str)
|
||||
if param_key in seen_params:
|
||||
continue
|
||||
seen_params[param_key] = True
|
||||
|
|
|
|||
|
|
@ -455,3 +455,28 @@ async def test_array_query_parameter_exploded_format(mock_client):
|
|||
json=None,
|
||||
timeout=None,
|
||||
)
|
||||
|
||||
|
||||
def test_parameter_location_enum_handling():
|
||||
"""Test that ParameterLocation enum values are handled correctly (issue #950)."""
|
||||
from fastapi import FastAPI, Path, Query
|
||||
|
||||
from fastmcp import FastMCP
|
||||
|
||||
# Create FastAPI app with path and query parameters
|
||||
app = FastAPI(title="Parameter Location Test")
|
||||
|
||||
@app.get("/tenants/{tenant_id}/data")
|
||||
async def get_tenant_data(
|
||||
tenant_id: str = Path(..., description="The tenant ID"),
|
||||
limit: int = Query(10, description="Data limit"),
|
||||
):
|
||||
return {"tenant_id": tenant_id, "limit": limit}
|
||||
|
||||
# This should not raise a validation error about ParameterLocation
|
||||
mcp_server = FastMCP(
|
||||
name="Test MCP", instructions="Test server for parameter location enum handling"
|
||||
).from_fastapi(app, name="Test MCP", tags={"test"})
|
||||
|
||||
# Verify the server was created successfully
|
||||
assert mcp_server is not None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue