Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add typescript raw option to the CLI #2009

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading