Skip to content

Commit 556ad1e

Browse files
committed
feat: add test-cases
Signed-off-by: warisniz02 <warisniz02@gmail.com>
1 parent 4a61490 commit 556ad1e

6 files changed

Lines changed: 372 additions & 9 deletions

File tree

packages/cli/.yo-rc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,14 @@
987987
"name": "promote-anonymous-schemas",
988988
"hide": false
989989
},
990+
"outDir": {
991+
"description": "Custom output directory for generated files.",
992+
"required": false,
993+
"default": "src",
994+
"type": "String",
995+
"name": "outDir",
996+
"hide": false
997+
},
990998
"config": {
991999
"type": "String",
9921000
"alias": "c",

packages/cli/generators/openapi/index.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,10 @@ module.exports = class OpenApiGenerator extends BaseGenerator {
324324
const originalServiceClassName = c.serviceClassName;
325325

326326
c.fileName = getControllerFileName(c.tag || originalClassName);
327-
if (this.options.prefix) {
327+
if (
328+
this.options.prefix &&
329+
(!this.options.outDir || this.options.outDir === 'src')
330+
) {
328331
c.fileName = this.options.prefix.toLowerCase() + '.' + c.fileName;
329332
}
330333
c.serviceFileName = getServiceFileName(c.tag || originalServiceClassName);
@@ -447,7 +450,28 @@ module.exports = class OpenApiGenerator extends BaseGenerator {
447450
if (debug.enabled) {
448451
debug('Copying artifact to: %s', dest);
449452
}
450-
const source = m.kind === 'class' ? modelSource : typeSource;
453+
let source = m.kind === 'class' ? modelSource : typeSource;
454+
if (
455+
m.kind === 'class' &&
456+
modelFile.includes('-with-relations.model.ts')
457+
) {
458+
const modelSourceWithExportsOnly = this.templatePath(
459+
'src/models/model-template-with-re-exports-only.ts.ejs',
460+
);
461+
source = modelSourceWithExportsOnly;
462+
if (this.options.prefix) m.prefix = this.options.prefix.toLowerCase();
463+
const exportModelFileName = modelFile.split(
464+
'-with-relations.model.ts',
465+
)[0];
466+
let modelName = exportModelFileName;
467+
if (m.prefix) {
468+
const stripped = exportModelFileName.split(m.prefix + '-')[1];
469+
modelName = stripped ?? exportModelFileName;
470+
}
471+
m.exportModelName = utils.toClassName(modelName);
472+
m.exportModelFileName = exportModelFileName + '.model';
473+
if (m.prefix) m.prefix = utils.toClassName(m.prefix);
474+
}
451475
this.copyTemplatedFiles(source, dest, mixinEscapeComment(m));
452476
}
453477
}

packages/cli/test/fixtures/copyright/single-package/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
2-
// Node module: @loopback/cli
3-
// This file is licensed under the MIT License.
4-
// License text available at https://opensource.org/licenses/MIT
1+
// Copyright ACME Inc. 2020,2026. All Rights Reserved.
2+
// Node module: myapp
3+
// This file is licensed under the ISC License.
4+
// License text available at https://www.isc.org/licenses/
55

66
// Use the same set of files (except index.js) in this folder
77
const files = require('../index')(__dirname);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
// Copyright ACME Inc. 2020,2026. All Rights Reserved.
2+
// Node module: myapp
3+
// This file is licensed under the ISC License.
4+
// License text available at https://www.isc.org/licenses/
5+
16
// XYZ
27
exports.xyz = {};
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright IBM Corp. 2020. All Rights Reserved.
1+
// Copyright ACME Inc. 2020,2026. All Rights Reserved.
22
// Node module: myapp
3-
// This file is licensed under the MIT License.
4-
// License text available at https://opensource.org/licenses/MIT
3+
// This file is licensed under the ISC License.
4+
// License text available at https://www.isc.org/licenses/
55

66
export class MyApplication {}

0 commit comments

Comments
 (0)