Skip to content

Commit

Permalink
fix: Fixed bug with AnyOf/OneOf in parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Jun 1, 2024
1 parent 2e6dc6b commit aa6a4e2
Show file tree
Hide file tree
Showing 37 changed files with 117 additions and 117 deletions.
2 changes: 1 addition & 1 deletion src/libs/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</ItemGroup>

<PropertyGroup Label="Versioning">
<Version>0.9.6</Version>
<Version>0.9.7</Version>
<MinVerMinimumMajorMinor>0.1</MinVerMinimumMajorMinor>
<MinVerTagPrefix>v</MinVerTagPrefix>
<MinVerDefaultPreReleaseIdentifiers>dev</MinVerDefaultPreReleaseIdentifiers>
Expand Down
8 changes: 4 additions & 4 deletions src/libs/OpenApiGenerator.Core/Models/TypeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public static string GetCSharpType(
var model = ModelData.FromSchema(schema, settings, parents);
var (type, reference) = (schema.Value.Type, schema.Value.Format) switch
{
(null, _) when schema.Value.AnyOf.Any() => ($"global::System.AnyOf<{string.Join(", ", schema.Value.AnyOf.Select(x => GetCSharpType(x.WithKey(schema.Key), settings, parents)))}>", false),
(null, _) when schema.Value.OneOf.Any() => ($"global::System.OneOf<{string.Join(", ", schema.Value.OneOf.Select(x => GetCSharpType(x.WithKey(schema.Key), settings, parents)))}>", false),
(null, _) when schema.Value.AllOf.Any() => ($"global::System.AllOf<{string.Join(", ", schema.Value.AllOf.Select(x => GetCSharpType(x.WithKey(schema.Key), settings, parents)))}>", false),

("object", _) or (null, _) when schema.Value.Reference != null =>
($"{ModelData.FromKey(schema.Value.Reference.Id, settings).ClassName}", true),
("object", _) when schema.Value.Reference == null &&
Expand All @@ -104,10 +108,6 @@ public static string GetCSharpType(
("object", _) when schema.Value.Reference == null =>
($"{model.ExternalClassName}", true),

(null, _) when schema.Value.AnyOf.Any() => ($"global::System.AnyOf<{string.Join(", ", schema.Value.AnyOf.Select(x => GetCSharpType(x.WithKey(schema.Key), settings, parents)))}>", false),
(null, _) when schema.Value.OneOf.Any() => ($"global::System.OneOf<{string.Join(", ", schema.Value.OneOf.Select(x => GetCSharpType(x.WithKey(schema.Key), settings, parents)))}>", false),
(null, _) when schema.Value.AllOf.Any() => ($"global::System.AllOf<{string.Join(", ", schema.Value.AllOf.Select(x => GetCSharpType(x.WithKey(schema.Key), settings, parents)))}>", false),

("string", _) when schema.Value.Enum.Any() =>
($"{(model with { Style = ModelStyle.Enumeration }).ExternalClassName}", true),
// ("string", _) when schema.Value.Enum.Any() && settings.JsonSerializerType != JsonSerializerType.NewtonsoftJson =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed partial class CreateModelResponse
/// Status creating the model
/// </summary>
[global::Newtonsoft.Json.JsonProperty("status")]
public CreateModelStatus? Status { get; set; }
public global::System.AnyOf<string?, CreateModelResponseStatus?> Status { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed partial class PullModelResponse
/// <br/>Example: pulling manifest
/// </summary>
[global::Newtonsoft.Json.JsonProperty("status")]
public PullModelStatus? Status { get; set; }
public global::System.AnyOf<string?, PullModelResponseStatus?> Status { get; set; }

/// <summary>
/// The model's digest.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed partial class PushModelResponse
/// Status pushing the model.
/// </summary>
[global::Newtonsoft.Json.JsonProperty("status")]
public PushModelStatus? Status { get; set; }
public global::System.AnyOf<string?, PushModelResponseStatus?> Status { get; set; }

/// <summary>
/// the model's digest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed partial class CreateModelResponse
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("status")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.AnyOfJsonConverterFactory2))]
public CreateModelStatus? Status { get; set; }
public global::System.AnyOf<string?, CreateModelResponseStatus?> Status { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed partial class PullModelResponse
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("status")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.AnyOfJsonConverterFactory2))]
public PullModelStatus? Status { get; set; }
public global::System.AnyOf<string?, PullModelResponseStatus?> Status { get; set; }

