Skip to content

Commit 243201c

Browse files
Revert nullable changes for allOf
Reverts 141a54c.
1 parent 73b897c commit 243201c

13 files changed

Lines changed: 24 additions & 21 deletions

src/Swashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/SchemaGenerator.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,9 @@ private IOpenApiSchema GenerateSchemaForMember(
4949
? GeneratePolymorphicSchema(schemaRepository, knownTypesDataContracts)
5050
: GenerateConcreteSchema(dataContract, schemaRepository);
5151

52-
bool usingAllOf = false;
53-
5452
if (_generatorOptions.UseAllOfToExtendReferenceSchemas && schema is OpenApiSchemaReference reference)
5553
{
5654
schema = new OpenApiSchema() { AllOf = [reference] };
57-
usingAllOf = true;
5855
}
5956

6057
if (schema is OpenApiSchema concrete)
@@ -66,12 +63,12 @@ private IOpenApiSchema GenerateSchemaForMember(
6663
{
6764
var requiredAttribute = customAttributes.OfType<RequiredAttribute>().FirstOrDefault();
6865

69-
// "nullable" cannot be used without "type"
70-
if (!usingAllOf)
71-
{
72-
var nullable = IsNullable(requiredAttribute, dataProperty, memberInfo);
73-
SetNullable(concrete, nullable);
74-
}
66+
// "nullable" cannot be used without "type", however this was added in a patch
67+
// change to OpenAPI 3.0 which would cause compatibility issues for existing users
68+
// if it were changed, so this is intentionally not compliant with the OpenAPI specification.
69+
// See https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/3683#issuecomment-3593065197.
70+
var nullable = IsNullable(requiredAttribute, dataProperty, memberInfo);
71+
SetNullable(concrete, nullable);
7572

7673
concrete.ReadOnly = dataProperty.IsReadOnly;
7774
concrete.WriteOnly = dataProperty.IsWriteOnly;

test/Swashbuckle.AspNetCore.IntegrationTests/KiotaClientTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ await WithTodoAppClientAsync(async (client) =>
2121
// Act - Get all the items
2222
var items = await client.Api.Items.GetAsync(cancellationToken: cancellationToken);
2323

24-
// Assert - There should be no items
24+
// Assert
2525
Assert.NotNull(items);
2626
Assert.NotNull(items.Items);
2727

test/Swashbuckle.AspNetCore.IntegrationTests/KiotaTodoClient/kiota-lock.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"descriptionHash": "6220470D2DBDA8D33A3A26AE0D99FD08E8CA025558CE7AF3EFA771BEE7F540049DFB9E14E28367BD30CC488F5A918670E40CF226C0C825CC163EDBFFA1CCE766",
2+
"descriptionHash": "DF0ACFCDC1F5CFB97A2DFB0E7A7BB004B889E5742C1925E797BC2A6B816489D5C9A4A8413CB3795FA45E7589D0E04D80856F3558CD656308C19DBDA9446A0712",
33
"descriptionLocation": "../snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=TodoApp.Program_swaggerRequestUri=v1.DotNet10_0.verified.txt",
44
"lockFileVersion": "1.0.0",
55
"kiotaVersion": "1.29.0",

test/Swashbuckle.AspNetCore.IntegrationTests/NSwagClientTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ await WithTodoAppClientAsync(async (client) =>
4646
Assert.Null(item.CompletedAt);
4747
Assert.NotEqual(default, item.CreatedAt);
4848
Assert.Equal(item.CreatedAt, item.LastUpdated);
49-
Assert.Equal(TodoPriority.Normal, item.Priority);
49+
Assert.Null(item.Priority);
5050
Assert.Equal(text, item.Text);
5151

5252
// Act - Update the item to be high priority

test/Swashbuckle.AspNetCore.IntegrationTests/NSwagTodoClient/NSwagTodoClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,9 +1113,9 @@ public partial class TodoItemModel
11131113
/// <summary>
11141114
/// Gets or sets the optional priority of the Todo item.
11151115
/// </summary>
1116-
[Newtonsoft.Json.JsonProperty("priority", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
1116+
[Newtonsoft.Json.JsonProperty("priority", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
11171117
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
1118-
public TodoPriority Priority { get; set; }
1118+
public TodoPriority? Priority { get; set; }
11191119

11201120
}
11211121

test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyNSwagTodoAppClient/NSwagTodoClient.verified.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,9 +1113,9 @@ public partial class TodoItemModel
11131113
/// <summary>
11141114
/// Gets or sets the optional priority of the Todo item.
11151115
/// </summary>
1116-
[Newtonsoft.Json.JsonProperty("priority", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
1116+
[Newtonsoft.Json.JsonProperty("priority", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
11171117
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
1118-
public TodoPriority Priority { get; set; }
1118+
public TodoPriority? Priority { get; set; }
11191119

11201120
}
11211121

test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_a4dcbaf37de46e5e/NSwagOpenApiClient.verified.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,9 +1113,9 @@ public partial class TodoItemModel
11131113
/// <summary>
11141114
/// Gets or sets the optional priority of the Todo item.
11151115
/// </summary>
1116-
[Newtonsoft.Json.JsonProperty("priority", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
1116+
[Newtonsoft.Json.JsonProperty("priority", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
11171117
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
1118-
public TodoPriority Priority { get; set; }
1118+
public TodoPriority? Priority { get; set; }
11191119

11201120
}
11211121

test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=MinimalAppWithNullableEnums.Program_swaggerRequestUri=v1.DotNet10_0.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"type": "object",
4949
"properties": {
5050
"child": {
51+
"type": "null",
5152
"allOf": [
5253
{
5354
"$ref": "#/components/schemas/Child"

test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=MinimalAppWithNullableEnums.Program_swaggerRequestUri=v1.DotNet8_0.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"type": "object",
4949
"properties": {
5050
"child": {
51+
"type": "null",
5152
"allOf": [
5253
{
5354
"$ref": "#/components/schemas/Child"

test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=MinimalAppWithNullableEnums.Program_swaggerRequestUri=v1.DotNet9_0.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"type": "object",
4949
"properties": {
5050
"child": {
51+
"type": "null",
5152
"allOf": [
5253
{
5354
"$ref": "#/components/schemas/Child"

0 commit comments

Comments
 (0)