11using System ;
2- using System . Collections . Generic ;
32using System . IO ;
43using System . Linq ;
54using System . Net ;
65using System . Net . Http ;
7- using System . Text ;
86using System . Threading . Tasks ;
97using JetBrains . Annotations ;
108using JsonApiDotNetCore . Configuration ;
1311using JsonApiDotNetCore . Serialization . Objects ;
1412using Microsoft . AspNetCore . Http ;
1513using Microsoft . AspNetCore . Http . Features ;
16- using Microsoft . AspNetCore . Mvc ;
1714using Microsoft . AspNetCore . Mvc . Controllers ;
1815using Microsoft . AspNetCore . Routing ;
1916using Microsoft . Net . Http . Headers ;
@@ -218,7 +215,6 @@ private static void SetupResourceRequest(JsonApiRequest request, ResourceContext
218215 request . Kind = EndpointKind . Primary ;
219216 request . PrimaryResource = primaryResourceContext ;
220217 request . PrimaryId = GetPrimaryRequestId ( routeValues ) ;
221- request . BasePath = GetBasePath ( primaryResourceContext . PublicName , options , httpRequest ) ;
222218
223219 string relationshipName = GetRelationshipNameForSecondaryRequest ( routeValues ) ;
224220
@@ -245,58 +241,6 @@ private static string GetPrimaryRequestId(RouteValueDictionary routeValues)
245241 return routeValues . TryGetValue ( "id" , out object id ) ? ( string ) id : null ;
246242 }
247243
248- private static string GetBasePath ( string resourceName , IJsonApiOptions options , HttpRequest httpRequest )
249- {
250- var builder = new StringBuilder ( ) ;
251-
252- if ( ! options . UseRelativeLinks )
253- {
254- builder . Append ( httpRequest . Scheme ) ;
255- builder . Append ( "://" ) ;
256- builder . Append ( httpRequest . Host ) ;
257- }
258-
259- if ( httpRequest . PathBase . HasValue )
260- {
261- builder . Append ( httpRequest . PathBase ) ;
262- }
263-
264- string customRoute = GetCustomRoute ( resourceName , options . Namespace , httpRequest . HttpContext ) ;
265-
266- if ( ! string . IsNullOrEmpty ( customRoute ) )
267- {
268- builder . Append ( '/' ) ;
269- builder . Append ( customRoute ) ;
270- }
271- else if ( ! string . IsNullOrEmpty ( options . Namespace ) )
272- {
273- builder . Append ( '/' ) ;
274- builder . Append ( options . Namespace ) ;
275- }
276-
277- return builder . ToString ( ) ;
278- }
279-
280- private static string GetCustomRoute ( string resourceName , string apiNamespace , HttpContext httpContext )
281- {
282- if ( resourceName != null )
283- {
284- Endpoint endpoint = httpContext . GetEndpoint ( ) ;
285- var routeAttribute = endpoint ? . Metadata . GetMetadata < RouteAttribute > ( ) ;
286-
287- if ( routeAttribute != null && httpContext . Request . Path . Value != null )
288- {
289- List < string > trimmedComponents = httpContext . Request . Path . Value . Trim ( '/' ) . Split ( '/' ) . ToList ( ) ;
290- int resourceNameIndex = trimmedComponents . FindIndex ( component => component == resourceName ) ;
291- string [ ] newComponents = trimmedComponents . Take ( resourceNameIndex ) . ToArray ( ) ;
292- string customRoute = string . Join ( '/' , newComponents ) ;
293- return customRoute == apiNamespace ? null : customRoute ;
294- }
295- }
296-
297- return null ;
298- }
299-
300244 private static string GetRelationshipNameForSecondaryRequest ( RouteValueDictionary routeValues )
301245 {
302246 return routeValues . TryGetValue ( "relationshipName" , out object routeValue ) ? ( string ) routeValue : null ;
@@ -318,7 +262,6 @@ private static void SetupOperationsRequest(JsonApiRequest request, IJsonApiOptio
318262 {
319263 request . IsReadOnly = false ;
320264 request . Kind = EndpointKind . AtomicOperations ;
321- request . BasePath = GetBasePath ( null , options , httpRequest ) ;
322265 }
323266 }
324267}
0 commit comments