Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix XML element naming for collections and single items #62

Closed
ttu opened this issue Jul 23, 2019 · 0 comments
Closed

Fix XML element naming for collections and single items #62

ttu opened this issue Jul 23, 2019 · 0 comments

Comments

@ttu
Copy link
Owner

ttu commented Jul 23, 2019

Regardless of collection naming, elements in XML should be singularized / pluralized.

E.g. for endpoints
/api/family
/api/families

XML should be:

<families>
  <family>
    <id>

Current implementation has e.g. for /api/families

<families>
  <families_0>
    <id>

for /api/family

<family>
  <family_0>
    <id>

Implementation:

var itemName = ObjectHelper.GetCollectionFromPath(context.HttpContext.Request.Path.Value);

var children = itemCollection.Select((i, idx) => ((ExpandoObject)i).Aggregate(new XElement($"{name}_{idx}"), HandleExpandoField));

var children = innerList.Select((i, idx) => ((ExpandoObject)i).Aggregate(new XElement($"{fields.Key}_{idx}"), HandleExpandoField));

Mayble library like https://www.nuget.org/packages/Pluralize.NET.Core/ will do the trick?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant