Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Introduce UnixTimestampJsonConverter for DateTimeOffset handling #73

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/libs/OpenAI/Generated/JsonConverters.UnixTimestamp.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#nullable enable

namespace OpenApiGenerator.JsonConverters
{
/// <inheritdoc />
public class UnixTimestampJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::System.DateTimeOffset>
{
/// <inheritdoc />
public override global::System.DateTimeOffset Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
if (reader.TokenType == global::System.Text.Json.JsonTokenType.Number)
{
if (reader.TryGetInt64(out long unixTimestamp))
{
return global::System.DateTimeOffset.FromUnixTimeSeconds(unixTimestamp);
}
if (reader.TryGetInt32(out int unixTimestampInt))
{
return global::System.DateTimeOffset.FromUnixTimeSeconds(unixTimestampInt);
}
}

return default;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::System.DateTimeOffset value,
global::System.Text.Json.JsonSerializerOptions options)
{
long unixTimestamp = value.ToUnixTimeSeconds();
writer.WriteNumberValue(unixTimestamp);
}
}
}
1,524 changes: 764 additions & 760 deletions src/libs/OpenAI/Generated/JsonSerializerContextTypes.g.cs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/libs/OpenAI/Generated/OpenAI.Models.AssistantObject.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ public sealed partial class AssistantObject
/// The Unix timestamp (in seconds) for when the assistant was created.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("created_at")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int CreatedAt { get; set; }
public required global::System.DateTimeOffset CreatedAt { get; set; }

/// <summary>
/// The name of the assistant. The maximum length is 256 characters.
Expand Down
3 changes: 2 additions & 1 deletion src/libs/OpenAI/Generated/OpenAI.Models.AuditLog.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public sealed partial class AuditLog
/// The Unix timestamp (in seconds) of the event.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("effective_at")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int EffectiveAt { get; set; }
public required global::System.DateTimeOffset EffectiveAt { get; set; }

/// <summary>
/// The project that the action was scoped to. Absent for actions not scoped to projects.
Expand Down
27 changes: 18 additions & 9 deletions src/libs/OpenAI/Generated/OpenAI.Models.Batch.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,56 +73,65 @@ public sealed partial class Batch
/// The Unix timestamp (in seconds) for when the batch was created.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("created_at")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int CreatedAt { get; set; }
public required global::System.DateTimeOffset CreatedAt { get; set; }

/// <summary>
/// The Unix timestamp (in seconds) for when the batch started processing.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("in_progress_at")]
public int InProgressAt { get; set; }
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
public global::System.DateTimeOffset InProgressAt { get; set; }

/// <summary>
/// The Unix timestamp (in seconds) for when the batch will expire.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("expires_at")]
public int ExpiresAt { get; set; }
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
public global::System.DateTimeOffset ExpiresAt { get; set; }

/// <summary>
/// The Unix timestamp (in seconds) for when the batch started finalizing.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("finalizing_at")]
public int FinalizingAt { get; set; }
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
public global::System.DateTimeOffset FinalizingAt { get; set; }

/// <summary>
/// The Unix timestamp (in seconds) for when the batch was completed.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("completed_at")]
public int CompletedAt { get; set; }
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
public global::System.DateTimeOffset CompletedAt { get; set; }

/// <summary>
/// The Unix timestamp (in seconds) for when the batch failed.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("failed_at")]
public int FailedAt { get; set; }
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
public global::System.DateTimeOffset FailedAt { get; set; }

/// <summary>
/// The Unix timestamp (in seconds) for when the batch expired.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("expired_at")]
public int ExpiredAt { get; set; }
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
public global::System.DateTimeOffset ExpiredAt { get; set; }

/// <summary>
/// The Unix timestamp (in seconds) for when the batch started cancelling.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("cancelling_at")]
public int CancellingAt { get; set; }
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
public global::System.DateTimeOffset CancellingAt { get; set; }

/// <summary>
/// The Unix timestamp (in seconds) for when the batch was cancelled.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("cancelled_at")]
public int CancelledAt { get; set; }
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
public global::System.DateTimeOffset CancelledAt { get; set; }

/// <summary>
/// The request counts for different statuses within the batch.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public sealed partial class CreateChatCompletionFunctionResponse
/// The Unix timestamp (in seconds) of when the chat completion was created.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("created")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int Created { get; set; }
public required global::System.DateTimeOffset Created { get; set; }

/// <summary>
/// The model used for the chat completion.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public sealed partial class CreateChatCompletionResponse
/// The Unix timestamp (in seconds) of when the chat completion was created.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("created")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int Created { get; set; }
public required global::System.DateTimeOffset Created { get; set; }

/// <summary>
/// The model used for the chat completion.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public sealed partial class CreateChatCompletionStreamResponse
/// The Unix timestamp (in seconds) of when the chat completion was created. Each chunk has the same timestamp.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("created")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int Created { get; set; }
public required global::System.DateTimeOffset Created { get; set; }

/// <summary>
/// The model to generate the completion.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public sealed partial class CreateCompletionResponse
/// The Unix timestamp (in seconds) of when the completion was created.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("created")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int Created { get; set; }
public required global::System.DateTimeOffset Created { get; set; }

/// <summary>
/// The model used for completion.
Expand Down
9 changes: 6 additions & 3 deletions src/libs/OpenAI/Generated/OpenAI.Models.FineTuningJob.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ public sealed partial class FineTuningJob
/// The Unix timestamp (in seconds) for when the fine-tuning job was created.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("created_at")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int CreatedAt { get; set; }
public required global::System.DateTimeOffset CreatedAt { get; set; }

