Repository: microsoft/semantic-kernel
File: dotnet/src/Connectors/Connectors.Google/Core/Gemini/Models/GeminiRequest.cs (C#)

Code before:
    /// <remarks>
    /// This method recursively processes all nested objects in the schema. For each property that has a type array
    /// containing "null", it:
    /// - Extracts the main type (non-null value)
    /// - Replaces the type array with a single type value
    /// - Adds "nullable": true as a property
    /// </remarks>
    private static JsonElement AdjustOpenApi3Nullables(JsonElement jsonElement)
    {
        JsonNode? node = JsonNode.Parse(jsonElement.GetRawText());
        if (node is JsonObject rootObject)
        {
            AdjustOpenApi3Object(rootObject);
        }

        return JsonSerializer.SerializeToElement(node, GetDefaultOptions());

        static void AdjustOpenApi3Object(JsonObject obj)
        {
            if (obj.TryGetPropertyValue("properties", out JsonNode? propsNode) && propsNode is JsonObject properties)
            {
                foreach (var property in properties)
                {
                    if (property.Value is JsonObject propertyObj)
                    {
                        // Handle enum properties - add "type": "string" if missing
                        if (propertyObj.TryGetPropertyValue("enum", out JsonNode? enumNode) && !propertyObj.ContainsKey("type"))
                        {
                            propertyObj["type"] = JsonValue.Create("string");
                        }
                        else if (propertyObj.TryGetPropertyValue("type", out JsonNode? typeNode))
                        {
                            if (typeNode is JsonArray typeArray)
                            {
                                var types = typeArray.Select(t => t?.GetValue<string>()).Where(t => t != null).ToList();
                                if (types.Contains("null"))
                                {
                                    var mainType = types.First(t => t != "null");
                                    propertyObj["type"] = JsonValue.Create(mainType);
                                    propertyObj["nullable"] = JsonValue.Create(true);
                                }
                            }
                            else if (typeNode is JsonValue typeValue && typeValue.GetValue<string>() == "array")
                            {
                                if (propertyObj.TryGetPropertyValue("items", out JsonNode? itemsNode) && itemsNode is JsonObject itemsObj)
                                {
                                    AdjustOpenApi3Object(itemsObj);
                                }
                            }
                        }


Review comment (suggestion):
The `AdjustOpenApi3Nullables` method does more than just adjusting nullables. I would suggest renaming it to something like this - "TransformToOpenApi3Schema".

Code after:
    /// <remarks>
    /// This method recursively processes all nested objects in the schema. For each property that has a type array
    /// containing "null", it:
    /// - Extracts the main type (non-null value)
    /// - Replaces the type array with a single type value
    /// - Adds "nullable": true as a property
    /// </remarks>
    private static JsonElement TransformToOpenApi3Schema(JsonElement jsonElement)
    {
        JsonNode? node = JsonNode.Parse(jsonElement.GetRawText());
        if (node is JsonObject rootObject)
        {
            TransformOpenApi3Object(rootObject);
        }

        return JsonSerializer.SerializeToElement(node, GetDefaultOptions());

        static void TransformOpenApi3Object(JsonObject obj)
        {
            if (obj.TryGetPropertyValue("properties", out JsonNode? propsNode) && propsNode is JsonObject properties)
            {
                foreach (var property in properties)
                {
                    if (property.Value is JsonObject propertyObj)
                    {
                        // Handle enum properties - add "type": "string" if missing
                        if (propertyObj.TryGetPropertyValue("enum", out JsonNode? enumNode) && !propertyObj.ContainsKey("type"))
                        {
                            propertyObj["type"] = JsonValue.Create("string");
                        }
                        else if (propertyObj.TryGetPropertyValue("type", out JsonNode? typeNode))
                        {
                            if (typeNode is JsonArray typeArray)
                            {
                                var types = typeArray.Select(t => t?.GetValue<string>()).Where(t => t != null).ToList();
                                if (types.Contains("null"))
                                {
                                    var mainType = types.First(t => t != "null");
                                    propertyObj["type"] = JsonValue.Create(mainType);
                                    propertyObj["nullable"] = JsonValue.Create(true);
                                }
                            }
                            else if (typeNode is JsonValue typeValue && typeValue.GetValue<string>() == "array")
                            {
                                if (propertyObj.TryGetPropertyValue("items", out JsonNode? itemsNode) && itemsNode is JsonObject itemsObj)
                                {
                                    TransformOpenApi3Object(itemsObj);
                                }
                            }
                        }