Skip to content

Commit 504928f

Browse files
committed
feat: Add postfixModels to generate function & rename postfix to postfixServices
1 parent 4d56304 commit 504928f

File tree

8 files changed

+153
-129
lines changed

8 files changed

+153
-129
lines changed

src/index.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ export type Options = {
2424
exportModels?: boolean;
2525
exportSchemas?: boolean;
2626
indent?: Indent;
27+
/**
28+
* @deprecated use postfixServices instead
29+
*/
2730
postfix?: string;
31+
postfixServices?: string;
32+
postfixModels?: string;
2833
request?: string;
2934
write?: boolean;
3035
};
@@ -44,7 +49,9 @@ export type Options = {
4449
* @param exportModels Generate models
4550
* @param exportSchemas Generate schemas
4651
* @param indent Indentation options (4, 2 or tab)
47-
* @param postfix Service name postfix
52+
* @param postfix Deprecated: Param to support old parameter postfix, use postfixServices instead
53+
* @param postfixServices Service name postfix
54+
* @param postfixModels Model name postfix
4855
* @param request Path to custom request file
4956
* @param write Write the files to disk (true or false)
5057
*/
@@ -60,7 +67,9 @@ export const generate = async ({
6067
exportModels = true,
6168
exportSchemas = false,
6269
indent = Indent.SPACE_4,
63-
postfix = 'Service',
70+
postfix,
71+
postfixServices = 'Service',
72+
postfixModels = '',
6473
request,
6574
write = true,
6675
}: Options): Promise<void> => {
@@ -89,7 +98,8 @@ export const generate = async ({
8998
exportModels,
9099
exportSchemas,
91100
indent,
92-
postfix,
101+
postfix ?? postfixServices,
102+
postfixModels,
93103
clientName,
94104
request
95105
);
@@ -112,7 +122,8 @@ export const generate = async ({
112122
exportModels,
113123
exportSchemas,
114124
indent,
115-
postfix,
125+
postfix ?? postfixServices,
126+
postfixModels,
116127
clientName,
117128
request
118129
);

src/templates/index.hbs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ export type { OpenAPIConfig } from './core/OpenAPI';
1818

1919
{{#each models}}
2020
{{#if @root.useUnionTypes}}
21-
export type { {{{name}}} } from './models/{{{name}}}';
21+
export type { {{{name}}} as {{{name}}}{{{@root.postfixModels}}} } from './models/{{{name}}}';
2222
{{else if enum}}
23-
export { {{{name}}} } from './models/{{{name}}}';
23+
export { {{{name}}} as {{{name}}}{{{@root.postfixModels}}} } from './models/{{{name}}}';
2424
{{else if enums}}
25-
export { {{{name}}} } from './models/{{{name}}}';
25+
export { {{{name}}} as {{{name}}}{{{@root.postfixModels}}} } from './models/{{{name}}}';
2626
{{else}}
27-
export type { {{{name}}} } from './models/{{{name}}}';
27+
export type { {{{name}}} as {{{name}}}{{{@root.postfixModels}}} } from './models/{{{name}}}';
2828
{{/if}}
2929
{{/each}}
3030
{{/if}}
@@ -41,7 +41,7 @@ export { ${{{name}}} } from './schemas/${{{name}}}';
4141
{{#if services}}
4242

4343
{{#each services}}
44-
export { {{{name}}}{{{@root.postfix}}} } from './services/{{{name}}}{{{@root.postfix}}}';
44+
export { {{{name}}}{{{@root.postfixServices}}} } from './services/{{{name}}}{{{@root.postfixServices}}}';
4545
{{/each}}
4646
{{/if}}
4747
{{/if}}

src/utils/writeClient.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import { writeClientServices } from './writeClientServices';
2828
* @param exportSchemas Generate schemas
2929
* @param exportSchemas Generate schemas
3030
* @param indent Indentation options (4, 2 or tab)
31-
* @param postfix Service name postfix
31+
* @param postfixServices Service name postfix
32+
* @param postfixModels Model name postfix
3233
* @param clientName Custom client class name
3334
* @param request Path to custom request file
3435
*/
@@ -44,7 +45,8 @@ export const writeClient = async (
4445
exportModels: boolean,
4546
exportSchemas: boolean,
4647
indent: Indent,
47-
postfix: string,
48+
postfixServices: string,
49+
postfixModels: string,
4850
clientName?: string,
4951
request?: string
5052
): Promise<void> => {
@@ -75,7 +77,7 @@ export const writeClient = async (
7577
useUnionTypes,
7678
useOptions,
7779
indent,
78-
postfix,
80+
postfixServices,
7981
clientName
8082
);
8183
}
@@ -94,7 +96,7 @@ export const writeClient = async (
9496

9597
if (isDefined(clientName)) {
9698
await mkdir(outputPath);
97-
await writeClientClass(client, templates, outputPath, httpClient, clientName, indent, postfix);
99+
await writeClientClass(client, templates, outputPath, httpClient, clientName, indent, postfixServices);
98100
}
99101

100102
if (exportCore || exportServices || exportSchemas || exportModels) {
@@ -108,7 +110,8 @@ export const writeClient = async (
108110
exportServices,
109111
exportModels,
110112
exportSchemas,
111-
postfix,
113+
postfixServices,
114+
postfixModels,
112115
clientName
113116
);
114117
}

src/utils/writeClientIndex.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('writeClientIndex', () => {
3434
},
3535
};
3636

37-
await writeClientIndex(client, templates, '/', true, true, true, true, true, 'Service');
37+
await writeClientIndex(client, templates, '/', true, true, true, true, true, 'Service', '');
3838

3939
expect(writeFile).toBeCalledWith('/index.ts', 'index');
4040
});

src/utils/writeClientIndex.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import { sortServicesByName } from './sortServicesByName';
1919
* @param exportServices Generate services
2020
* @param exportModels Generate models
2121
* @param exportSchemas Generate schemas
22-
* @param postfix Service name postfix
22+
* @param postfixServices Service name postfix
23+
* @param postfixModels Model name postfix
2324
* @param clientName Custom client class name
2425
*/
2526
export const writeClientIndex = async (
@@ -31,7 +32,8 @@ export const writeClientIndex = async (
3132
exportServices: boolean,
3233
exportModels: boolean,
3334
exportSchemas: boolean,
34-
postfix: string,
35+
postfixServices: string,
36+
postfixModels: string,
3537
clientName?: string
3638
): Promise<void> => {
3739
const templateResult = templates.index({
@@ -40,7 +42,8 @@ export const writeClientIndex = async (
4042
exportModels,
4143
exportSchemas,
4244
useUnionTypes,
43-
postfix,
45+
postfixServices,
46+
postfixModels,
4447
clientName,
4548
server: client.server,
4649
version: client.version,

0 commit comments

Comments
 (0)