Skip to content

Commit

Permalink
fix: Fixed OpenAPI 3.1 examples support in json.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Oct 11, 2024
1 parent 35a2c6d commit 35ae324
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 146 deletions.
171 changes: 87 additions & 84 deletions src/libs/AutoSDK/Helpers/OpenApi31Support.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,94 +74,97 @@ private static void ConvertJsonNode(JsonObject node)
}

string keyString = entry.Key;
// if (keyString == "anyOf" &&
// entry.Value is JsonArray anyOfList && anyOfList.Count == 2 &&
// anyOfList.Any(v =>
// v is JsonObject objects &&
// objects.ContainsKey("type") &&
// objects["type"] == null))
// {
// var first = anyOfList[0] as JsonObject;
// var second = anyOfList[1] as JsonObject;
// var firstType = first?["type"];
// var secondType = second?["type"];
//
// if (firstType == null || secondType == null)
// {
// // Replace "anyOf" with "type: string, nullable: true"
// node["type"] = firstType?.ToString() ?? secondType?.ToString();
// node["nullable"] = true;
//
// var nonNullObject = firstType != null ? first : second;
// foreach (var kvp in nonNullObject)
// {
// node[kvp.Key] = kvp.Value;
// }
//
// node.Remove(keyString);
// }
// }
if (keyString == "openapi")
{
node["openapi"] = "3.0.3";
}
// if (keyString == "exclusiveMinimum" && entry.Value is not JsonValue)
// {
// node["minimum"] = entry.Value;
// node["exclusiveMinimum"] = true;
// }
// if (keyString == "exclusiveMaximum" && entry.Value is not JsonValue)
// {
// node["maximum"] = entry.Value;
// node["exclusiveMaximum"] = true;
// }
//
// // Identify "type" that is a list containing "string" and "null"
// if (keyString == "type" &&
// entry.Value is JsonArray typeList &&
// typeList.Contains(null))
// {
// // Replace "type" with "string" and add "nullable: true"
// node["type"] = typeList.First(v => v != null).ToString();
// node["nullable"] = true;
//
// // If there's an "enum", remove the "null" from its values
// if (node.TryGetPropertyValue("enum", out var enumValue) && enumValue is JsonArray enumList)
// {
// node["enum"] = new JsonArray(enumList.Where(v => v != null).ToArray());
// }
// }
//
// // Replace "examples" with single "example"
// if (keyString == "examples" && entry.Value is JsonArray { Count: > 0 } examplesList)
// {
// node.Remove(keyString);
// node["example"] = examplesList[0];
// }
//
// // Fix "example" node when "items" is missing and "example" is a list
// if (keyString == "example" && entry.Value is JsonArray { Count: > 0 } exampleList && !node.ContainsKey("items"))
// {
// node["example"] = exampleList[0];
// }
//
// // Identify "const" node for removal and convert to "enum" if "enum" is missing
// if (keyString == "const")
// {
// if (!node.ContainsKey("enum"))
// {
// node["enum"] = new JsonArray(entry.Value);
// }
// node.Remove(keyString);
// }
//
// // Fix "items" node when "$ref" is present and "items" is a list
// if (keyString == "items" && entry.Value is JsonArray itemsNode &&
// itemsNode.ElementAtOrDefault(0) is JsonObject itemsValue &&
// itemsValue.ElementAtOrDefault(0).Key == "$ref")
// {
// node["items"] = itemsValue;
// }

if (keyString == "anyOf" &&
entry.Value is JsonArray anyOfList && anyOfList.Count == 2 &&
anyOfList.Any(v =>
v is JsonObject objects &&
objects.ContainsKey("type") &&
objects["type"] == null))
{
var first = anyOfList[0] as JsonObject;
var second = anyOfList[1] as JsonObject;
var firstType = first?["type"];
var secondType = second?["type"];

if (firstType == null || secondType == null)
{
// Replace "anyOf" with "type: string, nullable: true"
node["type"] = firstType?.ToString() ?? secondType?.ToString();
node["nullable"] = true;

var nonNullObject = firstType != null ? first : second;
foreach (var kvp in nonNullObject!)
{
node[kvp.Key] = kvp.Value;
}

node.Remove(keyString);
}
}

if (keyString == "exclusiveMinimum" && entry.Value is not JsonValue)
{
node["minimum"] = entry.Value;
node["exclusiveMinimum"] = true;
}

if (keyString == "exclusiveMaximum" && entry.Value is not JsonValue)
{
node["maximum"] = entry.Value;
node["exclusiveMaximum"] = true;
}

// Identify "type" that is a list containing "string" and "null"
if (keyString == "type" &&
entry.Value is JsonArray typeList &&
typeList.Contains(null))
{
// Replace "type" with "string" and add "nullable: true"
node["type"] = typeList.First(v => v != null)?.ToString();
node["nullable"] = true;

// If there's an "enum", remove the "null" from its values
if (node.TryGetPropertyValue("enum", out var enumValue) && enumValue is JsonArray enumList)
{
node["enum"] = new JsonArray(enumList.Where(v => v != null).ToArray());
}
}

