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

added useLegacyEnums option #144

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const params = program
.option('--request <value>', 'Path to custom request file')
.option('--write', 'Write files to disk? (used for testing)')
.option('--no-write', 'Skip writing files to disk (used for testing)')
.option('--useLegacyEnums', 'Generate Typescript enum definitions')
.parse(process.argv)
.opts();

Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const getConfig = async (userConfig: UserConfig, dependencies: Dependencies) =>
useDateType = false,
useOptions = true,
write = true,
useLegacyEnums = false,
} = userConfig;

if (!input) {
Expand Down Expand Up @@ -158,6 +159,7 @@ const getConfig = async (userConfig: UserConfig, dependencies: Dependencies) =>
serviceResponse,
useDateType,
useOptions,
useLegacyEnums,
write,
};

Expand Down
1 change: 1 addition & 0 deletions src/openApi/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('parse', () => {
postfixServices: '',
serviceResponse: 'body',
useDateType: false,
useLegacyEnums: false,
useOptions: true,
write: false,
};
Expand Down
1 change: 1 addition & 0 deletions src/openApi/v2/parser/__tests__/getServices.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('getServices', () => {
useDateType: false,
useOptions: true,
write: false,
useLegacyEnums: false,
};
const services = getServices(
{
Expand Down
1 change: 1 addition & 0 deletions src/openApi/v3/parser/__tests__/getServices.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('getServices', () => {
postfixServices: 'Service',
serviceResponse: 'body',
useDateType: false,
useLegacyEnums: false,
useOptions: true,
write: false,
};
Expand Down
19 changes: 19 additions & 0 deletions src/templates/partials/exportEnum.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,28 @@
{{/if}}
*/
{{/ifdef}}

mlankamp marked this conversation as resolved.
Show resolved Hide resolved
{{#if @root.$config.useLegacyEnums}}
export enum {{{name}}} {
{{#each enum}}
{{#if x-enum-description}}
/**
* {{{escapeComment x-enum-description}}}
*/
{{else if description}}
/**
* {{{escapeComment description}}}
*/
{{/if}}
{{{enumKey value x-enum-varname}}} = {{{enumValue value}}},
{{/each}}
}
{{else}}
export type {{{name}}} = {{{enumUnionType enum}}};
{{/if}}

{{/if}}

mlankamp marked this conversation as resolved.
Show resolved Hide resolved
{{#if @root.$config.enums}}
Copy link
Collaborator

@jordanshatford jordanshatford Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add back one newline above this (below {{/if}}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mlankamp Please add back one newline, run npm run test:update and then add the changeset as mentioned above, I cannot modify this PR. Then I will merge and release

export const {{{enumName name }}} = {
{{#each enum}}
Expand Down
5 changes: 5 additions & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export interface UserConfig {
* @default true
*/
useOptions?: boolean;
/**
* Generate Typescript enum definitions
* @default false
*/
useLegacyEnums?: boolean;
/**
* Write the files to disk (true or false)
* @default true
Expand Down
2 changes: 2 additions & 0 deletions src/utils/__tests__/handlebars.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('registerHandlebarHelpers', () => {
postfixServices: '',
serviceResponse: 'body',
useDateType: false,
useLegacyEnums: false,
useOptions: false,
write: true,
},
Expand Down Expand Up @@ -75,6 +76,7 @@ describe('registerHandlebarTemplates', () => {
postfixServices: '',
serviceResponse: 'body',
useDateType: false,
useLegacyEnums: false,
useOptions: false,
write: true,
},
Expand Down
1 change: 1 addition & 0 deletions src/utils/write/__tests__/class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('writeClientClass', () => {
postfixServices: '',
serviceResponse: 'body',
useDateType: false,
useLegacyEnums: false,
useOptions: true,
write: true,
});
Expand Down
1 change: 1 addition & 0 deletions src/utils/write/__tests__/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('writeClient', () => {
postfixServices: 'Service',
serviceResponse: 'body',
useDateType: false,
useLegacyEnums: false,
useOptions: false,
write: true,
});
Expand Down
3 changes: 3 additions & 0 deletions src/utils/write/__tests__/core.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('writeClientCore', () => {
postfixServices: '',
serviceResponse: 'body',
useDateType: false,
useLegacyEnums: false,
useOptions: true,
write: true,
};
Expand Down Expand Up @@ -79,6 +80,7 @@ describe('writeClientCore', () => {
postfixServices: '',
serviceResponse: 'body',
useDateType: false,
useLegacyEnums: false,
useOptions: true,
write: true,
};
Expand Down Expand Up @@ -119,6 +121,7 @@ describe('writeClientCore', () => {
postfixServices: '',
serviceResponse: 'body',
useDateType: false,
useLegacyEnums: false,
useOptions: true,
write: true,
};
Expand Down
1 change: 1 addition & 0 deletions src/utils/write/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('writeClientIndex', () => {
postfixServices: 'Service',
serviceResponse: 'body',
useDateType: false,
useLegacyEnums: false,
useOptions: true,
write: true,
});
Expand Down
1 change: 1 addition & 0 deletions src/utils/write/__tests__/models.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('writeClientModels', () => {
postfixServices: '',
serviceResponse: 'body',
useDateType: false,
useLegacyEnums: false,
useOptions: true,
write: true,
});
Expand Down
1 change: 1 addition & 0 deletions src/utils/write/__tests__/schemas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('writeClientSchemas', () => {
postfixServices: '',
serviceResponse: 'body',
useDateType: false,
useLegacyEnums: false,
useOptions: true,
write: true,
});
Expand Down
1 change: 1 addition & 0 deletions src/utils/write/__tests__/services.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('writeClientServices', () => {
postfixServices: 'Service',
serviceResponse: 'body',
useDateType: false,
useLegacyEnums: false,
useOptions: false,
write: true,
});
Expand Down
Loading