Spaces:
Running
Running
Jeremiah Lowin Claude commited on
Commit ·
bbf015c
1
Parent(s): d33e60d
Use proper isinstance(Enum) check instead of hasattr
Browse filesReplace hasattr(param_in, 'value') with isinstance(param_in, Enum)
for more robust enum detection as suggested in review.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
src/fastmcp/utilities/openapi.py
CHANGED
|
@@ -303,8 +303,10 @@ class OpenAPIParser(
|
|
| 303 |
# Extract parameter info - handle both 3.0 and 3.1 parameter models
|
| 304 |
param_in = parameter.param_in # Both use param_in
|
| 305 |
# Handle enum or string parameter locations
|
|
|
|
|
|
|
| 306 |
param_in_str = (
|
| 307 |
-
param_in.value if
|
| 308 |
)
|
| 309 |
param_location = self._convert_to_parameter_location(param_in_str)
|
| 310 |
param_schema_obj = parameter.param_schema # Both use param_schema
|
|
|
|
| 303 |
# Extract parameter info - handle both 3.0 and 3.1 parameter models
|
| 304 |
param_in = parameter.param_in # Both use param_in
|
| 305 |
# Handle enum or string parameter locations
|
| 306 |
+
from enum import Enum
|
| 307 |
+
|
| 308 |
param_in_str = (
|
| 309 |
+
param_in.value if isinstance(param_in, Enum) else param_in
|
| 310 |
)
|
| 311 |
param_location = self._convert_to_parameter_location(param_in_str)
|
| 312 |
param_schema_obj = parameter.param_schema # Both use param_schema
|
tests/server/openapi/test_openapi_path_parameters.py
CHANGED
|
@@ -459,24 +459,27 @@ async def test_array_query_parameter_exploded_format(mock_client):
|
|
| 459 |
|
| 460 |
def test_parameter_location_enum_handling():
|
| 461 |
"""Test that ParameterLocation enum values are handled correctly (issue #950)."""
|
| 462 |
-
from
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
|
| 481 |
-
|
| 482 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 459 |
|
| 460 |
def test_parameter_location_enum_handling():
|
| 461 |
"""Test that ParameterLocation enum values are handled correctly (issue #950)."""
|
| 462 |
+
from enum import Enum
|
| 463 |
+
|
| 464 |
+
# Create a mock ParameterLocation enum like the one from openapi_pydantic
|
| 465 |
+
class MockParameterLocation(Enum):
|
| 466 |
+
PATH = "path"
|
| 467 |
+
QUERY = "query"
|
| 468 |
+
HEADER = "header"
|
| 469 |
+
COOKIE = "cookie"
|
| 470 |
+
|
| 471 |
+
# Test the enum handling logic directly (reproduces the fix in openapi.py)
|
| 472 |
+
test_cases = [
|
| 473 |
+
(MockParameterLocation.PATH, "path"),
|
| 474 |
+
(MockParameterLocation.QUERY, "query"),
|
| 475 |
+
(MockParameterLocation.HEADER, "header"),
|
| 476 |
+
(MockParameterLocation.COOKIE, "cookie"),
|
| 477 |
+
("path", "path"), # Also test that strings work
|
| 478 |
+
("query", "query"),
|
| 479 |
+
]
|
| 480 |
|
| 481 |
+
for param_in, expected_str in test_cases:
|
| 482 |
+
# This is the enum handling logic from the fix
|
| 483 |
+
param_in_str = param_in.value if isinstance(param_in, Enum) else param_in
|
| 484 |
+
assert param_in_str == expected_str
|
| 485 |
+
assert isinstance(param_in_str, str)
|