Repository: microsoft/kiota (csharp)

Issue:
DateOnly serialization doesn't play nice with GitHub's OpenAPI spec
Hi Kiota people! This issue is the Kiota side of https://github.com/octokit/source-generator/issues/23, in which the GitHub SDK team is using Kiota to generate Go code off of our (GitHub's) OpenAPI spec. 

Specifically, we're seeing errors with DateOnly arrays as @baywet pointed out. 

In the following code snippet, 

```go
// Get get all supported GitHub API versions.
// [API method documentation]
// 
// [API method documentation]: https://docs.github.com/rest/meta/meta#get-all-api-versions
func (m *VersionsRequestBuilder) Get(ctx context.Context, requestConfiguration *VersionsRequestBuilderGetRequestConfiguration)([]i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.DateOnly, error) {
    requestInfo, err := m.ToGetRequestInformation(ctx, requestConfiguration);
    if err != nil {
        return nil, err
    }
    errorMapping := i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.ErrorMappings {
        "404": i158396662f32fe591e8faa247af18558546841dba91f24f5c824e11e34188830.CreateBasicErrorFromDiscriminatorValue,
    }
    res, err := m.BaseRequestBuilder.RequestAdapter.SendCollection(ctx, requestInfo, i158396662f32fe591e8faa247af18558546841dba91f24f5c824e11e34188830.CreateKeySimpleFromDiscriminatorValue, errorMapping)
    if err != nil {
        return nil, err
    }
    val := make([]i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.DateOnly, len(res))
     for i, v := range res {
         if v != nil {
             val[i] = *(v.(*i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.DateOnly))
         }
    return val, nil
}
```

the cast `al[i] = *(v.(*i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.DateOnly))` will not compile, as Go complains that `*serialization.DateOnly does not implement serialization.Parsable (missing method GetFieldDeserializers)`. 

