From d9f49bcdab264cdbaffda99f816ba2be3186c606 Mon Sep 17 00:00:00 2001 From: "Suprovo Mallick (DYNO)" <143953131+DYNOSuprovo@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:57:58 +0530 Subject: [PATCH 1/2] fix(openapi): serialize boolean and array parameters according to OpenAPI standards (#14788) --- .../models/rest_api_operation.py | 24 +++++++++-- .../openapi_plugin/test_sk_openapi.py | 40 +++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/python/semantic_kernel/connectors/openapi_plugin/models/rest_api_operation.py b/python/semantic_kernel/connectors/openapi_plugin/models/rest_api_operation.py index cc137083b4da..303656533bab 100644 --- a/python/semantic_kernel/connectors/openapi_plugin/models/rest_api_operation.py +++ b/python/semantic_kernel/connectors/openapi_plugin/models/rest_api_operation.py @@ -215,7 +215,10 @@ def build_headers(self, arguments: dict[str, Any]) -> dict[str, str]: ) continue - headers[parameter.name] = str(argument) + if isinstance(argument, (list, tuple)): + headers[parameter.name] = ",".join(self._format_parameter_value(item) for item in argument) + else: + headers[parameter.name] = self._format_parameter_value(argument) return headers @@ -328,7 +331,11 @@ def build_path(self, path_template: str, arguments: dict[str, Any]) -> str: f"required parameter of the operation - `{self.id}`." ) continue - path_template = path_template.replace(f"{{{parameter.name}}}", quote(str(argument), safe="")) + if isinstance(argument, (list, tuple)): + 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="")) self._validate_path_segments(path_template) return path_template @@ -383,6 +390,13 @@ def _is_non_relative_path(path: str) -> bool: parsed = urlparse(path) return bool(parsed.scheme or parsed.netloc) + @staticmethod + def _format_parameter_value(value: Any) -> str: + """Format a parameter value for serialization according to OpenAPI conventions.""" + if isinstance(value, bool): + return "true" if value else "false" + return str(value) + def build_query_string(self, arguments: dict[str, Any]) -> str: """Build the query string for the operation.""" segments = [] @@ -396,7 +410,11 @@ def build_query_string(self, arguments: dict[str, Any]) -> str: f"required parameter of the operation - `{self.id}`." ) continue - segments.append((parameter.name, argument)) + if isinstance(argument, (list, tuple)): + for item in argument: + segments.append((parameter.name, self._format_parameter_value(item))) + else: + segments.append((parameter.name, self._format_parameter_value(argument))) return urlencode(segments) def replace_invalid_symbols(self, parameter_name): diff --git a/python/tests/unit/connectors/openapi_plugin/test_sk_openapi.py b/python/tests/unit/connectors/openapi_plugin/test_sk_openapi.py index 58f79f9850eb..abbdf617e3eb 100644 --- a/python/tests/unit/connectors/openapi_plugin/test_sk_openapi.py +++ b/python/tests/unit/connectors/openapi_plugin/test_sk_openapi.py @@ -685,6 +685,46 @@ def test_build_query_string_with_optional_and_required_parameters(): assert operation.build_query_string(arguments) == expected_query_string +def test_build_query_string_with_array_and_boolean_parameters(): + parameters = [ + RestApiParameter(name="tags", type="array", location=RestApiParameterLocation.QUERY, is_required=False), + RestApiParameter(name="active", type="boolean", location=RestApiParameterLocation.QUERY, is_required=False), + RestApiParameter(name="archived", type="boolean", location=RestApiParameterLocation.QUERY, is_required=False), + ] + operation = RestApiOperation( + id="test", method="GET", servers=["https://example.com/"], path="/resource", params=parameters + ) + arguments = {"tags": ["red", "blue"], "active": True, "archived": False} + expected_query_string = "tags=red&tags=blue&active=true&archived=false" + assert operation.build_query_string(arguments) == expected_query_string + + +def test_build_headers_with_array_and_boolean_parameters(): + parameters = [ + RestApiParameter(name="X-Flags", type="array", location=RestApiParameterLocation.HEADER, is_required=False), + RestApiParameter(name="X-Active", type="boolean", location=RestApiParameterLocation.HEADER, is_required=False), + ] + operation = RestApiOperation( + id="test", method="GET", servers=["https://example.com/"], path="/resource", params=parameters + ) + arguments = {"X-Flags": ["tag1", "tag2"], "X-Active": True} + expected_headers = {"X-Flags": "tag1,tag2", "X-Active": "true"} + assert operation.build_headers(arguments) == expected_headers + + +def test_build_path_with_boolean_and_array_parameters(): + parameters = [ + RestApiParameter(name="flag", type="boolean", location=RestApiParameterLocation.PATH, is_required=True), + RestApiParameter(name="items", type="array", location=RestApiParameterLocation.PATH, is_required=True), + ] + operation = RestApiOperation( + id="test", method="GET", servers=["https://example.com/"], path="/resource/{flag}/{items}", params=parameters + ) + arguments = {"flag": True, "items": ["a", "b"]} + expected_path = "/resource/true/a%2Cb" + assert operation.build_path(operation.path, arguments) == expected_path + + def test_create_payload_artificial_parameter_with_text_plain(): properties = [ RestApiPayloadProperty( From 9ea0be4f85be4e7af5b3e91f96ebb03ce4388831 Mon Sep 17 00:00:00 2001 From: "Suprovo Mallick (DYNO)" <143953131+DYNOSuprovo@users.noreply.github.com> Date: Mon, 16 Nov 2026 20:14:11 +0530 Subject: [PATCH 2/2] fix(openapi): preserve array separators when encoding path parameters --- .../openapi_plugin/models/rest_api_operation.py | 8 +++++--- .../unit/connectors/openapi_plugin/test_sk_openapi.py | 6 +++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/python/semantic_kernel/connectors/openapi_plugin/models/rest_api_operation.py b/python/semantic_kernel/connectors/openapi_plugin/models/rest_api_operation.py index 303656533bab..a9af303a2e10 100644 --- a/python/semantic_kernel/connectors/openapi_plugin/models/rest_api_operation.py +++ b/python/semantic_kernel/connectors/openapi_plugin/models/rest_api_operation.py @@ -332,10 +332,12 @@ def build_path(self, path_template: str, arguments: dict[str, Any]) -> str: ) continue if isinstance(argument, (list, tuple)): - formatted_value = ",".join(self._format_parameter_value(item) for item in argument) + encoded_value = ",".join( + quote(self._format_parameter_value(item), safe="") for item in argument + ) else: - formatted_value = self._format_parameter_value(argument) - path_template = path_template.replace(f"{{{parameter.name}}}", quote(formatted_value, safe="")) + encoded_value = quote(self._format_parameter_value(argument), safe="") + path_template = path_template.replace(f"{{{parameter.name}}}", encoded_value) self._validate_path_segments(path_template) return path_template diff --git a/python/tests/unit/connectors/openapi_plugin/test_sk_openapi.py b/python/tests/unit/connectors/openapi_plugin/test_sk_openapi.py index abbdf617e3eb..b377e84f8023 100644 --- a/python/tests/unit/connectors/openapi_plugin/test_sk_openapi.py +++ b/python/tests/unit/connectors/openapi_plugin/test_sk_openapi.py @@ -721,9 +721,13 @@ def test_build_path_with_boolean_and_array_parameters(): id="test", method="GET", servers=["https://example.com/"], path="/resource/{flag}/{items}", params=parameters ) arguments = {"flag": True, "items": ["a", "b"]} - expected_path = "/resource/true/a%2Cb" + expected_path = "/resource/true/a,b" assert operation.build_path(operation.path, arguments) == expected_path + # Verify that commas within individual array items are properly percent-encoded + arguments_with_inner_comma = {"flag": False, "items": ["a,b", "c"]} + assert operation.build_path(operation.path, arguments_with_inner_comma) == "/resource/false/a%2Cb,c" + def test_create_payload_artificial_parameter_with_text_plain(): properties = [