Skip to content

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

Merged
merged 4 commits into from
May 20, 2025
Merged

Ensure openapi path params are handled properly #519

merged 4 commits into from
May 20, 2025

Conversation

jlowin
Copy link
Owner

@jlowin jlowin commented May 20, 2025

Closes #497
Also unifies OpenAPI 3.0 and 3.1 parsing into a single generic utility

@Copilot Copilot AI review requested due to automatic review settings May 20, 2025 16:13
Copy link
Contributor

@Copilot Copilot AI left a 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 the ParameterInfo object likely defines this under schema. Please verify the correct attribute name to avoid an AttributeError at runtime.
schema = param_info.schema_

@jlowin jlowin requested a review from Copilot May 20, 2025 16:26
@jlowin jlowin merged commit 95a05c3 into main May 20, 2025
6 checks passed
@jlowin jlowin deleted the openapi-path branch May 20, 2025 16:28
Copy link
Contributor

@Copilot Copilot AI left a 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) with isinstance(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 = []
Copy link
Preview

Copilot AI May 20, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenAPI integration: issue with multi-valued path parameters
1 participant