jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.56k stars 4.02k forks source link

Issue in generating Spring controller. Newly generated controller goes to undefined/web/rest folder instead generating in existing package. #18656

Closed ArihantKumarJain1 closed 2 years ago

ArihantKumarJain1 commented 2 years ago

Rest controller generation issue Welcome to JHipster v7.8.1

The spring-controller Foo is being created. ? Do you want to add an action to your controller? Yes ? What is the name of your action? getData ? What is the HTTP method of your action? GET ? Do you want to add an action to your controller? Yes ? What is the name of your action? insertData ? What is the HTTP method of your action? POST ? Do you want to add an action to your controller? Yes ? What is the name of your action? updateData ? What is the HTTP method of your action? PUT ? Do you want to add an action to your controller? Yes ? What is the name of your action? deleteData ? What is the HTTP method of your action? DELETE ? Do you want to add an action to your controller? Yes ? What is the name of your action? fetchAllData ? What is the HTTP method of your action? GET ? Do you want to add an action to your controller? No adding Get action 'getData' for /api/foo/get-data adding Post action 'insertData' for /api/foo/insert-data adding Put action 'updateData' for /api/foo/update-data adding Delete action 'deleteData' for /api/foo/delete-data adding Get action 'fetchAllData' for /api/foo/fetch-all-data force .yo-rc-global.json force .yo-rc.json create src\main\java\undefined\web\rest\FooResource.java create src\test\java\undefined\web\rest\FooResourceIT.java

No change to package.json was detected. No package manager install will be executed. Congratulations, JHipster execution is complete! Sponsored with ❤️ by @oktadev.

Jhipster Info details. Welcome to JHipster v7.8.1

Welcome to the JHipster Information Sub-Generator

JHipster Version(s)
application-micro@0.0.0 C:\JHipsterTest\ApplicationMicro
`-- generator-jhipster@7.8.1
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "applicationType": "microservice",
    "authenticationType": "jwt",
    "baseName": "ApplicationMicro",
    "blueprints": [],
    "buildTool": "maven",
    "cacheProvider": "hazelcast",
    "creationTimestamp": 1652429665448,
    "databaseType": "sql",
    "devDatabaseType": "mysql",
    "dtoSuffix": "DTO",
    "enableGradleEnterprise": false,
    "enableHibernateCache": true,
    "enableSwaggerCodegen": false,
    "enableTranslation": false,
    "entities": ["FirstEntity"],
    "entitySuffix": "",
    "jhiPrefix": "jhi",
    "jhipsterVersion": "7.8.1",
    "jwtSecretKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
    "languages": ["en", "fr"],
    "lastLiquibaseTimestamp": 1652532155000,
    "messageBroker": false,
    "nativeLanguage": "en",
    "otherModules": [],
    "packageName": "com.micro",
    "pages": [],
    "prodDatabaseType": "mysql",
    "reactive": false,
    "searchEngine": "elasticsearch",
    "serverPort": "8081",
    "serverSideOptions": ["searchEngine:elasticsearch"],
    "serviceDiscoveryType": "no",
    "skipCheckLengthOfIdentifier": false,
    "skipClient": true,
    "skipFakeData": false,
    "skipUserManagement": true,
    "testFrameworks": ["cucumber"],
    "websocket": false,
    "withAdminUi": false
  }
}

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity FirstEntity
service FirstEntity with serviceImpl
search FirstEntity with true
microservice FirstEntity with ApplicationMicro
filter FirstEntity
clientRootFolder FirstEntity with ApplicationMicro

Environment and Tools

openjdk version "17.0.3" 2022-04-19 OpenJDK Runtime Environment Temurin-17.0.3+7 (build 17.0.3+7) OpenJDK 64-Bit Server VM Temurin-17.0.3+7 (build 17.0.3+7, mixed mode, sharing)

git version 2.36.0.windows.1

node: v16.15.0

npm: 8.9.0

No change to package.json was detected. No package manager install will be executed. Congratulations, JHipster execution is complete! Sponsored with ❤️ by @oktadev.

Tcharl commented 2 years ago

Not sure search with true is legit.

dwarakaprasad commented 2 years ago

Hi, I think I found the issue and would like to contribute.

/generators/spring-controller/index.js - This sub-generator does not seem to call the loadDerivedServerConfig() method that builds the configuration.get(PACKAGE_FOLDER);

I tried calling loadDerivedServerConfig() through the _loading() priority and everything seems to be working fine. This is how the spring-service subgenerator is coded.

I have the following questions regarding unit tests, The existing test seems to be using a .yo-rc.json (test/templates/default/.yo-rc.json) which has the packageFolder attribute set, but when a new project is generated using the latest JHipster this attribute is not found,

so my 1st attempt was to remove this attribute from the test and ran them. Around 7 tests failed (mostly due to snapshot mismatch) and I manually fixed all the failing snapshots (all of them were simply copying the .yo-rc.json to the test project for test generation)

My 2nd attempt was to create a new test and manipulate the test/templates/default/.yo-rc.json while copying to remove the packageFolder attribute. This way I don't have to touch any existing test snapshots.

Which approach would you guys prefer?