/// <summary>
/// For fine-tuning jobs that have `failed`, this will contain more information on the cause of the failure.
Expand All @@ -42,8 +43,9 @@ public sealed partial class FineTuningJob
/// The Unix timestamp (in seconds) for when the fine-tuning job was finished. The value will be null if the fine-tuning job is still running.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("finished_at")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int? FinishedAt { get; set; }
public required global::System.DateTimeOffset? FinishedAt { get; set; }

/// <summary>
/// The hyperparameters used for the fine-tuning job. See the [fine-tuning guide](/docs/guides/fine-tuning) for more details.
Expand Down Expand Up @@ -126,7 +128,8 @@ public sealed partial class FineTuningJob
/// The Unix timestamp (in seconds) for when the fine-tuning job is estimated to finish. The value will be null if the fine-tuning job is not running.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("estimated_finish")]
public int? EstimatedFinish { get; set; }
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
public global::System.DateTimeOffset? EstimatedFinish { 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 @@ -19,8 +19,9 @@ public sealed partial class FineTuningJobCheckpoint
/// The Unix timestamp (in seconds) for when the checkpoint was created.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("created_at")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int CreatedAt { get; set; }
public required global::System.DateTimeOffset CreatedAt { get; set; }

/// <summary>
/// The name of the fine-tuned checkpoint model that is created.
Expand Down
9 changes: 6 additions & 3 deletions src/libs/OpenAI/Generated/OpenAI.Models.Invite.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,24 @@ public sealed partial class Invite
/// The Unix timestamp (in seconds) of when the invite was sent.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("invited_at")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int InvitedAt { get; set; }
public required global::System.DateTimeOffset InvitedAt { get; set; }

/// <summary>
/// The Unix timestamp (in seconds) of when the invite expires.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("expires_at")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int ExpiresAt { get; set; }
public required global::System.DateTimeOffset ExpiresAt { get; set; }

/// <summary>
/// The Unix timestamp (in seconds) of when the invite was accepted.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("accepted_at")]
public int AcceptedAt { get; set; }
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
public global::System.DateTimeOffset AcceptedAt { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
Expand Down
9 changes: 6 additions & 3 deletions src/libs/OpenAI/Generated/OpenAI.Models.MessageObject.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ public sealed partial class MessageObject
/// The Unix timestamp (in seconds) for when the message was created.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("created_at")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int CreatedAt { get; set; }
public required global::System.DateTimeOffset CreatedAt { get; set; }

/// <summary>
/// The [thread](/docs/api-reference/threads) ID that this message belongs to.
Expand Down Expand Up @@ -57,15 +58,17 @@ public sealed partial class MessageObject
/// The Unix timestamp (in seconds) for when the message was completed.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("completed_at")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int? CompletedAt { get; set; }
public required global::System.DateTimeOffset? CompletedAt { get; set; }

/// <summary>
/// The Unix timestamp (in seconds) for when the message was marked as incomplete.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("incomplete_at")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int? IncompleteAt { get; set; }
public required global::System.DateTimeOffset? IncompleteAt { get; set; }

/// <summary>
/// The entity that produced the message. One of `user` or `assistant`.
Expand Down
3 changes: 2 additions & 1 deletion src/libs/OpenAI/Generated/OpenAI.Models.Model12.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public sealed partial class Model12
/// The Unix timestamp (in seconds) when the model was created.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("created")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int Created { get; set; }
public required global::System.DateTimeOffset Created { get; set; }

/// <summary>
/// The object type, which is always "model".
Expand Down
3 changes: 2 additions & 1 deletion src/libs/OpenAI/Generated/OpenAI.Models.OpenAIFile.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public sealed partial class OpenAIFile
/// The Unix timestamp (in seconds) for when the file was created.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("created_at")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int CreatedAt { get; set; }
public required global::System.DateTimeOffset CreatedAt { get; set; }

/// <summary>
/// The name of the file.
Expand Down
6 changes: 4 additions & 2 deletions src/libs/OpenAI/Generated/OpenAI.Models.Project.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ public sealed partial class Project
/// The Unix timestamp (in seconds) of when the project was created.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("created_at")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int CreatedAt { get; set; }
public required global::System.DateTimeOffset CreatedAt { get; set; }

/// <summary>
/// The Unix timestamp (in seconds) of when the project was archived or `null`.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("archived_at")]
public int? ArchivedAt { get; set; }
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
public global::System.DateTimeOffset? ArchivedAt { get; set; }

/// <summary>
/// `active` or `archived`
Expand Down
3 changes: 2 additions & 1 deletion src/libs/OpenAI/Generated/OpenAI.Models.ProjectApiKey.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ public sealed partial class ProjectApiKey
/// The Unix timestamp (in seconds) of when the API key was created
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("created_at")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int CreatedAt { get; set; }
public required global::System.DateTimeOffset CreatedAt { get; set; }

/// <summary>
/// The identifier, which can be referenced in API endpoints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ public sealed partial class ProjectServiceAccount
/// The Unix timestamp (in seconds) of when the service account was created
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("created_at")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.UnixTimestampJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required int CreatedAt { get; set; }
public required global::System.DateTimeOffset CreatedAt { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
Expand Down
Loading