Repository: microsoft/kiota (csharp)

Issue:
Issue with package names being converted from UpperCamel case to LowerCamel case.
If the package name is github.com/OrgName/RepoName, the import statement in the generated code will convert it to the lower camel case of github.com/orgname/reponame.

## Command
```
kiota generate -l go -c PostsClient -n github.com/OrgName/RepoName -d . /path/to/swagger.yaml -o . /go/kiota
```

## Result
Expect
"github.com/OrgName/RepoName/kiota/name"

Actual
"github.com/Orgname/reponame/kiota/name"

Pull request:
~This is work in progress and might be rewritten.~

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a4c2ff4300..0b787a0421 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed
 
+- Fix package casing normalizing for value passed using `--namespace-name` option when generating Go Client. [#4498](https://github.com/microsoft/kiota/issues/4498)
 - Aligns naming of sliced OpenAPI description generated by `plugin add` should be named `<plugin-name>-openapi.json|yml` [#4595](https://github.com/microsoft/kiota/issues/4595)
 - Fixed RPC server to respect the `KIOTA_CONFIG_PREVIEW` flag.
 - Added missing nullable directives for CLI generation.
diff --git a/src/Kiota.Builder/Refiners/GoRefiner.cs b/src/Kiota.Builder/Refiners/GoRefiner.cs
index 191497d776..113d1399c7 100644
--- a/src/Kiota.Builder/Refiners/GoRefiner.cs
+++ b/src/Kiota.Builder/Refiners/GoRefiner.cs
@@ -19,6 +19,7 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance
         {
             cancellationToken.ThrowIfCancellationRequested();
             DeduplicateErrorMappings(generatedCode);
+            NormalizeNamespaceNames(generatedCode);
             MoveRequestBuilderPropertiesToBaseType(generatedCode,
                 new CodeUsing
                 {
@@ -757,4 +758,25 @@ currentInnerClass.Parent is CodeClass currentParentClass &&
         }
         CrawlTree(currentElement, RenameInnerModelsToAppended);
     }
+
+    private void NormalizeNamespaceNames(CodeElement currentElement)
+    {
+        if (currentElement is CodeNamespace codeNamespace)
+        {
+            var clientNamespace = _configuration.ClientNamespaceName;
+            var namespaceName = codeNamespace.Name;
+            if (namespaceName.StartsWith(clientNamespace, StringComparison.OrdinalIgnoreCase) && !namespaceName.Equals(clientNamespace, StringComparison.OrdinalIgnoreCase))
+            {
+                var secondPart = namespaceName[clientNamespace.Length..]; // The rest of the name after the clientNamespace
+                var withEmptyRemoved = string.Join('.', secondPart.Split('.', StringSplitOptions.RemoveEmptyEntries));
+                var normalizedString = string.IsNullOrEmpty(withEmptyRemoved) switch
+                {
+                    true => string.Empty,
+                    false => $".{withEmptyRemoved}"
+                };
+                codeNamespace.Name = $"{clientNamespace}{normalizedString.ToLowerInvariant()}";
+            }
+        }
+        CrawlTree(currentElement, NormalizeNamespaceNames);
+    }
 }
diff --git a/src/Kiota.Builder/Writers/Go/GoNamespaceExtensions.cs b/src/Kiota.Builder/Writers/Go/GoNamespaceExtensions.cs
index 1a06c08602..80573818ba 100644
--- a/src/Kiota.Builder/Writers/Go/GoNamespaceExtensions.cs
+++ b/src/Kiota.Builder/Writers/Go/GoNamespaceExtensions.cs
@@ -13,13 +13,13 @@ public static string GetLastNamespaceSegment(this string nsName)
         var urlPrefixIndex = nsName.LastIndexOf('/') + 1;
         var tentativeSegment = nsName[urlPrefixIndex..].Split('.', StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
         if (string.IsNullOrEmpty(tentativeSegment)) tentativeSegment = nsName.Split('/', StringSplitOptions.RemoveEmptyEntries).Last();
-        return tentativeSegment.ToLowerInvariant();
+        return tentativeSegment;
     }
     public static string GetInternalNamespaceImport(this CodeElement ns)
     {
         if (ns == null) return string.Empty;
         var urlPrefixIndex = ns.Name.LastIndexOf('/') + 1;
-        return (ns.Name[..urlPrefixIndex] + string.Join("/", ns.Name[urlPrefixIndex..].Split('.', StringSplitOptions.RemoveEmptyEntries))).ToLowerInvariant();
+        return (ns.Name[..urlPrefixIndex] + string.Join("/", ns.Name[urlPrefixIndex..].Split('.', StringSplitOptions.RemoveEmptyEntries)));
     }
     public static string GetNamespaceImportSymbol(this CodeElement ns)
     {


Test patch:
diff --git a/tests/Kiota.Builder.Tests/Refiners/GoLanguageRefinerTests.cs b/tests/Kiota.Builder.Tests/Refiners/GoLanguageRefinerTests.cs
index f080ab861d..59f73cde09 100644
--- a/tests/Kiota.Builder.Tests/Refiners/GoLanguageRefinerTests.cs
+++ b/tests/Kiota.Builder.Tests/Refiners/GoLanguageRefinerTests.cs
@@ -6,6 +6,7 @@
 using Kiota.Builder.CodeDOM;
 using Kiota.Builder.Configuration;
 using Kiota.Builder.Refiners;
+using Kiota.Builder.Writers.Go;
 using Microsoft.Extensions.Logging;
 using Moq;
 using Xunit;
@@ -1181,5 +1182,16 @@ public async Task AddsUsingForUntypedNode()
         Assert.Single(nodeUsing);
         Assert.Equal("github.com/microsoft/kiota-abstractions-go/serialization", nodeUsing[0].Declaration.Name);
     }
+
+    [Fact]
+    public async Task NormalizeNamespaceName()
+    {
+        root.Name = "github.com/OrgName/RepoName";
+        var models = root.AddNamespace("ApiSdk.models");
+        var submodels = models.AddNamespace("ApiSdk.models.submodels");
+        await ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.Go, ClientNamespaceName = "github.com/OrgName/RepoName" }, root);
+        Assert.Equal("github.com/OrgName/RepoName.apisdk.models.submodels", submodels.Name);
+        Assert.Equal("github.com/OrgName/RepoName.apisdk.models", models.Name);
+    }
     #endregion
 }