yahoo / yahoo/elide

Add ability to auto-pluralize root collections

Open
#449 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Hacktoberfest
Dominant language
Java
Stars
1k
Forks
236
PR merge metrics
No merged PRs in 30d

Description

Many clients, like Ember, expect pluralized root-level collections, and a number of other APIs / frameworks do this by default (ie. Ruby on Rails). Elide supports changing the by manually setting the type parameter on the @Include annotation, but this is the sort of thing that automation and defaults are well suited to handle. Here's how this looks today:

// Assume you have a class titled Report
@Include(rootLevel = true, type = "reports")

Instead of having to do this for every root-level object, it would be amazing if Elide had a property to turn on auto-pluralization of root-level collections by default.

The EntityDictionary likely holds most everything needed, and Apache Commons may even provide a pluralizer that can be used for this. At first glance, the EntityDictionary::getJsonAliasFor(Class<?> entityClass) method seems like the place to add this new capability, though there's concern that that method calls into an entity binding. If so, this would require modifying the entity binding to bind the right thing or else types could get confused.

Another oddity of this approach is that the type for all instances would always be plural, which is likely undesired, so it might be better to be smarter and pluralize / unpluralize where relevant. This would let the type be singular, while having it's root-level json alias be plural.

To accomplish this extra set of smarts, this may need to happen in the state machine, with StartState.java being the only piece that would care about this.

Either way, the general guidance for this feature would be to follow what Ember expects by default. An Ember app is usually backed by a JSON-API, often served by a Ruby on Rails web service, and that is likely a common-enough pattern that other plural-expecting clients will be very similar or even the same with what they expect.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with EntityDictionary::getJsonAliasFor(Class<?> entityClass), the @Include type and rootLevel behavior, and StartState.java to determine where root collection aliases are resolved. Compare the options for configuring auto-pluralization and for keeping instance types singular while root-level JSON aliases are plural. Done means a configurable behavior that matches the pluralized collections expected by Ember without requiring per-entity type overrides.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.