Generator-jhipster: Add an option to configure an entity/dto class name suffix

Created on 24 Oct 2018  路  5Comments  路  Source: jhipster/generator-jhipster

Overview of the feature request

Adding an option to configure an entity/dto class name suffix.

Motivation for or Use Case

Some naming conventions force you to have the entity's class suffixed by 'Entity' and the DTO's class without suffix.

For example, a 'foo' entity will produce :

  • FooEntity for the entity class name ;
  • Foo for the DTO class name ;

Other classes name don't change (FooService, FooRepository, etc).

The default configuration would be an empty string for the entity suffix and 'DTO' for the dto suffix to reflect the current behaviour.

This configuration would be "application-wide" (no prompt on entity generation) and saved in the .yo-rc.json.

I have done almost all the job to see the feasibility of this feature (just took me about 1 hour for the simple case - without relationships). 馃挭

I can make a PR as soon as all the work is done (unless a jHipster core member says it's not a good idea).

Related issues or PR

None.

  • [x] Checking this box is mandatory (this is just to show you read everything)
area

Most helpful comment

I'm ok if below conditions are satisfied

  1. The code change for this will be minimum (I don't want to review a PR that touches too much)
  2. Its passed while app generation as a flag and its persisted and read from the yo-rc.json
  3. Support is added in jhipster-core to support JDL
  4. should work for import-jdl as well

All 5 comments

I'm ok if below conditions are satisfied

  1. The code change for this will be minimum (I don't want to review a PR that touches too much)
  2. Its passed while app generation as a flag and its persisted and read from the yo-rc.json
  3. Support is added in jhipster-core to support JDL
  4. should work for import-jdl as well

OK, just to give you a quick status :

  • [x] Code change : only inside the "entity-server" templates
  • [x] Passed with --domain-suffix and --dto-suffix flags with app generation
  • [x] Support added in jhipster-core
  • [x] Work with import-jdl
  • [x] Unit tests added

I have added two functions inside the entity-server generator : asDomain(string) and asDto(string) to add the appropriate suffix. These functions are used inside the templates. Thanks to that, it will be super easy to change the behaviour for generating the class & variables names (add a prefix, get the suffix from another config key or something else).

For example, the entity class declaration looks like this now :

public class <%= asDomain(entityClass) %> implements Serializable { ... }

And a field declaration :

private <%= asDomain(entityClass) %> <%= asDomain(entityInstance) %>;

I'll do the PR very soon.

Any feedback is welcome 馃槈

PR submitted : #8649

PR for jhipster-core : https://github.com/jhipster/jhipster-core/pull/274

closing as PR merged. @mselerin next time please add the fix or close keyword on PR description to autoclose ticket

closing as PR merged. @mselerin next time please add the fix or close keyword on PR description to autoclose ticket

Didn't see that the PR was merged... But, sure thing for next time !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kaidohallik picture kaidohallik  路  3Comments

trajakovic picture trajakovic  路  4Comments

chegola picture chegola  路  4Comments

lsadehaan picture lsadehaan  路  3Comments

Steven-Garcia picture Steven-Garcia  路  3Comments