Skip to content

Commit f4927d1

Browse files
TEC-XXXX: add exportSchemaArray, which puts all the schemas into an array
1 parent a986f66 commit f4927d1

File tree

9 files changed

+27
-2
lines changed

9 files changed

+27
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ $ openapi --help
4444
--exportServices <value> Write services to disk (default: true)
4545
--exportModels <value> Write models to disk (default: true)
4646
--exportSchemas <value> Write schemas to disk (default: false)
47+
--exportSchemaArray <value> Put all schemas into array (default: false)
4748
--indent <value> Indentation options [4, 2, tab] (default: "4")
4849
--postfixServices Service name postfix (default: "Service")
4950
--postfixModels Model name postfix

bin/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const params = program
2020
.option('--exportServices <value>', 'Write services to disk', true)
2121
.option('--exportModels <value>', 'Write models to disk', true)
2222
.option('--exportSchemas <value>', 'Write schemas to disk', false)
23+
.option('--exportSchemaArray <value>', 'Write an array of the schemas to disk', false)
2324
.option('--indent <value>', 'Indentation options [4, 2, tabs]', '4')
2425
.option('--postfixServices <value>', 'Service name postfix', 'Service')
2526
.option('--postfixModels <value>', 'Model name postfix')
@@ -41,6 +42,7 @@ if (OpenAPI) {
4142
exportServices: JSON.parse(params.exportServices) === true,
4243
exportModels: JSON.parse(params.exportModels) === true,
4344
exportSchemas: JSON.parse(params.exportSchemas) === true,
45+
exportSchemaArray: JSON.parse(params.exportSchemaArray) === true,
4446
indent: params.indent,
4547
postfixServices: params.postfixServices,
4648
postfixModels: params.postfixModels,

bin/index.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ describe('bin', () => {
3232
'true',
3333
'--exportSchemas',
3434
'true',
35+
'--exportSchemaArray',
36+
'false',
3537
'--indent',
3638
'4',
3739
'--postfixServices',

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type Options = {
2323
exportServices?: boolean;
2424
exportModels?: boolean;
2525
exportSchemas?: boolean;
26+
exportSchemaArray?: boolean;
2627
indent?: Indent;
2728
postfixServices?: string;
2829
postfixModels?: string;
@@ -44,6 +45,7 @@ export type Options = {
4445
* @param exportServices Generate services
4546
* @param exportModels Generate models
4647
* @param exportSchemas Generate schemas
48+
* @param exportSchemaArray List schemas in an array
4749
* @param indent Indentation options (4, 2 or tab)
4850
* @param postfixServices Service name postfix
4951
* @param postfixModels Model name postfix
@@ -61,6 +63,7 @@ export const generate = async ({
6163
exportServices = true,
6264
exportModels = true,
6365
exportSchemas = false,
66+
exportSchemaArray = false,
6467
indent = Indent.SPACE_4,
6568
postfixServices = 'Service',
6669
postfixModels = '',
@@ -91,6 +94,7 @@ export const generate = async ({
9194
exportServices,
9295
exportModels,
9396
exportSchemas,
97+
exportSchemaArray,
9498
indent,
9599
postfixServices,
96100
postfixModels,
@@ -115,6 +119,7 @@ export const generate = async ({
115119
exportServices,
116120
exportModels,
117121
exportSchemas,
122+
exportSchemaArray,
118123
indent,
119124
postfixServices,
120125
postfixModels,

src/templates/index.hbs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ export type { {{{name}}}{{#if @root.postfixModels}} as {{{name}}}{{{@root.postfi
3535
{{#each models}}
3636
export { ${{{name}}} } from './schemas/${{{name}}}';
3737
{{/each}}
38+
39+
{{#if @root.exportSchemaArray}}
40+
{{#each models}}
41+
import { ${{{name}}} } from './schemas/${{{name}}}';
42+
{{/each}}
43+
44+
export const AllSchemas = [{{#each models}} { ${{{name}}} } ,{{/each}}];
45+
{{/if}}
46+
3847
{{/if}}
3948
{{/if}}
4049
{{#if @root.exportServices}}

src/utils/writeClient.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe('writeClient', () => {
4747
true,
4848
true,
4949
true,
50+
false,
5051
Indent.SPACE_4,
5152
'Service',
5253
'AppClient'

src/utils/writeClient.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { writeClientServices } from './writeClientServices';
2626
* @param exportServices Generate services
2727
* @param exportModels Generate models
2828
* @param exportSchemas Generate schemas
29-
* @param exportSchemas Generate schemas
29+
* @param exportSchemaArray List schemas in an array
3030
* @param indent Indentation options (4, 2 or tab)
3131
* @param postfixServices Service name postfix
3232
* @param postfixModels Model name postfix
@@ -44,6 +44,7 @@ export const writeClient = async (
4444
exportServices: boolean,
4545
exportModels: boolean,
4646
exportSchemas: boolean,
47+
exportSchemaArray: boolean,
4748
indent: Indent,
4849
postfixServices: string,
4950
postfixModels: string,
@@ -110,6 +111,7 @@ export const writeClient = async (
110111
exportServices,
111112
exportModels,
112113
exportSchemas,
114+
exportSchemaArray,
113115
postfixServices,
114116
postfixModels,
115117
clientName

src/utils/writeClientIndex.spec.ts

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

39-
await writeClientIndex(client, templates, '/', true, true, true, true, true, 'Service', '');
39+
await writeClientIndex(client, templates, '/', true, true, true, true, true, false, 'Service', '');
4040

4141
expect(writeFile).toBeCalledWith(resolve('/', '/index.ts'), 'index');
4242
});

src/utils/writeClientIndex.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { sortServicesByName } from './sortServicesByName';
1919
* @param exportServices Generate services
2020
* @param exportModels Generate models
2121
* @param exportSchemas Generate schemas
22+
* @param exportSchemaArray List schemas in an array
2223
* @param postfixServices Service name postfix
2324
* @param postfixModels Model name postfix
2425
* @param clientName Custom client class name
@@ -32,6 +33,7 @@ export const writeClientIndex = async (
3233
exportServices: boolean,
3334
exportModels: boolean,
3435
exportSchemas: boolean,
36+
exportSchemaArray: boolean,
3537
postfixServices: string,
3638
postfixModels: string,
3739
clientName?: string
@@ -41,6 +43,7 @@ export const writeClientIndex = async (
4143
exportServices,
4244
exportModels,
4345
exportSchemas,
46+
exportSchemaArray,
4447
useUnionTypes,
4548
postfixServices,
4649
postfixModels,

0 commit comments

Comments
 (0)