Skip to content

Commit 1a27282

Browse files
committed
add new property "useDateType" for command line
1 parent d237343 commit 1a27282

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

bin/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ program
1919
.option('--exportServices <value>', 'Write services to disk', true)
2020
.option('--exportModels <value>', 'Write models to disk', true)
2121
.option('--exportSchemas <value>', 'Write schemas to disk', false)
22+
.option('--useDateType', 'Output Date instead of string for the format "date-time" in the models')
2223
.parse(process.argv);
2324

2425
const OpenAPI = require(path.resolve(__dirname, '../dist/index.js'));
@@ -34,6 +35,7 @@ if (OpenAPI) {
3435
exportServices: JSON.parse(program.exportServices) === true,
3536
exportModels: JSON.parse(program.exportModels) === true,
3637
exportSchemas: JSON.parse(program.exportSchemas) === true,
38+
useDateType: program.useDateType,
3739
})
3840
.then(() => {
3941
process.exit(0);

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface Options {
2424
exportModels?: boolean;
2525
exportSchemas?: boolean;
2626
write?: boolean;
27+
useDateType?: boolean;
2728
}
2829

2930
/**
@@ -52,6 +53,7 @@ export async function generate({
5253
exportModels = true,
5354
exportSchemas = false,
5455
write = true,
56+
useDateType = false,
5557
}: Options): Promise<void> {
5658
const openApi = isString(input) ? await getOpenApiSpec(input) : input;
5759
const openApiVersion = getOpenApiVersion(openApi);
@@ -62,15 +64,15 @@ export async function generate({
6264
const client = parseV2(openApi);
6365
const clientFinal = postProcessClient(client);
6466
if (!write) break;
65-
await writeClient(clientFinal, templates, output, httpClient, useOptions, useUnionTypes, exportCore, exportServices, exportModels, exportSchemas);
67+
await writeClient(clientFinal, templates, output, httpClient, useOptions, useUnionTypes, exportCore, exportServices, exportModels, exportSchemas, useDateType);
6668
break;
6769
}
6870

6971
case OpenApiVersion.V3: {
7072
const client = parseV3(openApi);
7173
const clientFinal = postProcessClient(client);
7274
if (!write) break;
73-
await writeClient(clientFinal, templates, output, httpClient, useOptions, useUnionTypes, exportCore, exportServices, exportModels, exportSchemas);
75+
await writeClient(clientFinal, templates, output, httpClient, useOptions, useUnionTypes, exportCore, exportServices, exportModels, exportSchemas, useDateType);
7476
break;
7577
}
7678
}

src/utils/writeClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export async function writeClient(
3434
exportCore: boolean,
3535
exportServices: boolean,
3636
exportModels: boolean,
37-
exportSchemas: boolean
37+
exportSchemas: boolean,
38+
useDateType: boolean
3839
): Promise<void> {
3940
const outputPath = path.resolve(process.cwd(), output);
4041
const outputPathCore = path.resolve(outputPath, 'core');

0 commit comments

Comments
 (0)