@@ -40,16 +40,16 @@ public JsonApiEndpointMetadataContainer Get(MethodInfo controllerAction)
40
40
throw new NotSupportedException ( $ "Unable to provide metadata for non-JsonApiDotNetCore endpoint '{ controllerAction . ReflectedType ! . FullName } '.") ;
41
41
}
42
42
43
- Type primaryResourceType = _controllerResourceMapping . GetResourceTypeForController ( controllerAction . ReflectedType ) ;
43
+ ResourceType primaryResourceType = _controllerResourceMapping . GetResourceTypeForController ( controllerAction . ReflectedType ) ! ;
44
44
45
45
return new JsonApiEndpointMetadataContainer
46
46
{
47
- RequestMetadata = GetRequestMetadata ( endpoint . Value , primaryResourceType ) ,
48
- ResponseMetadata = GetResponseMetadata ( endpoint . Value , primaryResourceType )
47
+ RequestMetadata = GetRequestMetadata ( endpoint . Value , primaryResourceType . ClrType ) ,
48
+ ResponseMetadata = GetResponseMetadata ( endpoint . Value , primaryResourceType . ClrType )
49
49
} ;
50
50
}
51
51
52
- private IJsonApiRequestMetadata GetRequestMetadata ( JsonApiEndpoint endpoint , Type primaryResourceType )
52
+ private IJsonApiRequestMetadata ? GetRequestMetadata ( JsonApiEndpoint endpoint , Type primaryResourceType )
53
53
{
54
54
switch ( endpoint )
55
55
{
@@ -76,23 +76,21 @@ private IJsonApiRequestMetadata GetRequestMetadata(JsonApiEndpoint endpoint, Typ
76
76
77
77
private static PrimaryRequestMetadata GetPostRequestMetadata ( Type primaryResourceType )
78
78
{
79
- return new ( )
80
- {
81
- Type = typeof ( ResourcePostRequestDocument < > ) . MakeGenericType ( primaryResourceType )
82
- } ;
79
+ Type documentType = typeof ( ResourcePostRequestDocument < > ) . MakeGenericType ( primaryResourceType ) ;
80
+
81
+ return new PrimaryRequestMetadata ( documentType ) ;
83
82
}
84
83
85
84
private static PrimaryRequestMetadata GetPatchRequestMetadata ( Type primaryResourceType )
86
85
{
87
- return new ( )
88
- {
89
- Type = typeof ( ResourcePatchRequestDocument < > ) . MakeGenericType ( primaryResourceType )
90
- } ;
86
+ Type documentType = typeof ( ResourcePatchRequestDocument < > ) . MakeGenericType ( primaryResourceType ) ;
87
+
88
+ return new PrimaryRequestMetadata ( documentType ) ;
91
89
}
92
90
93
91
private RelationshipRequestMetadata GetRelationshipRequestMetadata ( Type primaryResourceType , bool ignoreHasOneRelationships )
94
92
{
95
- IEnumerable < RelationshipAttribute > relationships = _resourceGraph . GetResourceContext ( primaryResourceType ) . Relationships ;
93
+ IEnumerable < RelationshipAttribute > relationships = _resourceGraph . GetResourceType ( primaryResourceType ) . Relationships ;
96
94
97
95
if ( ignoreHasOneRelationships )
98
96
{
@@ -101,16 +99,13 @@ private RelationshipRequestMetadata GetRelationshipRequestMetadata(Type primaryR
101
99
102
100
IDictionary < string , Type > resourceTypesByRelationshipName = relationships . ToDictionary ( relationship => relationship . PublicName ,
103
101
relationship => relationship is HasManyAttribute
104
- ? typeof ( ToManyRelationshipRequestData < > ) . MakeGenericType ( relationship . RightType )
105
- : typeof ( ToOneRelationshipRequestData < > ) . MakeGenericType ( relationship . RightType ) ) ;
102
+ ? typeof ( ToManyRelationshipRequestData < > ) . MakeGenericType ( relationship . RightType . ClrType )
103
+ : typeof ( ToOneRelationshipRequestData < > ) . MakeGenericType ( relationship . RightType . ClrType ) ) ;
106
104
107
- return new RelationshipRequestMetadata
108
- {
109
- RequestBodyTypeByRelationshipName = resourceTypesByRelationshipName
110
- } ;
105
+ return new RelationshipRequestMetadata ( resourceTypesByRelationshipName ) ;
111
106
}
112
107
113
- private IJsonApiResponseMetadata GetResponseMetadata ( JsonApiEndpoint endpoint , Type primaryResourceType )
108
+ private IJsonApiResponseMetadata ? GetResponseMetadata ( JsonApiEndpoint endpoint , Type primaryResourceType )
114
109
{
115
110
switch ( endpoint )
116
111
{
@@ -138,12 +133,10 @@ private IJsonApiResponseMetadata GetResponseMetadata(JsonApiEndpoint endpoint, T
138
133
139
134
private static PrimaryResponseMetadata GetPrimaryResponseMetadata ( Type primaryResourceType , bool endpointReturnsCollection )
140
135
{
141
- Type documentType = endpointReturnsCollection ? typeof ( ResourceCollectionResponseDocument < > ) : typeof ( PrimaryResourceResponseDocument < > ) ;
136
+ Type documentOpenType = endpointReturnsCollection ? typeof ( ResourceCollectionResponseDocument < > ) : typeof ( PrimaryResourceResponseDocument < > ) ;
137
+ Type documentType = documentOpenType . MakeGenericType ( primaryResourceType ) ;
142
138
143
- return new PrimaryResponseMetadata
144
- {
145
- Type = documentType . MakeGenericType ( primaryResourceType )
146
- } ;
139
+ return new PrimaryResponseMetadata ( documentType ) ;
147
140
}
148
141
149
142
private SecondaryResponseMetadata GetSecondaryResponseMetadata ( Type primaryResourceType )
@@ -154,19 +147,16 @@ private SecondaryResponseMetadata GetSecondaryResponseMetadata(Type primaryResou
154
147
? typeof ( ResourceCollectionResponseDocument < > )
155
148
: typeof ( SecondaryResourceResponseDocument < > ) ;
156
149
157
- return documentType . MakeGenericType ( relationship . RightType ) ;
150
+ return documentType . MakeGenericType ( relationship . RightType . ClrType ) ;
158
151
} ) ;
159
152
160
- return new SecondaryResponseMetadata
161
- {
162
- ResponseTypesByRelationshipName = responseTypesByRelationshipName
163
- } ;
153
+ return new SecondaryResponseMetadata ( responseTypesByRelationshipName ) ;
164
154
}
165
155
166
156
private IDictionary < string , Type > GetMetadataByRelationshipName ( Type primaryResourceType ,
167
157
Func < RelationshipAttribute , Type > extractRelationshipMetadataCallback )
168
158
{
169
- IReadOnlyCollection < RelationshipAttribute > relationships = _resourceGraph . GetResourceContext ( primaryResourceType ) . Relationships ;
159
+ IReadOnlyCollection < RelationshipAttribute > relationships = _resourceGraph . GetResourceType ( primaryResourceType ) . Relationships ;
170
160
171
161
return relationships . ToDictionary ( relationship => relationship . PublicName , extractRelationshipMetadataCallback ) ;
172
162
}
@@ -175,13 +165,10 @@ private RelationshipResponseMetadata GetRelationshipResponseMetadata(Type primar
175
165
{
176
166
IDictionary < string , Type > responseTypesByRelationshipName = GetMetadataByRelationshipName ( primaryResourceType ,
177
167
relationship => relationship is HasManyAttribute
178
- ? typeof ( ResourceIdentifierCollectionResponseDocument < > ) . MakeGenericType ( relationship . RightType )
179
- : typeof ( ResourceIdentifierResponseDocument < > ) . MakeGenericType ( relationship . RightType ) ) ;
168
+ ? typeof ( ResourceIdentifierCollectionResponseDocument < > ) . MakeGenericType ( relationship . RightType . ClrType )
169
+ : typeof ( ResourceIdentifierResponseDocument < > ) . MakeGenericType ( relationship . RightType . ClrType ) ) ;
180
170
181
- return new RelationshipResponseMetadata
182
- {
183
- ResponseTypesByRelationshipName = responseTypesByRelationshipName
184
- } ;
171
+ return new RelationshipResponseMetadata ( responseTypesByRelationshipName ) ;
185
172
}
186
173
}
187
174
}
0 commit comments