jhipster / generator-jhipster-ionic

Ionic for JHipster ✨
https://developer.okta.com/blog/2022/05/12/ionic-angular-jhipster
Apache License 2.0
190 stars 49 forks source link

Error when generating the code if the jdl file has an entity with no fields #749

Closed codluca closed 1 year ago

codluca commented 1 year ago

Error when generating the code if the jdl file has an entity with no fields. I wanted to have an entity that groups 3 other entities, so it has only relations and no simple fields.

entity Calendar { }

jhipster-ionic INFO! No custom sharedOptions found within blueprint: generator-jhipster-ionic at /home/lucian/.nvm/versions/node/v16.17.0/lib/node_modules/generator-jhipster-ionic

Welcome to JHipster v7.8.1

 info Using blueprint generator-jhipster-ionic for project-name subgenerator

ERROR! baseName is required Error: baseName is required at default.get sharedData [as sharedData] (/home/lucian/.nvm/versions/node/v16.17.0/lib/node_modules/generator-jhipster-ionic/node_modules/generator-jhipster/generators/generator-base.js:211:15) at default.loadUser (file:///home/lucian/.nvm/versions/node/v16.17.0/lib/node_modules/generator-jhipster-ionic/node_modules/generator-jhipster/generators/bootstrap-application/generator.mjs:86:18) at Object. (/home/lucian/.nvm/versions/node/v16.17.0/lib/node_modules/generator-jhipster-ionic/node_modules/yeoman-generator/lib/index.js:1097:23) at /home/lucian/.nvm/versions/node/v16.17.0/lib/node_modules/generator-jhipster-ionic/node_modules/run-async/index.js:49:25 at new Promise () at /home/lucian/.nvm/versions/node/v16.17.0/lib/node_modules/generator-jhipster-ionic/node_modules/run-async/index.js:26:19 at /home/lucian/.nvm/versions/node/v16.17.0/lib/node_modules/generator-jhipster-ionic/node_modules/yeoman-generator/lib/index.js:1098:9 at new Promise () at default.executeTask (/home/lucian/.nvm/versions/node/v16.17.0/lib/node_modules/generator-jhipster-ionic/node_modules/yeoman-generator/lib/index.js:1069:12) at runLoop.add.once (/home/lucian/.nvm/versions/node/v16.17.0/lib/node_modules/generator-jhipster-ionic/node_modules/yeoman-generator/lib/index.js:1049:14)

mraible commented 1 year ago

@Luca1234 Does this error happen with the main jhipster generator as well?

codluca commented 1 year ago

The main generator seems to be working well.

Now the error with jhipster-ionic seems to be different:

Error running generator app: TypeError: /home/lucian/Documents/jhipster/test-error/ionic/node_modules/generator-jhipster-ionic/generators/ionic/templates/src/app/pages/entities/entity.model.ts.ejs:19 17| limitations under the License. 18| -%> 19| <% 20| const variables = {}; 21| const defaultVariablesValues = {}; 22| let tsKeyType;

Cannot read properties of undefined (reading 'type') TypeError: /home/lucian/Documents/jhipster/test-error/ionic/node_modules/generator-jhipster-ionic/generators/ionic/templates/src/app/pages/entities/entity.model.ts.ejs:19 17| limitations under the License. 18| -%> 19| <% 20| const variables = {}; 21| const defaultVariablesValues = {}; 22| let tsKeyType;

Cannot read properties of undefined (reading 'type') at default.eval ("/home/lucian/Documents/jhipster/test-error/ionic/node_modules/generator-jhipster-ionic/generators/ionic/templates/src/app/pages/entities/_entity.model.ts.ejs":16:16) at _entity.model.ts (/home/lucian/.nvm/versions/node/v16.17.0/lib/node_modules/generator-jhipster-ionic/node_modules/ejs/lib/ejs.js:692:17) at /home/lucian/.nvm/versions/node/v16.17.0/lib/node_modules/generator-jhipster-ionic/node_modules/ejs/lib/ejs.js:258:40 at new Promise () at tryHandleCache (/home/lucian/.nvm/versions/node/v16.17.0/lib/node_modules/generator-jhipster-ionic/node_modules/ejs/lib/ejs.js:256:14) at Object.exports.renderFile (/home/lucian/.nvm/versions/node/v16.17.0/lib/node_modules/generator-jhipster-ionic/node_modules/ejs/lib/ejs.js:489:10) at EditionInterface.processFile (/home/lucian/.nvm/versions/node/v16.17.0/lib/node_modules/generator-jhipster-ionic/node_modules/mem-fs-editor/lib/actions/copy-tpl-async.js:22:20) at EditionInterface.applyProcessingFileFunc (/home/lucian/.nvm/versions/node/v16.17.0/lib/node_modules/generator-jhipster-ionic/node_modules/mem-fs-editor/lib/actions/copy-async.js:14:52) at EditionInterface.exports._copySingleAsync (/home/lucian/.nvm/versions/node/v16.17.0/lib/node_modules/generator-jhipster-ionic/node_modules/mem-fs-editor/lib/actions/copy-async.js:94:50) at EditionInterface.exports.copyAsync (/home/lucian/.nvm/versions/node/v16.17.0/lib/node_modules/generator-jhipster-ionic/node_modules/mem-fs-editor/lib/actions/copy-async.js:50:17) { path: '/home/lucian/Documents/jhipster/test-error/ionic/node_modules/generator-jhipster-ionic/generators/ionic/templates/src/app/pages/entities/_entity.model.ts.ejs' }

This is the sample model I used for test:

application { config { baseName test packageName com.test applicationType monolith buildTool maven authenticationType jwt databaseType sql devDatabaseType mysql prodDatabaseType mysql cacheProvider ehcache clientFramework angular } entities service with serviceClass filter dto with mapstruct paginate * with infinite-scroll }

entity Parent { }

entity Child1 { name String }

relationship OneToMany { Parent{child} to Child1{parent} }

mraible commented 1 year ago

Thanks for providing the steps to reproduce. I'll try to look at this in the next few days.

mraible commented 1 year ago

@Luca1234 I was able to reproduce the issue and attempted to fix it with optional chaining in https://github.com/jhipster/generator-jhipster-ionic/pull/802. This fixes the generation process, but fails when running prettier:

Error: Error parsing file ../ionic4j/cypress/e2e/entities/parent/parent.cy.ts: SyntaxError: Identifier expected. (79:42)
  77 |         cy.authenticatedRequest({
  78 |           method: 'DELETE',
> 79 |           url: `${parentApiUrl}/${parent.}`,
     |                                          ^
  80 |         }).then(() => {
  81 |           parent = undefined;
  82 |         });

I also tried your JDL with regular JHipster, and it does generate but does not compile:

[INFO] Error: src/main/webapp/app/entities/parent/update/parent-form.service.ts:46:7 - error TS2322: Type '{}' is not assignable to type 'IParent | NewParent'.
[INFO]
[INFO] 46       return {};
[INFO]          ~~~~~~~~~~
mraible commented 1 year ago

I'm closing this issue since an empty entity doesn't compile with regular JHipster. Please don't hesitate to re-open this issue if it's fixed in the main generator.