Skip to content

Commit

Permalink
fix: Ignore OpenAPI errors
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Dec 19, 2024
1 parent 688c952 commit 7eff165
Show file tree
Hide file tree
Showing 40 changed files with 3,973 additions and 1,251 deletions.
45 changes: 18 additions & 27 deletions src/helpers/FixOpenApiSpec/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@
var text = await File.ReadAllTextAsync(path);
var realtimeText = await File.ReadAllTextAsync(path.Replace(".yaml", ".realtime.yaml"));

text = text.Replace("description: *run_temperature_description", "description: empty");
text = text.Replace("description: &run_temperature_description ", "description: ");

text = text.Replace("description: *run_top_p_description", "description: empty");
text = text.Replace("description: &run_top_p_description ", "description: ");

text = text.Replace("example: *moderation_example", "example: empty");
text = text.Replace("response: &moderation_example |", "response: |");

var openApiDocument = new OpenApiStringReader().Read(text, out var diagnostics);
var realtimeOpenApiDocument = new OpenApiStringReader().Read(realtimeText, out var realtimeDiagnostics);
foreach (var schema in realtimeOpenApiDocument.Components.Schemas)
Expand Down Expand Up @@ -53,23 +44,23 @@
Format = "binary",
}
});

openApiDocument.Components.Schemas["CreateChatCompletionRequest"]!.Properties["model"].AnyOf[1].Enum =
openApiDocument.Components.Schemas["CreateChatCompletionRequest"]!.Properties["model"].AnyOf[1].Enum
.DistinctBy(x => (x as OpenApiString)?.Value)
.ToList();
openApiDocument.Components.Schemas["CreateAssistantRequest"]!.Properties["model"].AnyOf[1].Enum =
openApiDocument.Components.Schemas["CreateAssistantRequest"]!.Properties["model"].AnyOf[1].Enum
.DistinctBy(x => (x as OpenApiString)?.Value)
.ToList();
openApiDocument.Components.Schemas["CreateRunRequest"]!.Properties["model"].AnyOf[1].Enum =
openApiDocument.Components.Schemas["CreateRunRequest"]!.Properties["model"].AnyOf[1].Enum
.DistinctBy(x => (x as OpenApiString)?.Value)
.ToList();
openApiDocument.Components.Schemas["CreateThreadAndRunRequest"]!.Properties["model"].AnyOf[1].Enum =
openApiDocument.Components.Schemas["CreateThreadAndRunRequest"]!.Properties["model"].AnyOf[1].Enum
.DistinctBy(x => (x as OpenApiString)?.Value)
.ToList();
//
// openApiDocument.Components.Schemas["CreateChatCompletionRequest"]!.Properties["model"].AnyOf[1].Enum =
// openApiDocument.Components.Schemas["CreateChatCompletionRequest"]!.Properties["model"].AnyOf[1].Enum
// .DistinctBy(x => (x as OpenApiString)?.Value)
// .ToList();
// openApiDocument.Components.Schemas["CreateAssistantRequest"]!.Properties["model"].AnyOf[1].Enum =
// openApiDocument.Components.Schemas["CreateAssistantRequest"]!.Properties["model"].AnyOf[1].Enum
// .DistinctBy(x => (x as OpenApiString)?.Value)
// .ToList();
// openApiDocument.Components.Schemas["CreateRunRequest"]!.Properties["model"].AnyOf[1].Enum =
// openApiDocument.Components.Schemas["CreateRunRequest"]!.Properties["model"].AnyOf[1].Enum
// .DistinctBy(x => (x as OpenApiString)?.Value)
// .ToList();
// openApiDocument.Components.Schemas["CreateThreadAndRunRequest"]!.Properties["model"].AnyOf[1].Enum =
// openApiDocument.Components.Schemas["CreateThreadAndRunRequest"]!.Properties["model"].AnyOf[1].Enum
// .DistinctBy(x => (x as OpenApiString)?.Value)
// .ToList();

text = openApiDocument.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
_ = new OpenApiStringReader().Read(text, out diagnostics);
Expand All @@ -81,7 +72,7 @@
Console.WriteLine(error.Message);
}
// Return Exit code 1
Environment.Exit(1);
//Environment.Exit(1);
}

