-
Notifications
You must be signed in to change notification settings - Fork 658
Ensure openapi path params are handled properly #519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for properly formatting array path parameters (both simple and complex) in the OpenAPITool, and unifies parsing for OpenAPI 3.0 and 3.1.
- Implements comma-separated serialization for array path parameters, including a fallback for nested objects
- Adds unit and integration tests covering simple and complex array path parameters
- Consolidates OpenAPI version handling into a single utility
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
tests/server/test_openapi_path_parameters.py | New fixtures and tests covering array path parameters (simple and complex) |
tests/server/test_openapi_array_params.py | Duplicate tests for simple array path parameter handling |
src/fastmcp/server/openapi.py | Core implementation for serializing array path parameters |
Comments suppressed due to low confidence (2)
src/fastmcp/server/openapi.py:189
- The isinstance check using a union type (
str | int | float | bool
) is not valid; use a tuple of types instead, e.g.,isinstance(item, (str, int, float, bool))
.
isinstance(item, str | int | float | bool)
src/fastmcp/server/openapi.py:182
- The code references
param_info.schema_
, but theParameterInfo
object likely defines this underschema
. Please verify the correct attribute name to avoid an AttributeError at runtime.
schema = param_info.schema_
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
A concise utility now unifies OpenAPI 3.0 and 3.1 parsing and ensures array path and query parameters are formatted correctly.
- Handles array path parameters in “simple” style (comma-separated) when building the request path.
- Serializes array query parameters with proper explode logic or comma separation.
- Consolidates OpenAPI parsing logic into a single generic utility.
Comments suppressed due to low confidence (3)
src/fastmcp/server/openapi.py:174
- New array formatting behavior for path parameters should be covered by unit tests—add tests for simple and complex array path parameters to ensure correctness.
# Handle array path parameters with style 'simple' (comma-separated)
src/fastmcp/server/openapi.py:189
- The expression
isinstance(item, str | int | float | bool)
is invalid; use a tuple of types instead, e.g.isinstance(item, (str, int, float, bool))
.
isinstance(item, str | int | float | bool)
src/fastmcp/server/openapi.py:259
- Same issue here: replace
isinstance(item, str | int | float | bool)
withisinstance(item, (str, int, float, bool))
.
isinstance(item, str | int | float | bool)
# Handle complex array types (containing objects/dicts) | ||
try: | ||
# Try to create a simple representation without Python syntax artifacts | ||
formatted_parts = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The logic for formatting complex array elements is duplicated for both path and query parameters; consider extracting it into a shared helper function to improve readability and reduce duplication.
Copilot uses AI. Check for mistakes.
Closes #497
Also unifies OpenAPI 3.0 and 3.1 parsing into a single generic utility