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

Allow means to disable or override rules of the Inflector #148

Open
mchenryc opened this issue Feb 9, 2014 · 7 comments
Open

Allow means to disable or override rules of the Inflector #148

mchenryc opened this issue Feb 9, 2014 · 7 comments

Comments

@mchenryc
Copy link

mchenryc commented Feb 9, 2014

English has too many exceptions when converting between singular and plural for the Inflector to handle all cases. Even a smallish schema I ran through found multiple nouns that failed to be converted correctly (e.g. "curves" => "curf").

@joelittlejohn
Copy link
Owner

Good idea. Would you prefer to add overrides to the plugin config or have some extension property on an array (in the schema) that allows the singular/item name to be specified?

I'd like to integrate as many of these exceptions as possible back into the inflector so that others can benefit from these when they're identified.

For anyone looking for an immediate workaround, remember you can always use the javaType extension property override the class name chosen by the inflector.

@mchenryc
Copy link
Author

It's quite a rabbit hole - no automation will work 100% of the time (homonyms like 'bases' may be 'basis' or 'base'... based on intent) and adding all known exceptions would be crazy (do you include classic plurals like 'bretheren', 'kine', and 'stigmata'?) . Word-net could help, as long as js2p is run online, and that is still fallible in many common cases. Sometimes there is no "right" answer, when it comes down to personal preference or context (fish vs. fishes)

The javaType property is useful, though can not be used when the schema is read only. That said, another custom property for the array element names would work in many cases.

Project specific rules and exceptions get my vote. One could specify singular, plural, uncountable, and/or irregular values through the various configurations. I would expect most to use the simple irregular rule, but see no reason not to provide the others.

An option to switch to a wordnet based inflector may or may not give better results, but would certainly preclude running offline. Unless that mechanism were extended to allow specifying ones own implementation, similar to annotationStyle and customAnnotator, but for inflection, I would look to the others first.

@danieljue
Copy link

I'm also having problems with the inflector, and would like to disable it, or wire in an inert version of the inflector interface through the configuration.
In my case I have a JSON array 'HomeAddress' that is getting turned into 'HomeAddres'. Was able to supress this behavior with a bunch of extra work, using explicit javaType values.

@joelittlejohn
Copy link
Owner

@danieljue Which version of the plugin are you using?

@danieljue
Copy link

@joelittlejohn My apologies, I am using core 0.4.5. Just noticed that the latest stable is 0.4.7. Has this been addressed in that version? I am fond of using inflector helpers in other ways, it's just that this time it got in the way. ;-)

@joelittlejohn
Copy link
Owner

@danieljue No problem. Someone else actually reported Address being singularized to Addres and this was fixed as #244. The fix went out in 0.4.6.

@nqzero
Copy link

nqzero commented Jul 4, 2017

rather than try to magically guess the correct singular, could we just append Item or Element (or some similar word).

  • Address -> AddressItem
  • Pages -> PagesItem
  • Calves -> CalvesItem

it's not pretty, but it's always correct

the biggest problem with the current magic is not the ugly mispellings [sic] but that the name changes depend on the content of the files, ie whether or not the content is an array, which makes automation difficult

just adopt some deterministic rule and then users can "fix" things using heuristics and ad hoc rules if they choose to

in my case, all my json sources end in _re (for requests) and _res (for responses) ... i couldn't figure out why half the generated source files were "missing"

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

4 participants