From fc4ecea0326e13cc919c744c739134522aaf1fb3 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 9 Sep 2022 09:50:52 -0400 Subject: [PATCH 1/2] - fixes a regression where the parsenode type would not be replaced anymore --- src/Kiota.Builder/Refiners/GoRefiner.cs | 10 +++++++--- src/Kiota.Builder/Refiners/JavaRefiner.cs | 3 ++- src/Kiota.Builder/Refiners/PhpRefiner.cs | 2 +- src/Kiota.Builder/Refiners/PythonRefiner.cs | 4 ++-- src/Kiota.Builder/Refiners/RubyRefiner.cs | 2 ++ src/Kiota.Builder/Refiners/SwiftRefiner.cs | 5 ++++- src/Kiota.Builder/Refiners/TypeScriptRefiner.cs | 3 ++- 7 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Kiota.Builder/Refiners/GoRefiner.cs b/src/Kiota.Builder/Refiners/GoRefiner.cs index 64c7efd6d2..1272c7cfc3 100644 --- a/src/Kiota.Builder/Refiners/GoRefiner.cs +++ b/src/Kiota.Builder/Refiners/GoRefiner.cs @@ -306,12 +306,16 @@ private static void CorrectMethodType(CodeMethod currentMethod) { if(rawUrlParam != null) rawUrlParam.Type.IsNullable = false; currentMethod.Parameters.Where(x => x.IsOfKind(CodeParameterKind.RequestAdapter)) - .Where(x => x.Type.Name.StartsWith("I", StringComparison.InvariantCultureIgnoreCase)) + .Where(static x => x.Type.Name.StartsWith("I", StringComparison.InvariantCultureIgnoreCase)) .ToList() - .ForEach(x => x.Type.Name = x.Type.Name[1..]); // removing the "I" + .ForEach(static x => x.Type.Name = x.Type.Name[1..]); // removing the "I" } else if(currentMethod.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility, CodeMethodKind.RequestBuilderWithParameters, CodeMethodKind.RequestBuilderBackwardCompatibility, CodeMethodKind.Factory)) { currentMethod.ReturnType.IsNullable = true; - currentMethod.Parameters.Where(x => x.IsOfKind(CodeParameterKind.ParseNode)).ToList().ForEach(x => x.Type.IsNullable = false); + if (currentMethod.Parameters.OfKind(CodeParameterKind.ParseNode) is CodeParameter parseNodeParam) { + parseNodeParam.Type.IsNullable = false; + parseNodeParam.Type.Name = parseNodeParam.Type.Name[1..]; + } + if(currentMethod.IsOfKind(CodeMethodKind.Factory)) currentMethod.ReturnType = new CodeType { Name = "Parsable", IsNullable = false, IsExternal = true }; } diff --git a/src/Kiota.Builder/Refiners/JavaRefiner.cs b/src/Kiota.Builder/Refiners/JavaRefiner.cs index b939a222d0..fad9227110 100644 --- a/src/Kiota.Builder/Refiners/JavaRefiner.cs +++ b/src/Kiota.Builder/Refiners/JavaRefiner.cs @@ -199,7 +199,8 @@ private static void CorrectMethodType(CodeMethod currentMethod) { var urlTplParams = currentMethod.Parameters.FirstOrDefault(x => x.IsOfKind(CodeParameterKind.PathParameters)); if(urlTplParams != null) urlTplParams.Type.Name = "HashMap"; - } + } else if(currentMethod.IsOfKind(CodeMethodKind.Factory) && currentMethod.Parameters.OfKind(CodeParameterKind.ParseNode) is CodeParameter parseNodeParam) + parseNodeParam.Type.Name = parseNodeParam.Type.Name[1..]; CorrectDateTypes(currentMethod.Parent as CodeClass, DateTypesReplacements, currentMethod.Parameters .Select(x => x.Type) .Union(new CodeTypeBase[] { currentMethod.ReturnType}) diff --git a/src/Kiota.Builder/Refiners/PhpRefiner.cs b/src/Kiota.Builder/Refiners/PhpRefiner.cs index edd301d055..5e77fd5a34 100644 --- a/src/Kiota.Builder/Refiners/PhpRefiner.cs +++ b/src/Kiota.Builder/Refiners/PhpRefiner.cs @@ -187,7 +187,7 @@ private static void CorrectMethodType(CodeMethod method) method.ReturnType.Name = "array"; } CorrectDateTypes(method.Parent as CodeClass, DateTypesReplacements, method.Parameters - .Select(x => x.Type) + .Select(static x => x.Type) .Union(new CodeTypeBase[] { method.ReturnType}) .ToArray()); } diff --git a/src/Kiota.Builder/Refiners/PythonRefiner.cs b/src/Kiota.Builder/Refiners/PythonRefiner.cs index 60c3754edd..3d2a40c977 100644 --- a/src/Kiota.Builder/Refiners/PythonRefiner.cs +++ b/src/Kiota.Builder/Refiners/PythonRefiner.cs @@ -136,9 +136,9 @@ private static void CorrectMethodType(CodeMethod currentMethod) { currentMethod.ReturnType.Name = $"Dict[str, Callable[[ParseNode], None]]"; else if(currentMethod.IsOfKind(CodeMethodKind.ClientConstructor, CodeMethodKind.Constructor, CodeMethodKind.Factory)) { currentMethod.Parameters.Where(x => x.IsOfKind(CodeParameterKind.RequestAdapter, CodeParameterKind.BackingStore, CodeParameterKind.ParseNode)) - .Where(x => x.Type.Name.StartsWith("I", StringComparison.InvariantCultureIgnoreCase)) + .Where(static x => x.Type.Name.StartsWith("I", StringComparison.InvariantCultureIgnoreCase)) .ToList() - .ForEach(x => x.Type.Name = x.Type.Name[1..]); // removing the "I" + .ForEach(static x => x.Type.Name = x.Type.Name[1..]); // removing the "I" var urlTplParams = currentMethod.Parameters.FirstOrDefault(x => x.IsOfKind(CodeParameterKind.PathParameters)); if(urlTplParams != null && urlTplParams.Type is CodeType originalType) { diff --git a/src/Kiota.Builder/Refiners/RubyRefiner.cs b/src/Kiota.Builder/Refiners/RubyRefiner.cs index 0e65b1ca6c..2553636127 100644 --- a/src/Kiota.Builder/Refiners/RubyRefiner.cs +++ b/src/Kiota.Builder/Refiners/RubyRefiner.cs @@ -45,6 +45,8 @@ public override void Refine(CodeNamespace generatedCode) new [] { "microsoft_kiota_abstractions.ParseNodeFactoryRegistry" }); } private static void CorrectMethodType(CodeMethod currentMethod) { + if(currentMethod.IsOfKind(CodeMethodKind.Factory) && currentMethod.Parameters.OfKind(CodeParameterKind.ParseNode) is CodeParameter parseNodeParam) + parseNodeParam.Type.Name = parseNodeParam.Type.Name[1..]; CorrectDateTypes(currentMethod.Parent as CodeClass, DateTypesReplacements, currentMethod.Parameters .Select(x => x.Type) .Union(new CodeTypeBase[] { currentMethod.ReturnType}) diff --git a/src/Kiota.Builder/Refiners/SwiftRefiner.cs b/src/Kiota.Builder/Refiners/SwiftRefiner.cs index 34e2b5df0d..8f59d8af27 100644 --- a/src/Kiota.Builder/Refiners/SwiftRefiner.cs +++ b/src/Kiota.Builder/Refiners/SwiftRefiner.cs @@ -85,7 +85,10 @@ private static void CorrectMethodType(CodeMethod currentMethod) { .ForEach(x => x.Type.Name = x.Type.Name[1..]); // removing the "I" } else if(currentMethod.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility, CodeMethodKind.RequestBuilderWithParameters, CodeMethodKind.RequestBuilderBackwardCompatibility, CodeMethodKind.Factory)) { currentMethod.ReturnType.IsNullable = true; - currentMethod.Parameters.Where(x => x.IsOfKind(CodeParameterKind.ParseNode)).ToList().ForEach(x => x.Type.IsNullable = false); + if (currentMethod.Parameters.OfKind(CodeParameterKind.ParseNode) is CodeParameter parseNodeParam) { + parseNodeParam.Type.Name = parseNodeParam.Type.Name[1..]; + parseNodeParam.Type.IsNullable = false; + } if(currentMethod.IsOfKind(CodeMethodKind.Factory)) currentMethod.ReturnType = new CodeType { Name = "Parsable", IsNullable = false, IsExternal = true }; } diff --git a/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs b/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs index 784bc9d3c2..d15d4861ce 100644 --- a/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs +++ b/src/Kiota.Builder/Refiners/TypeScriptRefiner.cs @@ -210,7 +210,8 @@ private static void CorrectMethodType(CodeMethod currentMethod) { }); urlTplParams.Type = unionType; } - } + } else if(currentMethod.IsOfKind(CodeMethodKind.Factory) && currentMethod.Parameters.OfKind(CodeParameterKind.ParseNode) is CodeParameter parseNodeParam) + parseNodeParam.Type.Name = parseNodeParam.Type.Name[1..]; CorrectDateTypes(currentMethod.Parent as CodeClass, DateTypesReplacements, currentMethod.Parameters .Select(x => x.Type) .Union(new CodeTypeBase[] { currentMethod.ReturnType}) From 954643098ea08c2149cc8d779a9f81a66d52481c Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 9 Sep 2022 09:52:42 -0400 Subject: [PATCH 2/2] - bumps version number for generator --- CHANGELOG.md | 8 ++++++++ src/Kiota.Builder/Kiota.Builder.csproj | 2 +- src/kiota/kiota.csproj | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d46a9caf66..4528c5359f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +### Changed + +## [0.5.1] - 2022-09-09 + +### Added + - Exempts read only properties from being serialized and sent to the service. [#1828](https://github.com/microsoft/kiota/issues/1828) ### Changed +- Fixed a regression where parse node parameter type for factories would be incorrect in Go, Ruby, Swift, Java and TypeScript. + ## [0.5.0] - 2022-09-08 ### Added diff --git a/src/Kiota.Builder/Kiota.Builder.csproj b/src/Kiota.Builder/Kiota.Builder.csproj index c79f35d424..71653677d9 100644 --- a/src/Kiota.Builder/Kiota.Builder.csproj +++ b/src/Kiota.Builder/Kiota.Builder.csproj @@ -12,7 +12,7 @@ Microsoft.OpenApi.Kiota.Builder Microsoft.OpenApi.Kiota.Builder ./nupkg - 0.5.0-preview + 0.5.1-preview https://github.com/microsoft/kiota/releases diff --git a/src/kiota/kiota.csproj b/src/kiota/kiota.csproj index 51dbe0d141..56624caf12 100644 --- a/src/kiota/kiota.csproj +++ b/src/kiota/kiota.csproj @@ -14,7 +14,7 @@ Microsoft.OpenApi.Kiota Microsoft.OpenApi.Kiota ./nupkg - 0.5.0-preview + 0.5.1-preview https://github.com/microsoft/kiota/releases