As noted in the code block, the docs endpoint for that request is [here](https://docs.github.com/en/rest/meta/meta?apiVersion=2022-11-28#get-all-api-versions) and our OpenAPI schema for it looks like:

```json
"/versions": {
      "get": {
        "summary": "Get all API versions",
        "description": "Get all supported GitHub API versions.",
        "tags": [
          "meta"
        ],
        "operationId": "meta/get-all-versions",
        "externalDocs": {
          "description": "API method documentation",
          "url": "https://docs.github.com/rest/meta/meta#get-all-api-versions"
        },
        "responses": {
          "200": {
            "description": "Response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "format": "date",
                    "example": "2021-01-01"
                  }
                },
                "examples": {
                  "default": {
                    "value": [
                      "2021-01-01",
                      "2021-06-01",
                      "2022-01-01"
                    ]
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/not_found"
          }
        },
        "x-github": {
          "githubCloudOnly": false,
          "enabledForGitHubApps": true,
          "category": "meta",
          "subcategory": "meta"
        }
      }
    },
```

Please let me know if we need to make schema changes, if we can help out on the Kiota side at all, or if I can provide more information!

Pull request:
Fixes https://github.com/microsoft/kiota/issues/3679

Resolves a bug affecting genration of collection primitives in Go request executors. ReturnTypes were passed as a combination of the PointerSymbols, collection and package reference e.g `[]i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.DateOnly`, the fix resolves extraction of the data type by only considering the collection symbol and the actual data type

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9b8ec88e76..4c6883a75a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - Added support for AnyOf arrays. [#3786](https://github.com/microsoft/kiota/pull/3792)
 - Fixed a bug where property names that matched reserved type would be replaced in dotnet.
 - Fixed pass by value for `contentType` param in Go `requestInfo.SetStreamContentAndContentType`[#3830](https://github.com/microsoft/kiota/issues/3830)
+- Fixed parsing of `DateOnly` values generated in request executors [#3679](https://github.com/microsoft/kiota/issues/3679)
 
 ## [1.8.2] - 2023-11-08
 
diff --git a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs
index a8e55d6e50..3edc3cf575 100644
--- a/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs
+++ b/src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs
@@ -742,7 +742,7 @@ private void WriteRequestExecutorBody(CodeMethod codeElement, RequestParams requ
         var constructorFunction = returnType switch
         {
             _ when isVoid => string.Empty,
-            _ when isPrimitive => $"\"{returnType.TrimCollectionAndPointerSymbols()}\", ",
+            _ when isPrimitive => $"\"{returnType.TrimCollectionAndPointerSymbols().TrimPackageReference().ToLowerInvariant()}\", ",
             _ when isBinary => $"\"{returnType}\", ",
             _ when isEnum => $"{conventions.GetImportedStaticMethodName(codeElement.ReturnType, parentClass, "Parse", string.Empty, string.Empty)}, ",
             _ => $"{conventions.GetImportedStaticMethodName(codeElement.ReturnType, parentClass, "Create", "FromDiscriminatorValue", "able")}, ",
diff --git a/src/Kiota.Builder/Writers/Go/GoConventionService.cs b/src/Kiota.Builder/Writers/Go/GoConventionService.cs
index 2f76f5e831..559c0e5876 100644
--- a/src/Kiota.Builder/Writers/Go/GoConventionService.cs
+++ b/src/Kiota.Builder/Writers/Go/GoConventionService.cs
@@ -114,7 +114,7 @@ public string TranslateType(CodeTypeBase type, bool includeImportSymbol)
     }
     public bool IsPrimitiveType(string typeName)
     {
-        return typeName.TrimCollectionAndPointerSymbols() switch
+        return typeName.TrimCollectionAndPointerSymbols().TrimPackageReference() switch
         {
             "void" or "string" or "float" or "integer" or "long" or "double" or "boolean" or "Guid" or "DateTimeOffset"
             or "bool" or "int32" or "int64" or "float32" or "float64" or "UUID" or "Time" or "decimal" or "TimeOnly"
diff --git a/src/Kiota.Builder/Writers/Go/StringExtensions.cs b/src/Kiota.Builder/Writers/Go/StringExtensions.cs
index 812ff59057..d56a749cab 100644
--- a/src/Kiota.Builder/Writers/Go/StringExtensions.cs
+++ b/src/Kiota.Builder/Writers/Go/StringExtensions.cs
@@ -1,10 +1,14 @@
 ﻿using System;
+using System.Linq;
 
 namespace Kiota.Builder.Writers.Go;
 public static class StringExtensions
 {
     public static string TrimCollectionAndPointerSymbols(this string s) =>
-    string.IsNullOrEmpty(s) ? s : s.TrimStart('[').TrimStart(']').TrimStart('*');
+        string.IsNullOrEmpty(s) ? s : s.TrimStart('[').TrimStart(']').TrimStart('*');
+
+    public static string TrimPackageReference(this string s) =>
+        !string.IsNullOrEmpty(s) && s.Contains('.', StringComparison.InvariantCultureIgnoreCase) ? s.Split('.').Last() : s;
 
     public static string TrimSuffix(this string s, string suffix) =>
         !string.IsNullOrEmpty(s) && suffix != null && s.EndsWith(suffix, StringComparison.Ordinal) ? s[..^suffix.Length] : s;


Test patch:
diff --git a/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs
index 31a40e7a56..2e634f430f 100644
--- a/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs
+++ b/tests/Kiota.Builder.Tests/Writers/Go/CodeMethodWriterTests.cs
@@ -1301,6 +1301,44 @@ public void WritesRequestGeneratorBodyKnownRequestBodyType()
         AssertExtensions.CurlyBracesAreClosed(result);
     }
     [Fact]
+    public async Task WritesRequestExecutorForScalarTypes()
+    {
+        setup();
+        method.Kind = CodeMethodKind.RequestExecutor;
+        method.HttpMethod = HttpMethod.Get;
+        method.ReturnType = new CodeType
+        {
+            Name = "DateOnly",
+            IsExternal = true,
+            CollectionKind = CodeTypeBase.CodeTypeCollectionKind.Complex,
+        };
+        AddRequestBodyParameters(method, false);
+        AddRequestBodyParameters(useComplexTypeForBody: false);
+        AddRequestProperties();
+        method.AddParameter(new CodeParameter
+        {
+            Name = "ctx",
+            Kind = CodeParameterKind.Cancellation,
+            Type = new CodeType
+            {
+                Name = "context.Context",
+                IsExternal = true,
+                IsNullable = false,
+            },
+            Optional = false,
+        });
+
+        await ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.Go }, parentClass.Parent as CodeNamespace);
+        method.AcceptedResponseTypes.Add("application/json");
+        writer.Write(method);
+        var result = tw.ToString();
+        Assert.Contains($"func (m *ParentClass) MethodName(ctx context.Context, b []RequestOption, c *RequestConfig)([]i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.DateOnly, error)", result);
+        Assert.Contains("res, err := m.BaseRequestBuilder.RequestAdapter.SendPrimitiveCollection(ctx, requestInfo, \"dateonly\", nil)", result);
+        Assert.Contains($"val := make([]i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.DateOnly, len(res))", result);
+        Assert.Contains("return val, nil", result);
+        AssertExtensions.CurlyBracesAreClosed(result);
+    }
+    [Fact]
     public void WritesRequestGeneratorBodyUnknownRequestBodyType()
     {
         setup();