Skip to content

Commit 9e33b33

Browse files
committed
Use oneOf instead of allOf
1 parent dc86b10 commit 9e33b33

12 files changed

+137
-137
lines changed

src/OpenApi/sample/Endpoints/MapSchemasEndpoints.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static IEndpointRouteBuilder MapSchemasEndpoints(this IEndpointRouteBuild
4747
schemas.MapPost("/project-response", (ProjectResponse project) => Results.Ok(project));
4848
schemas.MapPost("/subscription", (Subscription subscription) => Results.Ok(subscription));
4949

50-
// Tests for allOf nullable behavior on responses and request bodies
50+
// Tests for oneOf nullable behavior on responses and request bodies
5151
schemas.MapGet("/nullable-response", () => TypedResults.Ok(new NullableResponseModel
5252
{
5353
RequiredProperty = "required",
@@ -194,7 +194,7 @@ public sealed class RefUser
194194
public string Email { get; set; } = "";
195195
}
196196

197-
// Models for testing allOf nullable behavior
197+
// Models for testing oneOf nullable behavior
198198
public sealed class NullableResponseModel
199199
{
200200
public required string RequiredProperty { get; set; }

src/OpenApi/src/Extensions/OpenApiSchemaExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ internal static class OpenApiSchemaExtensions
77
{
88
private static readonly OpenApiSchema _nullSchema = new() { Type = JsonSchemaType.Null };
99

10-
public static IOpenApiSchema CreateAllOfNullableWrapper(this IOpenApiSchema originalSchema)
10+
public static IOpenApiSchema CreateOneOfNullableWrapper(this IOpenApiSchema originalSchema)
1111
{
1212
return new OpenApiSchema
1313
{
14-
AllOf =
14+
OneOf =
1515
[
1616
_nullSchema,
1717
originalSchema

src/OpenApi/src/Services/OpenApiDocumentService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ private async Task<OpenApiResponse> GetResponseAsync(
428428
{
429429
schema = await _componentService.GetOrCreateSchemaAsync(document, responseType, scopedServiceProvider, schemaTransformers, null, cancellationToken);
430430
schema = apiResponseType.ShouldApplyNullableResponseSchema(apiDescription)
431-
? schema.CreateAllOfNullableWrapper()
431+
? schema.CreateOneOfNullableWrapper()
432432
: schema;
433433
}
434434
response.Content[contentType] = new OpenApiMediaType { Schema = schema };
@@ -753,7 +753,7 @@ private async Task<OpenApiRequestBody> GetJsonRequestBody(
753753
var contentType = requestFormat.MediaType;
754754
var schema = await _componentService.GetOrCreateSchemaAsync(document, bodyParameter.Type, scopedServiceProvider, schemaTransformers, bodyParameter, cancellationToken: cancellationToken);
755755
schema = bodyParameter.ShouldApplyNullableRequestSchema()
756-
? schema.CreateAllOfNullableWrapper()
756+
? schema.CreateOneOfNullableWrapper()
757757
: schema;
758758
requestBody.Content[contentType] = new OpenApiMediaType { Schema = schema };
759759
}

src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ internal static IOpenApiSchema ResolveReferenceForSchema(OpenApiDocument documen
286286
isNullableProperty is true)
287287
{
288288
var resolvedProperty = ResolveReferenceForSchema(document, property.Value, rootSchemaId);
289-
schema.Properties[property.Key] = resolvedProperty.CreateAllOfNullableWrapper();
289+
schema.Properties[property.Key] = resolvedProperty.CreateOneOfNullableWrapper();
290290
}
291291
else
292292
{

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=schemas-by-ref.verified.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@
665665
"content": {
666666
"application/json": {
667667
"schema": {
668-
"allOf": [
668+
"oneOf": [
669669
{
670670
"nullable": true
671671
},
@@ -833,7 +833,7 @@
833833
"type": "string"
834834
},
835835
"optionalNested": {
836-
"allOf": [
836+
"oneOf": [
837837
{
838838
"nullable": true
839839
},
@@ -1074,7 +1074,7 @@
10741074
"nullable": true
10751075
},
10761076
"deepNested": {
1077-
"allOf": [
1077+
"oneOf": [
10781078
{
10791079
"nullable": true
10801080
},
@@ -1153,7 +1153,7 @@
11531153
"nullable": true
11541154
},
11551155
"nullableComplexProperty": {
1156-
"allOf": [
1156+
"oneOf": [
11571157
{
11581158
"nullable": true
11591159
},
@@ -1389,7 +1389,7 @@
13891389
"$ref": "#/components/schemas/RefProfile"
13901390
},
13911391
"secondaryUser": {
1392-
"allOf": [
1392+
"oneOf": [
13931393
{
13941394
"nullable": true
13951395
},

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_1/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=schemas-by-ref.verified.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@
665665
"content": {
666666
"application/json": {
667667
"schema": {
668-
"allOf": [
668+
"oneOf": [
669669
{
670670
"type": "null"
671671
},
@@ -833,7 +833,7 @@
833833
"type": "string"
834834
},
835835
"optionalNested": {
836-
"allOf": [
836+
"oneOf": [
837837
{
838838
"type": "null"
839839
},
@@ -1092,7 +1092,7 @@
10921092
"format": "int32"
10931093
},
10941094
"deepNested": {
1095-
"allOf": [
1095+
"oneOf": [
10961096
{
10971097
"type": "null"
10981098
},
@@ -1183,7 +1183,7 @@
11831183
]
11841184
},
11851185
"nullableComplexProperty": {
1186-
"allOf": [
1186+
"oneOf": [
11871187
{
11881188
"type": "null"
11891189
},
@@ -1419,7 +1419,7 @@
14191419
"$ref": "#/components/schemas/RefProfile"
14201420
},
14211421
"secondaryUser": {
1422-
"allOf": [
1422+
"oneOf": [
14231423
{
14241424
"type": "null"
14251425
},

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApiDocumentLocalizationTests.VerifyOpenApiDocumentIsInvariant.verified.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@
11901190
"content": {
11911191
"application/json": {
11921192
"schema": {
1193-
"allOf": [
1193+
"oneOf": [
11941194
{
11951195
"type": "null"
11961196
},
@@ -1571,7 +1571,7 @@
15711571
"type": "string"
15721572
},
15731573
"optionalNested": {
1574-
"allOf": [
1574+
"oneOf": [
15751575
{
15761576
"type": "null"
15771577
},
@@ -1871,7 +1871,7 @@
18711871
"format": "int32"
18721872
},
18731873
"deepNested": {
1874-
"allOf": [
1874+
"oneOf": [
18751875
{
18761876
"type": "null"
18771877
},
@@ -1962,7 +1962,7 @@
19621962
]
19631963
},
19641964
"nullableComplexProperty": {
1965-
"allOf": [
1965+
"oneOf": [
19661966
{
19671967
"type": "null"
19681968
},
@@ -2232,7 +2232,7 @@
22322232
"$ref": "#/components/schemas/RefProfile"
22332233
},
22342234
"secondaryUser": {
2235-
"allOf": [
2235+
"oneOf": [
22362236
{
22372237
"type": "null"
22382238
},

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Services/OpenApiSchemaService/OpenApiSchemaService.ParameterSchemas.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -920,11 +920,11 @@ await VerifyOpenApiDocument(builder, document =>
920920
var todoSchema = todoContent.Value.Schema;
921921

922922
// For complex types, check if it has both null and the reference type
923-
if (todoSchema.AllOf != null)
923+
if (todoSchema.OneOf != null)
924924
{
925-
// If it still uses allOf, verify the structure
926-
Assert.Equal(2, todoSchema.AllOf.Count);
927-
Assert.Collection(todoSchema.AllOf,
925+
// If it now uses oneOf, verify the structure
926+
Assert.Equal(2, todoSchema.OneOf.Count);
927+
Assert.Collection(todoSchema.OneOf,
928928
item =>
929929
{
930930
Assert.NotNull(item);
@@ -949,11 +949,11 @@ await VerifyOpenApiDocument(builder, document =>
949949
Assert.Equal("application/json", accountContent.Key);
950950
var accountSchema = accountContent.Value.Schema;
951951

952-
if (accountSchema.AllOf != null)
952+
if (accountSchema.OneOf != null)
953953
{
954-
// If it still uses allOf, verify the structure
955-
Assert.Equal(2, accountSchema.AllOf.Count);
956-
Assert.Collection(accountSchema.AllOf,
954+
// If it now uses oneOf, verify the structure
955+
Assert.Equal(2, accountSchema.OneOf.Count);
956+
Assert.Collection(accountSchema.OneOf,
957957
item =>
958958
{
959959
Assert.NotNull(item);

0 commit comments

Comments
 (0)