Skip to content

Commit ee9f2eb

Browse files
committed
removed JsonApiObjectNullabilityProcessor and enabled NRT support in Swashbuckle.
1 parent 40f6826 commit ee9f2eb

File tree

6 files changed

+6
-166
lines changed

6 files changed

+6
-166
lines changed

src/JsonApiDotNetCore.OpenApi/ServiceCollectionExtensions.cs

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ private static void AddSwaggerGenerator(IServiceScope scope, IServiceCollection
6666

6767
services.AddSwaggerGen(swaggerGenOptions =>
6868
{
69+
swaggerGenOptions.SupportNonNullableReferenceTypes();
6970
SetOperationInfo(swaggerGenOptions, controllerResourceMapping, namingPolicy);
7071
SetSchemaIdSelector(swaggerGenOptions, resourceGraph, resourceNameFormatter);
7172
swaggerGenOptions.DocumentFilter<EndpointOrderingFilter>();

src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiObjectNullabilityProcessor.cs

-133
This file was deleted.

src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiSchemaGenerator.cs

-28
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,9 @@ internal sealed class JsonApiSchemaGenerator : ISchemaGenerator
2828
typeof(SecondaryResourceResponseDocument<>)
2929
};
3030

31-
private static readonly Type[] JsonApiResourceIdentifierDocumentOpenTypes =
32-
{
33-
typeof(ResourceIdentifierCollectionResponseDocument<>),
34-
typeof(ResourceIdentifierResponseDocument<>)
35-
};
36-
3731
private readonly ISchemaGenerator _defaultSchemaGenerator;
3832
private readonly ResourceObjectSchemaGenerator _resourceObjectSchemaGenerator;
3933
private readonly NullableReferenceSchemaGenerator _nullableReferenceSchemaGenerator;
40-
private readonly JsonApiObjectNullabilityProcessor _jsonApiObjectNullabilityProcessor;
4134
private readonly SchemaRepositoryAccessor _schemaRepositoryAccessor = new();
4235

4336
public JsonApiSchemaGenerator(SchemaGenerator defaultSchemaGenerator, IResourceGraph resourceGraph, IJsonApiOptions options)
@@ -48,7 +41,6 @@ public JsonApiSchemaGenerator(SchemaGenerator defaultSchemaGenerator, IResourceG
4841

4942
_defaultSchemaGenerator = defaultSchemaGenerator;
5043
_nullableReferenceSchemaGenerator = new NullableReferenceSchemaGenerator(_schemaRepositoryAccessor);
51-
_jsonApiObjectNullabilityProcessor = new JsonApiObjectNullabilityProcessor(_schemaRepositoryAccessor);
5244
_resourceObjectSchemaGenerator = new ResourceObjectSchemaGenerator(defaultSchemaGenerator, resourceGraph, options, _schemaRepositoryAccessor);
5345
}
5446

@@ -73,11 +65,6 @@ public OpenApiSchema GenerateSchema(Type type, SchemaRepository schemaRepository
7365
SetDataObjectSchemaToNullable(schema);
7466
}
7567

76-
if (IsJsonApiDocument(type))
77-
{
78-
RemoveNotApplicableNullability(schema);
79-
}
80-
8168
return schema;
8269
}
8370

@@ -86,16 +73,6 @@ private static bool IsJsonApiResourceDocument(Type type)
8673
return type.IsConstructedGenericType && JsonApiResourceDocumentOpenTypes.Contains(type.GetGenericTypeDefinition());
8774
}
8875

89-
private static bool IsJsonApiDocument(Type type)
90-
{
91-
return IsJsonApiResourceDocument(type) || IsJsonApiResourceIdentifierDocument(type);
92-
}
93-
94-
private static bool IsJsonApiResourceIdentifierDocument(Type type)
95-
{
96-
return type.IsConstructedGenericType && JsonApiResourceIdentifierDocumentOpenTypes.Contains(type.GetGenericTypeDefinition());
97-
}
98-
9976
private OpenApiSchema GenerateResourceJsonApiDocumentSchema(Type type)
10077
{
10178
Type resourceObjectType = type.BaseType!.GenericTypeArguments[0];
@@ -141,10 +118,5 @@ private static OpenApiSchema CreateArrayTypeDataSchema(OpenApiSchema referenceSc
141118
Type = "array"
142119
};
143120
}
144-
145-
private void RemoveNotApplicableNullability(OpenApiSchema schema)
146-
{
147-
_jsonApiObjectNullabilityProcessor.ClearDocumentProperties(schema);
148-
}
149121
}
150122
}

test/OpenApiTests/LegacyOpenApiIntegration/Airplane.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public sealed class Airplane : Identifiable<string>
1717

1818
[Attr(Capabilities = AttrCapabilities.AllowView | AttrCapabilities.AllowCreate | AttrCapabilities.AllowChange)]
1919
[MaxLength(16)]
20-
public string SerialNumber { get; set; } = null!;
20+
public string? SerialNumber { get; set; }
2121

2222
[Attr(Capabilities = AttrCapabilities.AllowView | AttrCapabilities.AllowCreate | AttrCapabilities.AllowChange)]
2323
public int? AirtimeInHours { get; set; }
@@ -33,7 +33,7 @@ public sealed class Airplane : Identifiable<string>
3333

3434
[Attr(Capabilities = AttrCapabilities.AllowView | AttrCapabilities.AllowChange)]
3535
[MaxLength(85)]
36-
public string ManufacturedInCity { get; set; } = null!;
36+
public string? ManufacturedInCity { get; set; }
3737

3838
[Attr(Capabilities = AttrCapabilities.AllowView)]
3939
public AircraftKind Kind { get; set; }

test/OpenApiTests/LegacyOpenApiIntegration/Flight.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public sealed class Flight : Identifiable<string>
1818

1919
[Attr(Capabilities = AttrCapabilities.AllowView | AttrCapabilities.AllowChange)]
2020
[MaxLength(2000)]
21-
public string StopOverDestination { get; set; } = null!;
21+
public string? StopOverDestination { get; set; }
2222

2323
[Attr(PublicName = "operated-by", Capabilities = AttrCapabilities.AllowView | AttrCapabilities.AllowChange)]
2424
public Airline Airline { get; set; }
@@ -37,7 +37,7 @@ public sealed class Flight : Identifiable<string>
3737

3838
[Attr]
3939
[NotMapped]
40-
public ICollection<string> ServicesOnBoard { get; set; } = null!;
40+
public ICollection<string>? ServicesOnBoard { get; set; }
4141

4242
[HasMany]
4343
public ICollection<Passenger> Passengers { get; set; } = null!;

test/OpenApiTests/LegacyOpenApiIntegration/Passenger.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public sealed class Passenger : Identifiable<string>
1414
public string PassportNumber { get; set; } = null!;
1515

1616
[Attr]
17-
public string FullName { get; set; } = null!;
17+
public string? FullName { get; set; }
1818

1919
[Attr]
2020
public CabinArea CabinArea { get; set; }

0 commit comments

Comments
 (0)