tangled
alpha
login
or
join now
mokkenstorm.dev
/
openapi-ts
0
fork
atom
fork of hey-api/openapi-ts because I need some additional things
0
fork
atom
overview
issues
pulls
pipelines
add local option for zod datetimes
Björn Henriksson
7 months ago
991f0e01
e2507632
+76
-36
7 changed files
expand all
collapse all
unified
split
examples
openapi-ts-angular
angular.json
openapi-ts-angular-common
angular.json
packages
openapi-ts
src
plugins
zod
config.ts
mini
plugin.ts
types.d.ts
v3
plugin.ts
v4
plugin.ts
+3
examples/openapi-ts-angular-common/angular.json
···
88
88
}
89
89
}
90
90
}
91
91
+
},
92
92
+
"cli": {
93
93
+
"analytics": false
91
94
}
92
95
}
+3
examples/openapi-ts-angular/angular.json
···
88
88
}
89
89
}
90
90
}
91
91
+
},
92
92
+
"cli": {
93
93
+
"analytics": false
91
94
}
92
95
}
+1
packages/openapi-ts/src/plugins/zod/config.ts
···
67
67
68
68
plugin.config.dates = context.valueToObject({
69
69
defaultValue: {
70
70
+
local: false,
70
71
offset: false,
71
72
},
72
73
value: plugin.config.dates,
+17
-12
packages/openapi-ts/src/plugins/zod/mini/plugin.ts
···
536
536
}),
537
537
});
538
538
539
539
+
const dateTimeOptions: { key: string; value: boolean }[] = [];
540
540
+
541
541
+
if (plugin.config.dates.offset) {
542
542
+
dateTimeOptions.push({ key: 'offset', value: true });
543
543
+
}
544
544
+
if (plugin.config.dates.local) {
545
545
+
dateTimeOptions.push({ key: 'local', value: true });
546
546
+
}
547
547
+
539
548
if (schema.format) {
540
549
switch (schema.format) {
541
550
case 'date':
···
558
567
}),
559
568
name: identifiers.datetime,
560
569
}),
561
561
-
parameters: plugin.config.dates.offset
562
562
-
? [
563
563
-
tsc.objectExpression({
564
564
-
obj: [
565
565
-
{
566
566
-
key: 'offset',
567
567
-
value: true,
568
568
-
},
569
569
-
],
570
570
-
}),
571
571
-
]
572
572
-
: [],
570
570
+
parameters:
571
571
+
dateTimeOptions.length > 0
572
572
+
? [
573
573
+
tsc.objectExpression({
574
574
+
obj: dateTimeOptions,
575
575
+
}),
576
576
+
]
577
577
+
: [],
573
578
});
574
579
break;
575
580
case 'email':
+18
packages/openapi-ts/src/plugins/zod/types.d.ts
···
34
34
*/
35
35
dates?: {
36
36
/**
37
37
+
* Whether to allow unqualified (timezone-less) datetimes:
38
38
+
*
39
39
+
* When enabled, Zod will accept datetime strings without timezone information.
40
40
+
* When disabled, Zod will require timezone information in datetime strings.
41
41
+
*
42
42
+
* @default false
43
43
+
*/
44
44
+
local?: boolean;
45
45
+
/**
37
46
* Whether to include timezone offset information when handling dates.
38
47
*
39
48
* When enabled, date strings will preserve timezone information.
···
365
374
* date validation features.
366
375
*/
367
376
dates: {
377
377
+
/**
378
378
+
* Whether to allow unqualified (timezone-less) datetimes:
379
379
+
*
380
380
+
* When enabled, Zod will accept datetime strings without timezone information.
381
381
+
* When disabled, Zod will require timezone information in datetime strings.
382
382
+
*
383
383
+
* @default false
384
384
+
*/
385
385
+
local: boolean;
368
386
/**
369
387
* Whether to include timezone offset information when handling dates.
370
388
*
+17
-12
packages/openapi-ts/src/plugins/zod/v3/plugin.ts
···
449
449
}),
450
450
});
451
451
452
452
+
const dateTimeOptions: { key: string; value: boolean }[] = [];
453
453
+
454
454
+
if (plugin.config.dates.offset) {
455
455
+
dateTimeOptions.push({ key: 'offset', value: true });
456
456
+
}
457
457
+
if (plugin.config.dates.local) {
458
458
+
dateTimeOptions.push({ key: 'local', value: true });
459
459
+
}
460
460
+
452
461
if (schema.format) {
453
462
switch (schema.format) {
454
463
case 'date':
···
465
474
expression: stringExpression,
466
475
name: identifiers.datetime,
467
476
}),
468
468
-
parameters: plugin.config.dates.offset
469
469
-
? [
470
470
-
tsc.objectExpression({
471
471
-
obj: [
472
472
-
{
473
473
-
key: 'offset',
474
474
-
value: true,
475
475
-
},
476
476
-
],
477
477
-
}),
478
478
-
]
479
479
-
: [],
477
477
+
parameters:
478
478
+
dateTimeOptions.length > 0
479
479
+
? [
480
480
+
tsc.objectExpression({
481
481
+
obj: dateTimeOptions,
482
482
+
}),
483
483
+
]
484
484
+
: [],
480
485
});
481
486
break;
482
487
case 'email':
+17
-12
packages/openapi-ts/src/plugins/zod/v4/plugin.ts
···
515
515
}),
516
516
});
517
517
518
518
+
const dateTimeOptions: { key: string; value: boolean }[] = [];
519
519
+
520
520
+
if (plugin.config.dates.offset) {
521
521
+
dateTimeOptions.push({ key: 'offset', value: true });
522
522
+
}
523
523
+
if (plugin.config.dates.local) {
524
524
+
dateTimeOptions.push({ key: 'local', value: true });
525
525
+
}
526
526
+
518
527
if (schema.format) {
519
528
switch (schema.format) {
520
529
case 'date':
···
537
546
}),
538
547
name: identifiers.datetime,
539
548
}),
540
540
-
parameters: plugin.config.dates.offset
541
541
-
? [
542
542
-
tsc.objectExpression({
543
543
-
obj: [
544
544
-
{
545
545
-
key: 'offset',
546
546
-
value: true,
547
547
-
},
548
548
-
],
549
549
-
}),
550
550
-
]
551
551
-
: [],
549
549
+
parameters:
550
550
+
dateTimeOptions.length > 0
551
551
+
? [
552
552
+
tsc.objectExpression({
553
553
+
obj: dateTimeOptions,
554
554
+
}),
555
555
+
]
556
556
+
: [],
552
557
});
553
558
break;
554
559
case 'email':