Skip to content

Commit 88f613e

Browse files
committed
fix(document-builder): dasherize type names for included entities
1 parent 8d9af0b commit 88f613e

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/JsonApiDotNetCore/Builders/DocumentBuilder.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,10 @@ private void _addRelationships(DocumentData data, ContextEntity contextEntity, I
9595
.GetRelationship(entity, r.RelationshipName);
9696

9797
if(navigationEntity is IEnumerable)
98-
relationshipData.ManyData = GetRelationships((IEnumerable<object>)navigationEntity, r.RelationshipName);
98+
relationshipData.ManyData = _getRelationships((IEnumerable<object>)navigationEntity, r.RelationshipName);
9999
else
100-
relationshipData.SingleData = GetRelationship(navigationEntity, r.RelationshipName);
100+
relationshipData.SingleData = _getRelationship(navigationEntity, r.RelationshipName);
101101
}
102-
103-
104102

105103
data.Relationships.Add(r.RelationshipName.Dasherize(), relationshipData);
106104
});
@@ -112,7 +110,7 @@ private bool _hasRelationship(string relationshipName)
112110
_jsonApiContext.IncludedRelationships.Contains(relationshipName.ToProperCase());
113111
}
114112

115-
private List<Dictionary<string, string>> GetRelationships(IEnumerable<object> entities, string relationshipName)
113+
private List<Dictionary<string, string>> _getRelationships(IEnumerable<object> entities, string relationshipName)
116114
{
117115
var objType = entities.GetType().GenericTypeArguments[0];
118116

@@ -122,20 +120,20 @@ private List<Dictionary<string, string>> GetRelationships(IEnumerable<object> en
122120
foreach(var entity in entities)
123121
{
124122
relationships.Add(new Dictionary<string, string> {
125-
{"type", typeName.EntityName },
123+
{"type", typeName.EntityName.Dasherize() },
126124
{"id", ((IIdentifiable)entity).Id.ToString() }
127125
});
128126
}
129127
return relationships;
130128
}
131-
private Dictionary<string, string> GetRelationship(object entity, string relationshipName)
129+
private Dictionary<string, string> _getRelationship(object entity, string relationshipName)
132130
{
133131
var objType = entity.GetType();
134132

135133
var typeName = _jsonApiContext.ContextGraph.GetContextEntity(objType);
136134

137135
return new Dictionary<string, string> {
138-
{"type", typeName.EntityName },
136+
{"type", typeName.EntityName.Dasherize() },
139137
{"id", ((IIdentifiable)entity).Id.ToString() }
140138
};
141139
}

0 commit comments

Comments
 (0)