From 0e2ff4d930ded16945b6c1bc7a385e13381595ad Mon Sep 17 00:00:00 2001 From: Jonas Lagoni Date: Tue, 21 May 2024 11:44:02 +0200 Subject: [PATCH] feat: add typescript raw option to the CLI (#2009) --- modelina-cli/src/helpers/typescript.ts | 8 +++++++- modelina-cli/test/integration/generate.test.ts | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/modelina-cli/src/helpers/typescript.ts b/modelina-cli/src/helpers/typescript.ts index bfadb04eab..31daf74103 100644 --- a/modelina-cli/src/helpers/typescript.ts +++ b/modelina-cli/src/helpers/typescript.ts @@ -51,6 +51,11 @@ export const TypeScriptOclifFlags = { required: false, default: false, }), + tsRawPropertyNames: Flags.boolean({ + description: 'Typescript specific, generate the models using raw property names.', + required: false, + default: false, + }), } /** @@ -60,7 +65,7 @@ export const TypeScriptOclifFlags = { * @returns */ export function buildTypeScriptGenerator(flags: any): BuilderReturnType { - const { tsModelType, tsEnumType, tsIncludeComments, tsModuleSystem, tsExportType, tsJsonBinPack, tsMarshalling, tsExampleInstance } = flags; + const { tsModelType, tsEnumType, tsIncludeComments, tsModuleSystem, tsExportType, tsJsonBinPack, tsMarshalling, tsExampleInstance, tsRawPropertyNames } = flags; const presets = []; const options = { marshalling: tsMarshalling, @@ -82,6 +87,7 @@ export function buildTypeScriptGenerator(flags: any): BuilderReturnType { const fileGenerator = new TypeScriptFileGenerator({ modelType: tsModelType as 'class' | 'interface', enumType: tsEnumType as 'enum' | 'union', + rawPropertyNames: tsRawPropertyNames, presets }); const fileOptions = { diff --git a/modelina-cli/test/integration/generate.test.ts b/modelina-cli/test/integration/generate.test.ts index b0fd8a90c8..fdb77c67b6 100644 --- a/modelina-cli/test/integration/generate.test.ts +++ b/modelina-cli/test/integration/generate.test.ts @@ -94,13 +94,23 @@ describe('models', () => { test .stderr() .stdout() - .command([...generalOptions,'typescript', ASYNCAPI_V2_DOCUMENT, '--tsIncludeComments']) + .command([...generalOptions, 'typescript', ASYNCAPI_V2_DOCUMENT, '--tsIncludeComments']) .it('works when tsExampleInstance is set', (ctx, done) => { expect(ctx.stdout).to.contain( 'Successfully generated the following models: ' ); done(); }); + test + .stderr() + .stdout() + .command([...generalOptions, 'typescript', ASYNCAPI_V2_DOCUMENT, '--tsRawPropertyNames']) + .it('works when tsRawPropertyNames is set', (ctx, done) => { + expect(ctx.stdout).to.contain( + 'Successfully generated the following models: ' + ); + done(); + }); }); describe('for JavaScript', () => {