octokit / dotnet-sdk

MIT License
52 stars 8 forks source link

[BUG]: Users[].GetAsync() does not return correct data #87

Open martincostello opened 1 month ago

martincostello commented 1 month ago

What happened?

Using the GitHubClient.Users[].GetAsync() returns a value with a null value for the PublicUser and PrivateUser properties.

The generated code to call /users/{login} appears to not be expecting the correct payload:

public static WithUsernameGetResponse CreateFromDiscriminatorValue(IParseNode parseNode)
{
    if (parseNode == null)
    {
        throw new ArgumentNullException("parseNode");
    }

    string value = parseNode.GetChildNode("")?.GetStringValue();
    WithUsernameGetResponse withUsernameGetResponse = new WithUsernameGetResponse();
    if ("private-user".Equals(value, StringComparison.OrdinalIgnoreCase))
    {
        withUsernameGetResponse.PrivateUser = new PrivateUser();
    }
    else if ("public-user".Equals(value, StringComparison.OrdinalIgnoreCase))
    {
        withUsernameGetResponse.PublicUser = new PublicUser();
    }

    return withUsernameGetResponse;
}

I would expect it to just return the user as-is:

{
  "login": "martincostello",
  "id": 1439341,
  "node_id": "MDQ6VXNlcjE0MzkzNDE=",
  "avatar_url": "https://avatars.githubusercontent.com/u/1439341?v=4",
  "gravatar_id": "",
  "url": "https://api.github.com/users/martincostello",
  "html_url": "https://github.com/martincostello",
  "followers_url": "https://api.github.com/users/martincostello/followers",
  "following_url": "https://api.github.com/users/martincostello/following{/other_user}",
  "gists_url": "https://api.github.com/users/martincostello/gists{/gist_id}",
  "starred_url": "https://api.github.com/users/martincostello/starred{/owner}{/repo}",
  "subscriptions_url": "https://api.github.com/users/martincostello/subscriptions",
  "organizations_url": "https://api.github.com/users/martincostello/orgs",
  "repos_url": "https://api.github.com/users/martincostello/repos",
  "events_url": "https://api.github.com/users/martincostello/events{/privacy}",
  "received_events_url": "https://api.github.com/users/martincostello/received_events",
  "type": "User",
  "site_admin": false,
  "name": "Martin Costello",
  "company": "@justeattakeaway",
  "blog": "https://martincostello.com",
  "location": "London, UK",
  "email": null,
  "hireable": null,
  "bio": ".NET developer, tester and Microsoft MVP based in London working for Just Eat Takeaway.com",
  "twitter_username": "martin_costello",
  "public_repos": 163,
  "public_gists": 13,
  "followers": 504,
  "following": 20,
  "created_at": "2012-02-15T09:43:20Z",
  "updated_at": "2024-06-08T18:05:14Z"
}

Versions

0.0.16

Code of Conduct

github-actions[bot] commented 1 month ago

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

kfcampbell commented 1 month ago

Ooh, interesting find. I've confirmed this, and when you remove the if ("private-user".Equals(value, StringComparison.OrdinalIgnoreCase)) logic, the response gets populated exactly as you'd expect.

I'm going to file an issue with Kiota for this.

kfcampbell commented 1 month ago

Reported upstream at https://github.com/microsoft/kiota/issues/4844!

martincostello commented 2 days ago

The upstream issue seems to have been closed due to a lack of activity. Looks like they say the OpenAPI schema is wrong as it doesn't have a discriminator?