jhipster / jhipster-core

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

Min/Max constraint should allow decimal for Double types #423

Closed ruddell closed 4 years ago

ruddell commented 4 years ago
Overview of the issue

Adding a Max/Min constraint only allows you to set Integers when using JDL, fields such as Double should allow a . in the constraint.

Using the generator prompts works as expected. JDL exported from app that then fails to import:

entity Foo {
  test Double min(0.001)
}

Error message:

error: Error message:
    MismatchedTokenException: Expecting --> ')' <-- but found --> '.' <--
    at line: 1, column: 31
Error during import-jdl: Error: MismatchedTokenException: Expecting --> ')' <-- but found --> '.' <--
    at line: 1, column: 31
SyntaxError: Error: MismatchedTokenException: Expecting --> ')' <-- but found --> '.' <--
    at line: 1, column: 31
    at callApiMethod (/Users/ruddell/Contrib/generator-jhipster/node_modules/jhipster-core/lib/readers/jdl_reader.js:99:11)
    at parse (/Users/ruddell/Contrib/generator-jhipster/node_modules/jhipster-core/lib/readers/jdl_reader.js:83:10)
    at Object.parseFromContent (/Users/ruddell/Contrib/generator-jhipster/node_modules/jhipster-core/lib/readers/jdl_reader.js:54:10)
    at Object.createImporterFromContent (/Users/ruddell/Contrib/generator-jhipster/node_modules/jhipster-core/lib/jdl/jdl_importer.js:68:29)
    at JDLProcessor.importJDL (/Users/ruddell/Contrib/generator-jhipster/cli/import-jdl.js:304:36)
    at module.exports (/Users/ruddell/Contrib/generator-jhipster/cli/import-jdl.js:478:21)
    at Command.command.allowUnknownOption.description.action.args (/Users/ruddell/Contrib/generator-jhipster/cli/cli.js:71:36)
    at Command.listener (/Users/ruddell/Contrib/generator-jhipster/node_modules/commander/index.js:315:8)
    at emitTwo (events.js:126:13)
    at Command.emit (events.js:214:7)

If I add quotes around 0.001 it gives a different error

SyntaxError: Error: NoViableAltException: Expecting: one of these possible Token sequences:
  1. [INTEGER]
  2. [NAME]
but found: '"0.001"'
Motivation for or Use Case

You should be able to specify a decimal point in the min/max constraint when supported in the field type.

Reproduce the error

jhipster import-jdl --inline "entity Foo { test Double min(0.001) }"

Related issues

Did not find any related issues

Suggest a Fix

Not sure, have not looked into it.

JHipster Version(s)

Master, v6.6.0, v6.5.0

JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "com.mycompany.myapp",
      "nativeLanguage": "en"
    },
    "jhipsterVersion": "6.6.0",
    "applicationType": "monolith",
    "baseName": "mono",
    "packageName": "com.mycompany.myapp",
    "packageFolder": "com/mycompany/myapp",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "cacheProvider": "ehcache",
    "enableHibernateCache": true,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "prodDatabaseType": "mysql",
    "searchEngine": false,
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "maven",
    "enableSwaggerCodegen": false,
    "jwtSecretKey": "bXktc2VjcmV0LXRva2VuLXRvLWNoYW5nZS1pbi1wcm9kdWN0aW9uLWFuZC10by1rZWVwLWluLWEtc2VjdXJlLXBsYWNl",
    "clientFramework": "angularX",
    "useSass": true,
    "clientPackageManager": "npm",
    "testFrameworks": [],
    "jhiPrefix": "jhi",
    "enableTranslation": true,
    "nativeLanguage": "en",
    "languages": ["en"],
    "embeddableLaunchScript": false,
    "clientTheme": "none",
    "creationTimestamp": 1579525596706,
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "otherModules": [],
    "blueprints": []
  }
}

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity Foo {
  test Double min(0.001)
}
MathieuAA commented 4 years ago

To be honest, I didn't even know it was supported by JHipster :)