Skip to content

Commit

Permalink
fix: Fixed some nullability issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Aug 12, 2024
1 parent 3437e81 commit e92cfd8
Show file tree
Hide file tree
Showing 460 changed files with 129,649 additions and 8,088 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.15.0</Version>
<Version>0.15.1</Version>
<MinVerMinimumMajorMinor>0.1</MinVerMinimumMajorMinor>
<MinVerTagPrefix>v</MinVerTagPrefix>
<MinVerDefaultPreReleaseIdentifiers>dev</MinVerDefaultPreReleaseIdentifiers>
Expand Down
33 changes: 30 additions & 3 deletions src/libs/OpenApiGenerator.Core/Models/TypeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public readonly record struct TypeData(
bool IsDate,
bool IsDateTime,
bool IsBinary,
bool IsValueType,
int AnyOfCount,
int OneOfCount,
int AllOfCount,
Expand All @@ -33,6 +34,7 @@ public readonly record struct TypeData(
IsDate: false,
IsDateTime: false,
IsBinary: false,
IsValueType: false,
AnyOfCount: 0,
OneOfCount: 0,
AllOfCount: 0,
Expand All @@ -50,6 +52,9 @@ public readonly record struct TypeData(
public string ShortCSharpTypeWithoutNullability => CSharpTypeWithoutNullability.Replace($"global::{Namespace}.", string.Empty);
public string ShortCSharpTypeWithNullability => ShortCSharpTypeWithoutNullability + "?";
public bool IsAnyOf => AnyOfCount > 0 || OneOfCount > 0 || AllOfCount > 0;
public string CSharpTypeWithNullabilityForValueTypes => IsValueType
? CSharpTypeWithNullability
: CSharpTypeWithoutNullability;

public bool IsReferenceable =>
CSharpTypeWithoutNullability is "string" or "int" or "long" or "float" or "double" or "bool" ||
Expand Down Expand Up @@ -123,6 +128,7 @@ public static TypeData FromSchemaContext(SchemaContext context)

return new TypeData(
CSharpType: GetCSharpType(context),
IsValueType: ContextIsValueType(context),
IsArray: context.Schema.Type == "array",
IsEnum: context.Schema.IsEnum(),
IsBase64: context.Schema.IsBase64(),
Expand All @@ -142,6 +148,27 @@ public static TypeData FromSchemaContext(SchemaContext context)
GenerateJsonSerializerContextTypes: context.Settings.GenerateJsonSerializerContextTypes);
}

public static bool ContextIsValueType(SchemaContext context)
{
context = context ?? throw new ArgumentNullException(nameof(context));

return (context.Schema.Type, context.Schema.Format) switch
{
(_, _) when context.IsAnyOfLikeStructure => true,
(_, _) when context.IsEnum => true,

("boolean", _) => true,
("integer", _) => true,
("number", _) => true,
("string", null) => true,
("string", "date") => true,
("string", "date-time") => true,
("string", "password") => true,

_ => false,
};
}

public static string GetCSharpType(SchemaContext context, SchemaContext? additionalContext = null)
{
context = context ?? throw new ArgumentNullException(nameof(context));
Expand All @@ -152,9 +179,9 @@ public static string GetCSharpType(SchemaContext context, SchemaContext? additio
(_, _) when context.Schema.IsOneOf() && context.IsComponent => ($"global::{context.Settings.Namespace}.{context.Id}", true),
(_, _) when context.Schema.IsAllOf() && context.IsComponent => ($"global::{context.Settings.Namespace}.{context.Id}", true),

(_, _) when context.Schema.IsAnyOf() => ($"global::System.AnyOf<{string.Join(", ", context.Children.Where(x => x.Hint == Hint.AnyOf).Select(x => x.TypeData?.CSharpType))}>", true),
(_, _) when context.Schema.IsOneOf() => ($"global::System.OneOf<{string.Join(", ", context.Children.Where(x => x.Hint == Hint.OneOf).Select(x => x.TypeData?.CSharpType))}>", true),
(_, _) when context.Schema.IsAllOf() => ($"global::System.AllOf<{string.Join(", ", context.Children.Where(x => x.Hint == Hint.AllOf).Select(x => x.TypeData?.CSharpType))}>", true),
(_, _) when context.Schema.IsAnyOf() => ($"global::System.AnyOf<{string.Join(", ", context.Children.Where(x => x.Hint == Hint.AnyOf).Select(x => x.TypeData?.CSharpTypeWithNullabilityForValueTypes))}>", true),
(_, _) when context.Schema.IsOneOf() => ($"global::System.OneOf<{string.Join(", ", context.Children.Where(x => x.Hint == Hint.OneOf).Select(x => x.TypeData?.CSharpTypeWithNullabilityForValueTypes))}>", true),
(_, _) when context.Schema.IsAllOf() => ($"global::System.AllOf<{string.Join(", ", context.Children.Where(x => x.Hint == Hint.AllOf).Select(x => x.TypeData?.CSharpTypeWithNullabilityForValueTypes))}>", true),

("object", _) or (null, _) when context.Schema.Reference != null =>
($"global::{context.Settings.Namespace}.{context.Id}", true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public sealed partial class Message
/// The content of the message.
/// </summary>
[global::Newtonsoft.Json.JsonProperty("content", Required = global::Newtonsoft.Json.Required.Always)]
public global::System.OneOf<string?, global::System.Collections.Generic.IList<global::G.Block>?> Content { get; set; } = default!;
public global::System.OneOf<string?, global::System.Collections.Generic.IList<global::G.Block>> Content { get; set; } = default!;

/// <summary>
/// The role of the messages author.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public sealed partial class ToolResultBlock
/// These content blocks can use the text or image types.
/// </summary>
[global::Newtonsoft.Json.JsonProperty("content", Required = global::Newtonsoft.Json.Required.Always)]
public global::System.OneOf<string?, global::System.Collections.Generic.IList<global::G.Block>?> Content { get; set; } = default!;
public global::System.OneOf<string?, global::System.Collections.Generic.IList<global::G.Block>> Content { get; set; } = default!;

/// <summary>
/// Set to `true` if the tool execution resulted in an error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed partial class Message
[global::System.Text.Json.Serialization.JsonPropertyName("content")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.OneOfJsonConverterFactory2))]
[global::System.Text.Json.Serialization.JsonRequired]
public required global::System.OneOf<string?, global::System.Collections.Generic.IList<global::G.Block>?> Content { get; set; }
public required global::System.OneOf<string?, global::System.Collections.Generic.IList<global::G.Block>> Content { get; set; }

/// <summary>
/// The role of the messages author.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public sealed partial class ToolResultBlock
[global::System.Text.Json.Serialization.JsonPropertyName("content")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.OneOfJsonConverterFactory2))]
[global::System.Text.Json.Serialization.JsonRequired]
public required global::System.OneOf<string?, global::System.Collections.Generic.IList<global::G.Block>?> Content { get; set; }
public required global::System.OneOf<string?, global::System.Collections.Generic.IList<global::G.Block>> Content { get; set; }

/// <summary>
/// Set to `true` if the tool execution resulted in an error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public sealed partial class JsonSerializerContextTypes
/// <summary>
///
/// </summary>
public global::System.OneOf<string?, global::System.Collections.Generic.IList<global::G.Block>?>? Type6 { get; set; }
public global::System.OneOf<string?, global::System.Collections.Generic.IList<global::G.Block>>? Type6 { get; set; }
/// <summary>
///
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public sealed partial class ValidationErrorError
///
/// </summary>
[global::Newtonsoft.Json.JsonProperty("value")]
public global::System.OneOf<string?, int?, global::System.Collections.Generic.IList<string>?>? Value { get; set; }
public global::System.OneOf<string?, int?, global::System.Collections.Generic.IList<string>>? Value { 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 @@ -47,7 +47,7 @@ public sealed partial class ValidationErrorError
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("value")]
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.OneOfJsonConverterFactory3))]
public global::System.OneOf<string?, int?, global::System.Collections.Generic.IList<string>?>? Value { get; set; }
public global::System.OneOf<string?, int?, global::System.Collections.Generic.IList<string>>? Value { 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 @@ -10,14 +10,14 @@ partial void PrepareActionsCreateWorkflowDispatchArguments(
global::System.Net.Http.HttpClient httpClient,
ref string owner,
ref string repo,
ref global::System.OneOf<int, string?> workflowId,
ref global::System.OneOf<int?, string?> workflowId,
global::G.ActionsCreateWorkflowDispatchRequest request);
partial void PrepareActionsCreateWorkflowDispatchRequest(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpRequestMessage httpRequestMessage,
string owner,
string repo,
global::System.OneOf<int, string?> workflowId,
global::System.OneOf<int?, string?> workflowId,
global::G.ActionsCreateWorkflowDispatchRequest request);
partial void ProcessActionsCreateWorkflowDispatchResponse(
global::System.Net.Http.HttpClient httpClient,
Expand All @@ -38,7 +38,7 @@ partial void ProcessActionsCreateWorkflowDispatchResponse(
public async global::System.Threading.Tasks.Task ActionsCreateWorkflowDispatchAsync(
string owner,
string repo,
global::System.OneOf<int, string?> workflowId,
global::System.OneOf<int?, string?> workflowId,
global::G.ActionsCreateWorkflowDispatchRequest request,
global::System.Threading.CancellationToken cancellationToken = default)
{
Expand Down Expand Up @@ -107,7 +107,7 @@ partial void ProcessActionsCreateWorkflowDispatchResponse(
public async global::System.Threading.Tasks.Task ActionsCreateWorkflowDispatchAsync(
string owner,
string repo,
global::System.OneOf<int, string?> workflowId,
global::System.OneOf<int?, string?> workflowId,
string @ref,
global::G.ActionsCreateWorkflowDispatchRequestInputs? inputs = default,
global::System.Threading.CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ partial void PrepareActionsDisableWorkflowArguments(
global::System.Net.Http.HttpClient httpClient,
ref string owner,
ref string repo,
ref global::System.OneOf<int, string?> workflowId);
ref global::System.OneOf<int?, string?> workflowId);
partial void PrepareActionsDisableWorkflowRequest(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpRequestMessage httpRequestMessage,
string owner,
string repo,
global::System.OneOf<int, string?> workflowId);
global::System.OneOf<int?, string?> workflowId);
partial void ProcessActionsDisableWorkflowResponse(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage);
Expand All @@ -34,7 +34,7 @@ partial void ProcessActionsDisableWorkflowResponse(
public async global::System.Threading.Tasks.Task ActionsDisableWorkflowAsync(
string owner,
string repo,
global::System.OneOf<int, string?> workflowId,
global::System.OneOf<int?, string?> workflowId,
global::System.Threading.CancellationToken cancellationToken = default)
{
PrepareArguments(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ partial void PrepareActionsEnableWorkflowArguments(
global::System.Net.Http.HttpClient httpClient,
ref string owner,
ref string repo,
ref global::System.OneOf<int, string?> workflowId);
ref global::System.OneOf<int?, string?> workflowId);
partial void PrepareActionsEnableWorkflowRequest(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpRequestMessage httpRequestMessage,
string owner,
string repo,
global::System.OneOf<int, string?> workflowId);
global::System.OneOf<int?, string?> workflowId);
partial void ProcessActionsEnableWorkflowResponse(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage);
Expand All @@ -34,7 +34,7 @@ partial void ProcessActionsEnableWorkflowResponse(
public async global::System.Threading.Tasks.Task ActionsEnableWorkflowAsync(
string owner,
string repo,
global::System.OneOf<int, string?> workflowId,
global::System.OneOf<int?, string?> workflowId,
global::System.Threading.CancellationToken cancellationToken = default)
{
PrepareArguments(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ partial void PrepareActionsGetWorkflowArguments(
global::System.Net.Http.HttpClient httpClient,
ref string owner,
ref string repo,
ref global::System.OneOf<int, string?> workflowId);
ref global::System.OneOf<int?, string?> workflowId);
partial void PrepareActionsGetWorkflowRequest(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpRequestMessage httpRequestMessage,
string owner,
string repo,
global::System.OneOf<int, string?> workflowId);
global::System.OneOf<int?, string?> workflowId);
partial void ProcessActionsGetWorkflowResponse(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage);
Expand All @@ -41,7 +41,7 @@ partial void ProcessActionsGetWorkflowResponseContent(
public async global::System.Threading.Tasks.Task<global::G.Workflow> ActionsGetWorkflowAsync(
string owner,
string repo,
global::System.OneOf<int, string?> workflowId,
global::System.OneOf<int?, string?> workflowId,
global::System.Threading.CancellationToken cancellationToken = default)
{
PrepareArguments(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ partial void PrepareActionsGetWorkflowUsageArguments(
global::System.Net.Http.HttpClient httpClient,
ref string owner,
ref string repo,
ref global::System.OneOf<int, string?> workflowId);
ref global::System.OneOf<int?, string?> workflowId);
partial void PrepareActionsGetWorkflowUsageRequest(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpRequestMessage httpRequestMessage,
string owner,
string repo,
global::System.OneOf<int, string?> workflowId);
global::System.OneOf<int?, string?> workflowId);
partial void ProcessActionsGetWorkflowUsageResponse(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage);
Expand All @@ -41,7 +41,7 @@ partial void ProcessActionsGetWorkflowUsageResponseContent(
public async global::System.Threading.Tasks.Task<global::G.WorkflowUsage> ActionsGetWorkflowUsageAsync(
string owner,
string repo,
global::System.OneOf<int, string?> workflowId,
global::System.OneOf<int?, string?> workflowId,
global::System.Threading.CancellationToken cancellationToken = default)
{
PrepareArguments(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ partial void PrepareActionsListWorkflowRunsArguments(
global::System.Net.Http.HttpClient httpClient,
ref string owner,
ref string repo,
ref global::System.OneOf<int, string?> workflowId,
ref global::System.OneOf<int?, string?> workflowId,
ref string? actor,
ref string? branch,
ref string? @event,
Expand All @@ -26,7 +26,7 @@ partial void PrepareActionsListWorkflowRunsRequest(
global::System.Net.Http.HttpRequestMessage httpRequestMessage,
string owner,
string repo,
global::System.OneOf<int, string?> workflowId,
global::System.OneOf<int?, string?> workflowId,
string? actor,
string? branch,
string? @event,
Expand Down Expand Up @@ -76,7 +76,7 @@ partial void ProcessActionsListWorkflowRunsResponseContent(
public async global::System.Threading.Tasks.Task<global::G.ActionsListWorkflowRunsResponse> ActionsListWorkflowRunsAsync(
string owner,
string repo,
global::System.OneOf<int, string?> workflowId,
global::System.OneOf<int?, string?> workflowId,
string? actor,
string? branch,
string? @event,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ partial void PrepareActionsReviewCustomGatesForRunArguments(
ref string owner,
ref string repo,
ref int runId,
global::System.AnyOf<global::G.ReviewCustomGatesCommentRequired?, global::G.ReviewCustomGatesStateRequired?> request);
global::System.AnyOf<global::G.ReviewCustomGatesCommentRequired, global::G.ReviewCustomGatesStateRequired> request);
partial void PrepareActionsReviewCustomGatesForRunRequest(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpRequestMessage httpRequestMessage,
string owner,
string repo,
int runId,
global::System.AnyOf<global::G.ReviewCustomGatesCommentRequired?, global::G.ReviewCustomGatesStateRequired?> request);
global::System.AnyOf<global::G.ReviewCustomGatesCommentRequired, global::G.ReviewCustomGatesStateRequired> request);
partial void ProcessActionsReviewCustomGatesForRunResponse(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage);
Expand All @@ -40,7 +40,7 @@ partial void ProcessActionsReviewCustomGatesForRunResponse(
string owner,
string repo,
int runId,
global::System.AnyOf<global::G.ReviewCustomGatesCommentRequired?, global::G.ReviewCustomGatesStateRequired?> request,
global::System.AnyOf<global::G.ReviewCustomGatesCommentRequired, global::G.ReviewCustomGatesStateRequired> request,
global::System.Threading.CancellationToken cancellationToken = default)
{
PrepareArguments(
Expand Down Expand Up @@ -104,7 +104,7 @@ partial void ProcessActionsReviewCustomGatesForRunResponse(
int runId,
global::System.Threading.CancellationToken cancellationToken = default)
{
var request = new global::System.AnyOf<global::G.ReviewCustomGatesCommentRequired?, global::G.ReviewCustomGatesStateRequired?>
var request = new global::System.AnyOf<global::G.ReviewCustomGatesCommentRequired, global::G.ReviewCustomGatesStateRequired>
{
};

Expand Down
Loading

0 comments on commit e92cfd8

Please sign in to comment.