From a551442e6a12b3e6fb9729197fafe51a6546f15a Mon Sep 17 00:00:00 2001 From: HavenDV Date: Sat, 31 Aug 2024 04:41:15 +0400 Subject: [PATCH] fix: Fixed rare issue with oneOf usage to define required property. --- src/libs/OpenApiGenerator.Core/Models/TypeData.cs | 12 +++++++++--- .../_#G.ChecksClient.ChecksCreate.g.verified.cs | 2 ++ .../_#G.ChecksClient.ChecksUpdate.g.verified.cs | 2 ++ ...t.CodeScanningCreateVariantAnalysis.g.verified.cs | 2 ++ ...G.PullsClient.PullsRequestReviewers.g.verified.cs | 2 ++ ...#G.ReposClient.ReposCreatePagesSite.g.verified.cs | 2 ++ ...eposUpdateInformationAboutPagesSite.g.verified.cs | 2 ++ .../_#G.ChecksClient.ChecksCreate.g.verified.cs | 2 ++ .../_#G.ChecksClient.ChecksUpdate.g.verified.cs | 2 ++ ...t.CodeScanningCreateVariantAnalysis.g.verified.cs | 2 ++ ...G.PullsClient.PullsRequestReviewers.g.verified.cs | 2 ++ ...#G.ReposClient.ReposCreatePagesSite.g.verified.cs | 2 ++ ...eposUpdateInformationAboutPagesSite.g.verified.cs | 2 ++ ...CreateAssistantRequestToolResources.g.verified.cs | 1 - ...ls.CreateThreadRequestToolResources.g.verified.cs | 1 - 15 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/libs/OpenApiGenerator.Core/Models/TypeData.cs b/src/libs/OpenApiGenerator.Core/Models/TypeData.cs index bfd511320b..9942c7d019 100644 --- a/src/libs/OpenApiGenerator.Core/Models/TypeData.cs +++ b/src/libs/OpenApiGenerator.Core/Models/TypeData.cs @@ -155,9 +155,15 @@ Default with IsDateTime: context.Schema.IsDateTime(), IsBinary: context.Schema.IsBinary(), IsUnixTimestamp: context.Schema.IsUnixTimestamp(), - AnyOfCount: context.Schema.AnyOf?.Count ?? 0, - OneOfCount: context.Schema.OneOf?.Count ?? 0, - AllOfCount: context.Schema.AllOf?.Count ?? 0, + AnyOfCount: context.Schema.IsAnyOf() // Sometimes here AnyOf with only required properties + ? context.Schema.AnyOf?.Count ?? 0 + : 0, + OneOfCount: context.Schema.IsOneOf() // Sometimes here OneOf with only required properties + ? context.Schema.OneOf?.Count ?? 0 + : 0, + AllOfCount: context.Schema.IsAllOf() // Sometimes here AllOf with only required properties + ? context.Schema.AllOf?.Count ?? 0 + : 0, IsComponent: context.IsComponent, Properties: properties, EnumValues: enumValues, diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.ChecksClient.ChecksCreate.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.ChecksClient.ChecksCreate.g.verified.cs index 0db2c30d2f..f50ed7d685 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.ChecksClient.ChecksCreate.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.ChecksClient.ChecksCreate.g.verified.cs @@ -44,6 +44,8 @@ partial void ProcessChecksCreateResponseContent( global::G.ChecksCreateRequest request, global::System.Threading.CancellationToken cancellationToken = default) { + request = request ?? throw new global::System.ArgumentNullException(nameof(request)); + PrepareArguments( client: _httpClient); PrepareChecksCreateArguments( diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.ChecksClient.ChecksUpdate.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.ChecksClient.ChecksUpdate.g.verified.cs index 71ea2546bb..ecf5d056a8 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.ChecksClient.ChecksUpdate.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.ChecksClient.ChecksUpdate.g.verified.cs @@ -47,6 +47,8 @@ partial void ProcessChecksUpdateResponseContent( global::G.ChecksUpdateRequest request, global::System.Threading.CancellationToken cancellationToken = default) { + request = request ?? throw new global::System.ArgumentNullException(nameof(request)); + PrepareArguments( client: _httpClient); PrepareChecksUpdateArguments( diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.CodeScanningClient.CodeScanningCreateVariantAnalysis.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.CodeScanningClient.CodeScanningCreateVariantAnalysis.g.verified.cs index 1f13a5309a..848c87a080 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.CodeScanningClient.CodeScanningCreateVariantAnalysis.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.CodeScanningClient.CodeScanningCreateVariantAnalysis.g.verified.cs @@ -45,6 +45,8 @@ partial void ProcessCodeScanningCreateVariantAnalysisResponseContent( global::G.CodeScanningCreateVariantAnalysisRequest request, global::System.Threading.CancellationToken cancellationToken = default) { + request = request ?? throw new global::System.ArgumentNullException(nameof(request)); + PrepareArguments( client: _httpClient); PrepareCodeScanningCreateVariantAnalysisArguments( diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.PullsClient.PullsRequestReviewers.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.PullsClient.PullsRequestReviewers.g.verified.cs index 6b13fb5068..8db99e163a 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.PullsClient.PullsRequestReviewers.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.PullsClient.PullsRequestReviewers.g.verified.cs @@ -46,6 +46,8 @@ partial void ProcessPullsRequestReviewersResponseContent( global::G.PullsRequestReviewersRequest request, global::System.Threading.CancellationToken cancellationToken = default) { + request = request ?? throw new global::System.ArgumentNullException(nameof(request)); + PrepareArguments( client: _httpClient); PreparePullsRequestReviewersArguments( diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.ReposClient.ReposCreatePagesSite.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.ReposClient.ReposCreatePagesSite.g.verified.cs index dccce69482..a6728228f0 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.ReposClient.ReposCreatePagesSite.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.ReposClient.ReposCreatePagesSite.g.verified.cs @@ -43,6 +43,8 @@ partial void ProcessReposCreatePagesSiteResponseContent( global::G.ReposCreatePagesSiteRequest request, global::System.Threading.CancellationToken cancellationToken = default) { + request = request ?? throw new global::System.ArgumentNullException(nameof(request)); + PrepareArguments( client: _httpClient); PrepareReposCreatePagesSiteArguments( diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.ReposClient.ReposUpdateInformationAboutPagesSite.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.ReposClient.ReposUpdateInformationAboutPagesSite.g.verified.cs index b3ed987dab..42ecf8c478 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.ReposClient.ReposUpdateInformationAboutPagesSite.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.ReposClient.ReposUpdateInformationAboutPagesSite.g.verified.cs @@ -43,6 +43,8 @@ partial void ProcessReposUpdateInformationAboutPagesSiteResponseContent( global::G.ReposUpdateInformationAboutPagesSiteRequest request, global::System.Threading.CancellationToken cancellationToken = default) { + request = request ?? throw new global::System.ArgumentNullException(nameof(request)); + PrepareArguments( client: _httpClient); PrepareReposUpdateInformationAboutPagesSiteArguments( diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.ChecksClient.ChecksCreate.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.ChecksClient.ChecksCreate.g.verified.cs index f9f2b79378..1282cbafea 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.ChecksClient.ChecksCreate.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.ChecksClient.ChecksCreate.g.verified.cs @@ -44,6 +44,8 @@ partial void ProcessChecksCreateResponseContent( global::G.ChecksCreateRequest request, global::System.Threading.CancellationToken cancellationToken = default) { + request = request ?? throw new global::System.ArgumentNullException(nameof(request)); + PrepareArguments( client: _httpClient); PrepareChecksCreateArguments( diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.ChecksClient.ChecksUpdate.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.ChecksClient.ChecksUpdate.g.verified.cs index fcfeb52f7d..79242263aa 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.ChecksClient.ChecksUpdate.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.ChecksClient.ChecksUpdate.g.verified.cs @@ -47,6 +47,8 @@ partial void ProcessChecksUpdateResponseContent( global::G.ChecksUpdateRequest request, global::System.Threading.CancellationToken cancellationToken = default) { + request = request ?? throw new global::System.ArgumentNullException(nameof(request)); + PrepareArguments( client: _httpClient); PrepareChecksUpdateArguments( diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.CodeScanningClient.CodeScanningCreateVariantAnalysis.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.CodeScanningClient.CodeScanningCreateVariantAnalysis.g.verified.cs index 59e98b8e75..352f0fd83b 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.CodeScanningClient.CodeScanningCreateVariantAnalysis.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.CodeScanningClient.CodeScanningCreateVariantAnalysis.g.verified.cs @@ -45,6 +45,8 @@ partial void ProcessCodeScanningCreateVariantAnalysisResponseContent( global::G.CodeScanningCreateVariantAnalysisRequest request, global::System.Threading.CancellationToken cancellationToken = default) { + request = request ?? throw new global::System.ArgumentNullException(nameof(request)); + PrepareArguments( client: _httpClient); PrepareCodeScanningCreateVariantAnalysisArguments( diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.PullsClient.PullsRequestReviewers.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.PullsClient.PullsRequestReviewers.g.verified.cs index 01ed852e8b..f113a3da2c 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.PullsClient.PullsRequestReviewers.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.PullsClient.PullsRequestReviewers.g.verified.cs @@ -46,6 +46,8 @@ partial void ProcessPullsRequestReviewersResponseContent( global::G.PullsRequestReviewersRequest request, global::System.Threading.CancellationToken cancellationToken = default) { + request = request ?? throw new global::System.ArgumentNullException(nameof(request)); + PrepareArguments( client: _httpClient); PreparePullsRequestReviewersArguments( diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.ReposClient.ReposCreatePagesSite.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.ReposClient.ReposCreatePagesSite.g.verified.cs index e61d47455f..c340d4f01c 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.ReposClient.ReposCreatePagesSite.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.ReposClient.ReposCreatePagesSite.g.verified.cs @@ -43,6 +43,8 @@ partial void ProcessReposCreatePagesSiteResponseContent( global::G.ReposCreatePagesSiteRequest request, global::System.Threading.CancellationToken cancellationToken = default) { + request = request ?? throw new global::System.ArgumentNullException(nameof(request)); + PrepareArguments( client: _httpClient); PrepareReposCreatePagesSiteArguments( diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.ReposClient.ReposUpdateInformationAboutPagesSite.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.ReposClient.ReposUpdateInformationAboutPagesSite.g.verified.cs index f9157ab59a..ee2cbe259e 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.ReposClient.ReposUpdateInformationAboutPagesSite.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.ReposClient.ReposUpdateInformationAboutPagesSite.g.verified.cs @@ -43,6 +43,8 @@ partial void ProcessReposUpdateInformationAboutPagesSiteResponseContent( global::G.ReposUpdateInformationAboutPagesSiteRequest request, global::System.Threading.CancellationToken cancellationToken = default) { + request = request ?? throw new global::System.ArgumentNullException(nameof(request)); + PrepareArguments( client: _httpClient); PrepareReposUpdateInformationAboutPagesSiteArguments( diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#G.Models.CreateAssistantRequestToolResources.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#G.Models.CreateAssistantRequestToolResources.g.verified.cs index 240ac44e35..6013601687 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#G.Models.CreateAssistantRequestToolResources.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#G.Models.CreateAssistantRequestToolResources.g.verified.cs @@ -19,7 +19,6 @@ public sealed partial class CreateAssistantRequestToolResources /// /// [global::System.Text.Json.Serialization.JsonPropertyName("file_search")] - [global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.OneOfJsonConverterFactory2))] public global::G.CreateAssistantRequestToolResourcesFileSearch? FileSearch { get; set; } /// diff --git a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#G.Models.CreateThreadRequestToolResources.g.verified.cs b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#G.Models.CreateThreadRequestToolResources.g.verified.cs index 58b9e0d0d8..8c27a10ca9 100644 --- a/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#G.Models.CreateThreadRequestToolResources.g.verified.cs +++ b/src/tests/OpenApiGenerator.SnapshotTests/Snapshots/OpenAi/SystemTextJson/_#G.Models.CreateThreadRequestToolResources.g.verified.cs @@ -19,7 +19,6 @@ public sealed partial class CreateThreadRequestToolResources /// /// [global::System.Text.Json.Serialization.JsonPropertyName("file_search")] - [global::System.Text.Json.Serialization.JsonConverter(typeof(global::OpenApiGenerator.JsonConverters.OneOfJsonConverterFactory2))] public global::G.CreateThreadRequestToolResourcesFileSearch? FileSearch { get; set; } ///