From 022e3e934c29d6a03e9f27b658ddcad2ba7ee990 Mon Sep 17 00:00:00 2001 From: Jan Trejbal Date: Mon, 26 Aug 2024 14:17:51 +0200 Subject: [PATCH] fix: do not emit ObsoleteAttribute on method parameters (#5228) * Add DoesNotWriteDeprecatedBodyParameterRequestBuilder test * Fix GetParameterSignature * Update CHANGELOG.md --- CHANGELOG.md | 1 + .../Writers/CSharp/CSharpConventionService.cs | 2 +- .../Writers/CSharp/CodeMethodWriterTests.cs | 21 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3b2fe62fb..b3e1a33831 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added Collection, HashMap, Map, Objects, InputStream, BigDecimal to the list of reserved names for Java generation. [#5135](https://github.com/microsoft/kiota/issues/5135) - C# refiner now fixes data types for indexers. [#5201](https://github.com/microsoft/kiota/issues/5201) - C# do not report CS0618 in the generated code. [#5229](https://github.com/microsoft/kiota/issues/5229) +- C# do not decorate method parameter(s) with ObsoleteAttribute. [#5228](https://github.com/microsoft/kiota/issues/5228) ## [1.17.0] - 2024-08-09 diff --git a/src/Kiota.Builder/Writers/CSharp/CSharpConventionService.cs b/src/Kiota.Builder/Writers/CSharp/CSharpConventionService.cs index 5037cfe8d7..3ae7725e78 100644 --- a/src/Kiota.Builder/Writers/CSharp/CSharpConventionService.cs +++ b/src/Kiota.Builder/Writers/CSharp/CSharpConventionService.cs @@ -249,7 +249,7 @@ _ when nameof(String).Equals(parameterType, StringComparison.OrdinalIgnoreCase) _ when parameter.Optional => " = default", _ => string.Empty, }; - return $"{GetDeprecationInformation(parameter)}{parameterType} {parameter.Name.ToFirstCharacterLowerCase()}{defaultValue}"; + return $"{parameterType} {parameter.Name.ToFirstCharacterLowerCase()}{defaultValue}"; } private string GetDeprecationInformation(IDeprecableElement element) { diff --git a/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs index e1529d3112..9b2dc48247 100644 --- a/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs @@ -1450,6 +1450,27 @@ public void WritesPathParameterRequestBuilder() Assert.Contains("return new", result); } [Fact] + public void DoesNotWriteDeprecatedBodyParameterRequestBuilder() + { + setup(); + method.Kind = CodeMethodKind.RequestBuilderWithParameters; + method.AddParameter(new CodeParameter + { + Name = "pathParam", + Kind = CodeParameterKind.RequestBody, + Type = new CodeType + { + Name = "string" + }, + Deprecation = new DeprecationInformation("parameter") + }); + method.Deprecation = new DeprecationInformation("method"); + writer.Write(method); + var result = tw.ToString(); + Assert.Contains("[Obsolete(\"method\")]", result); + Assert.DoesNotContain("[Obsolete(\"parameter\")]", result); + } + [Fact] public void WritesConstructor() { setup();