// Replace "examples" with single "example"
if (keyString == "examples" && entry.Value is JsonArray { Count: > 0 } examplesList)
{
node.Remove(keyString);
node["example"] = examplesList[0]?.DeepClone();
}

// Fix "example" node when "items" is missing and "example" is a list
if (keyString == "example" && entry.Value is JsonArray { Count: > 0 } exampleList && !node.ContainsKey("items"))
{
node["example"] = exampleList[0]?.DeepClone();
}

// Identify "const" node for removal and convert to "enum" if "enum" is missing
if (keyString == "const")
{
if (!node.ContainsKey("enum"))
{
node["enum"] = new JsonArray(entry.Value);
}
node.Remove(keyString);
}

// Fix "items" node when "$ref" is present and "items" is a list
if (keyString == "items" && entry.Value is JsonArray itemsNode &&
itemsNode.ElementAtOrDefault(0) is JsonObject itemsValue &&
itemsValue.ElementAtOrDefault(0).Key == "$ref")
{
node["items"] = itemsValue.DeepClone();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ public partial interface IVoiceGenerationClient
/// Your API key. This is required by most endpoints to access our API programatically. You can view your xi-api-key using the 'Profile' tab on the website.
/// </param>
/// <param name="voiceName">
/// Name to use for the created voice.
/// Name to use for the created voice.<br/>
/// Example: Little squeaky mouse
/// </param>
/// <param name="voiceDescription">
/// Description to use for the created voice.
/// Description to use for the created voice.<br/>
/// Example: A sassy little squeaky mouse
/// </param>
/// <param name="generatedVoiceId">
/// The generated_voice_id to create, call POST /v1/voice-generation/generate-voice and fetch the generated_voice_id from the response header if don't have one yet.
/// The generated_voice_id to create, call POST /v1/voice-generation/generate-voice and fetch the generated_voice_id from the response header if don't have one yet.<br/>
/// Example: 37HceQefKmEi3bGovXjL
/// </param>
/// <param name="playedNotSelectedVoiceIds">
/// List of voice ids that the user has played but not selected. Used for RLHF.<br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public partial interface IVoiceGenerationClient
/// The strength of the accent of the generated voice. Has to be between 0.3 and 2.0.
/// </param>
/// <param name="text">
/// Text to generate, text length has to be between 100 and 1000.
/// Text to generate, text length has to be between 100 and 1000.<br/>
/// Example: Every act of kindness, no matter how small, carries value and can make a difference, as no gesture of goodwill is ever wasted.
/// </param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ namespace G
public sealed partial class BodyCreateAPreviouslyGeneratedVoiceV1VoiceGenerationCreateVoicePost
{
/// <summary>
/// Name to use for the created voice.
/// Name to use for the created voice.<br/>
/// Example: Little squeaky mouse
/// </summary>
[global::Newtonsoft.Json.JsonProperty("voice_name", Required = global::Newtonsoft.Json.Required.Always)]
public string VoiceName { get; set; } = default!;

/// <summary>
/// Description to use for the created voice.
/// Description to use for the created voice.<br/>
/// Example: A sassy little squeaky mouse
/// </summary>
[global::Newtonsoft.Json.JsonProperty("voice_description", Required = global::Newtonsoft.Json.Required.Always)]
public string VoiceDescription { get; set; } = default!;

/// <summary>
/// The generated_voice_id to create, call POST /v1/voice-generation/generate-voice and fetch the generated_voice_id from the response header if don't have one yet.
/// The generated_voice_id to create, call POST /v1/voice-generation/generate-voice and fetch the generated_voice_id from the response header if don't have one yet.<br/>
/// Example: 37HceQefKmEi3bGovXjL
/// </summary>
[global::Newtonsoft.Json.JsonProperty("generated_voice_id", Required = global::Newtonsoft.Json.Required.Always)]
public string GeneratedVoiceId { get; set; } = default!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public sealed partial class BodyGenerateARandomVoiceV1VoiceGenerationGenerateVoi
public double AccentStrength { get; set; } = default!;

/// <summary>
/// Text to generate, text length has to be between 100 and 1000.
/// Text to generate, text length has to be between 100 and 1000.<br/>
/// Example: Every act of kindness, no matter how small, carries value and can make a difference, as no gesture of goodwill is ever wasted.
/// </summary>
[global::Newtonsoft.Json.JsonProperty("text", Required = global::Newtonsoft.Json.Required.Always)]
public string Text { get; set; } = default!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,16 @@ partial void ProcessCreateAPreviouslyGeneratedVoiceV1VoiceGenerationCreateVoiceP
/// Your API key. This is required by most endpoints to access our API programatically. You can view your xi-api-key using the 'Profile' tab on the website.
/// </param>
/// <param name="voiceName">
/// Name to use for the created voice.
/// Name to use for the created voice.<br/>
/// Example: Little squeaky mouse
/// </param>
/// <param name="voiceDescription">
/// Description to use for the created voice.
/// Description to use for the created voice.<br/>
/// Example: A sassy little squeaky mouse
/// </param>
/// <param name="generatedVoiceId">
/// The generated_voice_id to create, call POST /v1/voice-generation/generate-voice and fetch the generated_voice_id from the response header if don't have one yet.
/// The generated_voice_id to create, call POST /v1/voice-generation/generate-voice and fetch the generated_voice_id from the response header if don't have one yet.<br/>
/// Example: 37HceQefKmEi3bGovXjL
/// </param>
/// <param name="playedNotSelectedVoiceIds">
/// List of voice ids that the user has played but not selected. Used for RLHF.<br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ partial void ProcessGenerateARandomVoiceV1VoiceGenerationGenerateVoicePostRespon
/// The strength of the accent of the generated voice. Has to be between 0.3 and 2.0.
/// </param>
/// <param name="text">
/// Text to generate, text length has to be between 100 and 1000.
/// Text to generate, text length has to be between 100 and 1000.<br/>
/// Example: Every act of kindness, no matter how small, carries value and can make a difference, as no gesture of goodwill is ever wasted.
/// </param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ public partial interface IVoiceGenerationClient
/// Your API key. This is required by most endpoints to access our API programatically. You can view your xi-api-key using the 'Profile' tab on the website.
/// </param>
/// <param name="voiceName">
/// Name to use for the created voice.
/// Name to use for the created voice.<br/>
/// Example: Little squeaky mouse
/// </param>
/// <param name="voiceDescription">
/// Description to use for the created voice.
/// Description to use for the created voice.<br/>
/// Example: A sassy little squeaky mouse
/// </param>
/// <param name="generatedVoiceId">
/// The generated_voice_id to create, call POST /v1/voice-generation/generate-voice and fetch the generated_voice_id from the response header if don't have one yet.
/// The generated_voice_id to create, call POST /v1/voice-generation/generate-voice and fetch the generated_voice_id from the response header if don't have one yet.<br/>
/// Example: 37HceQefKmEi3bGovXjL
/// </param>
/// <param name="playedNotSelectedVoiceIds">
/// List of voice ids that the user has played but not selected. Used for RLHF.<br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public partial interface IVoiceGenerationClient
/// The strength of the accent of the generated voice. Has to be between 0.3 and 2.0.
/// </param>
/// <param name="text">
/// Text to generate, text length has to be between 100 and 1000.
/// Text to generate, text length has to be between 100 and 1000.<br/>
/// Example: Every act of kindness, no matter how small, carries value and can make a difference, as no gesture of goodwill is ever wasted.
/// </param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ namespace G
public sealed partial class BodyCreateAPreviouslyGeneratedVoiceV1VoiceGenerationCreateVoicePost
{
/// <summary>
/// Name to use for the created voice.
/// Name to use for the created voice.<br/>
/// Example: Little squeaky mouse
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("voice_name")]
[global::System.Text.Json.Serialization.JsonRequired]
public required string VoiceName { get; set; }

/// <summary>
/// Description to use for the created voice.
/// Description to use for the created voice.<br/>
/// Example: A sassy little squeaky mouse
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("voice_description")]
[global::System.Text.Json.Serialization.JsonRequired]
public required string VoiceDescription { get; set; }

/// <summary>
/// The generated_voice_id to create, call POST /v1/voice-generation/generate-voice and fetch the generated_voice_id from the response header if don't have one yet.
/// The generated_voice_id to create, call POST /v1/voice-generation/generate-voice and fetch the generated_voice_id from the response header if don't have one yet.<br/>
/// Example: 37HceQefKmEi3bGovXjL
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("generated_voice_id")]
[global::System.Text.Json.Serialization.JsonRequired]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public sealed partial class BodyGenerateARandomVoiceV1VoiceGenerationGenerateVoi
public required double AccentStrength { get; set; }

