googleapis / google-api-dotnet-client

Google APIs Client Library for .NET
https://developers.google.com/api-client-library/dotnet
Apache License 2.0
1.36k stars 527 forks source link

Google.Apis.Admin.Directory.directory_v1.User have some propery poorly generated #2882

Closed allonzy closed 4 days ago

allonzy commented 4 days ago

Google.Apis.Admin.Directory.directory_v1.User have some properties generated as object, this is kinda hard to use it properly (set/get require newtonsoft object manipulation) Here, a list of the culprits

    public class User : Google.Apis.Requests.IDirectResponseSchema
    {
        /// <summary>The user's gender. The maximum allowed data size for this field is 1KB.</summary>
        [Newtonsoft.Json.JsonPropertyAttribute("gender")]
        public virtual object Gender { get; set; }
        /// <summary>The list of the user's keywords. The maximum allowed data size for this field is 1KB.</summary>
        [Newtonsoft.Json.JsonPropertyAttribute("keywords")]
        public virtual object Keywords { get; set; }

         /// <summary>The user's languages. The maximum allowed data size for this field is 1KB.</summary>
        [Newtonsoft.Json.JsonPropertyAttribute("languages")]
        public virtual object Languages { get; set; }

       /// <summary>The user's locations. The maximum allowed data size for this field is 10KB.</summary>
        [Newtonsoft.Json.JsonPropertyAttribute("locations")]
        public virtual object Locations { get; set; }

        /// <summary>Notes for the user.</summary>
        [Newtonsoft.Json.JsonPropertyAttribute("notes")]
        public virtual object Notes { get; set; }

         /// <summary>
        /// The list of [POSIX](https://www.opengroup.org/austin/papers/posix_faq.html) account information for the
        /// user.
        /// </summary>
        [Newtonsoft.Json.JsonPropertyAttribute("posixAccounts")]
        public virtual object PosixAccounts { get; set; }
}

I don't fully grasp how this code is generated, and why this result to this :/

jskeet commented 4 days ago

The API definition originates from https://github.com/googleapis/google-api-dotnet-client/blob/main/DiscoveryJson/admin.directory_v1.json

It looks like the properties in question are being generated from Discovery doc properties with a type of "any" - which really does just mean "any object" effectively. We could have potentially chosen to use JObject instead of object - but changing that now would be a breaking change, and wouldn't stop anyone from having to interact with Json.NET, it would just make it slightly clearly that they did have to do that.

allonzy commented 4 days ago

Maybe this json should be updated, because: The types exists in the sdk (userGender for instance) the type for addresses is correctly bind and in the REST api reference of all those field are well documented.

jskeet commented 4 days ago

The JSON is effectively derived straight from the service itself - see https://admin.googleapis.com/$discovery/rest?version=directory_v1 where you'll see that gender has a type of any. (And yes, it describes the UserGender type, but doesn't use it anywhere.)

I'm afraid there's nothing that the maintainers of this repository (just one of the consumers of the Discovery document) can do on this front. I'll ask internally, but the .NET generator is working as intended.

allonzy commented 4 days ago

Ah, too bad :/ Thanks for the reactivity, hoping the team in charge of this ressource will update the $ref

amanda-tarafa commented 4 days ago

Closing the loop, I've created an internal issue for the API team to look into this. Googlers see: b/379708974