/// <summary>
/// The model's digest.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed partial class PushModelResponse
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("status")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.AnyOfJsonConverterFactory2))]
public PushModelStatus? Status { get; set; }
public global::System.AnyOf<string?, PushModelResponseStatus?> Status { get; set; }

/// <summary>
/// the model's digest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public sealed partial class JsonSerializerContextTypes
/// <summary>
///
/// </summary>
public CreateModelStatus? Type15 { get; set; }
public global::System.AnyOf<string?, CreateModelResponseStatus?>? Type15 { get; set; }
/// <summary>
///
/// </summary>
Expand All @@ -84,11 +84,11 @@ public sealed partial class JsonSerializerContextTypes
/// <summary>
///
/// </summary>
public PullModelStatus? Type18 { get; set; }
public global::System.AnyOf<string?, PullModelResponseStatus?>? Type18 { get; set; }
/// <summary>
///
/// </summary>
public PushModelStatus? Type19 { get; set; }
public global::System.AnyOf<string?, PushModelResponseStatus?>? Type19 { get; set; }
/// <summary>
///
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public partial class AssistantsClient
object? metadata = default,
double? temperature = 1,
double? topP = 1,
AssistantsApiResponseFormatOption? responseFormat = default,
global::System.OneOf<CreateAssistantRequestResponseFormat?, AssistantsApiResponseFormat?> responseFormat = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
var request = new CreateAssistantRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public partial class AssistantsClient
int? maxPromptTokens = default,
int? maxCompletionTokens = default,
TruncationObject? truncationStrategy = default,
AssistantsApiToolChoiceOption? toolChoice = default,
AssistantsApiResponseFormatOption? responseFormat = default,
global::System.OneOf<CreateRunRequestToolChoice?, AssistantsNamedToolChoice?> toolChoice = default,
global::System.OneOf<CreateRunRequestResponseFormat?, AssistantsApiResponseFormat?> responseFormat = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
var request = new CreateRunRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public partial class AssistantsClient
int? maxPromptTokens = default,
int? maxCompletionTokens = default,
TruncationObject? truncationStrategy = default,
AssistantsApiToolChoiceOption? toolChoice = default,
AssistantsApiResponseFormatOption? responseFormat = default,
global::System.OneOf<CreateThreadAndRunRequestToolChoice?, AssistantsNamedToolChoice?> toolChoice = default,
global::System.OneOf<CreateThreadAndRunRequestResponseFormat?, AssistantsApiResponseFormat?> responseFormat = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
var request = new CreateThreadAndRunRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public partial class AssistantsClient
object? metadata = default,
double? temperature = 1,
double? topP = 1,
AssistantsApiResponseFormatOption? responseFormat = default,
global::System.OneOf<ModifyAssistantRequestResponseFormat?, AssistantsApiResponseFormat?> responseFormat = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
var request = new ModifyAssistantRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public partial class ChatClient
double? temperature = 1,
double? topP = 1,
global::System.Collections.Generic.IList<ChatCompletionTool>? tools = default,
ChatCompletionToolChoiceOption? toolChoice = default,
global::System.OneOf<CreateChatCompletionRequestToolChoice?, ChatCompletionNamedToolChoice?> toolChoice = default,
string? user = default,
global::System.OneOf<CreateChatCompletionRequestFunctionCall?, ChatCompletionFunctionCallOption?> functionCall = default,
global::System.Collections.Generic.IList<ChatCompletionFunctions>? functions = default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public sealed partial class AssistantObject
/// **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length.
/// </summary>
[global::Newtonsoft.Json.JsonProperty("response_format")]
public AssistantsApiResponseFormatOption? ResponseFormat { get; set; }
public global::System.OneOf<AssistantObjectResponseFormat?, AssistantsApiResponseFormat?> ResponseFormat { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public sealed partial class CreateAssistantRequest
/// **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length.
/// </summary>
[global::Newtonsoft.Json.JsonProperty("response_format")]
public AssistantsApiResponseFormatOption? ResponseFormat { get; set; }
public global::System.OneOf<CreateAssistantRequestResponseFormat?, AssistantsApiResponseFormat?> ResponseFormat { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public sealed partial class CreateChatCompletionRequest
/// `none` is the default when no tools are present. `auto` is the default if tools are present.
/// </summary>
[global::Newtonsoft.Json.JsonProperty("tool_choice")]
public ChatCompletionToolChoiceOption? ToolChoice { get; set; }
public global::System.OneOf<CreateChatCompletionRequestToolChoice?, ChatCompletionNamedToolChoice?> ToolChoice { get; set; }

/// <summary>
/// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ public sealed partial class CreateRunRequest
/// Specifying a particular tool like `{"type": "file_search"}` or `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that tool.
/// </summary>
[global::Newtonsoft.Json.JsonProperty("tool_choice")]
public AssistantsApiToolChoiceOption? ToolChoice { get; set; }
public global::System.OneOf<CreateRunRequestToolChoice?, AssistantsNamedToolChoice?> ToolChoice { get; set; }

/// <summary>
/// Specifies the format that the model must output. Compatible with [GPT-4 Turbo](/docs/models/gpt-4-and-gpt-4-turbo) and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
/// Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is valid JSON.
/// **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length.
/// </summary>
[global::Newtonsoft.Json.JsonProperty("response_format")]
public AssistantsApiResponseFormatOption? ResponseFormat { get; set; }
public global::System.OneOf<CreateRunRequestResponseFormat?, AssistantsApiResponseFormat?> ResponseFormat { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ public sealed partial class CreateThreadAndRunRequest
/// Specifying a particular tool like `{"type": "file_search"}` or `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that tool.
/// </summary>
[global::Newtonsoft.Json.JsonProperty("tool_choice")]
public AssistantsApiToolChoiceOption? ToolChoice { get; set; }
public global::System.OneOf<CreateThreadAndRunRequestToolChoice?, AssistantsNamedToolChoice?> ToolChoice { get; set; }

/// <summary>
/// Specifies the format that the model must output. Compatible with [GPT-4 Turbo](/docs/models/gpt-4-and-gpt-4-turbo) and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
/// Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is valid JSON.
/// **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length.
/// </summary>
[global::Newtonsoft.Json.JsonProperty("response_format")]
public AssistantsApiResponseFormatOption? ResponseFormat { get; set; }
public global::System.OneOf<CreateThreadAndRunRequestResponseFormat?, AssistantsApiResponseFormat?> ResponseFormat { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public sealed partial class ModifyAssistantRequest
/// **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length.
/// </summary>
[global::Newtonsoft.Json.JsonProperty("response_format")]
public AssistantsApiResponseFormatOption? ResponseFormat { get; set; }
public global::System.OneOf<ModifyAssistantRequestResponseFormat?, AssistantsApiResponseFormat?> ResponseFormat { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ public sealed partial class RunObject
/// Specifying a particular tool like `{"type": "file_search"}` or `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that tool.
/// </summary>
[global::Newtonsoft.Json.JsonProperty("tool_choice", Required = global::Newtonsoft.Json.Required.Always)]
public AssistantsApiToolChoiceOption ToolChoice { get; set; } = default!;
public global::System.OneOf<RunObjectToolChoice, AssistantsNamedToolChoice> ToolChoice { get; set; } = default!;

/// <summary>
/// Specifies the format that the model must output. Compatible with [GPT-4 Turbo](/docs/models/gpt-4-and-gpt-4-turbo) and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
/// Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is valid JSON.
/// **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length.
/// </summary>
[global::Newtonsoft.Json.JsonProperty("response_format", Required = global::Newtonsoft.Json.Required.Always)]
public AssistantsApiResponseFormatOption ResponseFormat { get; set; } = default!;
public global::System.OneOf<RunObjectResponseFormat, AssistantsApiResponseFormat> ResponseFormat { get; set; } = default!;

/// <summary>
/// Additional properties that are not explicitly defined in the schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public partial class AssistantsClient
object? metadata = default,
double? temperature = 1,
double? topP = 1,
AssistantsApiResponseFormatOption? responseFormat = default,
global::System.OneOf<CreateAssistantRequestResponseFormat?, AssistantsApiResponseFormat?> responseFormat = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
var request = new CreateAssistantRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public partial class AssistantsClient
int? maxPromptTokens = default,
int? maxCompletionTokens = default,
TruncationObject? truncationStrategy = default,
AssistantsApiToolChoiceOption? toolChoice = default,
AssistantsApiResponseFormatOption? responseFormat = default,
global::System.OneOf<CreateRunRequestToolChoice?, AssistantsNamedToolChoice?> toolChoice = default,
global::System.OneOf<CreateRunRequestResponseFormat?, AssistantsApiResponseFormat?> responseFormat = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
var request = new CreateRunRequest
Expand Down
Loading

0 comments on commit aa6a4e2

Please sign in to comment.