From 5246b05eb7d6b0c996c8faa8fa43d5056da53e09 Mon Sep 17 00:00:00 2001 From: Jonas Lagoni Date: Tue, 21 May 2024 09:57:48 +0200 Subject: [PATCH 1/2] add implementation from cli --- 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..abd35c368a 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', './test/fixtures/specification.yml', '--tsRawPropertyNames']) + .it('works when tsRawPropertyNames is set', (ctx, done) => { + expect(ctx.stdout).to.contain( + 'Successfully generated the following models: ' + ); + done(); + }); }); describe('for JavaScript', () => { From adb0ae3667c4a3e2ca8fccecfa983ac32c4e196b Mon Sep 17 00:00:00 2001 From: Jonas Lagoni Date: Tue, 21 May 2024 10:34:31 +0200 Subject: [PATCH 2/2] fix test --- modelina-cli/test/integration/generate.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modelina-cli/test/integration/generate.test.ts b/modelina-cli/test/integration/generate.test.ts index abd35c368a..fdb77c67b6 100644 --- a/modelina-cli/test/integration/generate.test.ts +++ b/modelina-cli/test/integration/generate.test.ts @@ -104,7 +104,7 @@ describe('models', () => { test .stderr() .stdout() - .command([...generalOptions,'typescript', './test/fixtures/specification.yml', '--tsRawPropertyNames']) + .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: '