await File.WriteAllTextAsync(path, text);
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#nullable enable

namespace OpenAI.JsonConverters
{
/// <inheritdoc />
public sealed class AdminApiKeysListOrderJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::OpenAI.AdminApiKeysListOrder>
{
/// <inheritdoc />
public override global::OpenAI.AdminApiKeysListOrder Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::OpenAI.AdminApiKeysListOrderExtensions.ToEnum(stringValue) ?? default;
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::OpenAI.AdminApiKeysListOrder)numValue;
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::OpenAI.AdminApiKeysListOrder value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

writer.WriteStringValue(global::OpenAI.AdminApiKeysListOrderExtensions.ToValueString(value));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#nullable enable

namespace OpenAI.JsonConverters
{
/// <inheritdoc />
public sealed class AdminApiKeysListOrderNullableJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::OpenAI.AdminApiKeysListOrder?>
{
/// <inheritdoc />
public override global::OpenAI.AdminApiKeysListOrder? Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::OpenAI.AdminApiKeysListOrderExtensions.ToEnum(stringValue);
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::OpenAI.AdminApiKeysListOrder)numValue;
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::OpenAI.AdminApiKeysListOrder? value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

if (value == null)
{
writer.WriteNullValue();
}
else
{
writer.WriteStringValue(global::OpenAI.AdminApiKeysListOrderExtensions.ToValueString(value.Value));
}
}
}
}
49 changes: 49 additions & 0 deletions src/libs/OpenAI/Generated/JsonConverters.InviteProjectRole.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#nullable enable

namespace OpenAI.JsonConverters
{
/// <inheritdoc />
public sealed class InviteProjectRoleJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::OpenAI.InviteProjectRole>
{
/// <inheritdoc />
public override global::OpenAI.InviteProjectRole Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::OpenAI.InviteProjectRoleExtensions.ToEnum(stringValue) ?? default;
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::OpenAI.InviteProjectRole)numValue;
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::OpenAI.InviteProjectRole value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

writer.WriteStringValue(global::OpenAI.InviteProjectRoleExtensions.ToValueString(value));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#nullable enable

namespace OpenAI.JsonConverters
{
/// <inheritdoc />
public sealed class InviteProjectRoleNullableJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::OpenAI.InviteProjectRole?>
{
/// <inheritdoc />
public override global::OpenAI.InviteProjectRole? Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::OpenAI.InviteProjectRoleExtensions.ToEnum(stringValue);
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::OpenAI.InviteProjectRole)numValue;
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::OpenAI.InviteProjectRole? value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

if (value == null)
{
writer.WriteNullValue();
}
else
{
writer.WriteStringValue(global::OpenAI.InviteProjectRoleExtensions.ToValueString(value.Value));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#nullable enable

namespace OpenAI.JsonConverters
{
/// <inheritdoc />
public sealed class InviteRequestProjectRoleJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::OpenAI.InviteRequestProjectRole>
{
/// <inheritdoc />
public override global::OpenAI.InviteRequestProjectRole Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::OpenAI.InviteRequestProjectRoleExtensions.ToEnum(stringValue) ?? default;
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::OpenAI.InviteRequestProjectRole)numValue;
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::OpenAI.InviteRequestProjectRole value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

writer.WriteStringValue(global::OpenAI.InviteRequestProjectRoleExtensions.ToValueString(value));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#nullable enable

namespace OpenAI.JsonConverters
{
/// <inheritdoc />
public sealed class InviteRequestProjectRoleNullableJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::OpenAI.InviteRequestProjectRole?>
{
/// <inheritdoc />
public override global::OpenAI.InviteRequestProjectRole? Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::OpenAI.InviteRequestProjectRoleExtensions.ToEnum(stringValue);
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::OpenAI.InviteRequestProjectRole)numValue;
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::OpenAI.InviteRequestProjectRole? value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

if (value == null)
{
writer.WriteNullValue();
}
else
{
writer.WriteStringValue(global::OpenAI.InviteRequestProjectRoleExtensions.ToValueString(value.Value));
}
}
}
}
Loading

0 comments on commit 7eff165

Please sign in to comment.