/// <summary>
/// Text to generate, text length has to be between 100 and 1000.
/// Text to generate, text length has to be between 100 and 1000.<br/>
/// Example: Every act of kindness, no matter how small, carries value and can make a difference, as no gesture of goodwill is ever wasted.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("text")]
[global::System.Text.Json.Serialization.JsonRequired]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,16 @@ partial void ProcessCreateAPreviouslyGeneratedVoiceV1VoiceGenerationCreateVoiceP
/// Your API key. This is required by most endpoints to access our API programatically. You can view your xi-api-key using the 'Profile' tab on the website.
/// </param>
/// <param name="voiceName">
/// Name to use for the created voice.
/// Name to use for the created voice.<br/>
/// Example: Little squeaky mouse
/// </param>
/// <param name="voiceDescription">
/// Description to use for the created voice.
/// Description to use for the created voice.<br/>
/// Example: A sassy little squeaky mouse
/// </param>
/// <param name="generatedVoiceId">
/// The generated_voice_id to create, call POST /v1/voice-generation/generate-voice and fetch the generated_voice_id from the response header if don't have one yet.
/// The generated_voice_id to create, call POST /v1/voice-generation/generate-voice and fetch the generated_voice_id from the response header if don't have one yet.<br/>
/// Example: 37HceQefKmEi3bGovXjL
/// </param>
/// <param name="playedNotSelectedVoiceIds">
/// List of voice ids that the user has played but not selected. Used for RLHF.<br/>
Expand Down
Loading

0 comments on commit 35ae324

Please sign in to comment.