Skip to content

Python: fix(python): serialize OpenAPI boolean and array parameters according to specification (#14788) - #14800

Open
Suprovo Mallick (DYNO) (DYNOSuprovo) wants to merge 2 commits into
microsoft:mainfrom
DYNOSuprovo:fix/openapi-param-serialization-14788
Open

Suprovo Mallick (DYNO) (DYNOSuprovo) wants to merge 2 commits into
microsoft:mainfrom
DYNOSuprovo:fix/openapi-param-serialization-14788

Conversation

@DYNOSuprovo

Copy link
Copy Markdown

Motivation and Context

  1. Why is this change required?
    When using the OpenAPI plugin with operations that accept �oolean or �rray parameters (in query, header, or path), parameters were previously serialized using Python's default str() representation ( ags=['a', 'b'], �ctive=True). This caused remote APIs to fail parsing requests since OpenAPI specifies lowercase JSON booleans ( rue/ alse) and style: form, explode: true repeated query parameters ( ags=a&tags=b) by default.
  2. What problem does it solve?
    Fixes .Net: Python: Bug: OpenAPI plugin sends array and boolean query parameters as Python repr (tags=['a', 'b'], active=True) #14788. Ensures �uild_query_string, �uild_headers, and �uild_path format booleans and array parameters compliant with OpenAPI standard serialization rules.
  3. What scenario does it contribute to?
    Any tool invocation or agent action via Kernel.add_plugin_from_openapi targeting standard REST APIs that declare boolean flags or array query/header/path parameters.
  4. Linked issue:
    Fixes .Net: Python: Bug: OpenAPI plugin sends array and boolean query parameters as Python repr (tags=['a', 'b'], active=True) #14788.

Description

  • Introduced _format_parameter_value(value) helper in RestApiOperation to serialize booleans as lowercase "true"/"false" and strings/numbers as str(value).
  • Updated �uild_query_string:
    • Expands list/ uple values into individual (name, formatted_item) tuples to produce standard OpenAPI form/explode format (e.g. ags=red&tags=blue).
    • Serializes boolean scalars as "true"/"false" (e.g. �ctive=true).
  • Updated �uild_headers:
    • Formats arrays as comma-separated values (item1,item2).
    • Formats booleans as "true"/"false".
  • Updated �uild_path:
    • Formats arrays as comma-separated values before URL encoding.
    • Formats booleans as "true"/"false".
  • Added unit tests in ests/unit/connectors/openapi_plugin/test_sk_openapi.py:
    • est_build_query_string_with_array_and_boolean_parameters
      
    • est_build_headers_with_array_and_boolean_parameters
      
    • est_build_path_with_boolean_and_array_parameters
      

Contribution Checklist

Copilot AI balanced review requested due to automatic review settings November 16, 2026 12:29
@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Nov 16, 2026
@github-actions github-actions Bot changed the title fix(python): serialize OpenAPI boolean and array parameters according to specification (#14788) Python: fix(python): serialize OpenAPI boolean and array parameters according to specification (#14788) Nov 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Path-array serialization incorrectly percent-encodes separator commas, violating OpenAPI simple-style formatting and conflating multiple items with a single comma-containing value.

1 open issue
What changed in this PR

Addresses #14788 by updating the Python OpenAPI plugin’s boolean and array parameter serialization instead of using Python’s default string representations.

Changes:

  • Adds shared formatting for lowercase boolean values.
  • Expands query arrays into repeated keys and joins header/path arrays with commas.
  • Adds unit tests for boolean and array parameters in all three locations.
File Description
python/​tests/​unit/​connectors/​openapi_plugin/​test_sk_openapi.py Adds query, header, and path serialization tests.
python/​semantic_kernel/​connectors/​openapi_plugin/​models/​rest_api_operation.py Adds value formatting and updates parameter serialization.

Review effort: Balanced

Comment on lines +335 to +338
formatted_value = ",".join(self._format_parameter_value(item) for item in argument)
else:
formatted_value = self._format_parameter_value(argument)
path_template = path_template.replace(f"{{{parameter.name}}}", quote(formatted_value, safe=""))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Updated path parameter serialization in commit 9ea0be4f8 so each array item is percent-encoded individually before joining with literal commas, preserving OpenAPI simple-style delimiter syntax (item1,item2) while properly encoding any literal commas within elements (item%2C1,item2). Also updated unit tests and verified all tests pass.

@DYNOSuprovo

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

This branch was successfully deployed

1 active deployment
github-app-auth — 9ea0be4f Deployed Nov 16, 2026 by DYNOSuprovo via add_label #29701
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.Net: Python: Bug: OpenAPI plugin sends array and boolean query parameters as Python repr (tags=['a', 'b'], active=True)

2 participants