jhipster / jhipster-core

JHipster Domain Language, used by JHipster UML and JDL-Studio to generate entities
Apache License 2.0
345 stars 116 forks source link

Reserved keyword not consistent between JDL and Sub-Gen entity #290

Closed pascalgrimaud closed 5 years ago

pascalgrimaud commented 5 years ago

Reported by @jdubois When using a reserved Keyword (like group) in a JDL file, we got this error:

➜ jhipster import-jdl jdl.jdl
INFO! Using JHipster version installed globally
INFO! Executing import-jdl jdl.jdl
INFO! Options: from-cli: true
INFO! The JDL is being parsed.
Error: The name 'Group' is a reserved keyword and can not be used as an entity table name for at least one of these applications: blog.
ERROR! Error while parsing applications and entities from the JDL Error: The name 'Group' is a reserved keyword and can not be used as an entity table name for at least one of these applications: blog.
Error: The name 'Group' is a reserved keyword and can not be used as an entity table name for at least one of these applications: blog.
    at jdlObject.forEachEntity.jdlEntity (/home/pgrimaud/projects/jhipster/generator-jhipster/node_modules/jhipster-core/lib/exceptions/business_error_checker.js:98:15)
    at Object.keys.forEach.entityName (/home/pgrimaud/projects/jhipster/generator-jhipster/node_modules/jhipster-core/lib/core/jdl_object.js:127:7)
    at Array.forEach (<anonymous>)
    at JDLObject.forEachEntity (/home/pgrimaud/projects/jhipster/generator-jhipster/node_modules/jhipster-core/lib/core/jdl_object.js:125:32)
    at BusinessErrorChecker.checkForEntityErrors (/home/pgrimaud/projects/jhipster/generator-jhipster/node_modules/jhipster-core/lib/exceptions/business_error_checker.js:81:20)
    at BusinessErrorChecker.checkForErrors (/home/pgrimaud/projects/jhipster/generator-jhipster/node_modules/jhipster-core/lib/exceptions/business_error_checker.js:61:12)
    at checkForErrors (/home/pgrimaud/projects/jhipster/generator-jhipster/node_modules/jhipster-core/lib/jdl/jdl_importer.js:98:16)
    at JDLImporter.import (/home/pgrimaud/projects/jhipster/generator-jhipster/node_modules/jhipster-core/lib/jdl/jdl_importer.js:65:5)
    at JDLProcessor.importJDL (/home/pgrimaud/projects/jhipster/generator-jhipster/cli/import-jdl.js:76:41)
    at JDLProcessor.importJDL (/home/pgrimaud/projects/jhipster/generator-jhipster/cli/import-jdl.js:292:38)

When using directly the sub-generator entity, we got a warning but we can still use the reserved keyword:

➜ jhipster entity Group
INFO! Using JHipster version installed globally
INFO! Executing jhipster:entity Group
INFO! Options: from-cli: true

The entity Group is being created.

WARNING! The table name cannot contain the 'GROUP' reserved keyword, so it will be prefixed with 'jhi_'.
You can specify a different table name in your JDL file or change it in .jhipster/Group.json file and then run again 'jhipster entity Group.'

Generating field #1

? Do you want to add a field to your entity? (Y/n) 

Both generation should be consistent.

Here my JDL:

application {
  config {
    baseName blog,
    applicationType monolith,
    packageName com.jhipster.demo.group,
    prodDatabaseType mysql,
    cacheProvider hazelcast,
    buildTool maven,
    clientFramework react,
    useSass true,
    testFrameworks [protractor]
  }
  entities *
}

entity Group {
    name String required minlength(3),
    handle String required minlength(2)
}

entity GroupEntry {
    title String required,
    content TextBlob required,
    date Instant required
}

entity Tag {
    name String required minlength(2)
}

relationship ManyToOne {
    Group{user(login)} to User,
    GroupEntry{group(name)} to Group
}

relationship ManyToMany {
    GroupEntry{tag(name)} to Tag{entry}
}

paginate GroupEntry, Tag with infinite-scroll
jdubois commented 5 years ago

I'm adding the $100 tag here as I really want the JDL import and the entity sub-generator to work the same

deepu105 commented 5 years ago

The reserved words are actually defined in jh core, so unless there is a logical difference in validation somewhere, this shouldn't have happened

On Tue, 4 Dec 2018, 6:08 pm Julien Dubois <notifications@github.com wrote:

I'm adding the $100 tag here as I really want the JDL import and the entity sub-generator to work the same

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jhipster/jhipster-core/issues/290#issuecomment-444178388, or mute the thread https://github.com/notifications/unsubscribe-auth/ABDlF-ZdSTckrkPZcRpw0vVHxqN7Zt3Bks5u1qwegaJpZM4ZBGaA .

murdos commented 5 years ago

I can look at this issue, since I need to better understand how the generator interacts/uses jh core.

pascalgrimaud commented 5 years ago

thanks @murdos The logic is here: https://github.com/jhipster/generator-jhipster/blob/master/generators/entity/index.js#L301-L307

I think we don't apply it during the import-jdl

jdubois commented 5 years ago

Yes the reserved keywords are good, it's the validation that is different:

MathieuAA commented 5 years ago

Not that bad actually Julien, just an inconsistent choice.Anyway, I'm surprised about all this as nobody seemed to be that annoyed by such a behaviour in the past. I'm working on greatly extending the jdl export and the v4 release right now and I have a lot on my plate, so if anyone wants to adjust the code in this repo, be my guest :)