From 91e885b493499c562c3ec6ec59990c5d4bb4af83 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Apr 2026 02:17:07 +0000 Subject: [PATCH 1/4] Initial plan From 9b9de6564b9fc51da6844012a6d664566594d640 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Apr 2026 02:24:09 +0000 Subject: [PATCH 2/4] fix: refine api_version argument doc to show None as default value For optional api_version parameters: - Known values now include "and None" since None is valid - Default value shows None instead of the version string - Adds note: "If not set, the operation's default API version will be used." - Removes "Note that overriding this default value may result in unsupported behavior." Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/0ef852ae-fc44-4ef7-9ec1-8ae7ec0e062d Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com> --- .../pygen/codegen/models/parameter.py | 25 ++-- .../unit/test_api_version_description.py | 126 ++++++++++++++++++ 2 files changed, 138 insertions(+), 13 deletions(-) create mode 100644 packages/http-client-python/tests/unit/test_api_version_description.py diff --git a/packages/http-client-python/generator/pygen/codegen/models/parameter.py b/packages/http-client-python/generator/pygen/codegen/models/parameter.py index bcca96fa75c..26f5c1dc82b 100644 --- a/packages/http-client-python/generator/pygen/codegen/models/parameter.py +++ b/packages/http-client-python/generator/pygen/codegen/models/parameter.py @@ -109,29 +109,28 @@ def description(self) -> str: if type_description: base_description = add_to_description(base_description, type_description) if self.optional and isinstance(self.type, ConstantType): - if self.is_api_version: - base_description = add_to_description( - base_description, - f"Known values are {self.get_declaration()}.", - ) - else: - base_description = add_to_description( - base_description, - f"Known values are {self.get_declaration()} and None.", - ) + base_description = add_to_description( + base_description, + f"Known values are {self.get_declaration()} and None.", + ) if not (self.optional or self.client_default_value): base_description = add_to_description(base_description, "Required.") - if self.client_default_value is not None: + if self.is_api_version and self.optional: + base_description = add_to_description( + base_description, + "Default value is None. If not set, the operation's default API version will be used.", + ) + elif self.client_default_value is not None: base_description = add_to_description( base_description, f"Default value is {self.client_default_value_declaration}.", ) - if self.optional and self.client_default_value is None: + elif self.optional: base_description = add_to_description( base_description, f"Default value is {self.client_default_value_declaration}.", ) - if self.constant: + if self.constant and not self.is_api_version: base_description = add_to_description( base_description, "Note that overriding this default value may result in unsupported behavior.", diff --git a/packages/http-client-python/tests/unit/test_api_version_description.py b/packages/http-client-python/tests/unit/test_api_version_description.py new file mode 100644 index 00000000000..e66805cd636 --- /dev/null +++ b/packages/http-client-python/tests/unit/test_api_version_description.py @@ -0,0 +1,126 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +from pygen.codegen.models import Parameter, CodeModel, ConstantType, StringType + + +def get_code_model(): + return CodeModel( + { + "clients": [ + { + "name": "client", + "namespace": "blah", + "moduleName": "blah", + "parameters": [], + "url": "", + "operationGroups": [], + } + ], + "namespace": "namespace", + }, + options={ + "show-send-request": True, + "builders-visibility": "public", + "show-operations": True, + "models-mode": "dpg", + "only-path-and-body-params-positional": True, + }, + ) + + +def _make_constant_type(value): + code_model = get_code_model() + string_type = StringType( + yaml_data={"type": "str"}, + code_model=code_model, + ) + return ConstantType( + yaml_data={"type": "constant"}, + code_model=code_model, + value_type=string_type, + value=value, + ) + + +def test_api_version_parameter_description(): + """Test that api_version parameter description shows None as default.""" + code_model = get_code_model() + constant_type = _make_constant_type("2025-11-01") + param = Parameter( + yaml_data={ + "wireName": "api-version", + "clientName": "api_version", + "location": "query", + "clientDefaultValue": "2025-11-01", + "optional": True, + "implementation": "Client", + "isApiVersion": True, + "description": "The API version to use for this operation.", + "inOverload": False, + "inOverloaded": False, + "type": {"type": "constant"}, + }, + code_model=code_model, + type=constant_type, + ) + desc = param.description + assert "Default value is None." in desc + assert "If not set, the operation's default API version will be used." in desc + assert 'Known values are "2025-11-01" and None.' in desc + assert "Note that overriding this default value may result in unsupported behavior" not in desc + + +def test_non_api_version_constant_parameter_description(): + """Test that non-api_version optional constant parameters still show the original behavior.""" + code_model = get_code_model() + constant_type = _make_constant_type("some-value") + param = Parameter( + yaml_data={ + "wireName": "some-param", + "clientName": "some_param", + "location": "query", + "clientDefaultValue": "some-value", + "optional": True, + "implementation": "Method", + "isApiVersion": False, + "description": "Some parameter.", + "inOverload": False, + "inOverloaded": False, + "type": {"type": "constant"}, + }, + code_model=code_model, + type=constant_type, + ) + desc = param.description + assert 'Known values are "some-value" and None.' in desc + assert 'Default value is "some-value".' in desc + assert "Note that overriding this default value may result in unsupported behavior" not in desc + + +def test_required_api_version_parameter_description(): + """Test that required api_version parameter description shows overriding note.""" + code_model = get_code_model() + constant_type = _make_constant_type("2025-11-01") + param = Parameter( + yaml_data={ + "wireName": "api-version", + "clientName": "api_version", + "location": "query", + "clientDefaultValue": "2025-11-01", + "optional": False, + "implementation": "Client", + "isApiVersion": True, + "description": "The API version to use for this operation.", + "inOverload": False, + "inOverloaded": False, + "type": {"type": "constant"}, + }, + code_model=code_model, + type=constant_type, + ) + desc = param.description + # Required api_version is constant - should not have the override note + assert "Note that overriding this default value may result in unsupported behavior" not in desc From 73affe9a8380911683f1a3ad2c0ca78692bc4bd0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Apr 2026 10:40:32 +0000 Subject: [PATCH 3/4] fix: keep "overriding this default value" note for api-version parameters Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/73bd662d-7b42-4b56-a125-107799d617ff Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com> --- .../generator/pygen/codegen/models/parameter.py | 2 +- .../tests/unit/test_api_version_description.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/http-client-python/generator/pygen/codegen/models/parameter.py b/packages/http-client-python/generator/pygen/codegen/models/parameter.py index 26f5c1dc82b..88a2f0ccb2c 100644 --- a/packages/http-client-python/generator/pygen/codegen/models/parameter.py +++ b/packages/http-client-python/generator/pygen/codegen/models/parameter.py @@ -130,7 +130,7 @@ def description(self) -> str: base_description, f"Default value is {self.client_default_value_declaration}.", ) - if self.constant and not self.is_api_version: + if self.constant: base_description = add_to_description( base_description, "Note that overriding this default value may result in unsupported behavior.", diff --git a/packages/http-client-python/tests/unit/test_api_version_description.py b/packages/http-client-python/tests/unit/test_api_version_description.py index e66805cd636..025e57d06ae 100644 --- a/packages/http-client-python/tests/unit/test_api_version_description.py +++ b/packages/http-client-python/tests/unit/test_api_version_description.py @@ -70,7 +70,7 @@ def test_api_version_parameter_description(): assert "Default value is None." in desc assert "If not set, the operation's default API version will be used." in desc assert 'Known values are "2025-11-01" and None.' in desc - assert "Note that overriding this default value may result in unsupported behavior" not in desc + assert "Note that overriding this default value may result in unsupported behavior" in desc def test_non_api_version_constant_parameter_description(): @@ -122,5 +122,5 @@ def test_required_api_version_parameter_description(): type=constant_type, ) desc = param.description - # Required api_version is constant - should not have the override note - assert "Note that overriding this default value may result in unsupported behavior" not in desc + # Required api_version is constant - should have the override note + assert "Note that overriding this default value may result in unsupported behavior" in desc From 3faf10ad80e04a48e3eac639b5413b83a073529d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Apr 2026 10:45:01 +0000 Subject: [PATCH 4/4] test: remove test_api_version_description.py per reviewer request Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/99c1d213-7362-4e48-a2bf-e3c44ce9a519 Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com> --- .../unit/test_api_version_description.py | 126 ------------------ 1 file changed, 126 deletions(-) delete mode 100644 packages/http-client-python/tests/unit/test_api_version_description.py diff --git a/packages/http-client-python/tests/unit/test_api_version_description.py b/packages/http-client-python/tests/unit/test_api_version_description.py deleted file mode 100644 index 025e57d06ae..00000000000 --- a/packages/http-client-python/tests/unit/test_api_version_description.py +++ /dev/null @@ -1,126 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from pygen.codegen.models import Parameter, CodeModel, ConstantType, StringType - - -def get_code_model(): - return CodeModel( - { - "clients": [ - { - "name": "client", - "namespace": "blah", - "moduleName": "blah", - "parameters": [], - "url": "", - "operationGroups": [], - } - ], - "namespace": "namespace", - }, - options={ - "show-send-request": True, - "builders-visibility": "public", - "show-operations": True, - "models-mode": "dpg", - "only-path-and-body-params-positional": True, - }, - ) - - -def _make_constant_type(value): - code_model = get_code_model() - string_type = StringType( - yaml_data={"type": "str"}, - code_model=code_model, - ) - return ConstantType( - yaml_data={"type": "constant"}, - code_model=code_model, - value_type=string_type, - value=value, - ) - - -def test_api_version_parameter_description(): - """Test that api_version parameter description shows None as default.""" - code_model = get_code_model() - constant_type = _make_constant_type("2025-11-01") - param = Parameter( - yaml_data={ - "wireName": "api-version", - "clientName": "api_version", - "location": "query", - "clientDefaultValue": "2025-11-01", - "optional": True, - "implementation": "Client", - "isApiVersion": True, - "description": "The API version to use for this operation.", - "inOverload": False, - "inOverloaded": False, - "type": {"type": "constant"}, - }, - code_model=code_model, - type=constant_type, - ) - desc = param.description - assert "Default value is None." in desc - assert "If not set, the operation's default API version will be used." in desc - assert 'Known values are "2025-11-01" and None.' in desc - assert "Note that overriding this default value may result in unsupported behavior" in desc - - -def test_non_api_version_constant_parameter_description(): - """Test that non-api_version optional constant parameters still show the original behavior.""" - code_model = get_code_model() - constant_type = _make_constant_type("some-value") - param = Parameter( - yaml_data={ - "wireName": "some-param", - "clientName": "some_param", - "location": "query", - "clientDefaultValue": "some-value", - "optional": True, - "implementation": "Method", - "isApiVersion": False, - "description": "Some parameter.", - "inOverload": False, - "inOverloaded": False, - "type": {"type": "constant"}, - }, - code_model=code_model, - type=constant_type, - ) - desc = param.description - assert 'Known values are "some-value" and None.' in desc - assert 'Default value is "some-value".' in desc - assert "Note that overriding this default value may result in unsupported behavior" not in desc - - -def test_required_api_version_parameter_description(): - """Test that required api_version parameter description shows overriding note.""" - code_model = get_code_model() - constant_type = _make_constant_type("2025-11-01") - param = Parameter( - yaml_data={ - "wireName": "api-version", - "clientName": "api_version", - "location": "query", - "clientDefaultValue": "2025-11-01", - "optional": False, - "implementation": "Client", - "isApiVersion": True, - "description": "The API version to use for this operation.", - "inOverload": False, - "inOverloaded": False, - "type": {"type": "constant"}, - }, - code_model=code_model, - type=constant_type, - ) - desc = param.description - # Required api_version is constant - should have the override note - assert "Note that overriding this default value may result in unsupported behavior" in desc