Skip to content

Commit a741d37

Browse files
committed
fix(link-builder): include entity name in the base path
1 parent 7f84dd2 commit a741d37

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/JsonApiDotNetCore/Builders/DocumentBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ private void _addRelationships(DocumentData data, ContextEntity contextEntity, I
8383
{
8484
Links = new Links
8585
{
86-
Self = linkBuilder.GetSelfRelationLink(contextEntity.EntityName, entity.Id.ToString(), r.RelationshipName),
87-
Related = linkBuilder.GetRelatedRelationLink(contextEntity.EntityName, entity.Id.ToString(), r.RelationshipName)
86+
Self = linkBuilder.GetSelfRelationLink(entity.Id.ToString(), r.RelationshipName),
87+
Related = linkBuilder.GetRelatedRelationLink(entity.Id.ToString(), r.RelationshipName)
8888
}
8989
};
9090

src/JsonApiDotNetCore/Builders/LinkBuilder.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,21 @@ private string GetNamespaceFromPath(string path, string entityName)
2424
{
2525
var nSpace = string.Empty;
2626
var segments = path.Split('/');
27+
2728
for(var i = 1; i < segments.Length; i++)
28-
{
29-
if(segments[i].ToLower() == entityName.ToLower())
30-
break;
31-
3229
nSpace += $"/{segments[i].Dasherize()}";
33-
}
30+
3431
return nSpace;
3532
}
3633

37-
public string GetSelfRelationLink(string parent, string parentId, string child)
34+
public string GetSelfRelationLink(string parentId, string child)
3835
{
39-
return $"{_context.BasePath}/relationships/{child.Dasherize()}";
36+
return $"{_context.BasePath}/{parentId}/relationships/{child.Dasherize()}";
4037
}
4138

42-
public string GetRelatedRelationLink(string parent, string parentId, string child)
39+
public string GetRelatedRelationLink(string parentId, string child)
4340
{
44-
return $"{_context.BasePath}/{child.Dasherize()}";
41+
return $"{_context.BasePath}/{parentId}/{child.Dasherize()}";
4542
}
4643
}
4744
}

0 commit comments

Comments
 (0)