diff --git a/generators/jdl/__snapshots__/generator.spec.ts.snap b/generators/jdl/__snapshots__/generator.spec.ts.snap index ccbaba5aa2e1..fce89863f29e 100644 --- a/generators/jdl/__snapshots__/generator.spec.ts.snap +++ b/generators/jdl/__snapshots__/generator.spec.ts.snap @@ -231,6 +231,42 @@ Options: " `; +exports[`generator - jdl with a gateway generating json should generate expected config 1`] = ` +{ + ".jhipster/Bar.json": { + "contents": "{ + "annotations": {}, + "applications": [ + "gatewayApp" + ], + "fields": [], + "microserviceName": "ms", + "name": "Bar", + "relationships": [] +} +", + "stateCleared": "modified", + }, + ".yo-rc.json": { + "contents": "{ + "generator-jhipster": { + "applicationIndex": 0, + "applicationType": "gateway", + "applications": { + "ms": {} + }, + "baseName": "gatewayApp", + "entities": [ + "Bar" + ] + } +} +", + "stateCleared": "modified", + }, +} +`; + exports[`generator - jdl with a microservices stack generating json should generate expected config 1`] = ` { "gatewayApp/.jhipster/Bar.json": { diff --git a/generators/jdl/generator.spec.ts b/generators/jdl/generator.spec.ts index 241f5786c527..a71c02785299 100644 --- a/generators/jdl/generator.spec.ts +++ b/generators/jdl/generator.spec.ts @@ -472,4 +472,20 @@ entity Bar }); }); }); + describe('with a gateway', () => { + const jdl = ` +application { config { baseName gatewayApp applicationType gateway } entities * } +microservice Bar with ms +entity Bar +`; + describe('generating json', () => { + before(async () => { + await helpers.runJHipster(GENERATOR_JDL).withMockedGenerators(mockedGenerators).withOptions({ inline: jdl, jsonOnly: true }); + }); + + it('should generate expected config', () => { + expect(runResult.getSnapshot()).toMatchSnapshot(); + }); + }); + }); }); diff --git a/generators/jdl/internal/application.ts b/generators/jdl/internal/application.ts index 3cd25be727ee..711f7352ad29 100644 --- a/generators/jdl/internal/application.ts +++ b/generators/jdl/internal/application.ts @@ -47,7 +47,7 @@ export const customizeForMicroservices = (applicationsWithEntities: Record 0) { gateway.config.applications = Object.fromEntries( relatedBaseNames.map(baseName => { - const appConfig = applicationsWithEntities[baseName].config; + const appConfig = applicationsWithEntities[baseName]?.config ?? {}; appConfig.gatewayServerPort = appConfig.gatewayServerPort || gatewayServerPort; const { clientFramework, serverPort, applicationIndex, devServerPort } = appConfig; return [baseName, { clientFramework, serverPort, applicationIndex, devServerPort }];