Skip to content

Commit

Permalink
feat: add typescript raw option to the CLI (#2009)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored May 21, 2024
1 parent 35c4781 commit 0e2ff4d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 7 additions & 1 deletion modelina-cli/src/helpers/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
}

/**
Expand All @@ -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,
Expand All @@ -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 = {
Expand Down
12 changes: 11 additions & 1 deletion modelina-cli/test/integration/generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 0e2ff4d

Please sign in to comment.