From aedd1b2326e69baf2f0205a1a583afae5faf994b Mon Sep 17 00:00:00 2001 From: Emond Papegaaij Date: Thu, 6 Jul 2023 15:20:40 +0200 Subject: [PATCH 1/4] Do not convert first char to upper on type names during code model construction Types are sometimes created with an upper case type name and sometimes with a lower case type name. This has no functional effect on the resulting code, because the writers will do this, but the converted name can end up in the comment. The comment should follow the spec and should be stable as much as possible. --- CHANGELOG.md | 1 + .../Extensions/OpenApiReferenceExtensions.cs | 3 +-- .../OpenApiReferenceExtensionsTests.cs | 2 +- .../OpenApiUrlTreeNodeExtensionsTests.cs | 2 +- .../Kiota.Builder.Tests/KiotaBuilderTests.cs | 24 +++++++++---------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0c1f43882..5c14f07114 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Allow configuration of the number of threads via the environment variable KIOTA_GENERATION_MAXDEGREEOFPARALLELISM. - Fixes regression where enum options would be renamed in CSharp. - Add locking to writing to log files. +- Typenames are not changed to first char upper case in comments in some cases. ## [1.3.0] - 2023-06-09 diff --git a/src/Kiota.Builder/Extensions/OpenApiReferenceExtensions.cs b/src/Kiota.Builder/Extensions/OpenApiReferenceExtensions.cs index 84b5c9b26c..c1c556ee35 100644 --- a/src/Kiota.Builder/Extensions/OpenApiReferenceExtensions.cs +++ b/src/Kiota.Builder/Extensions/OpenApiReferenceExtensions.cs @@ -6,8 +6,7 @@ public static class OpenApiReferenceExtensions public static string GetClassName(this OpenApiReference? reference) { if (reference?.Id is string referenceId && !string.IsNullOrEmpty(referenceId)) - return referenceId[(referenceId.LastIndexOf('.') + 1)..] - .ToFirstCharacterUpperCase(); + return referenceId[(referenceId.LastIndexOf('.') + 1)..]; return string.Empty; } } diff --git a/tests/Kiota.Builder.Tests/Extensions/OpenApiReferenceExtensionsTests.cs b/tests/Kiota.Builder.Tests/Extensions/OpenApiReferenceExtensionsTests.cs index 4330b23099..107cbe325d 100644 --- a/tests/Kiota.Builder.Tests/Extensions/OpenApiReferenceExtensionsTests.cs +++ b/tests/Kiota.Builder.Tests/Extensions/OpenApiReferenceExtensionsTests.cs @@ -14,7 +14,7 @@ public void GetsClassName() { Id = "microsoft.graph.user" }; - Assert.Equal("User", reference.GetClassName()); + Assert.Equal("user", reference.GetClassName()); } [Fact] public void GetsClassNameDefensive() diff --git a/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs b/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs index b88ccad7eb..5dba9cfbb6 100644 --- a/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs +++ b/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs @@ -362,6 +362,6 @@ public void GetsClassNameWithSegmentsToSkipForClassNames() .GetClassName(new() { "application/json" }, schema: responseSchema); // validate that we get a valid class name - Assert.Equal("Json", responseClassName); + Assert.Equal("json", responseClassName); } } diff --git a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs index 2ee1dea65a..00ee723b43 100644 --- a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs +++ b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs @@ -3427,7 +3427,7 @@ public void InheritedTypeWithInlineSchemaWorks() Assert.NotNull(requestExecutorMethod); var executorReturnType = requestExecutorMethod.ReturnType as CodeType; Assert.NotNull(executorReturnType); - Assert.Contains("DerivedObject", requestExecutorMethod.ReturnType.Name); + Assert.Contains("derivedObject", requestExecutorMethod.ReturnType.Name); var secondLevelDerivedClass = codeModel.FindChildByName("derivedObject"); Assert.NotNull(secondLevelDerivedObject); var factoryMethod = secondLevelDerivedClass.GetChildElements(true).OfType().FirstOrDefault(x => x.IsOfKind(CodeMethodKind.Factory)); @@ -4307,7 +4307,7 @@ public void AcceptVendorsTypes(string contentType) Assert.NotNull(rbClass); var executorMethod = rbClass.Methods.FirstOrDefault(x => x.IsOfKind(CodeMethodKind.RequestExecutor) && x.HttpMethod == Builder.CodeDOM.HttpMethod.Get); Assert.NotNull(executorMethod); - Assert.Equal("Myobject", executorMethod.ReturnType.Name); + Assert.Equal("myobject", executorMethod.ReturnType.Name); } [Fact] public void ModelsUseDescriptionWhenAvailable() @@ -4374,15 +4374,15 @@ public void ModelsUseDescriptionWhenAvailable() [InlineData("application/json", "205", false, "default", "void")] [InlineData("application/json", "204", true, "default", "void")] [InlineData("application/json", "204", false, "default", "void")] - [InlineData("application/json", "203", true, "default", "Myobject")] + [InlineData("application/json", "203", true, "default", "myobject")] [InlineData("application/json", "203", false, "default", "binary")] - [InlineData("application/json", "202", true, "default", "Myobject")] + [InlineData("application/json", "202", true, "default", "myobject")] [InlineData("application/json", "202", false, "default", "void")] - [InlineData("application/json", "201", true, "default", "Myobject")] + [InlineData("application/json", "201", true, "default", "myobject")] [InlineData("application/json", "201", false, "default", "void")] - [InlineData("application/json", "200", true, "default", "Myobject")] + [InlineData("application/json", "200", true, "default", "myobject")] [InlineData("application/json", "200", false, "default", "binary")] - [InlineData("application/json", "2XX", true, "default", "Myobject")] + [InlineData("application/json", "2XX", true, "default", "myobject")] [InlineData("application/json", "2XX", false, "default", "binary")] [InlineData("application/xml", "204", true, "default", "void")] [InlineData("application/xml", "204", false, "default", "void")] @@ -4410,7 +4410,7 @@ public void ModelsUseDescriptionWhenAvailable() [InlineData("*/*", "200", false, "default", "binary")] [InlineData("text/plain", "204", true, "default", "void")] [InlineData("text/plain", "204", false, "default", "void")] - [InlineData("text/plain", "200", true, "default", "Myobject")] + [InlineData("text/plain", "200", true, "default", "myobject")] [InlineData("text/plain", "200", false, "default", "string")] [InlineData("text/plain", "204", true, "application/json", "void")] [InlineData("text/plain", "204", false, "application/json", "void")] @@ -4587,7 +4587,7 @@ public void Considers200WithSchemaOver2XXWithSchema() Assert.NotNull(rbClass); var executor = rbClass.Methods.FirstOrDefault(x => x.IsOfKind(CodeMethodKind.RequestExecutor)); Assert.NotNull(executor); - Assert.Equal("Myobject", executor.ReturnType.Name); + Assert.Equal("myobject", executor.ReturnType.Name); } [Fact] public void Considers2XXWithSchemaOver204WithNoSchema() @@ -4660,7 +4660,7 @@ public void Considers2XXWithSchemaOver204WithNoSchema() Assert.NotNull(rbClass); var executor = rbClass.Methods.FirstOrDefault(x => x.IsOfKind(CodeMethodKind.RequestExecutor)); Assert.NotNull(executor); - Assert.Equal("Myobject", executor.ReturnType.Name); + Assert.Equal("myobject", executor.ReturnType.Name); } [Fact] public void Considers204WithNoSchemaOver206WithNoSchema() @@ -4729,7 +4729,7 @@ public void Considers204WithNoSchemaOver206WithNoSchema() Assert.NotNull(executor); Assert.Equal("void", executor.ReturnType.Name); } - [InlineData("application/json", true, "default", "Myobject")] + [InlineData("application/json", true, "default", "myobject")] [InlineData("application/json", false, "default", "binary")] [InlineData("application/xml", false, "default", "binary")] [InlineData("application/xml", true, "default", "binary")] //MyObject when we support it @@ -4744,7 +4744,7 @@ public void Considers204WithNoSchemaOver206WithNoSchema() [InlineData("*/*", true, "default", "binary")] [InlineData("*/*", false, "default", "binary")] [InlineData("text/plain", false, "default", "binary")] - [InlineData("text/plain", true, "default", "Myobject")] + [InlineData("text/plain", true, "default", "myobject")] [InlineData("text/plain", true, "application/json", "binary")] [InlineData("text/plain", false, "application/json", "binary")] [InlineData("text/yaml", true, "application/json", "binary")] From f4303522b35bb42aaf3e0461d7613fcbc0652b85 Mon Sep 17 00:00:00 2001 From: Emond Papegaaij Date: Thu, 6 Jul 2023 18:19:30 +0200 Subject: [PATCH 2/4] Fix generation of imports for error mapping Both import and location of usage must use toFirstCharacterUpperCase() to match. --- src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs index 7fbb06bd57..20641cf615 100644 --- a/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs @@ -562,7 +562,7 @@ private void WriteRequestExecutorBody(CodeMethod codeElement, RequestParams requ writer.StartBlock($"{errorMappingVarName}: Dict[str, ParsableFactory] = {{"); foreach (var errorMapping in codeElement.ErrorMappings) { - writer.WriteLine($"\"{errorMapping.Key.ToUpperInvariant()}\": {errorMapping.Value.Name},"); + writer.WriteLine($"\"{errorMapping.Key.ToUpperInvariant()}\": {errorMapping.Value.Name.ToFirstCharacterUpperCase()},"); } writer.CloseBlock(); } From 03ca6ae6afd054f23d348aa9efd8e642d92f665e Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 10 Jul 2023 12:59:00 -0400 Subject: [PATCH 3/4] - moves changelog entry to the next version --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c14f07114..0273410205 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Use schematized types for 206 response codes instead of binary. [#2880](https://github.com/microsoft/kiota/issues/2880) +- Typenames are not changed to first char upper case in comments in some cases. ## [1.4.0] - 2023-07-07 @@ -43,7 +44,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Allow configuration of the number of threads via the environment variable KIOTA_GENERATION_MAXDEGREEOFPARALLELISM. - Fixes regression where enum options would be renamed in CSharp. - Add locking to writing to log files. -- Typenames are not changed to first char upper case in comments in some cases. ## [1.3.0] - 2023-06-09 From 4e4e56e2401b2a0bc3457c22218ef47660186674 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 10 Jul 2023 13:07:32 -0400 Subject: [PATCH 4/4] - fixes casing for 206 status code --- tests/Kiota.Builder.Tests/KiotaBuilderTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs index 00ee723b43..d218821bf0 100644 --- a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs +++ b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs @@ -4368,7 +4368,7 @@ public void ModelsUseDescriptionWhenAvailable() Assert.Equal("some path item description", responseProperty.Documentation.Description); } - [InlineData("application/json", "206", true, "default", "Myobject")] + [InlineData("application/json", "206", true, "default", "myobject")] [InlineData("application/json", "206", false, "default", "binary")] [InlineData("application/json", "205", true, "default", "void")] [InlineData("application/json", "205", false, "default", "void")]