Skip to content

Commit 1bdb70a

Browse files
committed
Process review feedback
1 parent a6e11be commit 1bdb70a

File tree

6 files changed

+44
-31
lines changed

6 files changed

+44
-31
lines changed

src/JsonApiDotNetCore.OpenApi/JsonApiActionDescriptorCollectionProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ private static IEnumerable<ActionDescriptor> AddJsonApiMetadataToAction(ActionDe
7979
UpdateBodyParameterDescriptor(endpoint, primaryMetadata.DocumentType);
8080
return Array.Empty<ActionDescriptor>();
8181
}
82-
case NonPrimaryEndpointMetadata expansibleMetadata and (RelationshipResponseMetadata or SecondaryResponseMetadata):
82+
case NonPrimaryEndpointMetadata nonPrimaryEndpointMetadata and (RelationshipResponseMetadata or SecondaryResponseMetadata):
8383
{
84-
return Expand(endpoint, expansibleMetadata,
84+
return Expand(endpoint, nonPrimaryEndpointMetadata,
8585
(expandedEndpoint, documentType, _) => UpdateProducesResponseTypeAttribute(expandedEndpoint, documentType));
8686
}
87-
case NonPrimaryEndpointMetadata expansibleMetadata and RelationshipRequestMetadata:
87+
case NonPrimaryEndpointMetadata nonPrimaryEndpointMetadata and RelationshipRequestMetadata:
8888
{
89-
return Expand(endpoint, expansibleMetadata, UpdateBodyParameterDescriptor);
89+
return Expand(endpoint, nonPrimaryEndpointMetadata, UpdateBodyParameterDescriptor);
9090
}
9191
default:
9292
{

src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Documents/PrimaryResourceResponseDocument.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Documents
99
{
10-
// Types in the current namespace are never touched by ASP.NET ModelState validation, therefore using a non-nullable reference type for a property does not imply this property is required. Instead, we use [Required] explicitly, because is how Swashbuckle is instructed to mark properties as required.
10+
// Types in the current namespace are never touched by ASP.NET ModelState validation, therefore using a non-nullable reference type for a property does not
11+
// imply this property is required. Instead, we use [Required] explicitly, because this is how Swashbuckle is instructed to mark properties as required.
1112
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
1213
internal sealed class PrimaryResourceResponseDocument<TResource> : SingleData<ResourceResponseObject<TResource>>
1314
where TResource : IIdentifiable

src/JsonApiDotNetCore.OpenApi/JsonApiObjects/NonPrimaryDocumentTypeFactory.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects
77
{
88
internal sealed class NonPrimaryDocumentTypeFactory
99
{
10-
private static readonly DocumentOpenTypeOptions SecondaryResponseDocumentTypeOptions = new(typeof(ResourceCollectionResponseDocument<>),
10+
private static readonly DocumentOpenTypes SecondaryResponseDocumentOpenTypes = new(typeof(ResourceCollectionResponseDocument<>),
1111
typeof(NullableSecondaryResourceResponseDocument<>), typeof(SecondaryResourceResponseDocument<>));
1212

13-
private static readonly DocumentOpenTypeOptions RelationshipRequestDocumentTypeOptions = new(typeof(ToManyRelationshipRequestData<>),
13+
private static readonly DocumentOpenTypes RelationshipRequestDocumentOpenTypes = new(typeof(ToManyRelationshipRequestData<>),
1414
typeof(NullableToOneRelationshipRequestData<>), typeof(ToOneRelationshipRequestData<>));
1515

16-
private static readonly DocumentOpenTypeOptions RelationshipResponseDocumentTypeOptions = new(typeof(ResourceIdentifierCollectionResponseDocument<>),
16+
private static readonly DocumentOpenTypes RelationshipResponseDocumentOpenTypes = new(typeof(ResourceIdentifierCollectionResponseDocument<>),
1717
typeof(NullableResourceIdentifierResponseDocument<>), typeof(ResourceIdentifierResponseDocument<>));
1818

1919
public static NonPrimaryDocumentTypeFactory Instance { get; } = new();
@@ -26,53 +26,53 @@ public Type GetForSecondaryResponse(RelationshipAttribute relationship)
2626
{
2727
ArgumentGuard.NotNull(relationship, nameof(relationship));
2828

29-
return Get(relationship, SecondaryResponseDocumentTypeOptions);
29+
return Get(relationship, SecondaryResponseDocumentOpenTypes);
3030
}
3131

3232
public Type GetForRelationshipRequest(RelationshipAttribute relationship)
3333
{
3434
ArgumentGuard.NotNull(relationship, nameof(relationship));
3535

36-
return Get(relationship, RelationshipRequestDocumentTypeOptions);
36+
return Get(relationship, RelationshipRequestDocumentOpenTypes);
3737
}
3838

3939
public Type GetForRelationshipResponse(RelationshipAttribute relationship)
4040
{
4141
ArgumentGuard.NotNull(relationship, nameof(relationship));
4242

43-
return Get(relationship, RelationshipResponseDocumentTypeOptions);
43+
return Get(relationship, RelationshipResponseDocumentOpenTypes);
4444
}
4545

46-
private static Type Get(RelationshipAttribute relationship, DocumentOpenTypeOptions typeOptions)
46+
private static Type Get(RelationshipAttribute relationship, DocumentOpenTypes types)
4747
{
4848
// @formatter:nested_ternary_style expanded
4949

5050
Type documentOpenType = relationship is HasManyAttribute
51-
? typeOptions.ManyData
51+
? types.ManyDataOpenType
5252
: relationship.IsNullable()
53-
? typeOptions.NullableSingleData
54-
: typeOptions.SingleData;
53+
? types.NullableSingleDataOpenType
54+
: types.SingleDataOpenType;
5555

5656
// @formatter:nested_ternary_style restore
5757

5858
return documentOpenType.MakeGenericType(relationship.RightType.ClrType);
5959
}
6060

61-
private sealed class DocumentOpenTypeOptions
61+
private sealed class DocumentOpenTypes
6262
{
63-
public Type ManyData { get; }
64-
public Type NullableSingleData { get; }
65-
public Type SingleData { get; }
63+
public Type ManyDataOpenType { get; }
64+
public Type NullableSingleDataOpenType { get; }
65+
public Type SingleDataOpenType { get; }
6666

67-
public DocumentOpenTypeOptions(Type manyDataOpenType, Type nullableSingleDataOpenType, Type singleDataOpenType)
67+
public DocumentOpenTypes(Type manyDataOpenType, Type nullableSingleDataOpenType, Type singleDataOpenType)
6868
{
6969
ArgumentGuard.NotNull(manyDataOpenType, nameof(manyDataOpenType));
7070
ArgumentGuard.NotNull(nullableSingleDataOpenType, nameof(nullableSingleDataOpenType));
7171
ArgumentGuard.NotNull(singleDataOpenType, nameof(singleDataOpenType));
7272

73-
ManyData = manyDataOpenType;
74-
NullableSingleData = nullableSingleDataOpenType;
75-
SingleData = singleDataOpenType;
73+
ManyDataOpenType = manyDataOpenType;
74+
NullableSingleDataOpenType = nullableSingleDataOpenType;
75+
SingleDataOpenType = singleDataOpenType;
7676
}
7777
}
7878
}

src/JsonApiDotNetCore.OpenApi/MemberInfoExtensions.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,28 @@ public static TypeCategory GetTypeCategory(this MemberInfo source)
1010
{
1111
ArgumentGuard.NotNull(source, nameof(source));
1212

13-
Type memberType = source.MemberType switch
13+
Type memberType;
14+
15+
if (source.MemberType.HasFlag(MemberTypes.Field))
16+
{
17+
memberType = ((FieldInfo)source).FieldType;
18+
}
19+
else if (source.MemberType.HasFlag(MemberTypes.Property))
1420
{
15-
MemberTypes.Field => ((FieldInfo)source).FieldType,
16-
MemberTypes.Property => ((PropertyInfo)source).PropertyType,
17-
_ => throw new ArgumentException("Cannot get the type category for members of type other than 'MemberTypes.Field' or 'MemberTypes.Property'.")
18-
};
21+
memberType = ((PropertyInfo)source).PropertyType;
22+
}
23+
else
24+
{
25+
throw new NotSupportedException($"Cannot get the type category for members of type '{source.MemberType}' is not supported.");
26+
}
1927

2028
if (memberType.IsValueType)
2129
{
2230
return Nullable.GetUnderlyingType(memberType) != null ? TypeCategory.NullableValueType : TypeCategory.ValueType;
2331
}
2432

25-
// Once we switch to .NET 6, we should rely instead on the built-in reflection APIs for nullability information. See https://devblogs.microsoft.com/dotnet/announcing-net-6-preview-7/#libraries-reflection-apis-for-nullability-information.
33+
// Once we switch to .NET 6, we should rely instead on the built-in reflection APIs for nullability information.
34+
// See https://devblogs.microsoft.com/dotnet/announcing-net-6-preview-7/#libraries-reflection-apis-for-nullability-information.
2635
return source.IsNonNullableReferenceType() ? TypeCategory.NonNullableReferenceType : TypeCategory.NullableReferenceType;
2736
}
2837
}

src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiSchemaGenerator.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ private static bool IsDataPropertyNullable(Type type)
109109
throw new UnreachableCodeException();
110110
}
111111

112-
return dataProperty.GetTypeCategory() == TypeCategory.NullableReferenceType;
112+
TypeCategory typeCategory = dataProperty.GetTypeCategory();
113+
114+
return typeCategory == TypeCategory.NullableReferenceType;
113115
}
114116

115117
private void SetDataObjectSchemaToNullable(OpenApiSchema referenceSchemaForDocument)

test/OpenApiTests/LegacyOpenApiIntegration/LegacyIntegrationDbContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ protected override void OnModelCreating(ModelBuilder builder)
2929
.WithMany(flightAttendant => flightAttendant.PurserOnFlights);
3030

3131
builder.Entity<Flight>()
32-
.HasOne(flight => flight.BackupPurser);
32+
.HasOne(flight => flight.BackupPurser)
33+
.WithMany();
3334
}
3435
}
3536
}

0 commit comments

Comments
 (0)