fork of hey-api/openapi-ts because I need some additional things

Merge pull request #2991 from hey-api/refactor/dsl-type-nodes-5

refactor: zod plugin use dsl

authored by

Lubos and committed by
GitHub
7b9a4d05 62282112

+2325 -3709
+3 -3
dev/openapi-ts.config.ts
··· 40 40 // 'circular.yaml', 41 41 // 'dutchie.json', 42 42 // 'invalid', 43 - // 'full.yaml', 43 + 'full.yaml', 44 44 // 'openai.yaml', 45 45 // 'opencode.yaml', 46 - 'pagination-ref.yaml', 46 + // 'pagination-ref.yaml', 47 47 // 'sdk-instance.yaml', 48 48 // 'string-with-format.yaml', 49 49 // 'transformers.json', ··· 431 431 { 432 432 // case: 'snake_case', 433 433 // comments: false, 434 - compatibilityVersion: 'mini', 434 + compatibilityVersion: 4, 435 435 dates: { 436 436 // local: true, 437 437 // offset: true,
+1 -4
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/string-with-format/zod.gen.ts
··· 3 3 import { z } from 'zod'; 4 4 5 5 export const zFoo = z.object({ 6 - foo: z.optional(z.array(z.union([ 7 - z.string(), 8 - z.string() 9 - ]))) 6 + foo: z.optional(z.array(z.union([z.string(), z.string()]))) 10 7 });
+149 -212
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/webhooks/zod.gen.ts
··· 55 55 56 56 export const zSessionRecordingStartedWebhookRequest = z.object({ 57 57 body: z.optional(z.object({ 58 - event: z.enum([ 59 - 'session.recording_started' 60 - ]), 58 + event: z.enum(["session.recording_started"]), 61 59 event_ts: z.coerce.bigint(), 62 60 payload: z.object({ 63 61 account_id: z.string(), ··· 80 78 81 79 export const zSessionRecordingResumedWebhookRequest = z.object({ 82 80 body: z.optional(z.object({ 83 - event: z.enum([ 84 - 'session.recording_resumed' 85 - ]), 81 + event: z.enum(["session.recording_resumed"]), 86 82 event_ts: z.coerce.bigint(), 87 83 payload: z.object({ 88 84 account_id: z.string(), ··· 105 101 106 102 export const zSessionLiveStreamingStoppedWebhookRequest = z.object({ 107 103 body: z.optional(z.object({ 108 - event: z.enum([ 109 - 'session.live_streaming_stopped' 110 - ]), 104 + event: z.enum(["session.live_streaming_stopped"]), 111 105 event_ts: z.coerce.bigint(), 112 106 payload: z.object({ 113 107 account_id: z.string(), ··· 119 113 start_time: z.iso.datetime(), 120 114 live_streaming: z.object({ 121 115 service: z.enum([ 122 - 'Facebook', 123 - 'Workplace_by_Facebook', 124 - 'YouTube', 125 - 'Custom_Live_Streaming_Service' 116 + "Facebook", 117 + "Workplace_by_Facebook", 118 + "YouTube", 119 + "Custom_Live_Streaming_Service" 126 120 ]), 127 121 custom_live_streaming_settings: z.object({ 128 122 stream_url: z.string(), ··· 141 135 142 136 export const zSessionStreamIngestionStoppedWebhookRequest = z.object({ 143 137 body: z.optional(z.object({ 144 - event: z.enum([ 145 - 'session.stream_ingestion_stopped' 146 - ]), 138 + event: z.enum(["session.stream_ingestion_stopped"]), 147 139 event_ts: z.coerce.bigint(), 148 140 payload: z.object({ 149 141 account_id: z.string(), ··· 193 185 194 186 export const zSessionAlertWebhookRequest = z.object({ 195 187 body: z.optional(z.object({ 196 - event: z.enum([ 197 - 'session.alert' 198 - ]), 188 + event: z.enum(["session.alert"]), 199 189 event_ts: z.coerce.bigint(), 200 190 payload: z.object({ 201 191 account_id: z.string(), ··· 205 195 session_name: z.string(), 206 196 session_key: z.optional(z.string()), 207 197 issues: z.array(z.enum([ 208 - 'Unstable audio quality', 209 - 'Unstable video quality', 210 - 'Unstable screen share quality', 211 - 'High CPU occupation', 212 - 'Call Reconnection' 198 + "Unstable audio quality", 199 + "Unstable video quality", 200 + "Unstable screen share quality", 201 + "High CPU occupation", 202 + "Call Reconnection" 213 203 ])) 214 204 }) 215 205 }) ··· 220 210 221 211 export const zSessionSharingEndedWebhookRequest = z.object({ 222 212 body: z.optional(z.object({ 223 - event: z.enum([ 224 - 'session.sharing_ended' 225 - ]), 213 + event: z.enum(["session.sharing_ended"]), 226 214 event_ts: z.coerce.bigint(), 227 215 payload: z.object({ 228 216 account_id: z.string(), ··· 237 225 user_key: z.optional(z.string()), 238 226 sharing_details: z.object({ 239 227 content: z.enum([ 240 - 'application', 241 - 'whiteboard', 242 - 'desktop', 243 - 'unknown' 228 + "application", 229 + "whiteboard", 230 + "desktop", 231 + "unknown" 244 232 ]), 245 233 date_time: z.iso.datetime() 246 234 }) ··· 254 242 255 243 export const zSessionRecordingPausedWebhookRequest = z.object({ 256 244 body: z.optional(z.object({ 257 - event: z.enum([ 258 - 'session.recording_paused' 259 - ]), 245 + event: z.enum(["session.recording_paused"]), 260 246 event_ts: z.coerce.bigint(), 261 247 payload: z.object({ 262 248 account_id: z.string(), ··· 279 265 280 266 export const zSessionEndedWebhookRequest = z.object({ 281 267 body: z.optional(z.object({ 282 - event: z.enum([ 283 - 'session.ended' 284 - ]), 268 + event: z.enum(["session.ended"]), 285 269 event_ts: z.coerce.bigint(), 286 270 payload: z.object({ 287 271 account_id: z.string(), ··· 301 285 302 286 export const zSessionStartedWebhookRequest = z.object({ 303 287 body: z.optional(z.object({ 304 - event: z.enum([ 305 - 'session.started' 306 - ]), 288 + event: z.enum(["session.started"]), 307 289 event_ts: z.coerce.bigint(), 308 290 payload: z.object({ 309 291 account_id: z.string(), ··· 322 304 323 305 export const zSessionStreamIngestionUnbindWebhookRequest = z.object({ 324 306 body: z.optional(z.object({ 325 - event: z.enum([ 326 - 'session.stream_ingestion_unbind' 327 - ]), 307 + event: z.enum(["session.stream_ingestion_unbind"]), 328 308 event_ts: z.coerce.bigint(), 329 309 payload: z.object({ 330 310 account_id: z.string(), ··· 349 329 350 330 export const zSessionLiveStreamingStartedWebhookRequest = z.object({ 351 331 body: z.optional(z.object({ 352 - event: z.enum([ 353 - 'session.live_streaming_started' 354 - ]), 332 + event: z.enum(["session.live_streaming_started"]), 355 333 event_ts: z.coerce.bigint(), 356 334 payload: z.object({ 357 335 account_id: z.string(), ··· 363 341 start_time: z.iso.datetime(), 364 342 live_streaming: z.object({ 365 343 service: z.enum([ 366 - 'Facebook', 367 - 'Workplace_by_Facebook', 368 - 'YouTube', 369 - 'Custom_Live_Streaming_Service' 344 + "Facebook", 345 + "Workplace_by_Facebook", 346 + "YouTube", 347 + "Custom_Live_Streaming_Service" 370 348 ]), 371 349 custom_live_streaming_settings: z.object({ 372 350 stream_url: z.string(), ··· 436 414 437 415 export const zSessionUserLeftWebhookRequest = z.object({ 438 416 body: z.optional(z.object({ 439 - event: z.enum([ 440 - 'session.user_left' 441 - ]), 417 + event: z.enum(["session.user_left"]), 442 418 event_ts: z.coerce.bigint(), 443 419 payload: z.object({ 444 420 account_id: z.string(), ··· 465 441 466 442 export const zSessionSharingStartedWebhookRequest = z.object({ 467 443 body: z.optional(z.object({ 468 - event: z.enum([ 469 - 'session.sharing_started' 470 - ]), 444 + event: z.enum(["session.sharing_started"]), 471 445 event_ts: z.coerce.bigint(), 472 446 payload: z.object({ 473 447 account_id: z.string(), ··· 482 456 user_key: z.optional(z.string()), 483 457 sharing_details: z.object({ 484 458 content: z.enum([ 485 - 'application', 486 - 'whiteboard', 487 - 'desktop', 488 - 'unknown' 459 + "application", 460 + "whiteboard", 461 + "desktop", 462 + "unknown" 489 463 ]), 490 464 date_time: z.iso.datetime() 491 465 }) ··· 522 496 523 497 export const zSessionRecordingTranscriptCompletedWebhookRequest = z.object({ 524 498 body: z.optional(z.object({ 525 - event: z.enum([ 526 - 'session.recording_transcript_completed' 527 - ]), 499 + event: z.enum(["session.recording_transcript_completed"]), 528 500 event_ts: z.coerce.bigint(), 529 501 download_token: z.string(), 530 502 payload: z.object({ ··· 542 514 file_name: z.optional(z.string()), 543 515 file_path: z.optional(z.string()), 544 516 file_type: z.optional(z.enum([ 545 - 'MP4', 546 - 'M4A', 547 - 'CHAT', 548 - 'TRANSCRIPT', 549 - 'CSV', 550 - 'CC', 551 - 'TB', 552 - 'CHAT_MESSAGE', 553 - 'TIMELINE' 517 + "MP4", 518 + "M4A", 519 + "CHAT", 520 + "TRANSCRIPT", 521 + "CSV", 522 + "CC", 523 + "TB", 524 + "CHAT_MESSAGE", 525 + "TIMELINE" 554 526 ])), 555 527 file_size: z.optional(z.number()), 556 528 file_extension: z.optional(z.enum([ 557 - 'MP4', 558 - 'M4A', 559 - 'TXT', 560 - 'VTT', 561 - 'CSV', 562 - 'JSON', 563 - 'JPG' 529 + "MP4", 530 + "M4A", 531 + "TXT", 532 + "VTT", 533 + "CSV", 534 + "JSON", 535 + "JPG" 564 536 ])), 565 537 download_url: z.optional(z.string()), 566 - status: z.optional(z.enum([ 567 - 'completed' 568 - ])), 538 + status: z.optional(z.enum(["completed"])), 569 539 recording_type: z.optional(z.enum([ 570 - 'shared_screen_with_speaker_view(CC)', 571 - 'shared_screen_with_speaker_view', 572 - 'shared_screen_with_gallery_view', 573 - 'gallery_view', 574 - 'shared_screen', 575 - 'audio_only', 576 - 'audio_transcript', 577 - 'chat_file', 578 - 'active_speaker', 579 - 'host_video', 580 - 'audio_only_each_participant', 581 - 'cc_transcript', 582 - 'closed_caption', 583 - 'poll', 584 - 'timeline', 585 - 'thumbnail', 586 - 'chat_message' 540 + "shared_screen_with_speaker_view(CC)", 541 + "shared_screen_with_speaker_view", 542 + "shared_screen_with_gallery_view", 543 + "gallery_view", 544 + "shared_screen", 545 + "audio_only", 546 + "audio_transcript", 547 + "chat_file", 548 + "active_speaker", 549 + "host_video", 550 + "audio_only_each_participant", 551 + "cc_transcript", 552 + "closed_caption", 553 + "poll", 554 + "timeline", 555 + "thumbnail", 556 + "chat_message" 587 557 ])) 588 558 })) 589 559 }) ··· 595 565 596 566 export const zSessionRecordingDeletedWebhookRequest = z.object({ 597 567 body: z.optional(z.object({ 598 - event: z.enum([ 599 - 'session.recording_deleted' 600 - ]), 568 + event: z.enum(["session.recording_deleted"]), 601 569 event_ts: z.coerce.bigint(), 602 570 payload: z.object({ 603 571 account_id: z.string(), ··· 658 626 659 627 export const zSessionRecordingCompletedWebhookRequest = z.object({ 660 628 body: z.optional(z.object({ 661 - event: z.enum([ 662 - 'session.recording_completed' 663 - ]), 629 + event: z.enum(["session.recording_completed"]), 664 630 event_ts: z.coerce.bigint(), 665 631 download_token: z.string(), 666 632 payload: z.object({ ··· 678 644 file_name: z.optional(z.string()), 679 645 file_path: z.optional(z.string()), 680 646 file_type: z.optional(z.enum([ 681 - 'MP4', 682 - 'M4A', 683 - 'CHAT', 684 - 'TRANSCRIPT', 685 - 'CSV', 686 - 'CC', 687 - 'TB', 688 - 'CHAT_MESSAGE' 647 + "MP4", 648 + "M4A", 649 + "CHAT", 650 + "TRANSCRIPT", 651 + "CSV", 652 + "CC", 653 + "TB", 654 + "CHAT_MESSAGE" 689 655 ])), 690 656 file_size: z.optional(z.number()), 691 657 file_extension: z.optional(z.enum([ 692 - 'MP4', 693 - 'M4A', 694 - 'TXT', 695 - 'VTT', 696 - 'CSV', 697 - 'JSON', 698 - 'JPG' 658 + "MP4", 659 + "M4A", 660 + "TXT", 661 + "VTT", 662 + "CSV", 663 + "JSON", 664 + "JPG" 699 665 ])), 700 666 download_url: z.optional(z.string()), 701 - status: z.optional(z.enum([ 702 - 'completed' 703 - ])), 667 + status: z.optional(z.enum(["completed"])), 704 668 recording_type: z.optional(z.enum([ 705 - 'shared_screen_with_speaker_view(CC)', 706 - 'shared_screen_with_speaker_view', 707 - 'shared_screen_with_gallery_view', 708 - 'gallery_view', 709 - 'shared_screen', 710 - 'audio_only', 711 - 'audio_transcript', 712 - 'chat_file', 713 - 'active_speaker', 714 - 'host_video', 715 - 'audio_only_each_participant', 716 - 'cc_transcript', 717 - 'closed_caption', 718 - 'poll', 719 - 'timeline', 720 - 'thumbnail', 721 - 'chat_message' 669 + "shared_screen_with_speaker_view(CC)", 670 + "shared_screen_with_speaker_view", 671 + "shared_screen_with_gallery_view", 672 + "gallery_view", 673 + "shared_screen", 674 + "audio_only", 675 + "audio_transcript", 676 + "chat_file", 677 + "active_speaker", 678 + "host_video", 679 + "audio_only_each_participant", 680 + "cc_transcript", 681 + "closed_caption", 682 + "poll", 683 + "timeline", 684 + "thumbnail", 685 + "chat_message" 722 686 ])) 723 687 })), 724 688 participant_audio_files: z.optional(z.array(z.object({ ··· 728 692 file_name: z.optional(z.string()), 729 693 file_path: z.optional(z.string()), 730 694 file_type: z.optional(z.enum([ 731 - 'MP4', 732 - 'M4A', 733 - 'CHAT', 734 - 'TRANSCRIPT', 735 - 'CSV', 736 - 'CC', 737 - 'TB', 738 - 'CHAT_MESSAGE' 695 + "MP4", 696 + "M4A", 697 + "CHAT", 698 + "TRANSCRIPT", 699 + "CSV", 700 + "CC", 701 + "TB", 702 + "CHAT_MESSAGE" 739 703 ])), 740 704 file_size: z.optional(z.number()), 741 705 file_extension: z.optional(z.enum([ 742 - 'MP4', 743 - 'M4A', 744 - 'TXT', 745 - 'VTT', 746 - 'CSV', 747 - 'JSON', 748 - 'JPG' 706 + "MP4", 707 + "M4A", 708 + "TXT", 709 + "VTT", 710 + "CSV", 711 + "JSON", 712 + "JPG" 749 713 ])), 750 714 download_url: z.optional(z.string()), 751 - status: z.optional(z.enum([ 752 - 'completed' 753 - ])), 715 + status: z.optional(z.enum(["completed"])), 754 716 recording_type: z.optional(z.enum([ 755 - 'shared_screen_with_speaker_view(CC)', 756 - 'shared_screen_with_speaker_view', 757 - 'shared_screen_with_gallery_view', 758 - 'gallery_view', 759 - 'shared_screen', 760 - 'audio_only', 761 - 'audio_transcript', 762 - 'chat_file', 763 - 'active_speaker', 764 - 'host_video', 765 - 'audio_only_each_participant', 766 - 'cc_transcript', 767 - 'closed_caption', 768 - 'poll', 769 - 'timeline', 770 - 'thumbnail', 771 - 'chat_message' 717 + "shared_screen_with_speaker_view(CC)", 718 + "shared_screen_with_speaker_view", 719 + "shared_screen_with_gallery_view", 720 + "gallery_view", 721 + "shared_screen", 722 + "audio_only", 723 + "audio_transcript", 724 + "chat_file", 725 + "active_speaker", 726 + "host_video", 727 + "audio_only_each_participant", 728 + "cc_transcript", 729 + "closed_caption", 730 + "poll", 731 + "timeline", 732 + "thumbnail", 733 + "chat_message" 772 734 ])), 773 735 user_id: z.optional(z.string()), 774 736 user_key: z.optional(z.string()) ··· 779 741 recording_end: z.optional(z.string()), 780 742 file_name: z.optional(z.string()), 781 743 file_path: z.optional(z.string()), 782 - file_type: z.optional(z.enum([ 783 - 'MP4' 784 - ])), 744 + file_type: z.optional(z.enum(["MP4"])), 785 745 file_size: z.optional(z.number()), 786 - file_extension: z.optional(z.enum([ 787 - 'MP4' 788 - ])), 746 + file_extension: z.optional(z.enum(["MP4"])), 789 747 download_url: z.optional(z.string()), 790 - status: z.optional(z.enum([ 791 - 'completed' 792 - ])), 793 - recording_type: z.optional(z.enum([ 794 - 'individual_user', 795 - 'individual_shared_screen' 796 - ])), 748 + status: z.optional(z.enum(["completed"])), 749 + recording_type: z.optional(z.enum(["individual_user", "individual_shared_screen"])), 797 750 user_id: z.optional(z.string()), 798 751 user_key: z.optional(z.string()) 799 752 }))) ··· 806 759 807 760 export const zSessionRecordingTranscriptFailedWebhookRequest = z.object({ 808 761 body: z.optional(z.object({ 809 - event: z.enum([ 810 - 'session.recording_transcript_failed' 811 - ]), 762 + event: z.enum(["session.recording_transcript_failed"]), 812 763 event_ts: z.coerce.bigint(), 813 764 payload: z.object({ 814 765 account_id: z.string(), ··· 827 778 828 779 export const zSessionRecordingTrashedWebhookRequest = z.object({ 829 780 body: z.optional(z.object({ 830 - event: z.enum([ 831 - 'session.recording_trashed' 832 - ]), 781 + event: z.enum(["session.recording_trashed"]), 833 782 event_ts: z.coerce.bigint(), 834 783 payload: z.object({ 835 784 account_id: z.string(), ··· 850 799 851 800 export const zSessionUserJoinedWebhookRequest = z.object({ 852 801 body: z.optional(z.object({ 853 - event: z.enum([ 854 - 'session.user_joined' 855 - ]), 802 + event: z.enum(["session.user_joined"]), 856 803 event_ts: z.coerce.bigint(), 857 804 payload: z.object({ 858 805 account_id: z.string(), ··· 878 825 879 826 export const zSessionStreamIngestionStartedWebhookRequest = z.object({ 880 827 body: z.optional(z.object({ 881 - event: z.enum([ 882 - 'session.stream_ingestion_started' 883 - ]), 828 + event: z.enum(["session.stream_ingestion_started"]), 884 829 event_ts: z.coerce.bigint(), 885 830 payload: z.object({ 886 831 account_id: z.string(), ··· 905 850 906 851 export const zSessionStreamIngestionConnectedWebhookRequest = z.object({ 907 852 body: z.optional(z.object({ 908 - event: z.enum([ 909 - 'session.stream_ingestion_connected' 910 - ]), 853 + event: z.enum(["session.stream_ingestion_connected"]), 911 854 event_ts: z.coerce.bigint(), 912 855 payload: z.object({ 913 856 account_id: z.string(), ··· 932 875 933 876 export const zSessionStreamIngestionDisconnectedWebhookRequest = z.object({ 934 877 body: z.optional(z.object({ 935 - event: z.enum([ 936 - 'session.stream_ingestion_disconnected' 937 - ]), 878 + event: z.enum(["session.stream_ingestion_disconnected"]), 938 879 event_ts: z.coerce.bigint(), 939 880 payload: z.object({ 940 881 account_id: z.string(), ··· 959 900 960 901 export const zSessionRecordingRecoveredWebhookRequest = z.object({ 961 902 body: z.optional(z.object({ 962 - event: z.enum([ 963 - 'session.recording_recovered' 964 - ]), 903 + event: z.enum(["session.recording_recovered"]), 965 904 event_ts: z.coerce.bigint(), 966 905 payload: z.object({ 967 906 account_id: z.string(), ··· 1059 998 1060 999 export const zSessionRecordingStoppedWebhookRequest = z.object({ 1061 1000 body: z.optional(z.object({ 1062 - event: z.enum([ 1063 - 'session.recording_stopped' 1064 - ]), 1001 + event: z.enum(["session.recording_stopped"]), 1065 1002 event_ts: z.coerce.bigint(), 1066 1003 payload: z.object({ 1067 1004 account_id: z.string(),
+38 -40
packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts
··· 74 74 * This is a simple enum with strings 75 75 */ 76 76 export const zEnumWithStrings = z.enum([ 77 - 'Success', 78 - 'Warning', 79 - 'Error', 77 + "Success", 78 + "Warning", 79 + "Error", 80 80 "'Single Quote'", 81 - '"Double Quotes"', 82 - 'Non-ascii: øæåôöØÆÅÔÖ字符串' 81 + "\"Double Quotes\"", 82 + "Non-ascii: øæåôöØÆÅÔÖ字符串" 83 83 ]); 84 84 85 85 /** ··· 232 232 */ 233 233 export const zModelWithEnum = z.object({ 234 234 test: z.optional(z.enum([ 235 - 'Success', 236 - 'Warning', 237 - 'Error', 238 - 'ØÆÅ字符串' 235 + "Success", 236 + "Warning", 237 + "Error", 238 + "ØÆÅ字符串" 239 239 ])), 240 240 statusCode: z.optional(z.enum([ 241 - '100', 242 - '200 FOO', 243 - '300 FOO_BAR', 244 - '400 foo-bar', 245 - '500 foo.bar', 246 - '600 foo&bar' 241 + "100", 242 + "200 FOO", 243 + "300 FOO_BAR", 244 + "400 foo-bar", 245 + "500 foo.bar", 246 + "600 foo&bar" 247 247 ])), 248 248 bool: z.optional(z.literal(true)) 249 249 }); ··· 260 260 */ 261 261 export const zModelWithNestedEnums = z.object({ 262 262 dictionaryWithEnum: z.optional(z.record(z.string(), z.enum([ 263 - 'Success', 264 - 'Warning', 265 - 'Error' 263 + "Success", 264 + "Warning", 265 + "Error" 266 266 ]))), 267 267 dictionaryWithEnumFromDescription: z.optional(z.record(z.string(), z.int())), 268 268 arrayWithEnum: z.optional(z.array(z.enum([ 269 - 'Success', 270 - 'Warning', 271 - 'Error' 269 + "Success", 270 + "Warning", 271 + "Error" 272 272 ]))), 273 273 arrayWithDescription: z.optional(z.array(z.int())) 274 274 }); ··· 566 566 body: z.optional(z.never()), 567 567 path: z.optional(z.never()), 568 568 query: z.object({ 569 - parameterString: z._default(z.string(), 'Hello World!'), 569 + parameterString: z._default(z.string(), "Hello World!"), 570 570 parameterNumber: z._default(z.number(), 123), 571 571 parameterBoolean: z._default(z.boolean(), true), 572 572 parameterEnum: z.enum([ 573 - 'Success', 574 - 'Warning', 575 - 'Error' 573 + "Success", 574 + "Warning", 575 + "Error" 576 576 ]), 577 577 parameterModel: z._default(z.object({ 578 578 prop: z.optional(z.string()) 579 - }), { 580 - prop: 'Hello World!' 581 - }) 579 + }), { prop: "Hello World!" }) 582 580 }) 583 581 }); 584 582 ··· 586 584 body: z.optional(z.never()), 587 585 path: z.optional(z.never()), 588 586 query: z.optional(z.object({ 589 - parameterString: z._default(z.optional(z.string()), 'Hello World!'), 587 + parameterString: z._default(z.optional(z.string()), "Hello World!"), 590 588 parameterNumber: z._default(z.optional(z.number()), 123), 591 589 parameterBoolean: z._default(z.optional(z.boolean()), true), 592 590 parameterEnum: z.optional(z.enum([ 593 - 'Success', 594 - 'Warning', 595 - 'Error' 591 + "Success", 592 + "Warning", 593 + "Error" 596 594 ])) 597 595 })) 598 596 }); ··· 601 599 body: z.optional(z.never()), 602 600 path: z.optional(z.never()), 603 601 query: z.object({ 604 - parameterOptionalStringWithDefault: z._default(z.optional(z.string()), 'Hello World!'), 605 - parameterOptionalStringWithEmptyDefault: z._default(z.optional(z.string()), ''), 602 + parameterOptionalStringWithDefault: z._default(z.optional(z.string()), "Hello World!"), 603 + parameterOptionalStringWithEmptyDefault: z._default(z.optional(z.string()), ""), 606 604 parameterOptionalStringWithNoDefault: z.optional(z.string()), 607 - parameterStringWithDefault: z._default(z.string(), 'Hello World!'), 608 - parameterStringWithEmptyDefault: z._default(z.string(), ''), 605 + parameterStringWithDefault: z._default(z.string(), "Hello World!"), 606 + parameterStringWithEmptyDefault: z._default(z.string(), ""), 609 607 parameterStringWithNoDefault: z.string(), 610 608 parameterStringNullableWithNoDefault: z.optional(z.union([ 611 609 z.string(), ··· 728 726 })), 729 727 query: z.object({ 730 728 parameterNumber: z._default(z.number(), 123), 731 - parameterString: z._default(z.string(), 'default'), 729 + parameterString: z._default(z.string(), "default"), 732 730 parameterBoolean: z._default(z.boolean(), true), 733 731 parameterArray: z.array(z.string()), 734 732 parameterDictionary: z.record(z.string(), z.unknown()), 735 733 parameterEnum: z.enum([ 736 - 'Success', 737 - 'Warning', 738 - 'Error' 734 + "Success", 735 + "Warning", 736 + "Error" 739 737 ]) 740 738 }) 741 739 });
+38 -40
packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts
··· 74 74 * This is a simple enum with strings 75 75 */ 76 76 export const zEnumWithStrings = z.enum([ 77 - 'Success', 78 - 'Warning', 79 - 'Error', 77 + "Success", 78 + "Warning", 79 + "Error", 80 80 "'Single Quote'", 81 - '"Double Quotes"', 82 - 'Non-ascii: øæåôöØÆÅÔÖ字符串' 81 + "\"Double Quotes\"", 82 + "Non-ascii: øæåôöØÆÅÔÖ字符串" 83 83 ]); 84 84 85 85 /** ··· 232 232 */ 233 233 export const zModelWithEnum = z.object({ 234 234 test: z.enum([ 235 - 'Success', 236 - 'Warning', 237 - 'Error', 238 - 'ØÆÅ字符串' 235 + "Success", 236 + "Warning", 237 + "Error", 238 + "ØÆÅ字符串" 239 239 ]).optional(), 240 240 statusCode: z.enum([ 241 - '100', 242 - '200 FOO', 243 - '300 FOO_BAR', 244 - '400 foo-bar', 245 - '500 foo.bar', 246 - '600 foo&bar' 241 + "100", 242 + "200 FOO", 243 + "300 FOO_BAR", 244 + "400 foo-bar", 245 + "500 foo.bar", 246 + "600 foo&bar" 247 247 ]).optional(), 248 248 bool: z.literal(true).optional() 249 249 }); ··· 260 260 */ 261 261 export const zModelWithNestedEnums = z.object({ 262 262 dictionaryWithEnum: z.record(z.enum([ 263 - 'Success', 264 - 'Warning', 265 - 'Error' 263 + "Success", 264 + "Warning", 265 + "Error" 266 266 ])).optional(), 267 267 dictionaryWithEnumFromDescription: z.record(z.number().int()).optional(), 268 268 arrayWithEnum: z.array(z.enum([ 269 - 'Success', 270 - 'Warning', 271 - 'Error' 269 + "Success", 270 + "Warning", 271 + "Error" 272 272 ])).optional(), 273 273 arrayWithDescription: z.array(z.number().int()).optional() 274 274 }); ··· 564 564 body: z.never().optional(), 565 565 path: z.never().optional(), 566 566 query: z.object({ 567 - parameterString: z.string().default('Hello World!'), 567 + parameterString: z.string().default("Hello World!"), 568 568 parameterNumber: z.number().default(123), 569 569 parameterBoolean: z.boolean().default(true), 570 570 parameterEnum: z.enum([ 571 - 'Success', 572 - 'Warning', 573 - 'Error' 571 + "Success", 572 + "Warning", 573 + "Error" 574 574 ]), 575 575 parameterModel: z.object({ 576 576 prop: z.string().optional() 577 - }).default({ 578 - prop: 'Hello World!' 579 - }) 577 + }).default({ prop: "Hello World!" }) 580 578 }) 581 579 }); 582 580 ··· 584 582 body: z.never().optional(), 585 583 path: z.never().optional(), 586 584 query: z.object({ 587 - parameterString: z.string().optional().default('Hello World!'), 585 + parameterString: z.string().optional().default("Hello World!"), 588 586 parameterNumber: z.number().optional().default(123), 589 587 parameterBoolean: z.boolean().optional().default(true), 590 588 parameterEnum: z.enum([ 591 - 'Success', 592 - 'Warning', 593 - 'Error' 589 + "Success", 590 + "Warning", 591 + "Error" 594 592 ]).optional() 595 593 }).optional() 596 594 }); ··· 599 597 body: z.never().optional(), 600 598 path: z.never().optional(), 601 599 query: z.object({ 602 - parameterOptionalStringWithDefault: z.string().optional().default('Hello World!'), 603 - parameterOptionalStringWithEmptyDefault: z.string().optional().default(''), 600 + parameterOptionalStringWithDefault: z.string().optional().default("Hello World!"), 601 + parameterOptionalStringWithEmptyDefault: z.string().optional().default(""), 604 602 parameterOptionalStringWithNoDefault: z.string().optional(), 605 - parameterStringWithDefault: z.string().default('Hello World!'), 606 - parameterStringWithEmptyDefault: z.string().default(''), 603 + parameterStringWithDefault: z.string().default("Hello World!"), 604 + parameterStringWithEmptyDefault: z.string().default(""), 607 605 parameterStringWithNoDefault: z.string(), 608 606 parameterStringNullableWithNoDefault: z.union([ 609 607 z.string(), ··· 726 724 }).optional(), 727 725 query: z.object({ 728 726 parameterNumber: z.number().default(123), 729 - parameterString: z.string().default('default'), 727 + parameterString: z.string().default("default"), 730 728 parameterBoolean: z.boolean().default(true), 731 729 parameterArray: z.array(z.string()), 732 730 parameterDictionary: z.record(z.unknown()), 733 731 parameterEnum: z.enum([ 734 - 'Success', 735 - 'Warning', 736 - 'Error' 732 + "Success", 733 + "Warning", 734 + "Error" 737 735 ]) 738 736 }) 739 737 });
+38 -40
packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts
··· 74 74 * This is a simple enum with strings 75 75 */ 76 76 export const zEnumWithStrings = z.enum([ 77 - 'Success', 78 - 'Warning', 79 - 'Error', 77 + "Success", 78 + "Warning", 79 + "Error", 80 80 "'Single Quote'", 81 - '"Double Quotes"', 82 - 'Non-ascii: øæåôöØÆÅÔÖ字符串' 81 + "\"Double Quotes\"", 82 + "Non-ascii: øæåôöØÆÅÔÖ字符串" 83 83 ]); 84 84 85 85 /** ··· 232 232 */ 233 233 export const zModelWithEnum = z.object({ 234 234 test: z.optional(z.enum([ 235 - 'Success', 236 - 'Warning', 237 - 'Error', 238 - 'ØÆÅ字符串' 235 + "Success", 236 + "Warning", 237 + "Error", 238 + "ØÆÅ字符串" 239 239 ])), 240 240 statusCode: z.optional(z.enum([ 241 - '100', 242 - '200 FOO', 243 - '300 FOO_BAR', 244 - '400 foo-bar', 245 - '500 foo.bar', 246 - '600 foo&bar' 241 + "100", 242 + "200 FOO", 243 + "300 FOO_BAR", 244 + "400 foo-bar", 245 + "500 foo.bar", 246 + "600 foo&bar" 247 247 ])), 248 248 bool: z.optional(z.literal(true)) 249 249 }); ··· 260 260 */ 261 261 export const zModelWithNestedEnums = z.object({ 262 262 dictionaryWithEnum: z.optional(z.record(z.string(), z.enum([ 263 - 'Success', 264 - 'Warning', 265 - 'Error' 263 + "Success", 264 + "Warning", 265 + "Error" 266 266 ]))), 267 267 dictionaryWithEnumFromDescription: z.optional(z.record(z.string(), z.int())), 268 268 arrayWithEnum: z.optional(z.array(z.enum([ 269 - 'Success', 270 - 'Warning', 271 - 'Error' 269 + "Success", 270 + "Warning", 271 + "Error" 272 272 ]))), 273 273 arrayWithDescription: z.optional(z.array(z.int())) 274 274 }); ··· 566 566 body: z.optional(z.never()), 567 567 path: z.optional(z.never()), 568 568 query: z.object({ 569 - parameterString: z.string().default('Hello World!'), 569 + parameterString: z.string().default("Hello World!"), 570 570 parameterNumber: z.number().default(123), 571 571 parameterBoolean: z.boolean().default(true), 572 572 parameterEnum: z.enum([ 573 - 'Success', 574 - 'Warning', 575 - 'Error' 573 + "Success", 574 + "Warning", 575 + "Error" 576 576 ]), 577 577 parameterModel: z.object({ 578 578 prop: z.optional(z.string()) 579 - }).default({ 580 - prop: 'Hello World!' 581 - }) 579 + }).default({ prop: "Hello World!" }) 582 580 }) 583 581 }); 584 582 ··· 586 584 body: z.optional(z.never()), 587 585 path: z.optional(z.never()), 588 586 query: z.optional(z.object({ 589 - parameterString: z.optional(z.string()).default('Hello World!'), 587 + parameterString: z.optional(z.string()).default("Hello World!"), 590 588 parameterNumber: z.optional(z.number()).default(123), 591 589 parameterBoolean: z.optional(z.boolean()).default(true), 592 590 parameterEnum: z.optional(z.enum([ 593 - 'Success', 594 - 'Warning', 595 - 'Error' 591 + "Success", 592 + "Warning", 593 + "Error" 596 594 ])) 597 595 })) 598 596 }); ··· 601 599 body: z.optional(z.never()), 602 600 path: z.optional(z.never()), 603 601 query: z.object({ 604 - parameterOptionalStringWithDefault: z.optional(z.string()).default('Hello World!'), 605 - parameterOptionalStringWithEmptyDefault: z.optional(z.string()).default(''), 602 + parameterOptionalStringWithDefault: z.optional(z.string()).default("Hello World!"), 603 + parameterOptionalStringWithEmptyDefault: z.optional(z.string()).default(""), 606 604 parameterOptionalStringWithNoDefault: z.optional(z.string()), 607 - parameterStringWithDefault: z.string().default('Hello World!'), 608 - parameterStringWithEmptyDefault: z.string().default(''), 605 + parameterStringWithDefault: z.string().default("Hello World!"), 606 + parameterStringWithEmptyDefault: z.string().default(""), 609 607 parameterStringWithNoDefault: z.string(), 610 608 parameterStringNullableWithNoDefault: z.optional(z.union([ 611 609 z.string(), ··· 728 726 })), 729 727 query: z.object({ 730 728 parameterNumber: z.number().default(123), 731 - parameterString: z.string().default('default'), 729 + parameterString: z.string().default("default"), 732 730 parameterBoolean: z.boolean().default(true), 733 731 parameterArray: z.array(z.string()), 734 732 parameterDictionary: z.record(z.string(), z.unknown()), 735 733 parameterEnum: z.enum([ 736 - 'Success', 737 - 'Warning', 738 - 'Error' 734 + "Success", 735 + "Warning", 736 + "Error" 739 737 ]) 740 738 }) 741 739 });
+85 -142
packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts
··· 90 90 * This is a simple enum with strings 91 91 */ 92 92 export const zEnumWithStrings = z.enum([ 93 - 'Success', 94 - 'Warning', 95 - 'Error', 93 + "Success", 94 + "Warning", 95 + "Error", 96 96 "'Single Quote'", 97 - '"Double Quotes"', 98 - 'Non-ascii: øæåôöØÆÅÔÖ字符串' 97 + "\"Double Quotes\"", 98 + "Non-ascii: øæåôöØÆÅÔÖ字符串" 99 99 ]); 100 100 101 101 export const zEnumWithReplacedCharacters = z.union([ 102 102 z.literal("'Single Quote'"), 103 - z.literal('"Double Quotes"'), 104 - z.literal('øæåôöØÆÅÔÖ字符串'), 103 + z.literal("\"Double Quotes\""), 104 + z.literal("øæåôöØÆÅÔÖ字符串"), 105 105 z.literal(3.1), 106 - z.literal('') 106 + z.literal("") 107 107 ]); 108 108 109 109 /** ··· 160 160 /** 161 161 * This is a simple array with strings 162 162 */ 163 - export const zArrayWithStrings = z._default(z.array(z.string()), ['test']); 163 + export const zArrayWithStrings = z._default(z.array(z.string()), ["test"]); 164 164 165 165 /** 166 166 * This is a simple array with properties ··· 173 173 /** 174 174 * This is a simple array with any of properties 175 175 */ 176 - export const zArrayWithAnyOfProperties = z.array(z.union([ 177 - z.object({ 178 - foo: z._default(z.optional(z.string()), 'test') 179 - }), 180 - z.object({ 176 + export const zArrayWithAnyOfProperties = z.array(z.union([z.object({ 177 + foo: z._default(z.optional(z.string()), "test") 178 + }), z.object({ 181 179 bar: z.optional(z.string()) 182 - }) 183 - ])); 180 + })])); 184 181 185 182 export const zAnyOfAnyAndNull = z.object({ 186 183 data: z.optional(z.unknown()) ··· 190 187 * This is a simple array with any of properties 191 188 */ 192 189 export const zAnyOfArrays = z.object({ 193 - results: z.optional(z.array(z.union([ 194 - z.object({ 190 + results: z.optional(z.array(z.union([z.object({ 195 191 foo: z.optional(z.string()) 196 - }), 197 - z.object({ 192 + }), z.object({ 198 193 bar: z.optional(z.string()) 199 - }) 200 - ]))) 194 + })]))) 201 195 }); 202 196 203 197 /** ··· 302 296 z.null() 303 297 ]), 304 298 'foo_bar-enum': z.optional(z.enum([ 305 - 'Success', 306 - 'Warning', 307 - 'Error', 308 - 'ØÆÅ字符串' 299 + "Success", 300 + "Warning", 301 + "Error", 302 + "ØÆÅ字符串" 309 303 ])) 310 304 }); 311 305 ··· 314 308 */ 315 309 export const zModelWithEnum = z.object({ 316 310 'foo_bar-enum': z.optional(z.enum([ 317 - 'Success', 318 - 'Warning', 319 - 'Error', 320 - 'ØÆÅ字符串' 311 + "Success", 312 + "Warning", 313 + "Error", 314 + "ØÆÅ字符串" 321 315 ])), 322 316 statusCode: z.optional(z.enum([ 323 - '100', 324 - '200 FOO', 325 - '300 FOO_BAR', 326 - '400 foo-bar', 327 - '500 foo.bar', 328 - '600 foo&bar' 317 + "100", 318 + "200 FOO", 319 + "300 FOO_BAR", 320 + "400 foo-bar", 321 + "500 foo.bar", 322 + "600 foo&bar" 329 323 ])), 330 324 bool: z.optional(z.literal(true)) 331 325 }); ··· 334 328 * This is a model with one enum with escaped name 335 329 */ 336 330 export const zModelWithEnumWithHyphen = z.object({ 337 - 'foo-bar-baz-qux': z.optional(z.enum([ 338 - '3.0' 339 - ])) 331 + 'foo-bar-baz-qux': z.optional(z.enum(["3.0"])) 340 332 }); 341 333 342 334 /** ··· 351 343 */ 352 344 export const zModelWithNestedEnums = z.object({ 353 345 dictionaryWithEnum: z.optional(z.record(z.string(), z.enum([ 354 - 'Success', 355 - 'Warning', 356 - 'Error' 346 + "Success", 347 + "Warning", 348 + "Error" 357 349 ]))), 358 350 dictionaryWithEnumFromDescription: z.optional(z.record(z.string(), z.int())), 359 351 arrayWithEnum: z.optional(z.array(z.enum([ 360 - 'Success', 361 - 'Warning', 362 - 'Error' 352 + "Success", 353 + "Warning", 354 + "Error" 363 355 ]))), 364 356 arrayWithDescription: z.optional(z.array(z.int())), 365 357 'foo_bar-enum': z.optional(z.enum([ 366 - 'Success', 367 - 'Warning', 368 - 'Error', 369 - 'ØÆÅ字符串' 358 + "Success", 359 + "Warning", 360 + "Error", 361 + "ØÆÅ字符串" 370 362 ])) 371 363 }); 372 364 ··· 498 490 ])) 499 491 }); 500 492 501 - export const z3eNum1Период = z.enum([ 502 - 'Bird', 503 - 'Dog' 504 - ]); 493 + export const z3eNum1Период = z.enum(["Bird", "Dog"]); 505 494 506 - export const zConstValue = z.enum([ 507 - 'ConstValue' 508 - ]); 495 + export const zConstValue = z.enum(["ConstValue"]); 509 496 510 497 /** 511 498 * This is a model with one property with a 'any of' relationship where the options are not $ref 512 499 */ 513 500 export const zCompositionWithNestedAnyOfAndNull = z.object({ 514 501 propA: z.optional(z.union([ 515 - z.array(z.union([ 516 - z3eNum1Период, 517 - zConstValue 518 - ])), 502 + z.array(z.union([z3eNum1Период, zConstValue])), 519 503 z.null() 520 504 ])) 521 505 }); ··· 561 545 export const zCompositionWithOneOfAndComplexArrayDictionary = z.object({ 562 546 propA: z.optional(z.union([ 563 547 z.boolean(), 564 - z.record(z.string(), z.array(z.union([ 565 - z.number(), 566 - z.string() 567 - ]))) 548 + z.record(z.string(), z.array(z.union([z.number(), z.string()]))) 568 549 ])) 569 550 }); 570 551 ··· 750 731 export const zFreeFormObjectWithAdditionalPropertiesEqEmptyObject = z.record(z.string(), z.unknown()); 751 732 752 733 export const zModelWithConst = z.object({ 753 - String: z.optional(z.enum([ 754 - 'String' 755 - ])), 734 + String: z.optional(z.enum(["String"])), 756 735 number: z.optional(z.literal(0)), 757 736 null: z.optional(z.unknown()), 758 - withType: z.optional(z.enum([ 759 - 'Some string' 760 - ])) 737 + withType: z.optional(z.enum(["Some string"])) 761 738 }); 762 739 763 740 /** ··· 769 746 770 747 export const zNestedAnyOfArraysNullable = z.object({ 771 748 nullableArray: z.optional(z.union([ 772 - z.array(z.union([ 773 - z.string(), 774 - z.boolean() 775 - ])), 749 + z.array(z.union([z.string(), z.boolean()])), 776 750 z.null() 777 751 ])) 778 752 }); ··· 798 772 799 773 export const zModelWithOneOfEnum = z.union([ 800 774 z.object({ 801 - foo: z.enum([ 802 - 'Bar' 803 - ]) 775 + foo: z.enum(["Bar"]) 804 776 }), 805 777 z.object({ 806 - foo: z.enum([ 807 - 'Baz' 808 - ]) 778 + foo: z.enum(["Baz"]) 809 779 }), 810 780 z.object({ 811 - foo: z.enum([ 812 - 'Qux' 813 - ]) 781 + foo: z.enum(["Qux"]) 814 782 }), 815 783 z.object({ 816 784 content: z.iso.datetime(), 817 - foo: z.enum([ 818 - 'Quux' 819 - ]) 785 + foo: z.enum(["Quux"]) 820 786 }), 821 787 z.object({ 822 - content: z.tuple([ 823 - z.iso.datetime(), 824 - z.iso.datetime() 825 - ]), 826 - foo: z.enum([ 827 - 'Corge' 828 - ]) 788 + content: z.tuple([z.iso.datetime(), z.iso.datetime()]), 789 + foo: z.enum(["Corge"]) 829 790 }) 830 791 ]); 831 792 832 - export const zModelWithNestedArrayEnumsDataFoo = z.enum([ 833 - 'foo', 834 - 'bar' 835 - ]); 793 + export const zModelWithNestedArrayEnumsDataFoo = z.enum(["foo", "bar"]); 836 794 837 - export const zModelWithNestedArrayEnumsDataBar = z.enum([ 838 - 'baz', 839 - 'qux' 840 - ]); 795 + export const zModelWithNestedArrayEnumsDataBar = z.enum(["baz", "qux"]); 841 796 842 797 export const zModelWithNestedArrayEnumsData = z.object({ 843 798 foo: z.optional(z.array(zModelWithNestedArrayEnumsDataFoo)), ··· 867 822 propWithNumber: z.optional(z.array(z.number())) 868 823 }); 869 824 870 - export const zModelWithConstantSizeArray = z.tuple([ 871 - z.number(), 872 - z.number() 873 - ]); 825 + export const zModelWithConstantSizeArray = z.tuple([z.number(), z.number()]); 874 826 875 827 export const zModelWithAnyOfConstantSizeArray = z.tuple([ 876 828 z.union([ ··· 911 863 ]) 912 864 ]); 913 865 914 - export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([ 915 - z.intersection(z.number(), z.string()), 916 - z.intersection(z.number(), z.string()) 917 - ]); 866 + export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([z.intersection(z.number(), z.string()), z.intersection(z.number(), z.string())]); 918 867 919 868 export const zModelWithNumericEnumUnion = z.object({ 920 869 value: z.optional(z.union([ ··· 965 914 */ 966 915 export const zImport = z.string(); 967 916 968 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([ 969 - z.union([ 917 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([z.union([ 970 918 z.number(), 971 919 zImport 972 - ]), 973 - z.union([ 920 + ]), z.union([ 974 921 z.number(), 975 922 zImport 976 - ]) 977 - ]); 923 + ])]); 978 924 979 925 export const zSchemaWithFormRestrictedKeys = z.object({ 980 926 description: z.optional(z.string()), ··· 1126 1072 propWithNumber: z.optional(z.array(z.number())) 1127 1073 }); 1128 1074 1129 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([ 1130 - z.union([ 1075 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([z.union([ 1131 1076 z.number(), 1132 1077 zImport 1133 - ]), 1134 - z.union([ 1078 + ]), z.union([ 1135 1079 z.number(), 1136 1080 zImport 1137 - ]) 1138 - ]); 1081 + ])]); 1139 1082 1140 1083 export const zAdditionalPropertiesUnknownIssueWritable = z.record(z.string(), z.union([ 1141 1084 z.string(), ··· 1452 1395 path: z.optional(z.never()), 1453 1396 query: z.optional(z.object({ 1454 1397 parameterString: z._default(z.optional(z.union([ 1455 - z._default(z.string(), 'Hello World!'), 1398 + z._default(z.string(), "Hello World!"), 1456 1399 z.null() 1457 - ])), 'Hello World!'), 1400 + ])), "Hello World!"), 1458 1401 parameterNumber: z._default(z.optional(z.union([ 1459 1402 z._default(z.number(), 123), 1460 1403 z.null() ··· 1464 1407 z.null() 1465 1408 ])), true), 1466 1409 parameterEnum: z.optional(z.enum([ 1467 - 'Success', 1468 - 'Warning', 1469 - 'Error' 1410 + "Success", 1411 + "Warning", 1412 + "Error" 1470 1413 ])), 1471 1414 parameterModel: z.optional(z.union([ 1472 1415 zModelWithString, ··· 1479 1422 body: z.optional(z.never()), 1480 1423 path: z.optional(z.never()), 1481 1424 query: z.optional(z.object({ 1482 - parameterString: z._default(z.optional(z.string()), 'Hello World!'), 1425 + parameterString: z._default(z.optional(z.string()), "Hello World!"), 1483 1426 parameterNumber: z._default(z.optional(z.number()), 123), 1484 1427 parameterBoolean: z._default(z.optional(z.boolean()), true), 1485 1428 parameterEnum: z.optional(z.enum([ 1486 - 'Success', 1487 - 'Warning', 1488 - 'Error' 1429 + "Success", 1430 + "Warning", 1431 + "Error" 1489 1432 ])), 1490 1433 parameterModel: z.optional(zModelWithString) 1491 1434 })) ··· 1495 1438 body: z.optional(z.never()), 1496 1439 path: z.optional(z.never()), 1497 1440 query: z.object({ 1498 - parameterOptionalStringWithDefault: z._default(z.optional(z.string()), 'Hello World!'), 1499 - parameterOptionalStringWithEmptyDefault: z._default(z.optional(z.string()), ''), 1441 + parameterOptionalStringWithDefault: z._default(z.optional(z.string()), "Hello World!"), 1442 + parameterOptionalStringWithEmptyDefault: z._default(z.optional(z.string()), ""), 1500 1443 parameterOptionalStringWithNoDefault: z.optional(z.string()), 1501 - parameterStringWithDefault: z._default(z.string(), 'Hello World!'), 1502 - parameterStringWithEmptyDefault: z._default(z.string(), ''), 1444 + parameterStringWithDefault: z._default(z.string(), "Hello World!"), 1445 + parameterStringWithEmptyDefault: z._default(z.string(), ""), 1503 1446 parameterStringWithNoDefault: z.string(), 1504 1447 parameterStringNullableWithNoDefault: z.optional(z.union([ 1505 1448 z.string(), ··· 1647 1590 query: z.object({ 1648 1591 parameterNumber: z._default(z.number(), 123), 1649 1592 parameterString: z._default(z.union([ 1650 - z._default(z.string(), 'default'), 1593 + z._default(z.string(), "default"), 1651 1594 z.null() 1652 - ]), 'default'), 1595 + ]), "default"), 1653 1596 parameterBoolean: z._default(z.union([ 1654 1597 z._default(z.boolean(), true), 1655 1598 z.null() ··· 1667 1610 z.null() 1668 1611 ]), 1669 1612 parameterEnum: z.enum([ 1670 - 'Success', 1671 - 'Warning', 1672 - 'Error' 1613 + "Success", 1614 + "Warning", 1615 + "Error" 1673 1616 ]) 1674 1617 }) 1675 1618 }); ··· 1769 1712 ]), 1770 1713 enabled: z._default(z.optional(z.boolean()), true), 1771 1714 type: z.enum([ 1772 - 'Monkey', 1773 - 'Horse', 1774 - 'Bird' 1715 + "Monkey", 1716 + "Horse", 1717 + "Bird" 1775 1718 ]), 1776 1719 listOfModels: z.optional(z.union([ 1777 1720 z.array(zModelWithString),
+3 -12
packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/enum-null/zod.gen.ts
··· 2 2 3 3 import * as z from 'zod/v4-mini'; 4 4 5 - export const zFoo = z.nullable(z.enum([ 6 - 'foo', 7 - 'bar' 8 - ])); 5 + export const zFoo = z.nullable(z.enum(["foo", "bar"])); 9 6 10 - export const zBar = z.enum([ 11 - 'foo', 12 - 'bar' 13 - ]); 7 + export const zBar = z.enum(["foo", "bar"]); 14 8 15 - export const zBaz = z.enum([ 16 - 'foo', 17 - 'bar' 18 - ]); 9 + export const zBaz = z.enum(["foo", "bar"]);
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/validators/zod.gen.ts
··· 2 2 3 3 import * as z from 'zod/v4-mini'; 4 4 5 - export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), 'baz'); 5 + export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), "baz"); 6 6 7 7 export const zFoo = z._default(z.union([ 8 8 z.object({
+85 -142
packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts
··· 90 90 * This is a simple enum with strings 91 91 */ 92 92 export const zEnumWithStrings = z.enum([ 93 - 'Success', 94 - 'Warning', 95 - 'Error', 93 + "Success", 94 + "Warning", 95 + "Error", 96 96 "'Single Quote'", 97 - '"Double Quotes"', 98 - 'Non-ascii: øæåôöØÆÅÔÖ字符串' 97 + "\"Double Quotes\"", 98 + "Non-ascii: øæåôöØÆÅÔÖ字符串" 99 99 ]); 100 100 101 101 export const zEnumWithReplacedCharacters = z.union([ 102 102 z.literal("'Single Quote'"), 103 - z.literal('"Double Quotes"'), 104 - z.literal('øæåôöØÆÅÔÖ字符串'), 103 + z.literal("\"Double Quotes\""), 104 + z.literal("øæåôöØÆÅÔÖ字符串"), 105 105 z.literal(3.1), 106 - z.literal('') 106 + z.literal("") 107 107 ]); 108 108 109 109 /** ··· 160 160 /** 161 161 * This is a simple array with strings 162 162 */ 163 - export const zArrayWithStrings = z.array(z.string()).default(['test']); 163 + export const zArrayWithStrings = z.array(z.string()).default(["test"]); 164 164 165 165 /** 166 166 * This is a simple array with properties ··· 173 173 /** 174 174 * This is a simple array with any of properties 175 175 */ 176 - export const zArrayWithAnyOfProperties = z.array(z.union([ 177 - z.object({ 178 - foo: z.string().optional().default('test') 179 - }), 180 - z.object({ 176 + export const zArrayWithAnyOfProperties = z.array(z.union([z.object({ 177 + foo: z.string().optional().default("test") 178 + }), z.object({ 181 179 bar: z.string().optional() 182 - }) 183 - ])); 180 + })])); 184 181 185 182 export const zAnyOfAnyAndNull = z.object({ 186 183 data: z.unknown().optional() ··· 190 187 * This is a simple array with any of properties 191 188 */ 192 189 export const zAnyOfArrays = z.object({ 193 - results: z.array(z.union([ 194 - z.object({ 190 + results: z.array(z.union([z.object({ 195 191 foo: z.string().optional() 196 - }), 197 - z.object({ 192 + }), z.object({ 198 193 bar: z.string().optional() 199 - }) 200 - ])).optional() 194 + })])).optional() 201 195 }); 202 196 203 197 /** ··· 302 296 z.null() 303 297 ]), 304 298 'foo_bar-enum': z.enum([ 305 - 'Success', 306 - 'Warning', 307 - 'Error', 308 - 'ØÆÅ字符串' 299 + "Success", 300 + "Warning", 301 + "Error", 302 + "ØÆÅ字符串" 309 303 ]).optional() 310 304 }); 311 305 ··· 314 308 */ 315 309 export const zModelWithEnum = z.object({ 316 310 'foo_bar-enum': z.enum([ 317 - 'Success', 318 - 'Warning', 319 - 'Error', 320 - 'ØÆÅ字符串' 311 + "Success", 312 + "Warning", 313 + "Error", 314 + "ØÆÅ字符串" 321 315 ]).optional(), 322 316 statusCode: z.enum([ 323 - '100', 324 - '200 FOO', 325 - '300 FOO_BAR', 326 - '400 foo-bar', 327 - '500 foo.bar', 328 - '600 foo&bar' 317 + "100", 318 + "200 FOO", 319 + "300 FOO_BAR", 320 + "400 foo-bar", 321 + "500 foo.bar", 322 + "600 foo&bar" 329 323 ]).optional(), 330 324 bool: z.literal(true).optional() 331 325 }); ··· 334 328 * This is a model with one enum with escaped name 335 329 */ 336 330 export const zModelWithEnumWithHyphen = z.object({ 337 - 'foo-bar-baz-qux': z.enum([ 338 - '3.0' 339 - ]).optional() 331 + 'foo-bar-baz-qux': z.enum(["3.0"]).optional() 340 332 }); 341 333 342 334 /** ··· 351 343 */ 352 344 export const zModelWithNestedEnums = z.object({ 353 345 dictionaryWithEnum: z.record(z.enum([ 354 - 'Success', 355 - 'Warning', 356 - 'Error' 346 + "Success", 347 + "Warning", 348 + "Error" 357 349 ])).optional(), 358 350 dictionaryWithEnumFromDescription: z.record(z.number().int()).optional(), 359 351 arrayWithEnum: z.array(z.enum([ 360 - 'Success', 361 - 'Warning', 362 - 'Error' 352 + "Success", 353 + "Warning", 354 + "Error" 363 355 ])).optional(), 364 356 arrayWithDescription: z.array(z.number().int()).optional(), 365 357 'foo_bar-enum': z.enum([ 366 - 'Success', 367 - 'Warning', 368 - 'Error', 369 - 'ØÆÅ字符串' 358 + "Success", 359 + "Warning", 360 + "Error", 361 + "ØÆÅ字符串" 370 362 ]).optional() 371 363 }); 372 364 ··· 496 488 ]).optional() 497 489 }); 498 490 499 - export const z3eNum1Период = z.enum([ 500 - 'Bird', 501 - 'Dog' 502 - ]); 491 + export const z3eNum1Период = z.enum(["Bird", "Dog"]); 503 492 504 - export const zConstValue = z.enum([ 505 - 'ConstValue' 506 - ]); 493 + export const zConstValue = z.enum(["ConstValue"]); 507 494 508 495 /** 509 496 * This is a model with one property with a 'any of' relationship where the options are not $ref 510 497 */ 511 498 export const zCompositionWithNestedAnyOfAndNull = z.object({ 512 499 propA: z.union([ 513 - z.array(z.union([ 514 - z3eNum1Период, 515 - zConstValue 516 - ])), 500 + z.array(z.union([z3eNum1Период, zConstValue])), 517 501 z.null() 518 502 ]).optional() 519 503 }); ··· 559 543 export const zCompositionWithOneOfAndComplexArrayDictionary = z.object({ 560 544 propA: z.union([ 561 545 z.boolean(), 562 - z.record(z.array(z.union([ 563 - z.number(), 564 - z.string() 565 - ]))) 546 + z.record(z.array(z.union([z.number(), z.string()]))) 566 547 ]).optional() 567 548 }); 568 549 ··· 748 729 export const zFreeFormObjectWithAdditionalPropertiesEqEmptyObject = z.record(z.unknown()); 749 730 750 731 export const zModelWithConst = z.object({ 751 - String: z.enum([ 752 - 'String' 753 - ]).optional(), 732 + String: z.enum(["String"]).optional(), 754 733 number: z.literal(0).optional(), 755 734 null: z.unknown().optional(), 756 - withType: z.enum([ 757 - 'Some string' 758 - ]).optional() 735 + withType: z.enum(["Some string"]).optional() 759 736 }); 760 737 761 738 /** ··· 767 744 768 745 export const zNestedAnyOfArraysNullable = z.object({ 769 746 nullableArray: z.union([ 770 - z.array(z.union([ 771 - z.string(), 772 - z.boolean() 773 - ])), 747 + z.array(z.union([z.string(), z.boolean()])), 774 748 z.null() 775 749 ]).optional() 776 750 }); ··· 796 770 797 771 export const zModelWithOneOfEnum = z.union([ 798 772 z.object({ 799 - foo: z.enum([ 800 - 'Bar' 801 - ]) 773 + foo: z.enum(["Bar"]) 802 774 }), 803 775 z.object({ 804 - foo: z.enum([ 805 - 'Baz' 806 - ]) 776 + foo: z.enum(["Baz"]) 807 777 }), 808 778 z.object({ 809 - foo: z.enum([ 810 - 'Qux' 811 - ]) 779 + foo: z.enum(["Qux"]) 812 780 }), 813 781 z.object({ 814 782 content: z.string().datetime(), 815 - foo: z.enum([ 816 - 'Quux' 817 - ]) 783 + foo: z.enum(["Quux"]) 818 784 }), 819 785 z.object({ 820 - content: z.tuple([ 821 - z.string().datetime(), 822 - z.string().datetime() 823 - ]), 824 - foo: z.enum([ 825 - 'Corge' 826 - ]) 786 + content: z.tuple([z.string().datetime(), z.string().datetime()]), 787 + foo: z.enum(["Corge"]) 827 788 }) 828 789 ]); 829 790 830 - export const zModelWithNestedArrayEnumsDataFoo = z.enum([ 831 - 'foo', 832 - 'bar' 833 - ]); 791 + export const zModelWithNestedArrayEnumsDataFoo = z.enum(["foo", "bar"]); 834 792 835 - export const zModelWithNestedArrayEnumsDataBar = z.enum([ 836 - 'baz', 837 - 'qux' 838 - ]); 793 + export const zModelWithNestedArrayEnumsDataBar = z.enum(["baz", "qux"]); 839 794 840 795 export const zModelWithNestedArrayEnumsData = z.object({ 841 796 foo: z.array(zModelWithNestedArrayEnumsDataFoo).optional(), ··· 865 820 propWithNumber: z.array(z.number()).optional() 866 821 }); 867 822 868 - export const zModelWithConstantSizeArray = z.tuple([ 869 - z.number(), 870 - z.number() 871 - ]); 823 + export const zModelWithConstantSizeArray = z.tuple([z.number(), z.number()]); 872 824 873 825 export const zModelWithAnyOfConstantSizeArray = z.tuple([ 874 826 z.union([ ··· 909 861 ]) 910 862 ]); 911 863 912 - export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([ 913 - z.intersection(z.number(), z.string()), 914 - z.intersection(z.number(), z.string()) 915 - ]); 864 + export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([z.intersection(z.number(), z.string()), z.intersection(z.number(), z.string())]); 916 865 917 866 export const zModelWithNumericEnumUnion = z.object({ 918 867 value: z.union([ ··· 963 912 */ 964 913 export const zImport = z.string(); 965 914 966 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([ 967 - z.union([ 915 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([z.union([ 968 916 z.number(), 969 917 zImport 970 - ]), 971 - z.union([ 918 + ]), z.union([ 972 919 z.number(), 973 920 zImport 974 - ]) 975 - ]); 921 + ])]); 976 922 977 923 export const zSchemaWithFormRestrictedKeys = z.object({ 978 924 description: z.string().optional(), ··· 1124 1070 propWithNumber: z.array(z.number()).optional() 1125 1071 }); 1126 1072 1127 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([ 1128 - z.union([ 1073 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([z.union([ 1129 1074 z.number(), 1130 1075 zImport 1131 - ]), 1132 - z.union([ 1076 + ]), z.union([ 1133 1077 z.number(), 1134 1078 zImport 1135 - ]) 1136 - ]); 1079 + ])]); 1137 1080 1138 1081 export const zAdditionalPropertiesUnknownIssueWritable = z.record(z.union([ 1139 1082 z.string(), ··· 1450 1393 path: z.never().optional(), 1451 1394 query: z.object({ 1452 1395 parameterString: z.union([ 1453 - z.string().default('Hello World!'), 1396 + z.string().default("Hello World!"), 1454 1397 z.null() 1455 - ]).optional().default('Hello World!'), 1398 + ]).optional().default("Hello World!"), 1456 1399 parameterNumber: z.union([ 1457 1400 z.number().default(123), 1458 1401 z.null() ··· 1462 1405 z.null() 1463 1406 ]).optional().default(true), 1464 1407 parameterEnum: z.enum([ 1465 - 'Success', 1466 - 'Warning', 1467 - 'Error' 1408 + "Success", 1409 + "Warning", 1410 + "Error" 1468 1411 ]).optional(), 1469 1412 parameterModel: z.union([ 1470 1413 zModelWithString, ··· 1477 1420 body: z.never().optional(), 1478 1421 path: z.never().optional(), 1479 1422 query: z.object({ 1480 - parameterString: z.string().optional().default('Hello World!'), 1423 + parameterString: z.string().optional().default("Hello World!"), 1481 1424 parameterNumber: z.number().optional().default(123), 1482 1425 parameterBoolean: z.boolean().optional().default(true), 1483 1426 parameterEnum: z.enum([ 1484 - 'Success', 1485 - 'Warning', 1486 - 'Error' 1427 + "Success", 1428 + "Warning", 1429 + "Error" 1487 1430 ]).optional(), 1488 1431 parameterModel: zModelWithString.optional() 1489 1432 }).optional() ··· 1493 1436 body: z.never().optional(), 1494 1437 path: z.never().optional(), 1495 1438 query: z.object({ 1496 - parameterOptionalStringWithDefault: z.string().optional().default('Hello World!'), 1497 - parameterOptionalStringWithEmptyDefault: z.string().optional().default(''), 1439 + parameterOptionalStringWithDefault: z.string().optional().default("Hello World!"), 1440 + parameterOptionalStringWithEmptyDefault: z.string().optional().default(""), 1498 1441 parameterOptionalStringWithNoDefault: z.string().optional(), 1499 - parameterStringWithDefault: z.string().default('Hello World!'), 1500 - parameterStringWithEmptyDefault: z.string().default(''), 1442 + parameterStringWithDefault: z.string().default("Hello World!"), 1443 + parameterStringWithEmptyDefault: z.string().default(""), 1501 1444 parameterStringWithNoDefault: z.string(), 1502 1445 parameterStringNullableWithNoDefault: z.union([ 1503 1446 z.string(), ··· 1645 1588 query: z.object({ 1646 1589 parameterNumber: z.number().default(123), 1647 1590 parameterString: z.union([ 1648 - z.string().default('default'), 1591 + z.string().default("default"), 1649 1592 z.null() 1650 - ]).default('default'), 1593 + ]).default("default"), 1651 1594 parameterBoolean: z.union([ 1652 1595 z.boolean().default(true), 1653 1596 z.null() ··· 1665 1608 z.null() 1666 1609 ]), 1667 1610 parameterEnum: z.enum([ 1668 - 'Success', 1669 - 'Warning', 1670 - 'Error' 1611 + "Success", 1612 + "Warning", 1613 + "Error" 1671 1614 ]) 1672 1615 }) 1673 1616 }); ··· 1767 1710 ]), 1768 1711 enabled: z.boolean().optional().default(true), 1769 1712 type: z.enum([ 1770 - 'Monkey', 1771 - 'Horse', 1772 - 'Bird' 1713 + "Monkey", 1714 + "Horse", 1715 + "Bird" 1773 1716 ]), 1774 1717 listOfModels: z.union([ 1775 1718 z.array(zModelWithString),
+3 -12
packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/enum-null/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod'; 4 4 5 - export const zFoo = z.enum([ 6 - 'foo', 7 - 'bar' 8 - ]).nullable(); 5 + export const zFoo = z.enum(["foo", "bar"]).nullable(); 9 6 10 - export const zBar = z.enum([ 11 - 'foo', 12 - 'bar' 13 - ]); 7 + export const zBar = z.enum(["foo", "bar"]); 14 8 15 - export const zBaz = z.enum([ 16 - 'foo', 17 - 'bar' 18 - ]); 9 + export const zBaz = z.enum(["foo", "bar"]);
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/validators/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export const zFoo: z.ZodTypeAny = z.union([ 8 8 z.object({
+85 -142
packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts
··· 90 90 * This is a simple enum with strings 91 91 */ 92 92 export const zEnumWithStrings = z.enum([ 93 - 'Success', 94 - 'Warning', 95 - 'Error', 93 + "Success", 94 + "Warning", 95 + "Error", 96 96 "'Single Quote'", 97 - '"Double Quotes"', 98 - 'Non-ascii: øæåôöØÆÅÔÖ字符串' 97 + "\"Double Quotes\"", 98 + "Non-ascii: øæåôöØÆÅÔÖ字符串" 99 99 ]); 100 100 101 101 export const zEnumWithReplacedCharacters = z.union([ 102 102 z.literal("'Single Quote'"), 103 - z.literal('"Double Quotes"'), 104 - z.literal('øæåôöØÆÅÔÖ字符串'), 103 + z.literal("\"Double Quotes\""), 104 + z.literal("øæåôöØÆÅÔÖ字符串"), 105 105 z.literal(3.1), 106 - z.literal('') 106 + z.literal("") 107 107 ]); 108 108 109 109 /** ··· 160 160 /** 161 161 * This is a simple array with strings 162 162 */ 163 - export const zArrayWithStrings = z.array(z.string()).default(['test']); 163 + export const zArrayWithStrings = z.array(z.string()).default(["test"]); 164 164 165 165 /** 166 166 * This is a simple array with properties ··· 173 173 /** 174 174 * This is a simple array with any of properties 175 175 */ 176 - export const zArrayWithAnyOfProperties = z.array(z.union([ 177 - z.object({ 178 - foo: z.optional(z.string()).default('test') 179 - }), 180 - z.object({ 176 + export const zArrayWithAnyOfProperties = z.array(z.union([z.object({ 177 + foo: z.optional(z.string()).default("test") 178 + }), z.object({ 181 179 bar: z.optional(z.string()) 182 - }) 183 - ])); 180 + })])); 184 181 185 182 export const zAnyOfAnyAndNull = z.object({ 186 183 data: z.optional(z.unknown()) ··· 190 187 * This is a simple array with any of properties 191 188 */ 192 189 export const zAnyOfArrays = z.object({ 193 - results: z.optional(z.array(z.union([ 194 - z.object({ 190 + results: z.optional(z.array(z.union([z.object({ 195 191 foo: z.optional(z.string()) 196 - }), 197 - z.object({ 192 + }), z.object({ 198 193 bar: z.optional(z.string()) 199 - }) 200 - ]))) 194 + })]))) 201 195 }); 202 196 203 197 /** ··· 302 296 z.null() 303 297 ]), 304 298 'foo_bar-enum': z.optional(z.enum([ 305 - 'Success', 306 - 'Warning', 307 - 'Error', 308 - 'ØÆÅ字符串' 299 + "Success", 300 + "Warning", 301 + "Error", 302 + "ØÆÅ字符串" 309 303 ])) 310 304 }); 311 305 ··· 314 308 */ 315 309 export const zModelWithEnum = z.object({ 316 310 'foo_bar-enum': z.optional(z.enum([ 317 - 'Success', 318 - 'Warning', 319 - 'Error', 320 - 'ØÆÅ字符串' 311 + "Success", 312 + "Warning", 313 + "Error", 314 + "ØÆÅ字符串" 321 315 ])), 322 316 statusCode: z.optional(z.enum([ 323 - '100', 324 - '200 FOO', 325 - '300 FOO_BAR', 326 - '400 foo-bar', 327 - '500 foo.bar', 328 - '600 foo&bar' 317 + "100", 318 + "200 FOO", 319 + "300 FOO_BAR", 320 + "400 foo-bar", 321 + "500 foo.bar", 322 + "600 foo&bar" 329 323 ])), 330 324 bool: z.optional(z.literal(true)) 331 325 }); ··· 334 328 * This is a model with one enum with escaped name 335 329 */ 336 330 export const zModelWithEnumWithHyphen = z.object({ 337 - 'foo-bar-baz-qux': z.optional(z.enum([ 338 - '3.0' 339 - ])) 331 + 'foo-bar-baz-qux': z.optional(z.enum(["3.0"])) 340 332 }); 341 333 342 334 /** ··· 351 343 */ 352 344 export const zModelWithNestedEnums = z.object({ 353 345 dictionaryWithEnum: z.optional(z.record(z.string(), z.enum([ 354 - 'Success', 355 - 'Warning', 356 - 'Error' 346 + "Success", 347 + "Warning", 348 + "Error" 357 349 ]))), 358 350 dictionaryWithEnumFromDescription: z.optional(z.record(z.string(), z.int())), 359 351 arrayWithEnum: z.optional(z.array(z.enum([ 360 - 'Success', 361 - 'Warning', 362 - 'Error' 352 + "Success", 353 + "Warning", 354 + "Error" 363 355 ]))), 364 356 arrayWithDescription: z.optional(z.array(z.int())), 365 357 'foo_bar-enum': z.optional(z.enum([ 366 - 'Success', 367 - 'Warning', 368 - 'Error', 369 - 'ØÆÅ字符串' 358 + "Success", 359 + "Warning", 360 + "Error", 361 + "ØÆÅ字符串" 370 362 ])) 371 363 }); 372 364 ··· 498 490 ])) 499 491 }); 500 492 501 - export const z3eNum1Период = z.enum([ 502 - 'Bird', 503 - 'Dog' 504 - ]); 493 + export const z3eNum1Период = z.enum(["Bird", "Dog"]); 505 494 506 - export const zConstValue = z.enum([ 507 - 'ConstValue' 508 - ]); 495 + export const zConstValue = z.enum(["ConstValue"]); 509 496 510 497 /** 511 498 * This is a model with one property with a 'any of' relationship where the options are not $ref 512 499 */ 513 500 export const zCompositionWithNestedAnyOfAndNull = z.object({ 514 501 propA: z.optional(z.union([ 515 - z.array(z.union([ 516 - z3eNum1Период, 517 - zConstValue 518 - ])), 502 + z.array(z.union([z3eNum1Период, zConstValue])), 519 503 z.null() 520 504 ])) 521 505 }); ··· 561 545 export const zCompositionWithOneOfAndComplexArrayDictionary = z.object({ 562 546 propA: z.optional(z.union([ 563 547 z.boolean(), 564 - z.record(z.string(), z.array(z.union([ 565 - z.number(), 566 - z.string() 567 - ]))) 548 + z.record(z.string(), z.array(z.union([z.number(), z.string()]))) 568 549 ])) 569 550 }); 570 551 ··· 750 731 export const zFreeFormObjectWithAdditionalPropertiesEqEmptyObject = z.record(z.string(), z.unknown()); 751 732 752 733 export const zModelWithConst = z.object({ 753 - String: z.optional(z.enum([ 754 - 'String' 755 - ])), 734 + String: z.optional(z.enum(["String"])), 756 735 number: z.optional(z.literal(0)), 757 736 null: z.optional(z.unknown()), 758 - withType: z.optional(z.enum([ 759 - 'Some string' 760 - ])) 737 + withType: z.optional(z.enum(["Some string"])) 761 738 }); 762 739 763 740 /** ··· 769 746 770 747 export const zNestedAnyOfArraysNullable = z.object({ 771 748 nullableArray: z.optional(z.union([ 772 - z.array(z.union([ 773 - z.string(), 774 - z.boolean() 775 - ])), 749 + z.array(z.union([z.string(), z.boolean()])), 776 750 z.null() 777 751 ])) 778 752 }); ··· 798 772 799 773 export const zModelWithOneOfEnum = z.union([ 800 774 z.object({ 801 - foo: z.enum([ 802 - 'Bar' 803 - ]) 775 + foo: z.enum(["Bar"]) 804 776 }), 805 777 z.object({ 806 - foo: z.enum([ 807 - 'Baz' 808 - ]) 778 + foo: z.enum(["Baz"]) 809 779 }), 810 780 z.object({ 811 - foo: z.enum([ 812 - 'Qux' 813 - ]) 781 + foo: z.enum(["Qux"]) 814 782 }), 815 783 z.object({ 816 784 content: z.iso.datetime(), 817 - foo: z.enum([ 818 - 'Quux' 819 - ]) 785 + foo: z.enum(["Quux"]) 820 786 }), 821 787 z.object({ 822 - content: z.tuple([ 823 - z.iso.datetime(), 824 - z.iso.datetime() 825 - ]), 826 - foo: z.enum([ 827 - 'Corge' 828 - ]) 788 + content: z.tuple([z.iso.datetime(), z.iso.datetime()]), 789 + foo: z.enum(["Corge"]) 829 790 }) 830 791 ]); 831 792 832 - export const zModelWithNestedArrayEnumsDataFoo = z.enum([ 833 - 'foo', 834 - 'bar' 835 - ]); 793 + export const zModelWithNestedArrayEnumsDataFoo = z.enum(["foo", "bar"]); 836 794 837 - export const zModelWithNestedArrayEnumsDataBar = z.enum([ 838 - 'baz', 839 - 'qux' 840 - ]); 795 + export const zModelWithNestedArrayEnumsDataBar = z.enum(["baz", "qux"]); 841 796 842 797 export const zModelWithNestedArrayEnumsData = z.object({ 843 798 foo: z.optional(z.array(zModelWithNestedArrayEnumsDataFoo)), ··· 867 822 propWithNumber: z.optional(z.array(z.number())) 868 823 }); 869 824 870 - export const zModelWithConstantSizeArray = z.tuple([ 871 - z.number(), 872 - z.number() 873 - ]); 825 + export const zModelWithConstantSizeArray = z.tuple([z.number(), z.number()]); 874 826 875 827 export const zModelWithAnyOfConstantSizeArray = z.tuple([ 876 828 z.union([ ··· 911 863 ]) 912 864 ]); 913 865 914 - export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([ 915 - z.intersection(z.number(), z.string()), 916 - z.intersection(z.number(), z.string()) 917 - ]); 866 + export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([z.intersection(z.number(), z.string()), z.intersection(z.number(), z.string())]); 918 867 919 868 export const zModelWithNumericEnumUnion = z.object({ 920 869 value: z.optional(z.union([ ··· 965 914 */ 966 915 export const zImport = z.string(); 967 916 968 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([ 969 - z.union([ 917 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([z.union([ 970 918 z.number(), 971 919 zImport 972 - ]), 973 - z.union([ 920 + ]), z.union([ 974 921 z.number(), 975 922 zImport 976 - ]) 977 - ]); 923 + ])]); 978 924 979 925 export const zSchemaWithFormRestrictedKeys = z.object({ 980 926 description: z.optional(z.string()), ··· 1126 1072 propWithNumber: z.optional(z.array(z.number())) 1127 1073 }); 1128 1074 1129 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([ 1130 - z.union([ 1075 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([z.union([ 1131 1076 z.number(), 1132 1077 zImport 1133 - ]), 1134 - z.union([ 1078 + ]), z.union([ 1135 1079 z.number(), 1136 1080 zImport 1137 - ]) 1138 - ]); 1081 + ])]); 1139 1082 1140 1083 export const zAdditionalPropertiesUnknownIssueWritable = z.record(z.string(), z.union([ 1141 1084 z.string(), ··· 1452 1395 path: z.optional(z.never()), 1453 1396 query: z.optional(z.object({ 1454 1397 parameterString: z.optional(z.union([ 1455 - z.string().default('Hello World!'), 1398 + z.string().default("Hello World!"), 1456 1399 z.null() 1457 - ])).default('Hello World!'), 1400 + ])).default("Hello World!"), 1458 1401 parameterNumber: z.optional(z.union([ 1459 1402 z.number().default(123), 1460 1403 z.null() ··· 1464 1407 z.null() 1465 1408 ])).default(true), 1466 1409 parameterEnum: z.optional(z.enum([ 1467 - 'Success', 1468 - 'Warning', 1469 - 'Error' 1410 + "Success", 1411 + "Warning", 1412 + "Error" 1470 1413 ])), 1471 1414 parameterModel: z.optional(z.union([ 1472 1415 zModelWithString, ··· 1479 1422 body: z.optional(z.never()), 1480 1423 path: z.optional(z.never()), 1481 1424 query: z.optional(z.object({ 1482 - parameterString: z.optional(z.string()).default('Hello World!'), 1425 + parameterString: z.optional(z.string()).default("Hello World!"), 1483 1426 parameterNumber: z.optional(z.number()).default(123), 1484 1427 parameterBoolean: z.optional(z.boolean()).default(true), 1485 1428 parameterEnum: z.optional(z.enum([ 1486 - 'Success', 1487 - 'Warning', 1488 - 'Error' 1429 + "Success", 1430 + "Warning", 1431 + "Error" 1489 1432 ])), 1490 1433 parameterModel: z.optional(zModelWithString) 1491 1434 })) ··· 1495 1438 body: z.optional(z.never()), 1496 1439 path: z.optional(z.never()), 1497 1440 query: z.object({ 1498 - parameterOptionalStringWithDefault: z.optional(z.string()).default('Hello World!'), 1499 - parameterOptionalStringWithEmptyDefault: z.optional(z.string()).default(''), 1441 + parameterOptionalStringWithDefault: z.optional(z.string()).default("Hello World!"), 1442 + parameterOptionalStringWithEmptyDefault: z.optional(z.string()).default(""), 1500 1443 parameterOptionalStringWithNoDefault: z.optional(z.string()), 1501 - parameterStringWithDefault: z.string().default('Hello World!'), 1502 - parameterStringWithEmptyDefault: z.string().default(''), 1444 + parameterStringWithDefault: z.string().default("Hello World!"), 1445 + parameterStringWithEmptyDefault: z.string().default(""), 1503 1446 parameterStringWithNoDefault: z.string(), 1504 1447 parameterStringNullableWithNoDefault: z.optional(z.union([ 1505 1448 z.string(), ··· 1647 1590 query: z.object({ 1648 1591 parameterNumber: z.number().default(123), 1649 1592 parameterString: z.union([ 1650 - z.string().default('default'), 1593 + z.string().default("default"), 1651 1594 z.null() 1652 - ]).default('default'), 1595 + ]).default("default"), 1653 1596 parameterBoolean: z.union([ 1654 1597 z.boolean().default(true), 1655 1598 z.null() ··· 1667 1610 z.null() 1668 1611 ]), 1669 1612 parameterEnum: z.enum([ 1670 - 'Success', 1671 - 'Warning', 1672 - 'Error' 1613 + "Success", 1614 + "Warning", 1615 + "Error" 1673 1616 ]) 1674 1617 }) 1675 1618 }); ··· 1769 1712 ]), 1770 1713 enabled: z.optional(z.boolean()).default(true), 1771 1714 type: z.enum([ 1772 - 'Monkey', 1773 - 'Horse', 1774 - 'Bird' 1715 + "Monkey", 1716 + "Horse", 1717 + "Bird" 1775 1718 ]), 1776 1719 listOfModels: z.optional(z.union([ 1777 1720 z.array(zModelWithString),
+3 -12
packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/enum-null/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod/v4'; 4 4 5 - export const zFoo = z.nullable(z.enum([ 6 - 'foo', 7 - 'bar' 8 - ])); 5 + export const zFoo = z.nullable(z.enum(["foo", "bar"])); 9 6 10 - export const zBar = z.enum([ 11 - 'foo', 12 - 'bar' 13 - ]); 7 + export const zBar = z.enum(["foo", "bar"]); 14 8 15 - export const zBaz = z.enum([ 16 - 'foo', 17 - 'bar' 18 - ]); 9 + export const zBaz = z.enum(["foo", "bar"]);
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/validators/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod/v4'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export const zFoo = z.union([ 8 8 z.object({
+83 -144
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts
··· 90 90 * This is a simple enum with strings 91 91 */ 92 92 export const zEnumWithStrings = z.enum([ 93 - 'Success', 94 - 'Warning', 95 - 'Error', 93 + "Success", 94 + "Warning", 95 + "Error", 96 96 "'Single Quote'", 97 - '"Double Quotes"', 98 - 'Non-ascii: øæåôöØÆÅÔÖ字符串' 97 + "\"Double Quotes\"", 98 + "Non-ascii: øæåôöØÆÅÔÖ字符串" 99 99 ]); 100 100 101 101 export const zEnumWithReplacedCharacters = z.union([ 102 102 z.literal("'Single Quote'"), 103 - z.literal('"Double Quotes"'), 104 - z.literal('øæåôöØÆÅÔÖ字符串'), 103 + z.literal("\"Double Quotes\""), 104 + z.literal("øæåôöØÆÅÔÖ字符串"), 105 105 z.literal(3.1), 106 - z.literal('') 106 + z.literal("") 107 107 ]); 108 108 109 109 /** ··· 160 160 /** 161 161 * This is a simple array with strings 162 162 */ 163 - export const zArrayWithStrings = z._default(z.array(z.string()), ['test']); 163 + export const zArrayWithStrings = z._default(z.array(z.string()), ["test"]); 164 164 165 165 /** 166 166 * This is a simple array with properties ··· 173 173 /** 174 174 * This is a simple array with any of properties 175 175 */ 176 - export const zArrayWithAnyOfProperties = z.array(z.union([ 177 - z.object({ 178 - foo: z._default(z.optional(z.string()), 'test') 179 - }), 180 - z.object({ 176 + export const zArrayWithAnyOfProperties = z.array(z.union([z.object({ 177 + foo: z._default(z.optional(z.string()), "test") 178 + }), z.object({ 181 179 bar: z.optional(z.string()) 182 - }) 183 - ])); 180 + })])); 184 181 185 182 export const zAnyOfAnyAndNull = z.object({ 186 183 data: z.optional(z.union([ ··· 193 190 * This is a simple array with any of properties 194 191 */ 195 192 export const zAnyOfArrays = z.object({ 196 - results: z.optional(z.array(z.union([ 197 - z.object({ 193 + results: z.optional(z.array(z.union([z.object({ 198 194 foo: z.optional(z.string()) 199 - }), 200 - z.object({ 195 + }), z.object({ 201 196 bar: z.optional(z.string()) 202 - }) 203 - ]))) 197 + })]))) 204 198 }); 205 199 206 200 /** ··· 305 299 z.null() 306 300 ]), 307 301 'foo_bar-enum': z.optional(z.enum([ 308 - 'Success', 309 - 'Warning', 310 - 'Error', 311 - 'ØÆÅ字符串' 302 + "Success", 303 + "Warning", 304 + "Error", 305 + "ØÆÅ字符串" 312 306 ])) 313 307 }); 314 308 ··· 317 311 */ 318 312 export const zModelWithEnum = z.object({ 319 313 'foo_bar-enum': z.optional(z.enum([ 320 - 'Success', 321 - 'Warning', 322 - 'Error', 323 - 'ØÆÅ字符串' 314 + "Success", 315 + "Warning", 316 + "Error", 317 + "ØÆÅ字符串" 324 318 ])), 325 319 statusCode: z.optional(z.enum([ 326 - '100', 327 - '200 FOO', 328 - '300 FOO_BAR', 329 - '400 foo-bar', 330 - '500 foo.bar', 331 - '600 foo&bar' 320 + "100", 321 + "200 FOO", 322 + "300 FOO_BAR", 323 + "400 foo-bar", 324 + "500 foo.bar", 325 + "600 foo&bar" 332 326 ])), 333 327 bool: z.optional(z.literal(true)) 334 328 }); ··· 337 331 * This is a model with one enum with escaped name 338 332 */ 339 333 export const zModelWithEnumWithHyphen = z.object({ 340 - 'foo-bar-baz-qux': z.optional(z.enum([ 341 - '3.0' 342 - ])) 334 + 'foo-bar-baz-qux': z.optional(z.enum(["3.0"])) 343 335 }); 344 336 345 337 /** ··· 354 346 */ 355 347 export const zModelWithNestedEnums = z.object({ 356 348 dictionaryWithEnum: z.optional(z.record(z.string(), z.enum([ 357 - 'Success', 358 - 'Warning', 359 - 'Error' 349 + "Success", 350 + "Warning", 351 + "Error" 360 352 ]))), 361 353 dictionaryWithEnumFromDescription: z.optional(z.record(z.string(), z.int())), 362 354 arrayWithEnum: z.optional(z.array(z.enum([ 363 - 'Success', 364 - 'Warning', 365 - 'Error' 355 + "Success", 356 + "Warning", 357 + "Error" 366 358 ]))), 367 359 arrayWithDescription: z.optional(z.array(z.int())), 368 360 'foo_bar-enum': z.optional(z.enum([ 369 - 'Success', 370 - 'Warning', 371 - 'Error', 372 - 'ØÆÅ字符串' 361 + "Success", 362 + "Warning", 363 + "Error", 364 + "ØÆÅ字符串" 373 365 ])) 374 366 }); 375 367 ··· 490 482 */ 491 483 export const zCompositionWithNestedAnyAndTypeNull = z.object({ 492 484 propA: z.optional(z.union([ 493 - z.array(z.union([ 494 - zModelWithDictionary, 495 - z.null() 496 - ])), 497 - z.array(z.union([ 498 - zModelWithArray, 499 - z.null() 500 - ])) 485 + z.array(z.union([zModelWithDictionary, z.null()])), 486 + z.array(z.union([zModelWithArray, z.null()])) 501 487 ])) 502 488 }); 503 489 504 - export const z3eNum1Период = z.enum([ 505 - 'Bird', 506 - 'Dog' 507 - ]); 490 + export const z3eNum1Период = z.enum(["Bird", "Dog"]); 508 491 509 492 export const zConstValue = z.literal("ConstValue"); 510 493 ··· 513 496 */ 514 497 export const zCompositionWithNestedAnyOfAndNull = z.object({ 515 498 propA: z.optional(z.union([ 516 - z.array(z.union([ 517 - z3eNum1Период, 518 - zConstValue 519 - ])), 499 + z.array(z.union([z3eNum1Период, zConstValue])), 520 500 z.null() 521 501 ])) 522 502 }); ··· 562 542 export const zCompositionWithOneOfAndComplexArrayDictionary = z.object({ 563 543 propA: z.optional(z.union([ 564 544 z.boolean(), 565 - z.record(z.string(), z.array(z.union([ 566 - z.number(), 567 - z.string() 568 - ]))) 545 + z.record(z.string(), z.array(z.union([z.number(), z.string()]))) 569 546 ])) 570 547 }); 571 548 ··· 766 743 767 744 export const zNestedAnyOfArraysNullable = z.object({ 768 745 nullableArray: z.optional(z.union([ 769 - z.array(z.union([ 770 - z.string(), 771 - z.boolean() 772 - ])), 746 + z.array(z.union([z.string(), z.boolean()])), 773 747 z.null() 774 748 ])) 775 749 }); ··· 795 769 796 770 export const zModelWithOneOfEnum = z.union([ 797 771 z.object({ 798 - foo: z.enum([ 799 - 'Bar' 800 - ]) 772 + foo: z.enum(["Bar"]) 801 773 }), 802 774 z.object({ 803 - foo: z.enum([ 804 - 'Baz' 805 - ]) 775 + foo: z.enum(["Baz"]) 806 776 }), 807 777 z.object({ 808 - foo: z.enum([ 809 - 'Qux' 810 - ]) 778 + foo: z.enum(["Qux"]) 811 779 }), 812 780 z.object({ 813 781 content: z.iso.datetime(), 814 - foo: z.enum([ 815 - 'Quux' 816 - ]) 782 + foo: z.enum(["Quux"]) 817 783 }), 818 784 z.object({ 819 - content: z.tuple([ 820 - z.iso.datetime(), 821 - z.string() 822 - ]), 823 - foo: z.enum([ 824 - 'Corge' 825 - ]) 785 + content: z.tuple([z.iso.datetime(), z.string()]), 786 + foo: z.enum(["Corge"]) 826 787 }) 827 788 ]); 828 789 829 - export const zModelWithNestedArrayEnumsDataFoo = z.enum([ 830 - 'foo', 831 - 'bar' 832 - ]); 790 + export const zModelWithNestedArrayEnumsDataFoo = z.enum(["foo", "bar"]); 833 791 834 - export const zModelWithNestedArrayEnumsDataBar = z.enum([ 835 - 'baz', 836 - 'qux' 837 - ]); 792 + export const zModelWithNestedArrayEnumsDataBar = z.enum(["baz", "qux"]); 838 793 839 794 export const zModelWithNestedArrayEnumsData = z.object({ 840 795 foo: z.optional(z.array(zModelWithNestedArrayEnumsDataFoo)), ··· 864 819 propWithNumber: z.optional(z.array(z.number())) 865 820 }); 866 821 867 - export const zModelWithConstantSizeArray = z.tuple([ 868 - z.number(), 869 - z.number() 870 - ]); 822 + export const zModelWithConstantSizeArray = z.tuple([z.number(), z.number()]); 871 823 872 824 export const zModelWithAnyOfConstantSizeArray = z.tuple([ 873 825 z.union([ ··· 911 863 ]) 912 864 ]); 913 865 914 - export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([ 915 - z.intersection(z.number(), z.string()), 916 - z.intersection(z.number(), z.string()) 917 - ]); 866 + export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([z.intersection(z.number(), z.string()), z.intersection(z.number(), z.string())]); 918 867 919 868 export const zModelWithNumericEnumUnion = z.object({ 920 869 value: z.optional(z.union([ ··· 965 914 */ 966 915 export const zImport = z.string(); 967 916 968 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([ 969 - z.union([ 917 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([z.union([ 970 918 z.number(), 971 919 zImport 972 - ]), 973 - z.union([ 920 + ]), z.union([ 974 921 z.number(), 975 922 zImport 976 - ]) 977 - ]); 923 + ])]); 978 924 979 925 export const zSchemaWithFormRestrictedKeys = z.object({ 980 926 description: z.optional(z.string()), ··· 1132 1078 propWithNumber: z.optional(z.array(z.number())) 1133 1079 }); 1134 1080 1135 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([ 1136 - z.union([ 1081 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([z.union([ 1137 1082 z.number(), 1138 1083 zImport 1139 - ]), 1140 - z.union([ 1084 + ]), z.union([ 1141 1085 z.number(), 1142 1086 zImport 1143 - ]) 1144 - ]); 1087 + ])]); 1145 1088 1146 1089 export const zAdditionalPropertiesUnknownIssueWritable = z.record(z.string(), z.union([ 1147 1090 z.string(), ··· 1467 1410 path: z.optional(z.never()), 1468 1411 query: z.optional(z.object({ 1469 1412 parameterString: z._default(z.optional(z.union([ 1470 - z._default(z.string(), 'Hello World!'), 1413 + z._default(z.string(), "Hello World!"), 1471 1414 z.null() 1472 - ])), 'Hello World!'), 1415 + ])), "Hello World!"), 1473 1416 parameterNumber: z._default(z.optional(z.union([ 1474 1417 z._default(z.number(), 123), 1475 1418 z.null() ··· 1479 1422 z.null() 1480 1423 ])), true), 1481 1424 parameterEnum: z.optional(z.enum([ 1482 - 'Success', 1483 - 'Warning', 1484 - 'Error' 1425 + "Success", 1426 + "Warning", 1427 + "Error" 1485 1428 ])), 1486 1429 parameterModel: z.optional(z.union([ 1487 - z._default(zModelWithString, { 1488 - prop: 'Hello World!' 1489 - }), 1430 + z._default(zModelWithString, { prop: "Hello World!" }), 1490 1431 z.null() 1491 1432 ])) 1492 1433 })) ··· 1496 1437 body: z.optional(z.never()), 1497 1438 path: z.optional(z.never()), 1498 1439 query: z.optional(z.object({ 1499 - parameterString: z._default(z.optional(z.string()), 'Hello World!'), 1440 + parameterString: z._default(z.optional(z.string()), "Hello World!"), 1500 1441 parameterNumber: z._default(z.optional(z.number()), 123), 1501 1442 parameterBoolean: z._default(z.optional(z.boolean()), true), 1502 1443 parameterEnum: z.optional(z.enum([ 1503 - 'Success', 1504 - 'Warning', 1505 - 'Error' 1444 + "Success", 1445 + "Warning", 1446 + "Error" 1506 1447 ])), 1507 - parameterModel: z._default(z.optional(zModelWithString), { 1508 - prop: 'Hello World!' 1509 - }) 1448 + parameterModel: z._default(z.optional(zModelWithString), { prop: "Hello World!" }) 1510 1449 })) 1511 1450 }); 1512 1451 ··· 1514 1453 body: z.optional(z.never()), 1515 1454 path: z.optional(z.never()), 1516 1455 query: z.object({ 1517 - parameterOptionalStringWithDefault: z._default(z.optional(z.string()), 'Hello World!'), 1518 - parameterOptionalStringWithEmptyDefault: z._default(z.optional(z.string()), ''), 1456 + parameterOptionalStringWithDefault: z._default(z.optional(z.string()), "Hello World!"), 1457 + parameterOptionalStringWithEmptyDefault: z._default(z.optional(z.string()), ""), 1519 1458 parameterOptionalStringWithNoDefault: z.optional(z.string()), 1520 - parameterStringWithDefault: z._default(z.string(), 'Hello World!'), 1521 - parameterStringWithEmptyDefault: z._default(z.string(), ''), 1459 + parameterStringWithDefault: z._default(z.string(), "Hello World!"), 1460 + parameterStringWithEmptyDefault: z._default(z.string(), ""), 1522 1461 parameterStringWithNoDefault: z.string(), 1523 1462 parameterStringNullableWithNoDefault: z.optional(z.union([ 1524 1463 z.string(), ··· 1666 1605 query: z.object({ 1667 1606 parameterNumber: z._default(z.number(), 123), 1668 1607 parameterString: z._default(z.union([ 1669 - z._default(z.string(), 'default'), 1608 + z._default(z.string(), "default"), 1670 1609 z.null() 1671 - ]), 'default'), 1610 + ]), "default"), 1672 1611 parameterBoolean: z._default(z.union([ 1673 1612 z._default(z.boolean(), true), 1674 1613 z.null() ··· 1789 1728 ]), 1790 1729 enabled: z._default(z.optional(z.boolean()), true), 1791 1730 type: z.enum([ 1792 - 'Monkey', 1793 - 'Horse', 1794 - 'Bird' 1731 + "Monkey", 1732 + "Horse", 1733 + "Bird" 1795 1734 ]), 1796 1735 listOfModels: z.optional(z.union([ 1797 1736 z.array(zModelWithString),
+3 -12
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/enum-null/zod.gen.ts
··· 2 2 3 3 import * as z from 'zod/v4-mini'; 4 4 5 - export const zFoo = z.nullable(z.enum([ 6 - 'foo', 7 - 'bar' 8 - ])); 5 + export const zFoo = z.nullable(z.enum(["foo", "bar"])); 9 6 10 - export const zBar = z.enum([ 11 - 'foo', 12 - 'bar' 13 - ]); 7 + export const zBar = z.enum(["foo", "bar"]); 14 8 15 - export const zBaz = z.enum([ 16 - 'foo', 17 - 'bar' 18 - ]); 9 + export const zBaz = z.enum(["foo", "bar"]);
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts
··· 11 11 z.literal(1), 12 12 z.literal(2), 13 13 z.literal(3), 14 - z.literal('foo'), 14 + z.literal("foo"), 15 15 z.literal(true) 16 16 ])), 17 17 corge: z.optional(z.record(z.string(), z.unknown())),
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts
··· 2 2 3 3 import * as z from 'zod/v4-mini'; 4 4 5 - export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), 'baz'); 5 + export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), "baz"); 6 6 7 7 export const zQux = z.record(z.string(), z.object({ 8 8 qux: z.optional(z.string())
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts
··· 2 2 3 3 import * as z from 'zod/v4-mini'; 4 4 5 - export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), 'baz'); 5 + export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), "baz"); 6 6 7 7 export const zQux = z.record(z.string(), z.object({ 8 8 qux: z.optional(z.string())
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts
··· 2 2 3 3 import * as z from 'zod/v4-mini'; 4 4 5 - export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), 'baz'); 5 + export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), "baz"); 6 6 7 7 export type BazZodType = z.infer<typeof zBaz>; 8 8
+4 -7
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-union-merge/zod.gen.ts
··· 22 22 23 23 export const zCatDetails = z.object({ 24 24 furLength: z.enum([ 25 - 'short', 26 - 'medium', 27 - 'long' 25 + "short", 26 + "medium", 27 + "long" 28 28 ]), 29 29 purrs: z.boolean() 30 30 }); ··· 32 32 export const zPetStore = z.object({ 33 33 animals: z.array(z.object({ 34 34 name: z.string(), 35 - type: z.optional(z.enum([ 36 - 'dog', 37 - 'cat' 38 - ])), 35 + type: z.optional(z.enum(["dog", "cat"])), 39 36 details: z.union([ 40 37 zDogDetails, 41 38 zCatDetails
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators/zod.gen.ts
··· 2 2 3 3 import * as z from 'zod/v4-mini'; 4 4 5 - export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), 'baz'); 5 + export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), "baz"); 6 6 7 7 export const zQux = z.record(z.string(), z.object({ 8 8 qux: z.optional(z.string())
+83 -144
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts
··· 90 90 * This is a simple enum with strings 91 91 */ 92 92 export const zEnumWithStrings = z.enum([ 93 - 'Success', 94 - 'Warning', 95 - 'Error', 93 + "Success", 94 + "Warning", 95 + "Error", 96 96 "'Single Quote'", 97 - '"Double Quotes"', 98 - 'Non-ascii: øæåôöØÆÅÔÖ字符串' 97 + "\"Double Quotes\"", 98 + "Non-ascii: øæåôöØÆÅÔÖ字符串" 99 99 ]); 100 100 101 101 export const zEnumWithReplacedCharacters = z.union([ 102 102 z.literal("'Single Quote'"), 103 - z.literal('"Double Quotes"'), 104 - z.literal('øæåôöØÆÅÔÖ字符串'), 103 + z.literal("\"Double Quotes\""), 104 + z.literal("øæåôöØÆÅÔÖ字符串"), 105 105 z.literal(3.1), 106 - z.literal('') 106 + z.literal("") 107 107 ]); 108 108 109 109 /** ··· 160 160 /** 161 161 * This is a simple array with strings 162 162 */ 163 - export const zArrayWithStrings = z.array(z.string()).default(['test']); 163 + export const zArrayWithStrings = z.array(z.string()).default(["test"]); 164 164 165 165 /** 166 166 * This is a simple array with properties ··· 173 173 /** 174 174 * This is a simple array with any of properties 175 175 */ 176 - export const zArrayWithAnyOfProperties = z.array(z.union([ 177 - z.object({ 178 - foo: z.string().optional().default('test') 179 - }), 180 - z.object({ 176 + export const zArrayWithAnyOfProperties = z.array(z.union([z.object({ 177 + foo: z.string().optional().default("test") 178 + }), z.object({ 181 179 bar: z.string().optional() 182 - }) 183 - ])); 180 + })])); 184 181 185 182 export const zAnyOfAnyAndNull = z.object({ 186 183 data: z.union([ ··· 193 190 * This is a simple array with any of properties 194 191 */ 195 192 export const zAnyOfArrays = z.object({ 196 - results: z.array(z.union([ 197 - z.object({ 193 + results: z.array(z.union([z.object({ 198 194 foo: z.string().optional() 199 - }), 200 - z.object({ 195 + }), z.object({ 201 196 bar: z.string().optional() 202 - }) 203 - ])).optional() 197 + })])).optional() 204 198 }); 205 199 206 200 /** ··· 305 299 z.null() 306 300 ]), 307 301 'foo_bar-enum': z.enum([ 308 - 'Success', 309 - 'Warning', 310 - 'Error', 311 - 'ØÆÅ字符串' 302 + "Success", 303 + "Warning", 304 + "Error", 305 + "ØÆÅ字符串" 312 306 ]).optional() 313 307 }); 314 308 ··· 317 311 */ 318 312 export const zModelWithEnum = z.object({ 319 313 'foo_bar-enum': z.enum([ 320 - 'Success', 321 - 'Warning', 322 - 'Error', 323 - 'ØÆÅ字符串' 314 + "Success", 315 + "Warning", 316 + "Error", 317 + "ØÆÅ字符串" 324 318 ]).optional(), 325 319 statusCode: z.enum([ 326 - '100', 327 - '200 FOO', 328 - '300 FOO_BAR', 329 - '400 foo-bar', 330 - '500 foo.bar', 331 - '600 foo&bar' 320 + "100", 321 + "200 FOO", 322 + "300 FOO_BAR", 323 + "400 foo-bar", 324 + "500 foo.bar", 325 + "600 foo&bar" 332 326 ]).optional(), 333 327 bool: z.literal(true).optional() 334 328 }); ··· 337 331 * This is a model with one enum with escaped name 338 332 */ 339 333 export const zModelWithEnumWithHyphen = z.object({ 340 - 'foo-bar-baz-qux': z.enum([ 341 - '3.0' 342 - ]).optional() 334 + 'foo-bar-baz-qux': z.enum(["3.0"]).optional() 343 335 }); 344 336 345 337 /** ··· 354 346 */ 355 347 export const zModelWithNestedEnums = z.object({ 356 348 dictionaryWithEnum: z.record(z.enum([ 357 - 'Success', 358 - 'Warning', 359 - 'Error' 349 + "Success", 350 + "Warning", 351 + "Error" 360 352 ])).optional(), 361 353 dictionaryWithEnumFromDescription: z.record(z.number().int()).optional(), 362 354 arrayWithEnum: z.array(z.enum([ 363 - 'Success', 364 - 'Warning', 365 - 'Error' 355 + "Success", 356 + "Warning", 357 + "Error" 366 358 ])).optional(), 367 359 arrayWithDescription: z.array(z.number().int()).optional(), 368 360 'foo_bar-enum': z.enum([ 369 - 'Success', 370 - 'Warning', 371 - 'Error', 372 - 'ØÆÅ字符串' 361 + "Success", 362 + "Warning", 363 + "Error", 364 + "ØÆÅ字符串" 373 365 ]).optional() 374 366 }); 375 367 ··· 488 480 */ 489 481 export const zCompositionWithNestedAnyAndTypeNull = z.object({ 490 482 propA: z.union([ 491 - z.array(z.union([ 492 - zModelWithDictionary, 493 - z.null() 494 - ])), 495 - z.array(z.union([ 496 - zModelWithArray, 497 - z.null() 498 - ])) 483 + z.array(z.union([zModelWithDictionary, z.null()])), 484 + z.array(z.union([zModelWithArray, z.null()])) 499 485 ]).optional() 500 486 }); 501 487 502 - export const z3eNum1Период = z.enum([ 503 - 'Bird', 504 - 'Dog' 505 - ]); 488 + export const z3eNum1Период = z.enum(["Bird", "Dog"]); 506 489 507 490 export const zConstValue = z.literal("ConstValue"); 508 491 ··· 511 494 */ 512 495 export const zCompositionWithNestedAnyOfAndNull = z.object({ 513 496 propA: z.union([ 514 - z.array(z.union([ 515 - z3eNum1Период, 516 - zConstValue 517 - ])), 497 + z.array(z.union([z3eNum1Период, zConstValue])), 518 498 z.null() 519 499 ]).optional() 520 500 }); ··· 560 540 export const zCompositionWithOneOfAndComplexArrayDictionary = z.object({ 561 541 propA: z.union([ 562 542 z.boolean(), 563 - z.record(z.array(z.union([ 564 - z.number(), 565 - z.string() 566 - ]))) 543 + z.record(z.array(z.union([z.number(), z.string()]))) 567 544 ]).optional() 568 545 }); 569 546 ··· 764 741 765 742 export const zNestedAnyOfArraysNullable = z.object({ 766 743 nullableArray: z.union([ 767 - z.array(z.union([ 768 - z.string(), 769 - z.boolean() 770 - ])), 744 + z.array(z.union([z.string(), z.boolean()])), 771 745 z.null() 772 746 ]).optional() 773 747 }); ··· 793 767 794 768 export const zModelWithOneOfEnum = z.union([ 795 769 z.object({ 796 - foo: z.enum([ 797 - 'Bar' 798 - ]) 770 + foo: z.enum(["Bar"]) 799 771 }), 800 772 z.object({ 801 - foo: z.enum([ 802 - 'Baz' 803 - ]) 773 + foo: z.enum(["Baz"]) 804 774 }), 805 775 z.object({ 806 - foo: z.enum([ 807 - 'Qux' 808 - ]) 776 + foo: z.enum(["Qux"]) 809 777 }), 810 778 z.object({ 811 779 content: z.string().datetime(), 812 - foo: z.enum([ 813 - 'Quux' 814 - ]) 780 + foo: z.enum(["Quux"]) 815 781 }), 816 782 z.object({ 817 - content: z.tuple([ 818 - z.string().datetime(), 819 - z.string() 820 - ]), 821 - foo: z.enum([ 822 - 'Corge' 823 - ]) 783 + content: z.tuple([z.string().datetime(), z.string()]), 784 + foo: z.enum(["Corge"]) 824 785 }) 825 786 ]); 826 787 827 - export const zModelWithNestedArrayEnumsDataFoo = z.enum([ 828 - 'foo', 829 - 'bar' 830 - ]); 788 + export const zModelWithNestedArrayEnumsDataFoo = z.enum(["foo", "bar"]); 831 789 832 - export const zModelWithNestedArrayEnumsDataBar = z.enum([ 833 - 'baz', 834 - 'qux' 835 - ]); 790 + export const zModelWithNestedArrayEnumsDataBar = z.enum(["baz", "qux"]); 836 791 837 792 export const zModelWithNestedArrayEnumsData = z.object({ 838 793 foo: z.array(zModelWithNestedArrayEnumsDataFoo).optional(), ··· 862 817 propWithNumber: z.array(z.number()).optional() 863 818 }); 864 819 865 - export const zModelWithConstantSizeArray = z.tuple([ 866 - z.number(), 867 - z.number() 868 - ]); 820 + export const zModelWithConstantSizeArray = z.tuple([z.number(), z.number()]); 869 821 870 822 export const zModelWithAnyOfConstantSizeArray = z.tuple([ 871 823 z.union([ ··· 909 861 ]) 910 862 ]); 911 863 912 - export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([ 913 - z.intersection(z.number(), z.string()), 914 - z.intersection(z.number(), z.string()) 915 - ]); 864 + export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([z.intersection(z.number(), z.string()), z.intersection(z.number(), z.string())]); 916 865 917 866 export const zModelWithNumericEnumUnion = z.object({ 918 867 value: z.union([ ··· 963 912 */ 964 913 export const zImport = z.string(); 965 914 966 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([ 967 - z.union([ 915 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([z.union([ 968 916 z.number(), 969 917 zImport 970 - ]), 971 - z.union([ 918 + ]), z.union([ 972 919 z.number(), 973 920 zImport 974 - ]) 975 - ]); 921 + ])]); 976 922 977 923 export const zSchemaWithFormRestrictedKeys = z.object({ 978 924 description: z.string().optional(), ··· 1130 1076 propWithNumber: z.array(z.number()).optional() 1131 1077 }); 1132 1078 1133 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([ 1134 - z.union([ 1079 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([z.union([ 1135 1080 z.number(), 1136 1081 zImport 1137 - ]), 1138 - z.union([ 1082 + ]), z.union([ 1139 1083 z.number(), 1140 1084 zImport 1141 - ]) 1142 - ]); 1085 + ])]); 1143 1086 1144 1087 export const zAdditionalPropertiesUnknownIssueWritable = z.record(z.union([ 1145 1088 z.string(), ··· 1465 1408 path: z.never().optional(), 1466 1409 query: z.object({ 1467 1410 parameterString: z.union([ 1468 - z.string().default('Hello World!'), 1411 + z.string().default("Hello World!"), 1469 1412 z.null() 1470 - ]).optional().default('Hello World!'), 1413 + ]).optional().default("Hello World!"), 1471 1414 parameterNumber: z.union([ 1472 1415 z.number().default(123), 1473 1416 z.null() ··· 1477 1420 z.null() 1478 1421 ]).optional().default(true), 1479 1422 parameterEnum: z.enum([ 1480 - 'Success', 1481 - 'Warning', 1482 - 'Error' 1423 + "Success", 1424 + "Warning", 1425 + "Error" 1483 1426 ]).optional(), 1484 1427 parameterModel: z.union([ 1485 - zModelWithString.default({ 1486 - prop: 'Hello World!' 1487 - }), 1428 + zModelWithString.default({ prop: "Hello World!" }), 1488 1429 z.null() 1489 1430 ]).optional() 1490 1431 }).optional() ··· 1494 1435 body: z.never().optional(), 1495 1436 path: z.never().optional(), 1496 1437 query: z.object({ 1497 - parameterString: z.string().optional().default('Hello World!'), 1438 + parameterString: z.string().optional().default("Hello World!"), 1498 1439 parameterNumber: z.number().optional().default(123), 1499 1440 parameterBoolean: z.boolean().optional().default(true), 1500 1441 parameterEnum: z.enum([ 1501 - 'Success', 1502 - 'Warning', 1503 - 'Error' 1442 + "Success", 1443 + "Warning", 1444 + "Error" 1504 1445 ]).optional(), 1505 - parameterModel: zModelWithString.optional().default({ 1506 - prop: 'Hello World!' 1507 - }) 1446 + parameterModel: zModelWithString.optional().default({ prop: "Hello World!" }) 1508 1447 }).optional() 1509 1448 }); 1510 1449 ··· 1512 1451 body: z.never().optional(), 1513 1452 path: z.never().optional(), 1514 1453 query: z.object({ 1515 - parameterOptionalStringWithDefault: z.string().optional().default('Hello World!'), 1516 - parameterOptionalStringWithEmptyDefault: z.string().optional().default(''), 1454 + parameterOptionalStringWithDefault: z.string().optional().default("Hello World!"), 1455 + parameterOptionalStringWithEmptyDefault: z.string().optional().default(""), 1517 1456 parameterOptionalStringWithNoDefault: z.string().optional(), 1518 - parameterStringWithDefault: z.string().default('Hello World!'), 1519 - parameterStringWithEmptyDefault: z.string().default(''), 1457 + parameterStringWithDefault: z.string().default("Hello World!"), 1458 + parameterStringWithEmptyDefault: z.string().default(""), 1520 1459 parameterStringWithNoDefault: z.string(), 1521 1460 parameterStringNullableWithNoDefault: z.union([ 1522 1461 z.string(), ··· 1664 1603 query: z.object({ 1665 1604 parameterNumber: z.number().default(123), 1666 1605 parameterString: z.union([ 1667 - z.string().default('default'), 1606 + z.string().default("default"), 1668 1607 z.null() 1669 - ]).default('default'), 1608 + ]).default("default"), 1670 1609 parameterBoolean: z.union([ 1671 1610 z.boolean().default(true), 1672 1611 z.null() ··· 1787 1726 ]), 1788 1727 enabled: z.boolean().optional().default(true), 1789 1728 type: z.enum([ 1790 - 'Monkey', 1791 - 'Horse', 1792 - 'Bird' 1729 + "Monkey", 1730 + "Horse", 1731 + "Bird" 1793 1732 ]), 1794 1733 listOfModels: z.union([ 1795 1734 z.array(zModelWithString),
+3 -12
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/enum-null/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod'; 4 4 5 - export const zFoo = z.enum([ 6 - 'foo', 7 - 'bar' 8 - ]).nullable(); 5 + export const zFoo = z.enum(["foo", "bar"]).nullable(); 9 6 10 - export const zBar = z.enum([ 11 - 'foo', 12 - 'bar' 13 - ]); 7 + export const zBar = z.enum(["foo", "bar"]); 14 8 15 - export const zBaz = z.enum([ 16 - 'foo', 17 - 'bar' 18 - ]); 9 + export const zBaz = z.enum(["foo", "bar"]);
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts
··· 11 11 z.literal(1), 12 12 z.literal(2), 13 13 z.literal(3), 14 - z.literal('foo'), 14 + z.literal("foo"), 15 15 z.literal(true) 16 16 ]).optional(), 17 17 corge: z.record(z.unknown()).optional(),
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export const zQux = z.record(z.object({ 8 8 qux: z.string().optional()
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export const zQux = z.record(z.object({ 8 8 qux: z.string().optional()
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export type BazZodType = z.infer<typeof zBaz>; 8 8
+4 -7
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-union-merge/zod.gen.ts
··· 22 22 23 23 export const zCatDetails = z.object({ 24 24 furLength: z.enum([ 25 - 'short', 26 - 'medium', 27 - 'long' 25 + "short", 26 + "medium", 27 + "long" 28 28 ]), 29 29 purrs: z.boolean() 30 30 }); ··· 32 32 export const zPetStore = z.object({ 33 33 animals: z.array(z.object({ 34 34 name: z.string(), 35 - type: z.enum([ 36 - 'dog', 37 - 'cat' 38 - ]).optional(), 35 + type: z.enum(["dog", "cat"]).optional(), 39 36 details: z.union([ 40 37 zDogDetails, 41 38 zCatDetails
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export const zQux = z.record(z.object({ 8 8 qux: z.string().optional()
+83 -144
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts
··· 90 90 * This is a simple enum with strings 91 91 */ 92 92 export const zEnumWithStrings = z.enum([ 93 - 'Success', 94 - 'Warning', 95 - 'Error', 93 + "Success", 94 + "Warning", 95 + "Error", 96 96 "'Single Quote'", 97 - '"Double Quotes"', 98 - 'Non-ascii: øæåôöØÆÅÔÖ字符串' 97 + "\"Double Quotes\"", 98 + "Non-ascii: øæåôöØÆÅÔÖ字符串" 99 99 ]); 100 100 101 101 export const zEnumWithReplacedCharacters = z.union([ 102 102 z.literal("'Single Quote'"), 103 - z.literal('"Double Quotes"'), 104 - z.literal('øæåôöØÆÅÔÖ字符串'), 103 + z.literal("\"Double Quotes\""), 104 + z.literal("øæåôöØÆÅÔÖ字符串"), 105 105 z.literal(3.1), 106 - z.literal('') 106 + z.literal("") 107 107 ]); 108 108 109 109 /** ··· 160 160 /** 161 161 * This is a simple array with strings 162 162 */ 163 - export const zArrayWithStrings = z.array(z.string()).default(['test']); 163 + export const zArrayWithStrings = z.array(z.string()).default(["test"]); 164 164 165 165 /** 166 166 * This is a simple array with properties ··· 173 173 /** 174 174 * This is a simple array with any of properties 175 175 */ 176 - export const zArrayWithAnyOfProperties = z.array(z.union([ 177 - z.object({ 178 - foo: z.optional(z.string()).default('test') 179 - }), 180 - z.object({ 176 + export const zArrayWithAnyOfProperties = z.array(z.union([z.object({ 177 + foo: z.optional(z.string()).default("test") 178 + }), z.object({ 181 179 bar: z.optional(z.string()) 182 - }) 183 - ])); 180 + })])); 184 181 185 182 export const zAnyOfAnyAndNull = z.object({ 186 183 data: z.optional(z.union([ ··· 193 190 * This is a simple array with any of properties 194 191 */ 195 192 export const zAnyOfArrays = z.object({ 196 - results: z.optional(z.array(z.union([ 197 - z.object({ 193 + results: z.optional(z.array(z.union([z.object({ 198 194 foo: z.optional(z.string()) 199 - }), 200 - z.object({ 195 + }), z.object({ 201 196 bar: z.optional(z.string()) 202 - }) 203 - ]))) 197 + })]))) 204 198 }); 205 199 206 200 /** ··· 305 299 z.null() 306 300 ]), 307 301 'foo_bar-enum': z.optional(z.enum([ 308 - 'Success', 309 - 'Warning', 310 - 'Error', 311 - 'ØÆÅ字符串' 302 + "Success", 303 + "Warning", 304 + "Error", 305 + "ØÆÅ字符串" 312 306 ])) 313 307 }); 314 308 ··· 317 311 */ 318 312 export const zModelWithEnum = z.object({ 319 313 'foo_bar-enum': z.optional(z.enum([ 320 - 'Success', 321 - 'Warning', 322 - 'Error', 323 - 'ØÆÅ字符串' 314 + "Success", 315 + "Warning", 316 + "Error", 317 + "ØÆÅ字符串" 324 318 ])), 325 319 statusCode: z.optional(z.enum([ 326 - '100', 327 - '200 FOO', 328 - '300 FOO_BAR', 329 - '400 foo-bar', 330 - '500 foo.bar', 331 - '600 foo&bar' 320 + "100", 321 + "200 FOO", 322 + "300 FOO_BAR", 323 + "400 foo-bar", 324 + "500 foo.bar", 325 + "600 foo&bar" 332 326 ])), 333 327 bool: z.optional(z.literal(true)) 334 328 }); ··· 337 331 * This is a model with one enum with escaped name 338 332 */ 339 333 export const zModelWithEnumWithHyphen = z.object({ 340 - 'foo-bar-baz-qux': z.optional(z.enum([ 341 - '3.0' 342 - ])) 334 + 'foo-bar-baz-qux': z.optional(z.enum(["3.0"])) 343 335 }); 344 336 345 337 /** ··· 354 346 */ 355 347 export const zModelWithNestedEnums = z.object({ 356 348 dictionaryWithEnum: z.optional(z.record(z.string(), z.enum([ 357 - 'Success', 358 - 'Warning', 359 - 'Error' 349 + "Success", 350 + "Warning", 351 + "Error" 360 352 ]))), 361 353 dictionaryWithEnumFromDescription: z.optional(z.record(z.string(), z.int())), 362 354 arrayWithEnum: z.optional(z.array(z.enum([ 363 - 'Success', 364 - 'Warning', 365 - 'Error' 355 + "Success", 356 + "Warning", 357 + "Error" 366 358 ]))), 367 359 arrayWithDescription: z.optional(z.array(z.int())), 368 360 'foo_bar-enum': z.optional(z.enum([ 369 - 'Success', 370 - 'Warning', 371 - 'Error', 372 - 'ØÆÅ字符串' 361 + "Success", 362 + "Warning", 363 + "Error", 364 + "ØÆÅ字符串" 373 365 ])) 374 366 }); 375 367 ··· 490 482 */ 491 483 export const zCompositionWithNestedAnyAndTypeNull = z.object({ 492 484 propA: z.optional(z.union([ 493 - z.array(z.union([ 494 - zModelWithDictionary, 495 - z.null() 496 - ])), 497 - z.array(z.union([ 498 - zModelWithArray, 499 - z.null() 500 - ])) 485 + z.array(z.union([zModelWithDictionary, z.null()])), 486 + z.array(z.union([zModelWithArray, z.null()])) 501 487 ])) 502 488 }); 503 489 504 - export const z3eNum1Период = z.enum([ 505 - 'Bird', 506 - 'Dog' 507 - ]); 490 + export const z3eNum1Период = z.enum(["Bird", "Dog"]); 508 491 509 492 export const zConstValue = z.literal("ConstValue"); 510 493 ··· 513 496 */ 514 497 export const zCompositionWithNestedAnyOfAndNull = z.object({ 515 498 propA: z.optional(z.union([ 516 - z.array(z.union([ 517 - z3eNum1Период, 518 - zConstValue 519 - ])), 499 + z.array(z.union([z3eNum1Период, zConstValue])), 520 500 z.null() 521 501 ])) 522 502 }); ··· 562 542 export const zCompositionWithOneOfAndComplexArrayDictionary = z.object({ 563 543 propA: z.optional(z.union([ 564 544 z.boolean(), 565 - z.record(z.string(), z.array(z.union([ 566 - z.number(), 567 - z.string() 568 - ]))) 545 + z.record(z.string(), z.array(z.union([z.number(), z.string()]))) 569 546 ])) 570 547 }); 571 548 ··· 766 743 767 744 export const zNestedAnyOfArraysNullable = z.object({ 768 745 nullableArray: z.optional(z.union([ 769 - z.array(z.union([ 770 - z.string(), 771 - z.boolean() 772 - ])), 746 + z.array(z.union([z.string(), z.boolean()])), 773 747 z.null() 774 748 ])) 775 749 }); ··· 795 769 796 770 export const zModelWithOneOfEnum = z.union([ 797 771 z.object({ 798 - foo: z.enum([ 799 - 'Bar' 800 - ]) 772 + foo: z.enum(["Bar"]) 801 773 }), 802 774 z.object({ 803 - foo: z.enum([ 804 - 'Baz' 805 - ]) 775 + foo: z.enum(["Baz"]) 806 776 }), 807 777 z.object({ 808 - foo: z.enum([ 809 - 'Qux' 810 - ]) 778 + foo: z.enum(["Qux"]) 811 779 }), 812 780 z.object({ 813 781 content: z.iso.datetime(), 814 - foo: z.enum([ 815 - 'Quux' 816 - ]) 782 + foo: z.enum(["Quux"]) 817 783 }), 818 784 z.object({ 819 - content: z.tuple([ 820 - z.iso.datetime(), 821 - z.string() 822 - ]), 823 - foo: z.enum([ 824 - 'Corge' 825 - ]) 785 + content: z.tuple([z.iso.datetime(), z.string()]), 786 + foo: z.enum(["Corge"]) 826 787 }) 827 788 ]); 828 789 829 - export const zModelWithNestedArrayEnumsDataFoo = z.enum([ 830 - 'foo', 831 - 'bar' 832 - ]); 790 + export const zModelWithNestedArrayEnumsDataFoo = z.enum(["foo", "bar"]); 833 791 834 - export const zModelWithNestedArrayEnumsDataBar = z.enum([ 835 - 'baz', 836 - 'qux' 837 - ]); 792 + export const zModelWithNestedArrayEnumsDataBar = z.enum(["baz", "qux"]); 838 793 839 794 export const zModelWithNestedArrayEnumsData = z.object({ 840 795 foo: z.optional(z.array(zModelWithNestedArrayEnumsDataFoo)), ··· 864 819 propWithNumber: z.optional(z.array(z.number())) 865 820 }); 866 821 867 - export const zModelWithConstantSizeArray = z.tuple([ 868 - z.number(), 869 - z.number() 870 - ]); 822 + export const zModelWithConstantSizeArray = z.tuple([z.number(), z.number()]); 871 823 872 824 export const zModelWithAnyOfConstantSizeArray = z.tuple([ 873 825 z.union([ ··· 911 863 ]) 912 864 ]); 913 865 914 - export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([ 915 - z.intersection(z.number(), z.string()), 916 - z.intersection(z.number(), z.string()) 917 - ]); 866 + export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([z.intersection(z.number(), z.string()), z.intersection(z.number(), z.string())]); 918 867 919 868 export const zModelWithNumericEnumUnion = z.object({ 920 869 value: z.optional(z.union([ ··· 965 914 */ 966 915 export const zImport = z.string(); 967 916 968 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([ 969 - z.union([ 917 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([z.union([ 970 918 z.number(), 971 919 zImport 972 - ]), 973 - z.union([ 920 + ]), z.union([ 974 921 z.number(), 975 922 zImport 976 - ]) 977 - ]); 923 + ])]); 978 924 979 925 export const zSchemaWithFormRestrictedKeys = z.object({ 980 926 description: z.optional(z.string()), ··· 1132 1078 propWithNumber: z.optional(z.array(z.number())) 1133 1079 }); 1134 1080 1135 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([ 1136 - z.union([ 1081 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([z.union([ 1137 1082 z.number(), 1138 1083 zImport 1139 - ]), 1140 - z.union([ 1084 + ]), z.union([ 1141 1085 z.number(), 1142 1086 zImport 1143 - ]) 1144 - ]); 1087 + ])]); 1145 1088 1146 1089 export const zAdditionalPropertiesUnknownIssueWritable = z.record(z.string(), z.union([ 1147 1090 z.string(), ··· 1467 1410 path: z.optional(z.never()), 1468 1411 query: z.optional(z.object({ 1469 1412 parameterString: z.optional(z.union([ 1470 - z.string().default('Hello World!'), 1413 + z.string().default("Hello World!"), 1471 1414 z.null() 1472 - ])).default('Hello World!'), 1415 + ])).default("Hello World!"), 1473 1416 parameterNumber: z.optional(z.union([ 1474 1417 z.number().default(123), 1475 1418 z.null() ··· 1479 1422 z.null() 1480 1423 ])).default(true), 1481 1424 parameterEnum: z.optional(z.enum([ 1482 - 'Success', 1483 - 'Warning', 1484 - 'Error' 1425 + "Success", 1426 + "Warning", 1427 + "Error" 1485 1428 ])), 1486 1429 parameterModel: z.optional(z.union([ 1487 - zModelWithString.default({ 1488 - prop: 'Hello World!' 1489 - }), 1430 + zModelWithString.default({ prop: "Hello World!" }), 1490 1431 z.null() 1491 1432 ])) 1492 1433 })) ··· 1496 1437 body: z.optional(z.never()), 1497 1438 path: z.optional(z.never()), 1498 1439 query: z.optional(z.object({ 1499 - parameterString: z.optional(z.string()).default('Hello World!'), 1440 + parameterString: z.optional(z.string()).default("Hello World!"), 1500 1441 parameterNumber: z.optional(z.number()).default(123), 1501 1442 parameterBoolean: z.optional(z.boolean()).default(true), 1502 1443 parameterEnum: z.optional(z.enum([ 1503 - 'Success', 1504 - 'Warning', 1505 - 'Error' 1444 + "Success", 1445 + "Warning", 1446 + "Error" 1506 1447 ])), 1507 - parameterModel: z.optional(zModelWithString).default({ 1508 - prop: 'Hello World!' 1509 - }) 1448 + parameterModel: z.optional(zModelWithString).default({ prop: "Hello World!" }) 1510 1449 })) 1511 1450 }); 1512 1451 ··· 1514 1453 body: z.optional(z.never()), 1515 1454 path: z.optional(z.never()), 1516 1455 query: z.object({ 1517 - parameterOptionalStringWithDefault: z.optional(z.string()).default('Hello World!'), 1518 - parameterOptionalStringWithEmptyDefault: z.optional(z.string()).default(''), 1456 + parameterOptionalStringWithDefault: z.optional(z.string()).default("Hello World!"), 1457 + parameterOptionalStringWithEmptyDefault: z.optional(z.string()).default(""), 1519 1458 parameterOptionalStringWithNoDefault: z.optional(z.string()), 1520 - parameterStringWithDefault: z.string().default('Hello World!'), 1521 - parameterStringWithEmptyDefault: z.string().default(''), 1459 + parameterStringWithDefault: z.string().default("Hello World!"), 1460 + parameterStringWithEmptyDefault: z.string().default(""), 1522 1461 parameterStringWithNoDefault: z.string(), 1523 1462 parameterStringNullableWithNoDefault: z.optional(z.union([ 1524 1463 z.string(), ··· 1666 1605 query: z.object({ 1667 1606 parameterNumber: z.number().default(123), 1668 1607 parameterString: z.union([ 1669 - z.string().default('default'), 1608 + z.string().default("default"), 1670 1609 z.null() 1671 - ]).default('default'), 1610 + ]).default("default"), 1672 1611 parameterBoolean: z.union([ 1673 1612 z.boolean().default(true), 1674 1613 z.null() ··· 1789 1728 ]), 1790 1729 enabled: z.optional(z.boolean()).default(true), 1791 1730 type: z.enum([ 1792 - 'Monkey', 1793 - 'Horse', 1794 - 'Bird' 1731 + "Monkey", 1732 + "Horse", 1733 + "Bird" 1795 1734 ]), 1796 1735 listOfModels: z.optional(z.union([ 1797 1736 z.array(zModelWithString),
+3 -12
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/enum-null/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod/v4'; 4 4 5 - export const zFoo = z.nullable(z.enum([ 6 - 'foo', 7 - 'bar' 8 - ])); 5 + export const zFoo = z.nullable(z.enum(["foo", "bar"])); 9 6 10 - export const zBar = z.enum([ 11 - 'foo', 12 - 'bar' 13 - ]); 7 + export const zBar = z.enum(["foo", "bar"]); 14 8 15 - export const zBaz = z.enum([ 16 - 'foo', 17 - 'bar' 18 - ]); 9 + export const zBaz = z.enum(["foo", "bar"]);
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts
··· 11 11 z.literal(1), 12 12 z.literal(2), 13 13 z.literal(3), 14 - z.literal('foo'), 14 + z.literal("foo"), 15 15 z.literal(true) 16 16 ])), 17 17 corge: z.optional(z.record(z.string(), z.unknown())),
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod/v4'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export const zQux = z.record(z.string(), z.object({ 8 8 qux: z.optional(z.string())
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod/v4'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export const zQux = z.record(z.string(), z.object({ 8 8 qux: z.optional(z.string())
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod/v4'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export type BazZodType = z.infer<typeof zBaz>; 8 8
+4 -7
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-union-merge/zod.gen.ts
··· 22 22 23 23 export const zCatDetails = z.object({ 24 24 furLength: z.enum([ 25 - 'short', 26 - 'medium', 27 - 'long' 25 + "short", 26 + "medium", 27 + "long" 28 28 ]), 29 29 purrs: z.boolean() 30 30 }); ··· 32 32 export const zPetStore = z.object({ 33 33 animals: z.array(z.object({ 34 34 name: z.string(), 35 - type: z.optional(z.enum([ 36 - 'dog', 37 - 'cat' 38 - ])), 35 + type: z.optional(z.enum(["dog", "cat"])), 39 36 details: z.union([ 40 37 zDogDetails, 41 38 zCatDetails
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod/v4'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export const zQux = z.record(z.string(), z.object({ 8 8 qux: z.optional(z.string())
+38 -40
packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/default/zod.gen.ts
··· 74 74 * This is a simple enum with strings 75 75 */ 76 76 export const zEnumWithStrings = z.enum([ 77 - 'Success', 78 - 'Warning', 79 - 'Error', 77 + "Success", 78 + "Warning", 79 + "Error", 80 80 "'Single Quote'", 81 - '"Double Quotes"', 82 - 'Non-ascii: øæåôöØÆÅÔÖ字符串' 81 + "\"Double Quotes\"", 82 + "Non-ascii: øæåôöØÆÅÔÖ字符串" 83 83 ]); 84 84 85 85 /** ··· 232 232 */ 233 233 export const zModelWithEnum = z.object({ 234 234 test: z.optional(z.enum([ 235 - 'Success', 236 - 'Warning', 237 - 'Error', 238 - 'ØÆÅ字符串' 235 + "Success", 236 + "Warning", 237 + "Error", 238 + "ØÆÅ字符串" 239 239 ])), 240 240 statusCode: z.optional(z.enum([ 241 - '100', 242 - '200 FOO', 243 - '300 FOO_BAR', 244 - '400 foo-bar', 245 - '500 foo.bar', 246 - '600 foo&bar' 241 + "100", 242 + "200 FOO", 243 + "300 FOO_BAR", 244 + "400 foo-bar", 245 + "500 foo.bar", 246 + "600 foo&bar" 247 247 ])), 248 248 bool: z.optional(z.literal(true)) 249 249 }); ··· 260 260 */ 261 261 export const zModelWithNestedEnums = z.object({ 262 262 dictionaryWithEnum: z.optional(z.record(z.string(), z.enum([ 263 - 'Success', 264 - 'Warning', 265 - 'Error' 263 + "Success", 264 + "Warning", 265 + "Error" 266 266 ]))), 267 267 dictionaryWithEnumFromDescription: z.optional(z.record(z.string(), z.int())), 268 268 arrayWithEnum: z.optional(z.array(z.enum([ 269 - 'Success', 270 - 'Warning', 271 - 'Error' 269 + "Success", 270 + "Warning", 271 + "Error" 272 272 ]))), 273 273 arrayWithDescription: z.optional(z.array(z.int())) 274 274 }); ··· 566 566 body: z.optional(z.never()), 567 567 path: z.optional(z.never()), 568 568 query: z.object({ 569 - parameterString: z._default(z.string(), 'Hello World!'), 569 + parameterString: z._default(z.string(), "Hello World!"), 570 570 parameterNumber: z._default(z.number(), 123), 571 571 parameterBoolean: z._default(z.boolean(), true), 572 572 parameterEnum: z.enum([ 573 - 'Success', 574 - 'Warning', 575 - 'Error' 573 + "Success", 574 + "Warning", 575 + "Error" 576 576 ]), 577 577 parameterModel: z._default(z.object({ 578 578 prop: z.optional(z.string()) 579 - }), { 580 - prop: 'Hello World!' 581 - }) 579 + }), { prop: "Hello World!" }) 582 580 }) 583 581 }); 584 582 ··· 586 584 body: z.optional(z.never()), 587 585 path: z.optional(z.never()), 588 586 query: z.optional(z.object({ 589 - parameterString: z._default(z.optional(z.string()), 'Hello World!'), 587 + parameterString: z._default(z.optional(z.string()), "Hello World!"), 590 588 parameterNumber: z._default(z.optional(z.number()), 123), 591 589 parameterBoolean: z._default(z.optional(z.boolean()), true), 592 590 parameterEnum: z.optional(z.enum([ 593 - 'Success', 594 - 'Warning', 595 - 'Error' 591 + "Success", 592 + "Warning", 593 + "Error" 596 594 ])) 597 595 })) 598 596 }); ··· 601 599 body: z.optional(z.never()), 602 600 path: z.optional(z.never()), 603 601 query: z.object({ 604 - parameterOptionalStringWithDefault: z._default(z.optional(z.string()), 'Hello World!'), 605 - parameterOptionalStringWithEmptyDefault: z._default(z.optional(z.string()), ''), 602 + parameterOptionalStringWithDefault: z._default(z.optional(z.string()), "Hello World!"), 603 + parameterOptionalStringWithEmptyDefault: z._default(z.optional(z.string()), ""), 606 604 parameterOptionalStringWithNoDefault: z.optional(z.string()), 607 - parameterStringWithDefault: z._default(z.string(), 'Hello World!'), 608 - parameterStringWithEmptyDefault: z._default(z.string(), ''), 605 + parameterStringWithDefault: z._default(z.string(), "Hello World!"), 606 + parameterStringWithEmptyDefault: z._default(z.string(), ""), 609 607 parameterStringWithNoDefault: z.string(), 610 608 parameterStringNullableWithNoDefault: z.optional(z.union([ 611 609 z.string(), ··· 728 726 })), 729 727 query: z.object({ 730 728 parameterNumber: z._default(z.number(), 123), 731 - parameterString: z._default(z.string(), 'default'), 729 + parameterString: z._default(z.string(), "default"), 732 730 parameterBoolean: z._default(z.boolean(), true), 733 731 parameterArray: z.array(z.string()), 734 732 parameterDictionary: z.record(z.string(), z.unknown()), 735 733 parameterEnum: z.enum([ 736 - 'Success', 737 - 'Warning', 738 - 'Error' 734 + "Success", 735 + "Warning", 736 + "Error" 739 737 ]) 740 738 }) 741 739 });
+38 -40
packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/default/zod.gen.ts
··· 74 74 * This is a simple enum with strings 75 75 */ 76 76 export const zEnumWithStrings = z.enum([ 77 - 'Success', 78 - 'Warning', 79 - 'Error', 77 + "Success", 78 + "Warning", 79 + "Error", 80 80 "'Single Quote'", 81 - '"Double Quotes"', 82 - 'Non-ascii: øæåôöØÆÅÔÖ字符串' 81 + "\"Double Quotes\"", 82 + "Non-ascii: øæåôöØÆÅÔÖ字符串" 83 83 ]); 84 84 85 85 /** ··· 232 232 */ 233 233 export const zModelWithEnum = z.object({ 234 234 test: z.enum([ 235 - 'Success', 236 - 'Warning', 237 - 'Error', 238 - 'ØÆÅ字符串' 235 + "Success", 236 + "Warning", 237 + "Error", 238 + "ØÆÅ字符串" 239 239 ]).optional(), 240 240 statusCode: z.enum([ 241 - '100', 242 - '200 FOO', 243 - '300 FOO_BAR', 244 - '400 foo-bar', 245 - '500 foo.bar', 246 - '600 foo&bar' 241 + "100", 242 + "200 FOO", 243 + "300 FOO_BAR", 244 + "400 foo-bar", 245 + "500 foo.bar", 246 + "600 foo&bar" 247 247 ]).optional(), 248 248 bool: z.literal(true).optional() 249 249 }); ··· 260 260 */ 261 261 export const zModelWithNestedEnums = z.object({ 262 262 dictionaryWithEnum: z.record(z.enum([ 263 - 'Success', 264 - 'Warning', 265 - 'Error' 263 + "Success", 264 + "Warning", 265 + "Error" 266 266 ])).optional(), 267 267 dictionaryWithEnumFromDescription: z.record(z.number().int()).optional(), 268 268 arrayWithEnum: z.array(z.enum([ 269 - 'Success', 270 - 'Warning', 271 - 'Error' 269 + "Success", 270 + "Warning", 271 + "Error" 272 272 ])).optional(), 273 273 arrayWithDescription: z.array(z.number().int()).optional() 274 274 }); ··· 564 564 body: z.never().optional(), 565 565 path: z.never().optional(), 566 566 query: z.object({ 567 - parameterString: z.string().default('Hello World!'), 567 + parameterString: z.string().default("Hello World!"), 568 568 parameterNumber: z.number().default(123), 569 569 parameterBoolean: z.boolean().default(true), 570 570 parameterEnum: z.enum([ 571 - 'Success', 572 - 'Warning', 573 - 'Error' 571 + "Success", 572 + "Warning", 573 + "Error" 574 574 ]), 575 575 parameterModel: z.object({ 576 576 prop: z.string().optional() 577 - }).default({ 578 - prop: 'Hello World!' 579 - }) 577 + }).default({ prop: "Hello World!" }) 580 578 }) 581 579 }); 582 580 ··· 584 582 body: z.never().optional(), 585 583 path: z.never().optional(), 586 584 query: z.object({ 587 - parameterString: z.string().optional().default('Hello World!'), 585 + parameterString: z.string().optional().default("Hello World!"), 588 586 parameterNumber: z.number().optional().default(123), 589 587 parameterBoolean: z.boolean().optional().default(true), 590 588 parameterEnum: z.enum([ 591 - 'Success', 592 - 'Warning', 593 - 'Error' 589 + "Success", 590 + "Warning", 591 + "Error" 594 592 ]).optional() 595 593 }).optional() 596 594 }); ··· 599 597 body: z.never().optional(), 600 598 path: z.never().optional(), 601 599 query: z.object({ 602 - parameterOptionalStringWithDefault: z.string().optional().default('Hello World!'), 603 - parameterOptionalStringWithEmptyDefault: z.string().optional().default(''), 600 + parameterOptionalStringWithDefault: z.string().optional().default("Hello World!"), 601 + parameterOptionalStringWithEmptyDefault: z.string().optional().default(""), 604 602 parameterOptionalStringWithNoDefault: z.string().optional(), 605 - parameterStringWithDefault: z.string().default('Hello World!'), 606 - parameterStringWithEmptyDefault: z.string().default(''), 603 + parameterStringWithDefault: z.string().default("Hello World!"), 604 + parameterStringWithEmptyDefault: z.string().default(""), 607 605 parameterStringWithNoDefault: z.string(), 608 606 parameterStringNullableWithNoDefault: z.union([ 609 607 z.string(), ··· 726 724 }).optional(), 727 725 query: z.object({ 728 726 parameterNumber: z.number().default(123), 729 - parameterString: z.string().default('default'), 727 + parameterString: z.string().default("default"), 730 728 parameterBoolean: z.boolean().default(true), 731 729 parameterArray: z.array(z.string()), 732 730 parameterDictionary: z.record(z.unknown()), 733 731 parameterEnum: z.enum([ 734 - 'Success', 735 - 'Warning', 736 - 'Error' 732 + "Success", 733 + "Warning", 734 + "Error" 737 735 ]) 738 736 }) 739 737 });
+38 -40
packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/default/zod.gen.ts
··· 74 74 * This is a simple enum with strings 75 75 */ 76 76 export const zEnumWithStrings = z.enum([ 77 - 'Success', 78 - 'Warning', 79 - 'Error', 77 + "Success", 78 + "Warning", 79 + "Error", 80 80 "'Single Quote'", 81 - '"Double Quotes"', 82 - 'Non-ascii: øæåôöØÆÅÔÖ字符串' 81 + "\"Double Quotes\"", 82 + "Non-ascii: øæåôöØÆÅÔÖ字符串" 83 83 ]); 84 84 85 85 /** ··· 232 232 */ 233 233 export const zModelWithEnum = z.object({ 234 234 test: z.optional(z.enum([ 235 - 'Success', 236 - 'Warning', 237 - 'Error', 238 - 'ØÆÅ字符串' 235 + "Success", 236 + "Warning", 237 + "Error", 238 + "ØÆÅ字符串" 239 239 ])), 240 240 statusCode: z.optional(z.enum([ 241 - '100', 242 - '200 FOO', 243 - '300 FOO_BAR', 244 - '400 foo-bar', 245 - '500 foo.bar', 246 - '600 foo&bar' 241 + "100", 242 + "200 FOO", 243 + "300 FOO_BAR", 244 + "400 foo-bar", 245 + "500 foo.bar", 246 + "600 foo&bar" 247 247 ])), 248 248 bool: z.optional(z.literal(true)) 249 249 }); ··· 260 260 */ 261 261 export const zModelWithNestedEnums = z.object({ 262 262 dictionaryWithEnum: z.optional(z.record(z.string(), z.enum([ 263 - 'Success', 264 - 'Warning', 265 - 'Error' 263 + "Success", 264 + "Warning", 265 + "Error" 266 266 ]))), 267 267 dictionaryWithEnumFromDescription: z.optional(z.record(z.string(), z.int())), 268 268 arrayWithEnum: z.optional(z.array(z.enum([ 269 - 'Success', 270 - 'Warning', 271 - 'Error' 269 + "Success", 270 + "Warning", 271 + "Error" 272 272 ]))), 273 273 arrayWithDescription: z.optional(z.array(z.int())) 274 274 }); ··· 566 566 body: z.optional(z.never()), 567 567 path: z.optional(z.never()), 568 568 query: z.object({ 569 - parameterString: z.string().default('Hello World!'), 569 + parameterString: z.string().default("Hello World!"), 570 570 parameterNumber: z.number().default(123), 571 571 parameterBoolean: z.boolean().default(true), 572 572 parameterEnum: z.enum([ 573 - 'Success', 574 - 'Warning', 575 - 'Error' 573 + "Success", 574 + "Warning", 575 + "Error" 576 576 ]), 577 577 parameterModel: z.object({ 578 578 prop: z.optional(z.string()) 579 - }).default({ 580 - prop: 'Hello World!' 581 - }) 579 + }).default({ prop: "Hello World!" }) 582 580 }) 583 581 }); 584 582 ··· 586 584 body: z.optional(z.never()), 587 585 path: z.optional(z.never()), 588 586 query: z.optional(z.object({ 589 - parameterString: z.optional(z.string()).default('Hello World!'), 587 + parameterString: z.optional(z.string()).default("Hello World!"), 590 588 parameterNumber: z.optional(z.number()).default(123), 591 589 parameterBoolean: z.optional(z.boolean()).default(true), 592 590 parameterEnum: z.optional(z.enum([ 593 - 'Success', 594 - 'Warning', 595 - 'Error' 591 + "Success", 592 + "Warning", 593 + "Error" 596 594 ])) 597 595 })) 598 596 }); ··· 601 599 body: z.optional(z.never()), 602 600 path: z.optional(z.never()), 603 601 query: z.object({ 604 - parameterOptionalStringWithDefault: z.optional(z.string()).default('Hello World!'), 605 - parameterOptionalStringWithEmptyDefault: z.optional(z.string()).default(''), 602 + parameterOptionalStringWithDefault: z.optional(z.string()).default("Hello World!"), 603 + parameterOptionalStringWithEmptyDefault: z.optional(z.string()).default(""), 606 604 parameterOptionalStringWithNoDefault: z.optional(z.string()), 607 - parameterStringWithDefault: z.string().default('Hello World!'), 608 - parameterStringWithEmptyDefault: z.string().default(''), 605 + parameterStringWithDefault: z.string().default("Hello World!"), 606 + parameterStringWithEmptyDefault: z.string().default(""), 609 607 parameterStringWithNoDefault: z.string(), 610 608 parameterStringNullableWithNoDefault: z.optional(z.union([ 611 609 z.string(), ··· 728 726 })), 729 727 query: z.object({ 730 728 parameterNumber: z.number().default(123), 731 - parameterString: z.string().default('default'), 729 + parameterString: z.string().default("default"), 732 730 parameterBoolean: z.boolean().default(true), 733 731 parameterArray: z.array(z.string()), 734 732 parameterDictionary: z.record(z.string(), z.unknown()), 735 733 parameterEnum: z.enum([ 736 - 'Success', 737 - 'Warning', 738 - 'Error' 734 + "Success", 735 + "Warning", 736 + "Error" 739 737 ]) 740 738 }) 741 739 });
+85 -142
packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts
··· 90 90 * This is a simple enum with strings 91 91 */ 92 92 export const zEnumWithStrings = z.enum([ 93 - 'Success', 94 - 'Warning', 95 - 'Error', 93 + "Success", 94 + "Warning", 95 + "Error", 96 96 "'Single Quote'", 97 - '"Double Quotes"', 98 - 'Non-ascii: øæåôöØÆÅÔÖ字符串' 97 + "\"Double Quotes\"", 98 + "Non-ascii: øæåôöØÆÅÔÖ字符串" 99 99 ]); 100 100 101 101 export const zEnumWithReplacedCharacters = z.union([ 102 102 z.literal("'Single Quote'"), 103 - z.literal('"Double Quotes"'), 104 - z.literal('øæåôöØÆÅÔÖ字符串'), 103 + z.literal("\"Double Quotes\""), 104 + z.literal("øæåôöØÆÅÔÖ字符串"), 105 105 z.literal(3.1), 106 - z.literal('') 106 + z.literal("") 107 107 ]); 108 108 109 109 /** ··· 160 160 /** 161 161 * This is a simple array with strings 162 162 */ 163 - export const zArrayWithStrings = z._default(z.array(z.string()), ['test']); 163 + export const zArrayWithStrings = z._default(z.array(z.string()), ["test"]); 164 164 165 165 /** 166 166 * This is a simple array with properties ··· 173 173 /** 174 174 * This is a simple array with any of properties 175 175 */ 176 - export const zArrayWithAnyOfProperties = z.array(z.union([ 177 - z.object({ 178 - foo: z._default(z.optional(z.string()), 'test') 179 - }), 180 - z.object({ 176 + export const zArrayWithAnyOfProperties = z.array(z.union([z.object({ 177 + foo: z._default(z.optional(z.string()), "test") 178 + }), z.object({ 181 179 bar: z.optional(z.string()) 182 - }) 183 - ])); 180 + })])); 184 181 185 182 export const zAnyOfAnyAndNull = z.object({ 186 183 data: z.optional(z.unknown()) ··· 190 187 * This is a simple array with any of properties 191 188 */ 192 189 export const zAnyOfArrays = z.object({ 193 - results: z.optional(z.array(z.union([ 194 - z.object({ 190 + results: z.optional(z.array(z.union([z.object({ 195 191 foo: z.optional(z.string()) 196 - }), 197 - z.object({ 192 + }), z.object({ 198 193 bar: z.optional(z.string()) 199 - }) 200 - ]))) 194 + })]))) 201 195 }); 202 196 203 197 /** ··· 302 296 z.null() 303 297 ]), 304 298 'foo_bar-enum': z.optional(z.enum([ 305 - 'Success', 306 - 'Warning', 307 - 'Error', 308 - 'ØÆÅ字符串' 299 + "Success", 300 + "Warning", 301 + "Error", 302 + "ØÆÅ字符串" 309 303 ])) 310 304 }); 311 305 ··· 314 308 */ 315 309 export const zModelWithEnum = z.object({ 316 310 'foo_bar-enum': z.optional(z.enum([ 317 - 'Success', 318 - 'Warning', 319 - 'Error', 320 - 'ØÆÅ字符串' 311 + "Success", 312 + "Warning", 313 + "Error", 314 + "ØÆÅ字符串" 321 315 ])), 322 316 statusCode: z.optional(z.enum([ 323 - '100', 324 - '200 FOO', 325 - '300 FOO_BAR', 326 - '400 foo-bar', 327 - '500 foo.bar', 328 - '600 foo&bar' 317 + "100", 318 + "200 FOO", 319 + "300 FOO_BAR", 320 + "400 foo-bar", 321 + "500 foo.bar", 322 + "600 foo&bar" 329 323 ])), 330 324 bool: z.optional(z.literal(true)) 331 325 }); ··· 334 328 * This is a model with one enum with escaped name 335 329 */ 336 330 export const zModelWithEnumWithHyphen = z.object({ 337 - 'foo-bar-baz-qux': z.optional(z.enum([ 338 - '3.0' 339 - ])) 331 + 'foo-bar-baz-qux': z.optional(z.enum(["3.0"])) 340 332 }); 341 333 342 334 /** ··· 351 343 */ 352 344 export const zModelWithNestedEnums = z.object({ 353 345 dictionaryWithEnum: z.optional(z.record(z.string(), z.enum([ 354 - 'Success', 355 - 'Warning', 356 - 'Error' 346 + "Success", 347 + "Warning", 348 + "Error" 357 349 ]))), 358 350 dictionaryWithEnumFromDescription: z.optional(z.record(z.string(), z.int())), 359 351 arrayWithEnum: z.optional(z.array(z.enum([ 360 - 'Success', 361 - 'Warning', 362 - 'Error' 352 + "Success", 353 + "Warning", 354 + "Error" 363 355 ]))), 364 356 arrayWithDescription: z.optional(z.array(z.int())), 365 357 'foo_bar-enum': z.optional(z.enum([ 366 - 'Success', 367 - 'Warning', 368 - 'Error', 369 - 'ØÆÅ字符串' 358 + "Success", 359 + "Warning", 360 + "Error", 361 + "ØÆÅ字符串" 370 362 ])) 371 363 }); 372 364 ··· 498 490 ])) 499 491 }); 500 492 501 - export const z3eNum1Период = z.enum([ 502 - 'Bird', 503 - 'Dog' 504 - ]); 493 + export const z3eNum1Период = z.enum(["Bird", "Dog"]); 505 494 506 - export const zConstValue = z.enum([ 507 - 'ConstValue' 508 - ]); 495 + export const zConstValue = z.enum(["ConstValue"]); 509 496 510 497 /** 511 498 * This is a model with one property with a 'any of' relationship where the options are not $ref 512 499 */ 513 500 export const zCompositionWithNestedAnyOfAndNull = z.object({ 514 501 propA: z.optional(z.union([ 515 - z.array(z.union([ 516 - z3eNum1Период, 517 - zConstValue 518 - ])), 502 + z.array(z.union([z3eNum1Период, zConstValue])), 519 503 z.null() 520 504 ])) 521 505 }); ··· 561 545 export const zCompositionWithOneOfAndComplexArrayDictionary = z.object({ 562 546 propA: z.optional(z.union([ 563 547 z.boolean(), 564 - z.record(z.string(), z.array(z.union([ 565 - z.number(), 566 - z.string() 567 - ]))) 548 + z.record(z.string(), z.array(z.union([z.number(), z.string()]))) 568 549 ])) 569 550 }); 570 551 ··· 750 731 export const zFreeFormObjectWithAdditionalPropertiesEqEmptyObject = z.record(z.string(), z.unknown()); 751 732 752 733 export const zModelWithConst = z.object({ 753 - String: z.optional(z.enum([ 754 - 'String' 755 - ])), 734 + String: z.optional(z.enum(["String"])), 756 735 number: z.optional(z.literal(0)), 757 736 null: z.optional(z.unknown()), 758 - withType: z.optional(z.enum([ 759 - 'Some string' 760 - ])) 737 + withType: z.optional(z.enum(["Some string"])) 761 738 }); 762 739 763 740 /** ··· 769 746 770 747 export const zNestedAnyOfArraysNullable = z.object({ 771 748 nullableArray: z.optional(z.union([ 772 - z.array(z.union([ 773 - z.string(), 774 - z.boolean() 775 - ])), 749 + z.array(z.union([z.string(), z.boolean()])), 776 750 z.null() 777 751 ])) 778 752 }); ··· 798 772 799 773 export const zModelWithOneOfEnum = z.union([ 800 774 z.object({ 801 - foo: z.enum([ 802 - 'Bar' 803 - ]) 775 + foo: z.enum(["Bar"]) 804 776 }), 805 777 z.object({ 806 - foo: z.enum([ 807 - 'Baz' 808 - ]) 778 + foo: z.enum(["Baz"]) 809 779 }), 810 780 z.object({ 811 - foo: z.enum([ 812 - 'Qux' 813 - ]) 781 + foo: z.enum(["Qux"]) 814 782 }), 815 783 z.object({ 816 784 content: z.iso.datetime(), 817 - foo: z.enum([ 818 - 'Quux' 819 - ]) 785 + foo: z.enum(["Quux"]) 820 786 }), 821 787 z.object({ 822 - content: z.tuple([ 823 - z.iso.datetime(), 824 - z.iso.datetime() 825 - ]), 826 - foo: z.enum([ 827 - 'Corge' 828 - ]) 788 + content: z.tuple([z.iso.datetime(), z.iso.datetime()]), 789 + foo: z.enum(["Corge"]) 829 790 }) 830 791 ]); 831 792 832 - export const zModelWithNestedArrayEnumsDataFoo = z.enum([ 833 - 'foo', 834 - 'bar' 835 - ]); 793 + export const zModelWithNestedArrayEnumsDataFoo = z.enum(["foo", "bar"]); 836 794 837 - export const zModelWithNestedArrayEnumsDataBar = z.enum([ 838 - 'baz', 839 - 'qux' 840 - ]); 795 + export const zModelWithNestedArrayEnumsDataBar = z.enum(["baz", "qux"]); 841 796 842 797 export const zModelWithNestedArrayEnumsData = z.object({ 843 798 foo: z.optional(z.array(zModelWithNestedArrayEnumsDataFoo)), ··· 867 822 propWithNumber: z.optional(z.array(z.number())) 868 823 }); 869 824 870 - export const zModelWithConstantSizeArray = z.tuple([ 871 - z.number(), 872 - z.number() 873 - ]); 825 + export const zModelWithConstantSizeArray = z.tuple([z.number(), z.number()]); 874 826 875 827 export const zModelWithAnyOfConstantSizeArray = z.tuple([ 876 828 z.union([ ··· 911 863 ]) 912 864 ]); 913 865 914 - export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([ 915 - z.intersection(z.number(), z.string()), 916 - z.intersection(z.number(), z.string()) 917 - ]); 866 + export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([z.intersection(z.number(), z.string()), z.intersection(z.number(), z.string())]); 918 867 919 868 export const zModelWithNumericEnumUnion = z.object({ 920 869 value: z.optional(z.union([ ··· 965 914 */ 966 915 export const zImport = z.string(); 967 916 968 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([ 969 - z.union([ 917 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([z.union([ 970 918 z.number(), 971 919 zImport 972 - ]), 973 - z.union([ 920 + ]), z.union([ 974 921 z.number(), 975 922 zImport 976 - ]) 977 - ]); 923 + ])]); 978 924 979 925 export const zSchemaWithFormRestrictedKeys = z.object({ 980 926 description: z.optional(z.string()), ··· 1126 1072 propWithNumber: z.optional(z.array(z.number())) 1127 1073 }); 1128 1074 1129 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([ 1130 - z.union([ 1075 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([z.union([ 1131 1076 z.number(), 1132 1077 zImport 1133 - ]), 1134 - z.union([ 1078 + ]), z.union([ 1135 1079 z.number(), 1136 1080 zImport 1137 - ]) 1138 - ]); 1081 + ])]); 1139 1082 1140 1083 export const zAdditionalPropertiesUnknownIssueWritable = z.record(z.string(), z.union([ 1141 1084 z.string(), ··· 1452 1395 path: z.optional(z.never()), 1453 1396 query: z.optional(z.object({ 1454 1397 parameterString: z._default(z.optional(z.union([ 1455 - z._default(z.string(), 'Hello World!'), 1398 + z._default(z.string(), "Hello World!"), 1456 1399 z.null() 1457 - ])), 'Hello World!'), 1400 + ])), "Hello World!"), 1458 1401 parameterNumber: z._default(z.optional(z.union([ 1459 1402 z._default(z.number(), 123), 1460 1403 z.null() ··· 1464 1407 z.null() 1465 1408 ])), true), 1466 1409 parameterEnum: z.optional(z.enum([ 1467 - 'Success', 1468 - 'Warning', 1469 - 'Error' 1410 + "Success", 1411 + "Warning", 1412 + "Error" 1470 1413 ])), 1471 1414 parameterModel: z.optional(z.union([ 1472 1415 zModelWithString, ··· 1479 1422 body: z.optional(z.never()), 1480 1423 path: z.optional(z.never()), 1481 1424 query: z.optional(z.object({ 1482 - parameterString: z._default(z.optional(z.string()), 'Hello World!'), 1425 + parameterString: z._default(z.optional(z.string()), "Hello World!"), 1483 1426 parameterNumber: z._default(z.optional(z.number()), 123), 1484 1427 parameterBoolean: z._default(z.optional(z.boolean()), true), 1485 1428 parameterEnum: z.optional(z.enum([ 1486 - 'Success', 1487 - 'Warning', 1488 - 'Error' 1429 + "Success", 1430 + "Warning", 1431 + "Error" 1489 1432 ])), 1490 1433 parameterModel: z.optional(zModelWithString) 1491 1434 })) ··· 1495 1438 body: z.optional(z.never()), 1496 1439 path: z.optional(z.never()), 1497 1440 query: z.object({ 1498 - parameterOptionalStringWithDefault: z._default(z.optional(z.string()), 'Hello World!'), 1499 - parameterOptionalStringWithEmptyDefault: z._default(z.optional(z.string()), ''), 1441 + parameterOptionalStringWithDefault: z._default(z.optional(z.string()), "Hello World!"), 1442 + parameterOptionalStringWithEmptyDefault: z._default(z.optional(z.string()), ""), 1500 1443 parameterOptionalStringWithNoDefault: z.optional(z.string()), 1501 - parameterStringWithDefault: z._default(z.string(), 'Hello World!'), 1502 - parameterStringWithEmptyDefault: z._default(z.string(), ''), 1444 + parameterStringWithDefault: z._default(z.string(), "Hello World!"), 1445 + parameterStringWithEmptyDefault: z._default(z.string(), ""), 1503 1446 parameterStringWithNoDefault: z.string(), 1504 1447 parameterStringNullableWithNoDefault: z.optional(z.union([ 1505 1448 z.string(), ··· 1647 1590 query: z.object({ 1648 1591 parameterNumber: z._default(z.number(), 123), 1649 1592 parameterString: z._default(z.union([ 1650 - z._default(z.string(), 'default'), 1593 + z._default(z.string(), "default"), 1651 1594 z.null() 1652 - ]), 'default'), 1595 + ]), "default"), 1653 1596 parameterBoolean: z._default(z.union([ 1654 1597 z._default(z.boolean(), true), 1655 1598 z.null() ··· 1667 1610 z.null() 1668 1611 ]), 1669 1612 parameterEnum: z.enum([ 1670 - 'Success', 1671 - 'Warning', 1672 - 'Error' 1613 + "Success", 1614 + "Warning", 1615 + "Error" 1673 1616 ]) 1674 1617 }) 1675 1618 }); ··· 1769 1712 ]), 1770 1713 enabled: z._default(z.optional(z.boolean()), true), 1771 1714 type: z.enum([ 1772 - 'Monkey', 1773 - 'Horse', 1774 - 'Bird' 1715 + "Monkey", 1716 + "Horse", 1717 + "Bird" 1775 1718 ]), 1776 1719 listOfModels: z.optional(z.union([ 1777 1720 z.array(zModelWithString),
+3 -12
packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/enum-null/zod.gen.ts
··· 2 2 3 3 import * as z from 'zod/mini'; 4 4 5 - export const zFoo = z.nullable(z.enum([ 6 - 'foo', 7 - 'bar' 8 - ])); 5 + export const zFoo = z.nullable(z.enum(["foo", "bar"])); 9 6 10 - export const zBar = z.enum([ 11 - 'foo', 12 - 'bar' 13 - ]); 7 + export const zBar = z.enum(["foo", "bar"]); 14 8 15 - export const zBaz = z.enum([ 16 - 'foo', 17 - 'bar' 18 - ]); 9 + export const zBaz = z.enum(["foo", "bar"]);
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/validators/zod.gen.ts
··· 2 2 3 3 import * as z from 'zod/mini'; 4 4 5 - export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), 'baz'); 5 + export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), "baz"); 6 6 7 7 export const zFoo = z._default(z.union([ 8 8 z.object({
+85 -142
packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts
··· 90 90 * This is a simple enum with strings 91 91 */ 92 92 export const zEnumWithStrings = z.enum([ 93 - 'Success', 94 - 'Warning', 95 - 'Error', 93 + "Success", 94 + "Warning", 95 + "Error", 96 96 "'Single Quote'", 97 - '"Double Quotes"', 98 - 'Non-ascii: øæåôöØÆÅÔÖ字符串' 97 + "\"Double Quotes\"", 98 + "Non-ascii: øæåôöØÆÅÔÖ字符串" 99 99 ]); 100 100 101 101 export const zEnumWithReplacedCharacters = z.union([ 102 102 z.literal("'Single Quote'"), 103 - z.literal('"Double Quotes"'), 104 - z.literal('øæåôöØÆÅÔÖ字符串'), 103 + z.literal("\"Double Quotes\""), 104 + z.literal("øæåôöØÆÅÔÖ字符串"), 105 105 z.literal(3.1), 106 - z.literal('') 106 + z.literal("") 107 107 ]); 108 108 109 109 /** ··· 160 160 /** 161 161 * This is a simple array with strings 162 162 */ 163 - export const zArrayWithStrings = z.array(z.string()).default(['test']); 163 + export const zArrayWithStrings = z.array(z.string()).default(["test"]); 164 164 165 165 /** 166 166 * This is a simple array with properties ··· 173 173 /** 174 174 * This is a simple array with any of properties 175 175 */ 176 - export const zArrayWithAnyOfProperties = z.array(z.union([ 177 - z.object({ 178 - foo: z.string().optional().default('test') 179 - }), 180 - z.object({ 176 + export const zArrayWithAnyOfProperties = z.array(z.union([z.object({ 177 + foo: z.string().optional().default("test") 178 + }), z.object({ 181 179 bar: z.string().optional() 182 - }) 183 - ])); 180 + })])); 184 181 185 182 export const zAnyOfAnyAndNull = z.object({ 186 183 data: z.unknown().optional() ··· 190 187 * This is a simple array with any of properties 191 188 */ 192 189 export const zAnyOfArrays = z.object({ 193 - results: z.array(z.union([ 194 - z.object({ 190 + results: z.array(z.union([z.object({ 195 191 foo: z.string().optional() 196 - }), 197 - z.object({ 192 + }), z.object({ 198 193 bar: z.string().optional() 199 - }) 200 - ])).optional() 194 + })])).optional() 201 195 }); 202 196 203 197 /** ··· 302 296 z.null() 303 297 ]), 304 298 'foo_bar-enum': z.enum([ 305 - 'Success', 306 - 'Warning', 307 - 'Error', 308 - 'ØÆÅ字符串' 299 + "Success", 300 + "Warning", 301 + "Error", 302 + "ØÆÅ字符串" 309 303 ]).optional() 310 304 }); 311 305 ··· 314 308 */ 315 309 export const zModelWithEnum = z.object({ 316 310 'foo_bar-enum': z.enum([ 317 - 'Success', 318 - 'Warning', 319 - 'Error', 320 - 'ØÆÅ字符串' 311 + "Success", 312 + "Warning", 313 + "Error", 314 + "ØÆÅ字符串" 321 315 ]).optional(), 322 316 statusCode: z.enum([ 323 - '100', 324 - '200 FOO', 325 - '300 FOO_BAR', 326 - '400 foo-bar', 327 - '500 foo.bar', 328 - '600 foo&bar' 317 + "100", 318 + "200 FOO", 319 + "300 FOO_BAR", 320 + "400 foo-bar", 321 + "500 foo.bar", 322 + "600 foo&bar" 329 323 ]).optional(), 330 324 bool: z.literal(true).optional() 331 325 }); ··· 334 328 * This is a model with one enum with escaped name 335 329 */ 336 330 export const zModelWithEnumWithHyphen = z.object({ 337 - 'foo-bar-baz-qux': z.enum([ 338 - '3.0' 339 - ]).optional() 331 + 'foo-bar-baz-qux': z.enum(["3.0"]).optional() 340 332 }); 341 333 342 334 /** ··· 351 343 */ 352 344 export const zModelWithNestedEnums = z.object({ 353 345 dictionaryWithEnum: z.record(z.enum([ 354 - 'Success', 355 - 'Warning', 356 - 'Error' 346 + "Success", 347 + "Warning", 348 + "Error" 357 349 ])).optional(), 358 350 dictionaryWithEnumFromDescription: z.record(z.number().int()).optional(), 359 351 arrayWithEnum: z.array(z.enum([ 360 - 'Success', 361 - 'Warning', 362 - 'Error' 352 + "Success", 353 + "Warning", 354 + "Error" 363 355 ])).optional(), 364 356 arrayWithDescription: z.array(z.number().int()).optional(), 365 357 'foo_bar-enum': z.enum([ 366 - 'Success', 367 - 'Warning', 368 - 'Error', 369 - 'ØÆÅ字符串' 358 + "Success", 359 + "Warning", 360 + "Error", 361 + "ØÆÅ字符串" 370 362 ]).optional() 371 363 }); 372 364 ··· 496 488 ]).optional() 497 489 }); 498 490 499 - export const z3eNum1Период = z.enum([ 500 - 'Bird', 501 - 'Dog' 502 - ]); 491 + export const z3eNum1Период = z.enum(["Bird", "Dog"]); 503 492 504 - export const zConstValue = z.enum([ 505 - 'ConstValue' 506 - ]); 493 + export const zConstValue = z.enum(["ConstValue"]); 507 494 508 495 /** 509 496 * This is a model with one property with a 'any of' relationship where the options are not $ref 510 497 */ 511 498 export const zCompositionWithNestedAnyOfAndNull = z.object({ 512 499 propA: z.union([ 513 - z.array(z.union([ 514 - z3eNum1Период, 515 - zConstValue 516 - ])), 500 + z.array(z.union([z3eNum1Период, zConstValue])), 517 501 z.null() 518 502 ]).optional() 519 503 }); ··· 559 543 export const zCompositionWithOneOfAndComplexArrayDictionary = z.object({ 560 544 propA: z.union([ 561 545 z.boolean(), 562 - z.record(z.array(z.union([ 563 - z.number(), 564 - z.string() 565 - ]))) 546 + z.record(z.array(z.union([z.number(), z.string()]))) 566 547 ]).optional() 567 548 }); 568 549 ··· 748 729 export const zFreeFormObjectWithAdditionalPropertiesEqEmptyObject = z.record(z.unknown()); 749 730 750 731 export const zModelWithConst = z.object({ 751 - String: z.enum([ 752 - 'String' 753 - ]).optional(), 732 + String: z.enum(["String"]).optional(), 754 733 number: z.literal(0).optional(), 755 734 null: z.unknown().optional(), 756 - withType: z.enum([ 757 - 'Some string' 758 - ]).optional() 735 + withType: z.enum(["Some string"]).optional() 759 736 }); 760 737 761 738 /** ··· 767 744 768 745 export const zNestedAnyOfArraysNullable = z.object({ 769 746 nullableArray: z.union([ 770 - z.array(z.union([ 771 - z.string(), 772 - z.boolean() 773 - ])), 747 + z.array(z.union([z.string(), z.boolean()])), 774 748 z.null() 775 749 ]).optional() 776 750 }); ··· 796 770 797 771 export const zModelWithOneOfEnum = z.union([ 798 772 z.object({ 799 - foo: z.enum([ 800 - 'Bar' 801 - ]) 773 + foo: z.enum(["Bar"]) 802 774 }), 803 775 z.object({ 804 - foo: z.enum([ 805 - 'Baz' 806 - ]) 776 + foo: z.enum(["Baz"]) 807 777 }), 808 778 z.object({ 809 - foo: z.enum([ 810 - 'Qux' 811 - ]) 779 + foo: z.enum(["Qux"]) 812 780 }), 813 781 z.object({ 814 782 content: z.string().datetime(), 815 - foo: z.enum([ 816 - 'Quux' 817 - ]) 783 + foo: z.enum(["Quux"]) 818 784 }), 819 785 z.object({ 820 - content: z.tuple([ 821 - z.string().datetime(), 822 - z.string().datetime() 823 - ]), 824 - foo: z.enum([ 825 - 'Corge' 826 - ]) 786 + content: z.tuple([z.string().datetime(), z.string().datetime()]), 787 + foo: z.enum(["Corge"]) 827 788 }) 828 789 ]); 829 790 830 - export const zModelWithNestedArrayEnumsDataFoo = z.enum([ 831 - 'foo', 832 - 'bar' 833 - ]); 791 + export const zModelWithNestedArrayEnumsDataFoo = z.enum(["foo", "bar"]); 834 792 835 - export const zModelWithNestedArrayEnumsDataBar = z.enum([ 836 - 'baz', 837 - 'qux' 838 - ]); 793 + export const zModelWithNestedArrayEnumsDataBar = z.enum(["baz", "qux"]); 839 794 840 795 export const zModelWithNestedArrayEnumsData = z.object({ 841 796 foo: z.array(zModelWithNestedArrayEnumsDataFoo).optional(), ··· 865 820 propWithNumber: z.array(z.number()).optional() 866 821 }); 867 822 868 - export const zModelWithConstantSizeArray = z.tuple([ 869 - z.number(), 870 - z.number() 871 - ]); 823 + export const zModelWithConstantSizeArray = z.tuple([z.number(), z.number()]); 872 824 873 825 export const zModelWithAnyOfConstantSizeArray = z.tuple([ 874 826 z.union([ ··· 909 861 ]) 910 862 ]); 911 863 912 - export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([ 913 - z.intersection(z.number(), z.string()), 914 - z.intersection(z.number(), z.string()) 915 - ]); 864 + export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([z.intersection(z.number(), z.string()), z.intersection(z.number(), z.string())]); 916 865 917 866 export const zModelWithNumericEnumUnion = z.object({ 918 867 value: z.union([ ··· 963 912 */ 964 913 export const zImport = z.string(); 965 914 966 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([ 967 - z.union([ 915 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([z.union([ 968 916 z.number(), 969 917 zImport 970 - ]), 971 - z.union([ 918 + ]), z.union([ 972 919 z.number(), 973 920 zImport 974 - ]) 975 - ]); 921 + ])]); 976 922 977 923 export const zSchemaWithFormRestrictedKeys = z.object({ 978 924 description: z.string().optional(), ··· 1124 1070 propWithNumber: z.array(z.number()).optional() 1125 1071 }); 1126 1072 1127 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([ 1128 - z.union([ 1073 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([z.union([ 1129 1074 z.number(), 1130 1075 zImport 1131 - ]), 1132 - z.union([ 1076 + ]), z.union([ 1133 1077 z.number(), 1134 1078 zImport 1135 - ]) 1136 - ]); 1079 + ])]); 1137 1080 1138 1081 export const zAdditionalPropertiesUnknownIssueWritable = z.record(z.union([ 1139 1082 z.string(), ··· 1450 1393 path: z.never().optional(), 1451 1394 query: z.object({ 1452 1395 parameterString: z.union([ 1453 - z.string().default('Hello World!'), 1396 + z.string().default("Hello World!"), 1454 1397 z.null() 1455 - ]).optional().default('Hello World!'), 1398 + ]).optional().default("Hello World!"), 1456 1399 parameterNumber: z.union([ 1457 1400 z.number().default(123), 1458 1401 z.null() ··· 1462 1405 z.null() 1463 1406 ]).optional().default(true), 1464 1407 parameterEnum: z.enum([ 1465 - 'Success', 1466 - 'Warning', 1467 - 'Error' 1408 + "Success", 1409 + "Warning", 1410 + "Error" 1468 1411 ]).optional(), 1469 1412 parameterModel: z.union([ 1470 1413 zModelWithString, ··· 1477 1420 body: z.never().optional(), 1478 1421 path: z.never().optional(), 1479 1422 query: z.object({ 1480 - parameterString: z.string().optional().default('Hello World!'), 1423 + parameterString: z.string().optional().default("Hello World!"), 1481 1424 parameterNumber: z.number().optional().default(123), 1482 1425 parameterBoolean: z.boolean().optional().default(true), 1483 1426 parameterEnum: z.enum([ 1484 - 'Success', 1485 - 'Warning', 1486 - 'Error' 1427 + "Success", 1428 + "Warning", 1429 + "Error" 1487 1430 ]).optional(), 1488 1431 parameterModel: zModelWithString.optional() 1489 1432 }).optional() ··· 1493 1436 body: z.never().optional(), 1494 1437 path: z.never().optional(), 1495 1438 query: z.object({ 1496 - parameterOptionalStringWithDefault: z.string().optional().default('Hello World!'), 1497 - parameterOptionalStringWithEmptyDefault: z.string().optional().default(''), 1439 + parameterOptionalStringWithDefault: z.string().optional().default("Hello World!"), 1440 + parameterOptionalStringWithEmptyDefault: z.string().optional().default(""), 1498 1441 parameterOptionalStringWithNoDefault: z.string().optional(), 1499 - parameterStringWithDefault: z.string().default('Hello World!'), 1500 - parameterStringWithEmptyDefault: z.string().default(''), 1442 + parameterStringWithDefault: z.string().default("Hello World!"), 1443 + parameterStringWithEmptyDefault: z.string().default(""), 1501 1444 parameterStringWithNoDefault: z.string(), 1502 1445 parameterStringNullableWithNoDefault: z.union([ 1503 1446 z.string(), ··· 1645 1588 query: z.object({ 1646 1589 parameterNumber: z.number().default(123), 1647 1590 parameterString: z.union([ 1648 - z.string().default('default'), 1591 + z.string().default("default"), 1649 1592 z.null() 1650 - ]).default('default'), 1593 + ]).default("default"), 1651 1594 parameterBoolean: z.union([ 1652 1595 z.boolean().default(true), 1653 1596 z.null() ··· 1665 1608 z.null() 1666 1609 ]), 1667 1610 parameterEnum: z.enum([ 1668 - 'Success', 1669 - 'Warning', 1670 - 'Error' 1611 + "Success", 1612 + "Warning", 1613 + "Error" 1671 1614 ]) 1672 1615 }) 1673 1616 }); ··· 1767 1710 ]), 1768 1711 enabled: z.boolean().optional().default(true), 1769 1712 type: z.enum([ 1770 - 'Monkey', 1771 - 'Horse', 1772 - 'Bird' 1713 + "Monkey", 1714 + "Horse", 1715 + "Bird" 1773 1716 ]), 1774 1717 listOfModels: z.union([ 1775 1718 z.array(zModelWithString),
+3 -12
packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/enum-null/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod/v3'; 4 4 5 - export const zFoo = z.enum([ 6 - 'foo', 7 - 'bar' 8 - ]).nullable(); 5 + export const zFoo = z.enum(["foo", "bar"]).nullable(); 9 6 10 - export const zBar = z.enum([ 11 - 'foo', 12 - 'bar' 13 - ]); 7 + export const zBar = z.enum(["foo", "bar"]); 14 8 15 - export const zBaz = z.enum([ 16 - 'foo', 17 - 'bar' 18 - ]); 9 + export const zBaz = z.enum(["foo", "bar"]);
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/validators/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod/v3'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export const zFoo: z.ZodTypeAny = z.union([ 8 8 z.object({
+85 -142
packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts
··· 90 90 * This is a simple enum with strings 91 91 */ 92 92 export const zEnumWithStrings = z.enum([ 93 - 'Success', 94 - 'Warning', 95 - 'Error', 93 + "Success", 94 + "Warning", 95 + "Error", 96 96 "'Single Quote'", 97 - '"Double Quotes"', 98 - 'Non-ascii: øæåôöØÆÅÔÖ字符串' 97 + "\"Double Quotes\"", 98 + "Non-ascii: øæåôöØÆÅÔÖ字符串" 99 99 ]); 100 100 101 101 export const zEnumWithReplacedCharacters = z.union([ 102 102 z.literal("'Single Quote'"), 103 - z.literal('"Double Quotes"'), 104 - z.literal('øæåôöØÆÅÔÖ字符串'), 103 + z.literal("\"Double Quotes\""), 104 + z.literal("øæåôöØÆÅÔÖ字符串"), 105 105 z.literal(3.1), 106 - z.literal('') 106 + z.literal("") 107 107 ]); 108 108 109 109 /** ··· 160 160 /** 161 161 * This is a simple array with strings 162 162 */ 163 - export const zArrayWithStrings = z.array(z.string()).default(['test']); 163 + export const zArrayWithStrings = z.array(z.string()).default(["test"]); 164 164 165 165 /** 166 166 * This is a simple array with properties ··· 173 173 /** 174 174 * This is a simple array with any of properties 175 175 */ 176 - export const zArrayWithAnyOfProperties = z.array(z.union([ 177 - z.object({ 178 - foo: z.optional(z.string()).default('test') 179 - }), 180 - z.object({ 176 + export const zArrayWithAnyOfProperties = z.array(z.union([z.object({ 177 + foo: z.optional(z.string()).default("test") 178 + }), z.object({ 181 179 bar: z.optional(z.string()) 182 - }) 183 - ])); 180 + })])); 184 181 185 182 export const zAnyOfAnyAndNull = z.object({ 186 183 data: z.optional(z.unknown()) ··· 190 187 * This is a simple array with any of properties 191 188 */ 192 189 export const zAnyOfArrays = z.object({ 193 - results: z.optional(z.array(z.union([ 194 - z.object({ 190 + results: z.optional(z.array(z.union([z.object({ 195 191 foo: z.optional(z.string()) 196 - }), 197 - z.object({ 192 + }), z.object({ 198 193 bar: z.optional(z.string()) 199 - }) 200 - ]))) 194 + })]))) 201 195 }); 202 196 203 197 /** ··· 302 296 z.null() 303 297 ]), 304 298 'foo_bar-enum': z.optional(z.enum([ 305 - 'Success', 306 - 'Warning', 307 - 'Error', 308 - 'ØÆÅ字符串' 299 + "Success", 300 + "Warning", 301 + "Error", 302 + "ØÆÅ字符串" 309 303 ])) 310 304 }); 311 305 ··· 314 308 */ 315 309 export const zModelWithEnum = z.object({ 316 310 'foo_bar-enum': z.optional(z.enum([ 317 - 'Success', 318 - 'Warning', 319 - 'Error', 320 - 'ØÆÅ字符串' 311 + "Success", 312 + "Warning", 313 + "Error", 314 + "ØÆÅ字符串" 321 315 ])), 322 316 statusCode: z.optional(z.enum([ 323 - '100', 324 - '200 FOO', 325 - '300 FOO_BAR', 326 - '400 foo-bar', 327 - '500 foo.bar', 328 - '600 foo&bar' 317 + "100", 318 + "200 FOO", 319 + "300 FOO_BAR", 320 + "400 foo-bar", 321 + "500 foo.bar", 322 + "600 foo&bar" 329 323 ])), 330 324 bool: z.optional(z.literal(true)) 331 325 }); ··· 334 328 * This is a model with one enum with escaped name 335 329 */ 336 330 export const zModelWithEnumWithHyphen = z.object({ 337 - 'foo-bar-baz-qux': z.optional(z.enum([ 338 - '3.0' 339 - ])) 331 + 'foo-bar-baz-qux': z.optional(z.enum(["3.0"])) 340 332 }); 341 333 342 334 /** ··· 351 343 */ 352 344 export const zModelWithNestedEnums = z.object({ 353 345 dictionaryWithEnum: z.optional(z.record(z.string(), z.enum([ 354 - 'Success', 355 - 'Warning', 356 - 'Error' 346 + "Success", 347 + "Warning", 348 + "Error" 357 349 ]))), 358 350 dictionaryWithEnumFromDescription: z.optional(z.record(z.string(), z.int())), 359 351 arrayWithEnum: z.optional(z.array(z.enum([ 360 - 'Success', 361 - 'Warning', 362 - 'Error' 352 + "Success", 353 + "Warning", 354 + "Error" 363 355 ]))), 364 356 arrayWithDescription: z.optional(z.array(z.int())), 365 357 'foo_bar-enum': z.optional(z.enum([ 366 - 'Success', 367 - 'Warning', 368 - 'Error', 369 - 'ØÆÅ字符串' 358 + "Success", 359 + "Warning", 360 + "Error", 361 + "ØÆÅ字符串" 370 362 ])) 371 363 }); 372 364 ··· 498 490 ])) 499 491 }); 500 492 501 - export const z3eNum1Период = z.enum([ 502 - 'Bird', 503 - 'Dog' 504 - ]); 493 + export const z3eNum1Период = z.enum(["Bird", "Dog"]); 505 494 506 - export const zConstValue = z.enum([ 507 - 'ConstValue' 508 - ]); 495 + export const zConstValue = z.enum(["ConstValue"]); 509 496 510 497 /** 511 498 * This is a model with one property with a 'any of' relationship where the options are not $ref 512 499 */ 513 500 export const zCompositionWithNestedAnyOfAndNull = z.object({ 514 501 propA: z.optional(z.union([ 515 - z.array(z.union([ 516 - z3eNum1Период, 517 - zConstValue 518 - ])), 502 + z.array(z.union([z3eNum1Период, zConstValue])), 519 503 z.null() 520 504 ])) 521 505 }); ··· 561 545 export const zCompositionWithOneOfAndComplexArrayDictionary = z.object({ 562 546 propA: z.optional(z.union([ 563 547 z.boolean(), 564 - z.record(z.string(), z.array(z.union([ 565 - z.number(), 566 - z.string() 567 - ]))) 548 + z.record(z.string(), z.array(z.union([z.number(), z.string()]))) 568 549 ])) 569 550 }); 570 551 ··· 750 731 export const zFreeFormObjectWithAdditionalPropertiesEqEmptyObject = z.record(z.string(), z.unknown()); 751 732 752 733 export const zModelWithConst = z.object({ 753 - String: z.optional(z.enum([ 754 - 'String' 755 - ])), 734 + String: z.optional(z.enum(["String"])), 756 735 number: z.optional(z.literal(0)), 757 736 null: z.optional(z.unknown()), 758 - withType: z.optional(z.enum([ 759 - 'Some string' 760 - ])) 737 + withType: z.optional(z.enum(["Some string"])) 761 738 }); 762 739 763 740 /** ··· 769 746 770 747 export const zNestedAnyOfArraysNullable = z.object({ 771 748 nullableArray: z.optional(z.union([ 772 - z.array(z.union([ 773 - z.string(), 774 - z.boolean() 775 - ])), 749 + z.array(z.union([z.string(), z.boolean()])), 776 750 z.null() 777 751 ])) 778 752 }); ··· 798 772 799 773 export const zModelWithOneOfEnum = z.union([ 800 774 z.object({ 801 - foo: z.enum([ 802 - 'Bar' 803 - ]) 775 + foo: z.enum(["Bar"]) 804 776 }), 805 777 z.object({ 806 - foo: z.enum([ 807 - 'Baz' 808 - ]) 778 + foo: z.enum(["Baz"]) 809 779 }), 810 780 z.object({ 811 - foo: z.enum([ 812 - 'Qux' 813 - ]) 781 + foo: z.enum(["Qux"]) 814 782 }), 815 783 z.object({ 816 784 content: z.iso.datetime(), 817 - foo: z.enum([ 818 - 'Quux' 819 - ]) 785 + foo: z.enum(["Quux"]) 820 786 }), 821 787 z.object({ 822 - content: z.tuple([ 823 - z.iso.datetime(), 824 - z.iso.datetime() 825 - ]), 826 - foo: z.enum([ 827 - 'Corge' 828 - ]) 788 + content: z.tuple([z.iso.datetime(), z.iso.datetime()]), 789 + foo: z.enum(["Corge"]) 829 790 }) 830 791 ]); 831 792 832 - export const zModelWithNestedArrayEnumsDataFoo = z.enum([ 833 - 'foo', 834 - 'bar' 835 - ]); 793 + export const zModelWithNestedArrayEnumsDataFoo = z.enum(["foo", "bar"]); 836 794 837 - export const zModelWithNestedArrayEnumsDataBar = z.enum([ 838 - 'baz', 839 - 'qux' 840 - ]); 795 + export const zModelWithNestedArrayEnumsDataBar = z.enum(["baz", "qux"]); 841 796 842 797 export const zModelWithNestedArrayEnumsData = z.object({ 843 798 foo: z.optional(z.array(zModelWithNestedArrayEnumsDataFoo)), ··· 867 822 propWithNumber: z.optional(z.array(z.number())) 868 823 }); 869 824 870 - export const zModelWithConstantSizeArray = z.tuple([ 871 - z.number(), 872 - z.number() 873 - ]); 825 + export const zModelWithConstantSizeArray = z.tuple([z.number(), z.number()]); 874 826 875 827 export const zModelWithAnyOfConstantSizeArray = z.tuple([ 876 828 z.union([ ··· 911 863 ]) 912 864 ]); 913 865 914 - export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([ 915 - z.intersection(z.number(), z.string()), 916 - z.intersection(z.number(), z.string()) 917 - ]); 866 + export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([z.intersection(z.number(), z.string()), z.intersection(z.number(), z.string())]); 918 867 919 868 export const zModelWithNumericEnumUnion = z.object({ 920 869 value: z.optional(z.union([ ··· 965 914 */ 966 915 export const zImport = z.string(); 967 916 968 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([ 969 - z.union([ 917 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([z.union([ 970 918 z.number(), 971 919 zImport 972 - ]), 973 - z.union([ 920 + ]), z.union([ 974 921 z.number(), 975 922 zImport 976 - ]) 977 - ]); 923 + ])]); 978 924 979 925 export const zSchemaWithFormRestrictedKeys = z.object({ 980 926 description: z.optional(z.string()), ··· 1126 1072 propWithNumber: z.optional(z.array(z.number())) 1127 1073 }); 1128 1074 1129 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([ 1130 - z.union([ 1075 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([z.union([ 1131 1076 z.number(), 1132 1077 zImport 1133 - ]), 1134 - z.union([ 1078 + ]), z.union([ 1135 1079 z.number(), 1136 1080 zImport 1137 - ]) 1138 - ]); 1081 + ])]); 1139 1082 1140 1083 export const zAdditionalPropertiesUnknownIssueWritable = z.record(z.string(), z.union([ 1141 1084 z.string(), ··· 1452 1395 path: z.optional(z.never()), 1453 1396 query: z.optional(z.object({ 1454 1397 parameterString: z.optional(z.union([ 1455 - z.string().default('Hello World!'), 1398 + z.string().default("Hello World!"), 1456 1399 z.null() 1457 - ])).default('Hello World!'), 1400 + ])).default("Hello World!"), 1458 1401 parameterNumber: z.optional(z.union([ 1459 1402 z.number().default(123), 1460 1403 z.null() ··· 1464 1407 z.null() 1465 1408 ])).default(true), 1466 1409 parameterEnum: z.optional(z.enum([ 1467 - 'Success', 1468 - 'Warning', 1469 - 'Error' 1410 + "Success", 1411 + "Warning", 1412 + "Error" 1470 1413 ])), 1471 1414 parameterModel: z.optional(z.union([ 1472 1415 zModelWithString, ··· 1479 1422 body: z.optional(z.never()), 1480 1423 path: z.optional(z.never()), 1481 1424 query: z.optional(z.object({ 1482 - parameterString: z.optional(z.string()).default('Hello World!'), 1425 + parameterString: z.optional(z.string()).default("Hello World!"), 1483 1426 parameterNumber: z.optional(z.number()).default(123), 1484 1427 parameterBoolean: z.optional(z.boolean()).default(true), 1485 1428 parameterEnum: z.optional(z.enum([ 1486 - 'Success', 1487 - 'Warning', 1488 - 'Error' 1429 + "Success", 1430 + "Warning", 1431 + "Error" 1489 1432 ])), 1490 1433 parameterModel: z.optional(zModelWithString) 1491 1434 })) ··· 1495 1438 body: z.optional(z.never()), 1496 1439 path: z.optional(z.never()), 1497 1440 query: z.object({ 1498 - parameterOptionalStringWithDefault: z.optional(z.string()).default('Hello World!'), 1499 - parameterOptionalStringWithEmptyDefault: z.optional(z.string()).default(''), 1441 + parameterOptionalStringWithDefault: z.optional(z.string()).default("Hello World!"), 1442 + parameterOptionalStringWithEmptyDefault: z.optional(z.string()).default(""), 1500 1443 parameterOptionalStringWithNoDefault: z.optional(z.string()), 1501 - parameterStringWithDefault: z.string().default('Hello World!'), 1502 - parameterStringWithEmptyDefault: z.string().default(''), 1444 + parameterStringWithDefault: z.string().default("Hello World!"), 1445 + parameterStringWithEmptyDefault: z.string().default(""), 1503 1446 parameterStringWithNoDefault: z.string(), 1504 1447 parameterStringNullableWithNoDefault: z.optional(z.union([ 1505 1448 z.string(), ··· 1647 1590 query: z.object({ 1648 1591 parameterNumber: z.number().default(123), 1649 1592 parameterString: z.union([ 1650 - z.string().default('default'), 1593 + z.string().default("default"), 1651 1594 z.null() 1652 - ]).default('default'), 1595 + ]).default("default"), 1653 1596 parameterBoolean: z.union([ 1654 1597 z.boolean().default(true), 1655 1598 z.null() ··· 1667 1610 z.null() 1668 1611 ]), 1669 1612 parameterEnum: z.enum([ 1670 - 'Success', 1671 - 'Warning', 1672 - 'Error' 1613 + "Success", 1614 + "Warning", 1615 + "Error" 1673 1616 ]) 1674 1617 }) 1675 1618 }); ··· 1769 1712 ]), 1770 1713 enabled: z.optional(z.boolean()).default(true), 1771 1714 type: z.enum([ 1772 - 'Monkey', 1773 - 'Horse', 1774 - 'Bird' 1715 + "Monkey", 1716 + "Horse", 1717 + "Bird" 1775 1718 ]), 1776 1719 listOfModels: z.optional(z.union([ 1777 1720 z.array(zModelWithString),
+3 -12
packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/enum-null/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod'; 4 4 5 - export const zFoo = z.nullable(z.enum([ 6 - 'foo', 7 - 'bar' 8 - ])); 5 + export const zFoo = z.nullable(z.enum(["foo", "bar"])); 9 6 10 - export const zBar = z.enum([ 11 - 'foo', 12 - 'bar' 13 - ]); 7 + export const zBar = z.enum(["foo", "bar"]); 14 8 15 - export const zBaz = z.enum([ 16 - 'foo', 17 - 'bar' 18 - ]); 9 + export const zBaz = z.enum(["foo", "bar"]);
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/validators/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export const zFoo = z.union([ 8 8 z.object({
+83 -144
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts
··· 90 90 * This is a simple enum with strings 91 91 */ 92 92 export const zEnumWithStrings = z.enum([ 93 - 'Success', 94 - 'Warning', 95 - 'Error', 93 + "Success", 94 + "Warning", 95 + "Error", 96 96 "'Single Quote'", 97 - '"Double Quotes"', 98 - 'Non-ascii: øæåôöØÆÅÔÖ字符串' 97 + "\"Double Quotes\"", 98 + "Non-ascii: øæåôöØÆÅÔÖ字符串" 99 99 ]); 100 100 101 101 export const zEnumWithReplacedCharacters = z.union([ 102 102 z.literal("'Single Quote'"), 103 - z.literal('"Double Quotes"'), 104 - z.literal('øæåôöØÆÅÔÖ字符串'), 103 + z.literal("\"Double Quotes\""), 104 + z.literal("øæåôöØÆÅÔÖ字符串"), 105 105 z.literal(3.1), 106 - z.literal('') 106 + z.literal("") 107 107 ]); 108 108 109 109 /** ··· 160 160 /** 161 161 * This is a simple array with strings 162 162 */ 163 - export const zArrayWithStrings = z._default(z.array(z.string()), ['test']); 163 + export const zArrayWithStrings = z._default(z.array(z.string()), ["test"]); 164 164 165 165 /** 166 166 * This is a simple array with properties ··· 173 173 /** 174 174 * This is a simple array with any of properties 175 175 */ 176 - export const zArrayWithAnyOfProperties = z.array(z.union([ 177 - z.object({ 178 - foo: z._default(z.optional(z.string()), 'test') 179 - }), 180 - z.object({ 176 + export const zArrayWithAnyOfProperties = z.array(z.union([z.object({ 177 + foo: z._default(z.optional(z.string()), "test") 178 + }), z.object({ 181 179 bar: z.optional(z.string()) 182 - }) 183 - ])); 180 + })])); 184 181 185 182 export const zAnyOfAnyAndNull = z.object({ 186 183 data: z.optional(z.union([ ··· 193 190 * This is a simple array with any of properties 194 191 */ 195 192 export const zAnyOfArrays = z.object({ 196 - results: z.optional(z.array(z.union([ 197 - z.object({ 193 + results: z.optional(z.array(z.union([z.object({ 198 194 foo: z.optional(z.string()) 199 - }), 200 - z.object({ 195 + }), z.object({ 201 196 bar: z.optional(z.string()) 202 - }) 203 - ]))) 197 + })]))) 204 198 }); 205 199 206 200 /** ··· 305 299 z.null() 306 300 ]), 307 301 'foo_bar-enum': z.optional(z.enum([ 308 - 'Success', 309 - 'Warning', 310 - 'Error', 311 - 'ØÆÅ字符串' 302 + "Success", 303 + "Warning", 304 + "Error", 305 + "ØÆÅ字符串" 312 306 ])) 313 307 }); 314 308 ··· 317 311 */ 318 312 export const zModelWithEnum = z.object({ 319 313 'foo_bar-enum': z.optional(z.enum([ 320 - 'Success', 321 - 'Warning', 322 - 'Error', 323 - 'ØÆÅ字符串' 314 + "Success", 315 + "Warning", 316 + "Error", 317 + "ØÆÅ字符串" 324 318 ])), 325 319 statusCode: z.optional(z.enum([ 326 - '100', 327 - '200 FOO', 328 - '300 FOO_BAR', 329 - '400 foo-bar', 330 - '500 foo.bar', 331 - '600 foo&bar' 320 + "100", 321 + "200 FOO", 322 + "300 FOO_BAR", 323 + "400 foo-bar", 324 + "500 foo.bar", 325 + "600 foo&bar" 332 326 ])), 333 327 bool: z.optional(z.literal(true)) 334 328 }); ··· 337 331 * This is a model with one enum with escaped name 338 332 */ 339 333 export const zModelWithEnumWithHyphen = z.object({ 340 - 'foo-bar-baz-qux': z.optional(z.enum([ 341 - '3.0' 342 - ])) 334 + 'foo-bar-baz-qux': z.optional(z.enum(["3.0"])) 343 335 }); 344 336 345 337 /** ··· 354 346 */ 355 347 export const zModelWithNestedEnums = z.object({ 356 348 dictionaryWithEnum: z.optional(z.record(z.string(), z.enum([ 357 - 'Success', 358 - 'Warning', 359 - 'Error' 349 + "Success", 350 + "Warning", 351 + "Error" 360 352 ]))), 361 353 dictionaryWithEnumFromDescription: z.optional(z.record(z.string(), z.int())), 362 354 arrayWithEnum: z.optional(z.array(z.enum([ 363 - 'Success', 364 - 'Warning', 365 - 'Error' 355 + "Success", 356 + "Warning", 357 + "Error" 366 358 ]))), 367 359 arrayWithDescription: z.optional(z.array(z.int())), 368 360 'foo_bar-enum': z.optional(z.enum([ 369 - 'Success', 370 - 'Warning', 371 - 'Error', 372 - 'ØÆÅ字符串' 361 + "Success", 362 + "Warning", 363 + "Error", 364 + "ØÆÅ字符串" 373 365 ])) 374 366 }); 375 367 ··· 490 482 */ 491 483 export const zCompositionWithNestedAnyAndTypeNull = z.object({ 492 484 propA: z.optional(z.union([ 493 - z.array(z.union([ 494 - zModelWithDictionary, 495 - z.null() 496 - ])), 497 - z.array(z.union([ 498 - zModelWithArray, 499 - z.null() 500 - ])) 485 + z.array(z.union([zModelWithDictionary, z.null()])), 486 + z.array(z.union([zModelWithArray, z.null()])) 501 487 ])) 502 488 }); 503 489 504 - export const z3eNum1Период = z.enum([ 505 - 'Bird', 506 - 'Dog' 507 - ]); 490 + export const z3eNum1Период = z.enum(["Bird", "Dog"]); 508 491 509 492 export const zConstValue = z.literal("ConstValue"); 510 493 ··· 513 496 */ 514 497 export const zCompositionWithNestedAnyOfAndNull = z.object({ 515 498 propA: z.optional(z.union([ 516 - z.array(z.union([ 517 - z3eNum1Период, 518 - zConstValue 519 - ])), 499 + z.array(z.union([z3eNum1Период, zConstValue])), 520 500 z.null() 521 501 ])) 522 502 }); ··· 562 542 export const zCompositionWithOneOfAndComplexArrayDictionary = z.object({ 563 543 propA: z.optional(z.union([ 564 544 z.boolean(), 565 - z.record(z.string(), z.array(z.union([ 566 - z.number(), 567 - z.string() 568 - ]))) 545 + z.record(z.string(), z.array(z.union([z.number(), z.string()]))) 569 546 ])) 570 547 }); 571 548 ··· 766 743 767 744 export const zNestedAnyOfArraysNullable = z.object({ 768 745 nullableArray: z.optional(z.union([ 769 - z.array(z.union([ 770 - z.string(), 771 - z.boolean() 772 - ])), 746 + z.array(z.union([z.string(), z.boolean()])), 773 747 z.null() 774 748 ])) 775 749 }); ··· 795 769 796 770 export const zModelWithOneOfEnum = z.union([ 797 771 z.object({ 798 - foo: z.enum([ 799 - 'Bar' 800 - ]) 772 + foo: z.enum(["Bar"]) 801 773 }), 802 774 z.object({ 803 - foo: z.enum([ 804 - 'Baz' 805 - ]) 775 + foo: z.enum(["Baz"]) 806 776 }), 807 777 z.object({ 808 - foo: z.enum([ 809 - 'Qux' 810 - ]) 778 + foo: z.enum(["Qux"]) 811 779 }), 812 780 z.object({ 813 781 content: z.iso.datetime(), 814 - foo: z.enum([ 815 - 'Quux' 816 - ]) 782 + foo: z.enum(["Quux"]) 817 783 }), 818 784 z.object({ 819 - content: z.tuple([ 820 - z.iso.datetime(), 821 - z.string() 822 - ]), 823 - foo: z.enum([ 824 - 'Corge' 825 - ]) 785 + content: z.tuple([z.iso.datetime(), z.string()]), 786 + foo: z.enum(["Corge"]) 826 787 }) 827 788 ]); 828 789 829 - export const zModelWithNestedArrayEnumsDataFoo = z.enum([ 830 - 'foo', 831 - 'bar' 832 - ]); 790 + export const zModelWithNestedArrayEnumsDataFoo = z.enum(["foo", "bar"]); 833 791 834 - export const zModelWithNestedArrayEnumsDataBar = z.enum([ 835 - 'baz', 836 - 'qux' 837 - ]); 792 + export const zModelWithNestedArrayEnumsDataBar = z.enum(["baz", "qux"]); 838 793 839 794 export const zModelWithNestedArrayEnumsData = z.object({ 840 795 foo: z.optional(z.array(zModelWithNestedArrayEnumsDataFoo)), ··· 864 819 propWithNumber: z.optional(z.array(z.number())) 865 820 }); 866 821 867 - export const zModelWithConstantSizeArray = z.tuple([ 868 - z.number(), 869 - z.number() 870 - ]); 822 + export const zModelWithConstantSizeArray = z.tuple([z.number(), z.number()]); 871 823 872 824 export const zModelWithAnyOfConstantSizeArray = z.tuple([ 873 825 z.union([ ··· 911 863 ]) 912 864 ]); 913 865 914 - export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([ 915 - z.intersection(z.number(), z.string()), 916 - z.intersection(z.number(), z.string()) 917 - ]); 866 + export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([z.intersection(z.number(), z.string()), z.intersection(z.number(), z.string())]); 918 867 919 868 export const zModelWithNumericEnumUnion = z.object({ 920 869 value: z.optional(z.union([ ··· 965 914 */ 966 915 export const zImport = z.string(); 967 916 968 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([ 969 - z.union([ 917 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([z.union([ 970 918 z.number(), 971 919 zImport 972 - ]), 973 - z.union([ 920 + ]), z.union([ 974 921 z.number(), 975 922 zImport 976 - ]) 977 - ]); 923 + ])]); 978 924 979 925 export const zSchemaWithFormRestrictedKeys = z.object({ 980 926 description: z.optional(z.string()), ··· 1132 1078 propWithNumber: z.optional(z.array(z.number())) 1133 1079 }); 1134 1080 1135 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([ 1136 - z.union([ 1081 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([z.union([ 1137 1082 z.number(), 1138 1083 zImport 1139 - ]), 1140 - z.union([ 1084 + ]), z.union([ 1141 1085 z.number(), 1142 1086 zImport 1143 - ]) 1144 - ]); 1087 + ])]); 1145 1088 1146 1089 export const zAdditionalPropertiesUnknownIssueWritable = z.record(z.string(), z.union([ 1147 1090 z.string(), ··· 1467 1410 path: z.optional(z.never()), 1468 1411 query: z.optional(z.object({ 1469 1412 parameterString: z._default(z.optional(z.union([ 1470 - z._default(z.string(), 'Hello World!'), 1413 + z._default(z.string(), "Hello World!"), 1471 1414 z.null() 1472 - ])), 'Hello World!'), 1415 + ])), "Hello World!"), 1473 1416 parameterNumber: z._default(z.optional(z.union([ 1474 1417 z._default(z.number(), 123), 1475 1418 z.null() ··· 1479 1422 z.null() 1480 1423 ])), true), 1481 1424 parameterEnum: z.optional(z.enum([ 1482 - 'Success', 1483 - 'Warning', 1484 - 'Error' 1425 + "Success", 1426 + "Warning", 1427 + "Error" 1485 1428 ])), 1486 1429 parameterModel: z.optional(z.union([ 1487 - z._default(zModelWithString, { 1488 - prop: 'Hello World!' 1489 - }), 1430 + z._default(zModelWithString, { prop: "Hello World!" }), 1490 1431 z.null() 1491 1432 ])) 1492 1433 })) ··· 1496 1437 body: z.optional(z.never()), 1497 1438 path: z.optional(z.never()), 1498 1439 query: z.optional(z.object({ 1499 - parameterString: z._default(z.optional(z.string()), 'Hello World!'), 1440 + parameterString: z._default(z.optional(z.string()), "Hello World!"), 1500 1441 parameterNumber: z._default(z.optional(z.number()), 123), 1501 1442 parameterBoolean: z._default(z.optional(z.boolean()), true), 1502 1443 parameterEnum: z.optional(z.enum([ 1503 - 'Success', 1504 - 'Warning', 1505 - 'Error' 1444 + "Success", 1445 + "Warning", 1446 + "Error" 1506 1447 ])), 1507 - parameterModel: z._default(z.optional(zModelWithString), { 1508 - prop: 'Hello World!' 1509 - }) 1448 + parameterModel: z._default(z.optional(zModelWithString), { prop: "Hello World!" }) 1510 1449 })) 1511 1450 }); 1512 1451 ··· 1514 1453 body: z.optional(z.never()), 1515 1454 path: z.optional(z.never()), 1516 1455 query: z.object({ 1517 - parameterOptionalStringWithDefault: z._default(z.optional(z.string()), 'Hello World!'), 1518 - parameterOptionalStringWithEmptyDefault: z._default(z.optional(z.string()), ''), 1456 + parameterOptionalStringWithDefault: z._default(z.optional(z.string()), "Hello World!"), 1457 + parameterOptionalStringWithEmptyDefault: z._default(z.optional(z.string()), ""), 1519 1458 parameterOptionalStringWithNoDefault: z.optional(z.string()), 1520 - parameterStringWithDefault: z._default(z.string(), 'Hello World!'), 1521 - parameterStringWithEmptyDefault: z._default(z.string(), ''), 1459 + parameterStringWithDefault: z._default(z.string(), "Hello World!"), 1460 + parameterStringWithEmptyDefault: z._default(z.string(), ""), 1522 1461 parameterStringWithNoDefault: z.string(), 1523 1462 parameterStringNullableWithNoDefault: z.optional(z.union([ 1524 1463 z.string(), ··· 1666 1605 query: z.object({ 1667 1606 parameterNumber: z._default(z.number(), 123), 1668 1607 parameterString: z._default(z.union([ 1669 - z._default(z.string(), 'default'), 1608 + z._default(z.string(), "default"), 1670 1609 z.null() 1671 - ]), 'default'), 1610 + ]), "default"), 1672 1611 parameterBoolean: z._default(z.union([ 1673 1612 z._default(z.boolean(), true), 1674 1613 z.null() ··· 1789 1728 ]), 1790 1729 enabled: z._default(z.optional(z.boolean()), true), 1791 1730 type: z.enum([ 1792 - 'Monkey', 1793 - 'Horse', 1794 - 'Bird' 1731 + "Monkey", 1732 + "Horse", 1733 + "Bird" 1795 1734 ]), 1796 1735 listOfModels: z.optional(z.union([ 1797 1736 z.array(zModelWithString),
+7 -13
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/defaults-with-ref-and-anyof/zod.gen.ts
··· 2 2 3 3 import * as z from 'zod/mini'; 4 4 5 - export const zAudioFormat = z.enum([ 6 - 'pcm_16bit_44.1khz', 7 - 'pcm_16bit_24khz' 8 - ]); 5 + export const zAudioFormat = z.enum(["pcm_16bit_44.1khz", "pcm_16bit_24khz"]); 9 6 10 7 export const zLanguage = z.enum([ 11 - 'en', 12 - 'es', 13 - 'fr' 8 + "en", 9 + "es", 10 + "fr" 14 11 ]); 15 12 16 13 export const zNestedConfig = z.object({ 17 - model: z._default(z.string(), 'gpt-4'), 14 + model: z._default(z.string(), "gpt-4"), 18 15 temperature: z._default(z.number(), 1) 19 16 }); 20 17 21 18 export const zTestSchema = z.object({ 22 19 primitiveDefault: z._default(z.number(), 42), 23 - refWithPrimitiveDefault: z._default(zAudioFormat, 'pcm_16bit_44.1khz'), 24 - refWithObjectDefault: z._default(zNestedConfig, { 25 - model: 'gpt-4', 26 - temperature: 1 27 - }), 20 + refWithPrimitiveDefault: z._default(zAudioFormat, "pcm_16bit_44.1khz"), 21 + refWithObjectDefault: z._default(zNestedConfig, { model: "gpt-4", temperature: 1 }), 28 22 anyOfWithNullDefault: z._default(z.union([ 29 23 z.number(), 30 24 z.null()
+3 -12
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/enum-null/zod.gen.ts
··· 2 2 3 3 import * as z from 'zod/mini'; 4 4 5 - export const zFoo = z.nullable(z.enum([ 6 - 'foo', 7 - 'bar' 8 - ])); 5 + export const zFoo = z.nullable(z.enum(["foo", "bar"])); 9 6 10 - export const zBar = z.enum([ 11 - 'foo', 12 - 'bar' 13 - ]); 7 + export const zBar = z.enum(["foo", "bar"]); 14 8 15 - export const zBaz = z.enum([ 16 - 'foo', 17 - 'bar' 18 - ]); 9 + export const zBaz = z.enum(["foo", "bar"]);
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/schema-const/zod.gen.ts
··· 11 11 z.literal(1), 12 12 z.literal(2), 13 13 z.literal(3), 14 - z.literal('foo'), 14 + z.literal("foo"), 15 15 z.literal(true) 16 16 ])), 17 17 corge: z.optional(z.record(z.string(), z.unknown())),
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-dates/zod.gen.ts
··· 2 2 3 3 import * as z from 'zod/mini'; 4 4 5 - export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), 'baz'); 5 + export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), "baz"); 6 6 7 7 export const zQux = z.record(z.string(), z.object({ 8 8 qux: z.optional(z.string())
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-metadata/zod.gen.ts
··· 2 2 3 3 import * as z from 'zod/mini'; 4 4 5 - export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), 'baz'); 5 + export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), "baz"); 6 6 7 7 export const zQux = z.record(z.string(), z.object({ 8 8 qux: z.optional(z.string())
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-types/zod.gen.ts
··· 2 2 3 3 import * as z from 'zod/mini'; 4 4 5 - export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), 'baz'); 5 + export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), "baz"); 6 6 7 7 export type BazZodType = z.infer<typeof zBaz>; 8 8
+4 -7
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-union-merge/zod.gen.ts
··· 22 22 23 23 export const zCatDetails = z.object({ 24 24 furLength: z.enum([ 25 - 'short', 26 - 'medium', 27 - 'long' 25 + "short", 26 + "medium", 27 + "long" 28 28 ]), 29 29 purrs: z.boolean() 30 30 }); ··· 32 32 export const zPetStore = z.object({ 33 33 animals: z.array(z.object({ 34 34 name: z.string(), 35 - type: z.optional(z.enum([ 36 - 'dog', 37 - 'cat' 38 - ])), 35 + type: z.optional(z.enum(["dog", "cat"])), 39 36 details: z.union([ 40 37 zDogDetails, 41 38 zCatDetails
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators/zod.gen.ts
··· 2 2 3 3 import * as z from 'zod/mini'; 4 4 5 - export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), 'baz'); 5 + export const zBaz = z._default(z.readonly(z.string().check(z.regex(/foo\nbar/))), "baz"); 6 6 7 7 export const zQux = z.record(z.string(), z.object({ 8 8 qux: z.optional(z.string())
+83 -144
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts
··· 90 90 * This is a simple enum with strings 91 91 */ 92 92 export const zEnumWithStrings = z.enum([ 93 - 'Success', 94 - 'Warning', 95 - 'Error', 93 + "Success", 94 + "Warning", 95 + "Error", 96 96 "'Single Quote'", 97 - '"Double Quotes"', 98 - 'Non-ascii: øæåôöØÆÅÔÖ字符串' 97 + "\"Double Quotes\"", 98 + "Non-ascii: øæåôöØÆÅÔÖ字符串" 99 99 ]); 100 100 101 101 export const zEnumWithReplacedCharacters = z.union([ 102 102 z.literal("'Single Quote'"), 103 - z.literal('"Double Quotes"'), 104 - z.literal('øæåôöØÆÅÔÖ字符串'), 103 + z.literal("\"Double Quotes\""), 104 + z.literal("øæåôöØÆÅÔÖ字符串"), 105 105 z.literal(3.1), 106 - z.literal('') 106 + z.literal("") 107 107 ]); 108 108 109 109 /** ··· 160 160 /** 161 161 * This is a simple array with strings 162 162 */ 163 - export const zArrayWithStrings = z.array(z.string()).default(['test']); 163 + export const zArrayWithStrings = z.array(z.string()).default(["test"]); 164 164 165 165 /** 166 166 * This is a simple array with properties ··· 173 173 /** 174 174 * This is a simple array with any of properties 175 175 */ 176 - export const zArrayWithAnyOfProperties = z.array(z.union([ 177 - z.object({ 178 - foo: z.string().optional().default('test') 179 - }), 180 - z.object({ 176 + export const zArrayWithAnyOfProperties = z.array(z.union([z.object({ 177 + foo: z.string().optional().default("test") 178 + }), z.object({ 181 179 bar: z.string().optional() 182 - }) 183 - ])); 180 + })])); 184 181 185 182 export const zAnyOfAnyAndNull = z.object({ 186 183 data: z.union([ ··· 193 190 * This is a simple array with any of properties 194 191 */ 195 192 export const zAnyOfArrays = z.object({ 196 - results: z.array(z.union([ 197 - z.object({ 193 + results: z.array(z.union([z.object({ 198 194 foo: z.string().optional() 199 - }), 200 - z.object({ 195 + }), z.object({ 201 196 bar: z.string().optional() 202 - }) 203 - ])).optional() 197 + })])).optional() 204 198 }); 205 199 206 200 /** ··· 305 299 z.null() 306 300 ]), 307 301 'foo_bar-enum': z.enum([ 308 - 'Success', 309 - 'Warning', 310 - 'Error', 311 - 'ØÆÅ字符串' 302 + "Success", 303 + "Warning", 304 + "Error", 305 + "ØÆÅ字符串" 312 306 ]).optional() 313 307 }); 314 308 ··· 317 311 */ 318 312 export const zModelWithEnum = z.object({ 319 313 'foo_bar-enum': z.enum([ 320 - 'Success', 321 - 'Warning', 322 - 'Error', 323 - 'ØÆÅ字符串' 314 + "Success", 315 + "Warning", 316 + "Error", 317 + "ØÆÅ字符串" 324 318 ]).optional(), 325 319 statusCode: z.enum([ 326 - '100', 327 - '200 FOO', 328 - '300 FOO_BAR', 329 - '400 foo-bar', 330 - '500 foo.bar', 331 - '600 foo&bar' 320 + "100", 321 + "200 FOO", 322 + "300 FOO_BAR", 323 + "400 foo-bar", 324 + "500 foo.bar", 325 + "600 foo&bar" 332 326 ]).optional(), 333 327 bool: z.literal(true).optional() 334 328 }); ··· 337 331 * This is a model with one enum with escaped name 338 332 */ 339 333 export const zModelWithEnumWithHyphen = z.object({ 340 - 'foo-bar-baz-qux': z.enum([ 341 - '3.0' 342 - ]).optional() 334 + 'foo-bar-baz-qux': z.enum(["3.0"]).optional() 343 335 }); 344 336 345 337 /** ··· 354 346 */ 355 347 export const zModelWithNestedEnums = z.object({ 356 348 dictionaryWithEnum: z.record(z.enum([ 357 - 'Success', 358 - 'Warning', 359 - 'Error' 349 + "Success", 350 + "Warning", 351 + "Error" 360 352 ])).optional(), 361 353 dictionaryWithEnumFromDescription: z.record(z.number().int()).optional(), 362 354 arrayWithEnum: z.array(z.enum([ 363 - 'Success', 364 - 'Warning', 365 - 'Error' 355 + "Success", 356 + "Warning", 357 + "Error" 366 358 ])).optional(), 367 359 arrayWithDescription: z.array(z.number().int()).optional(), 368 360 'foo_bar-enum': z.enum([ 369 - 'Success', 370 - 'Warning', 371 - 'Error', 372 - 'ØÆÅ字符串' 361 + "Success", 362 + "Warning", 363 + "Error", 364 + "ØÆÅ字符串" 373 365 ]).optional() 374 366 }); 375 367 ··· 488 480 */ 489 481 export const zCompositionWithNestedAnyAndTypeNull = z.object({ 490 482 propA: z.union([ 491 - z.array(z.union([ 492 - zModelWithDictionary, 493 - z.null() 494 - ])), 495 - z.array(z.union([ 496 - zModelWithArray, 497 - z.null() 498 - ])) 483 + z.array(z.union([zModelWithDictionary, z.null()])), 484 + z.array(z.union([zModelWithArray, z.null()])) 499 485 ]).optional() 500 486 }); 501 487 502 - export const z3eNum1Период = z.enum([ 503 - 'Bird', 504 - 'Dog' 505 - ]); 488 + export const z3eNum1Период = z.enum(["Bird", "Dog"]); 506 489 507 490 export const zConstValue = z.literal("ConstValue"); 508 491 ··· 511 494 */ 512 495 export const zCompositionWithNestedAnyOfAndNull = z.object({ 513 496 propA: z.union([ 514 - z.array(z.union([ 515 - z3eNum1Период, 516 - zConstValue 517 - ])), 497 + z.array(z.union([z3eNum1Период, zConstValue])), 518 498 z.null() 519 499 ]).optional() 520 500 }); ··· 560 540 export const zCompositionWithOneOfAndComplexArrayDictionary = z.object({ 561 541 propA: z.union([ 562 542 z.boolean(), 563 - z.record(z.array(z.union([ 564 - z.number(), 565 - z.string() 566 - ]))) 543 + z.record(z.array(z.union([z.number(), z.string()]))) 567 544 ]).optional() 568 545 }); 569 546 ··· 764 741 765 742 export const zNestedAnyOfArraysNullable = z.object({ 766 743 nullableArray: z.union([ 767 - z.array(z.union([ 768 - z.string(), 769 - z.boolean() 770 - ])), 744 + z.array(z.union([z.string(), z.boolean()])), 771 745 z.null() 772 746 ]).optional() 773 747 }); ··· 793 767 794 768 export const zModelWithOneOfEnum = z.union([ 795 769 z.object({ 796 - foo: z.enum([ 797 - 'Bar' 798 - ]) 770 + foo: z.enum(["Bar"]) 799 771 }), 800 772 z.object({ 801 - foo: z.enum([ 802 - 'Baz' 803 - ]) 773 + foo: z.enum(["Baz"]) 804 774 }), 805 775 z.object({ 806 - foo: z.enum([ 807 - 'Qux' 808 - ]) 776 + foo: z.enum(["Qux"]) 809 777 }), 810 778 z.object({ 811 779 content: z.string().datetime(), 812 - foo: z.enum([ 813 - 'Quux' 814 - ]) 780 + foo: z.enum(["Quux"]) 815 781 }), 816 782 z.object({ 817 - content: z.tuple([ 818 - z.string().datetime(), 819 - z.string() 820 - ]), 821 - foo: z.enum([ 822 - 'Corge' 823 - ]) 783 + content: z.tuple([z.string().datetime(), z.string()]), 784 + foo: z.enum(["Corge"]) 824 785 }) 825 786 ]); 826 787 827 - export const zModelWithNestedArrayEnumsDataFoo = z.enum([ 828 - 'foo', 829 - 'bar' 830 - ]); 788 + export const zModelWithNestedArrayEnumsDataFoo = z.enum(["foo", "bar"]); 831 789 832 - export const zModelWithNestedArrayEnumsDataBar = z.enum([ 833 - 'baz', 834 - 'qux' 835 - ]); 790 + export const zModelWithNestedArrayEnumsDataBar = z.enum(["baz", "qux"]); 836 791 837 792 export const zModelWithNestedArrayEnumsData = z.object({ 838 793 foo: z.array(zModelWithNestedArrayEnumsDataFoo).optional(), ··· 862 817 propWithNumber: z.array(z.number()).optional() 863 818 }); 864 819 865 - export const zModelWithConstantSizeArray = z.tuple([ 866 - z.number(), 867 - z.number() 868 - ]); 820 + export const zModelWithConstantSizeArray = z.tuple([z.number(), z.number()]); 869 821 870 822 export const zModelWithAnyOfConstantSizeArray = z.tuple([ 871 823 z.union([ ··· 909 861 ]) 910 862 ]); 911 863 912 - export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([ 913 - z.intersection(z.number(), z.string()), 914 - z.intersection(z.number(), z.string()) 915 - ]); 864 + export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([z.intersection(z.number(), z.string()), z.intersection(z.number(), z.string())]); 916 865 917 866 export const zModelWithNumericEnumUnion = z.object({ 918 867 value: z.union([ ··· 963 912 */ 964 913 export const zImport = z.string(); 965 914 966 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([ 967 - z.union([ 915 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([z.union([ 968 916 z.number(), 969 917 zImport 970 - ]), 971 - z.union([ 918 + ]), z.union([ 972 919 z.number(), 973 920 zImport 974 - ]) 975 - ]); 921 + ])]); 976 922 977 923 export const zSchemaWithFormRestrictedKeys = z.object({ 978 924 description: z.string().optional(), ··· 1130 1076 propWithNumber: z.array(z.number()).optional() 1131 1077 }); 1132 1078 1133 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([ 1134 - z.union([ 1079 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([z.union([ 1135 1080 z.number(), 1136 1081 zImport 1137 - ]), 1138 - z.union([ 1082 + ]), z.union([ 1139 1083 z.number(), 1140 1084 zImport 1141 - ]) 1142 - ]); 1085 + ])]); 1143 1086 1144 1087 export const zAdditionalPropertiesUnknownIssueWritable = z.record(z.union([ 1145 1088 z.string(), ··· 1465 1408 path: z.never().optional(), 1466 1409 query: z.object({ 1467 1410 parameterString: z.union([ 1468 - z.string().default('Hello World!'), 1411 + z.string().default("Hello World!"), 1469 1412 z.null() 1470 - ]).optional().default('Hello World!'), 1413 + ]).optional().default("Hello World!"), 1471 1414 parameterNumber: z.union([ 1472 1415 z.number().default(123), 1473 1416 z.null() ··· 1477 1420 z.null() 1478 1421 ]).optional().default(true), 1479 1422 parameterEnum: z.enum([ 1480 - 'Success', 1481 - 'Warning', 1482 - 'Error' 1423 + "Success", 1424 + "Warning", 1425 + "Error" 1483 1426 ]).optional(), 1484 1427 parameterModel: z.union([ 1485 - zModelWithString.default({ 1486 - prop: 'Hello World!' 1487 - }), 1428 + zModelWithString.default({ prop: "Hello World!" }), 1488 1429 z.null() 1489 1430 ]).optional() 1490 1431 }).optional() ··· 1494 1435 body: z.never().optional(), 1495 1436 path: z.never().optional(), 1496 1437 query: z.object({ 1497 - parameterString: z.string().optional().default('Hello World!'), 1438 + parameterString: z.string().optional().default("Hello World!"), 1498 1439 parameterNumber: z.number().optional().default(123), 1499 1440 parameterBoolean: z.boolean().optional().default(true), 1500 1441 parameterEnum: z.enum([ 1501 - 'Success', 1502 - 'Warning', 1503 - 'Error' 1442 + "Success", 1443 + "Warning", 1444 + "Error" 1504 1445 ]).optional(), 1505 - parameterModel: zModelWithString.optional().default({ 1506 - prop: 'Hello World!' 1507 - }) 1446 + parameterModel: zModelWithString.optional().default({ prop: "Hello World!" }) 1508 1447 }).optional() 1509 1448 }); 1510 1449 ··· 1512 1451 body: z.never().optional(), 1513 1452 path: z.never().optional(), 1514 1453 query: z.object({ 1515 - parameterOptionalStringWithDefault: z.string().optional().default('Hello World!'), 1516 - parameterOptionalStringWithEmptyDefault: z.string().optional().default(''), 1454 + parameterOptionalStringWithDefault: z.string().optional().default("Hello World!"), 1455 + parameterOptionalStringWithEmptyDefault: z.string().optional().default(""), 1517 1456 parameterOptionalStringWithNoDefault: z.string().optional(), 1518 - parameterStringWithDefault: z.string().default('Hello World!'), 1519 - parameterStringWithEmptyDefault: z.string().default(''), 1457 + parameterStringWithDefault: z.string().default("Hello World!"), 1458 + parameterStringWithEmptyDefault: z.string().default(""), 1520 1459 parameterStringWithNoDefault: z.string(), 1521 1460 parameterStringNullableWithNoDefault: z.union([ 1522 1461 z.string(), ··· 1664 1603 query: z.object({ 1665 1604 parameterNumber: z.number().default(123), 1666 1605 parameterString: z.union([ 1667 - z.string().default('default'), 1606 + z.string().default("default"), 1668 1607 z.null() 1669 - ]).default('default'), 1608 + ]).default("default"), 1670 1609 parameterBoolean: z.union([ 1671 1610 z.boolean().default(true), 1672 1611 z.null() ··· 1787 1726 ]), 1788 1727 enabled: z.boolean().optional().default(true), 1789 1728 type: z.enum([ 1790 - 'Monkey', 1791 - 'Horse', 1792 - 'Bird' 1729 + "Monkey", 1730 + "Horse", 1731 + "Bird" 1793 1732 ]), 1794 1733 listOfModels: z.union([ 1795 1734 z.array(zModelWithString),
+7 -13
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/defaults-with-ref-and-anyof/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod/v3'; 4 4 5 - export const zAudioFormat = z.enum([ 6 - 'pcm_16bit_44.1khz', 7 - 'pcm_16bit_24khz' 8 - ]); 5 + export const zAudioFormat = z.enum(["pcm_16bit_44.1khz", "pcm_16bit_24khz"]); 9 6 10 7 export const zLanguage = z.enum([ 11 - 'en', 12 - 'es', 13 - 'fr' 8 + "en", 9 + "es", 10 + "fr" 14 11 ]); 15 12 16 13 export const zNestedConfig = z.object({ 17 - model: z.string().default('gpt-4'), 14 + model: z.string().default("gpt-4"), 18 15 temperature: z.number().default(1) 19 16 }); 20 17 21 18 export const zTestSchema = z.object({ 22 19 primitiveDefault: z.number().default(42), 23 - refWithPrimitiveDefault: zAudioFormat.default('pcm_16bit_44.1khz'), 24 - refWithObjectDefault: zNestedConfig.default({ 25 - model: 'gpt-4', 26 - temperature: 1 27 - }), 20 + refWithPrimitiveDefault: zAudioFormat.default("pcm_16bit_44.1khz"), 21 + refWithObjectDefault: zNestedConfig.default({ model: "gpt-4", temperature: 1 }), 28 22 anyOfWithNullDefault: z.union([ 29 23 z.number(), 30 24 z.null()
+3 -12
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/enum-null/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod/v3'; 4 4 5 - export const zFoo = z.enum([ 6 - 'foo', 7 - 'bar' 8 - ]).nullable(); 5 + export const zFoo = z.enum(["foo", "bar"]).nullable(); 9 6 10 - export const zBar = z.enum([ 11 - 'foo', 12 - 'bar' 13 - ]); 7 + export const zBar = z.enum(["foo", "bar"]); 14 8 15 - export const zBaz = z.enum([ 16 - 'foo', 17 - 'bar' 18 - ]); 9 + export const zBaz = z.enum(["foo", "bar"]);
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/schema-const/zod.gen.ts
··· 11 11 z.literal(1), 12 12 z.literal(2), 13 13 z.literal(3), 14 - z.literal('foo'), 14 + z.literal("foo"), 15 15 z.literal(true) 16 16 ]).optional(), 17 17 corge: z.record(z.unknown()).optional(),
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-dates/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod/v3'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export const zQux = z.record(z.object({ 8 8 qux: z.string().optional()
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-metadata/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod/v3'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export const zQux = z.record(z.object({ 8 8 qux: z.string().optional()
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-types/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod/v3'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export type BazZodType = z.infer<typeof zBaz>; 8 8
+4 -7
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-union-merge/zod.gen.ts
··· 22 22 23 23 export const zCatDetails = z.object({ 24 24 furLength: z.enum([ 25 - 'short', 26 - 'medium', 27 - 'long' 25 + "short", 26 + "medium", 27 + "long" 28 28 ]), 29 29 purrs: z.boolean() 30 30 }); ··· 32 32 export const zPetStore = z.object({ 33 33 animals: z.array(z.object({ 34 34 name: z.string(), 35 - type: z.enum([ 36 - 'dog', 37 - 'cat' 38 - ]).optional(), 35 + type: z.enum(["dog", "cat"]).optional(), 39 36 details: z.union([ 40 37 zDogDetails, 41 38 zCatDetails
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod/v3'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export const zQux = z.record(z.object({ 8 8 qux: z.string().optional()
+83 -144
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts
··· 90 90 * This is a simple enum with strings 91 91 */ 92 92 export const zEnumWithStrings = z.enum([ 93 - 'Success', 94 - 'Warning', 95 - 'Error', 93 + "Success", 94 + "Warning", 95 + "Error", 96 96 "'Single Quote'", 97 - '"Double Quotes"', 98 - 'Non-ascii: øæåôöØÆÅÔÖ字符串' 97 + "\"Double Quotes\"", 98 + "Non-ascii: øæåôöØÆÅÔÖ字符串" 99 99 ]); 100 100 101 101 export const zEnumWithReplacedCharacters = z.union([ 102 102 z.literal("'Single Quote'"), 103 - z.literal('"Double Quotes"'), 104 - z.literal('øæåôöØÆÅÔÖ字符串'), 103 + z.literal("\"Double Quotes\""), 104 + z.literal("øæåôöØÆÅÔÖ字符串"), 105 105 z.literal(3.1), 106 - z.literal('') 106 + z.literal("") 107 107 ]); 108 108 109 109 /** ··· 160 160 /** 161 161 * This is a simple array with strings 162 162 */ 163 - export const zArrayWithStrings = z.array(z.string()).default(['test']); 163 + export const zArrayWithStrings = z.array(z.string()).default(["test"]); 164 164 165 165 /** 166 166 * This is a simple array with properties ··· 173 173 /** 174 174 * This is a simple array with any of properties 175 175 */ 176 - export const zArrayWithAnyOfProperties = z.array(z.union([ 177 - z.object({ 178 - foo: z.optional(z.string()).default('test') 179 - }), 180 - z.object({ 176 + export const zArrayWithAnyOfProperties = z.array(z.union([z.object({ 177 + foo: z.optional(z.string()).default("test") 178 + }), z.object({ 181 179 bar: z.optional(z.string()) 182 - }) 183 - ])); 180 + })])); 184 181 185 182 export const zAnyOfAnyAndNull = z.object({ 186 183 data: z.optional(z.union([ ··· 193 190 * This is a simple array with any of properties 194 191 */ 195 192 export const zAnyOfArrays = z.object({ 196 - results: z.optional(z.array(z.union([ 197 - z.object({ 193 + results: z.optional(z.array(z.union([z.object({ 198 194 foo: z.optional(z.string()) 199 - }), 200 - z.object({ 195 + }), z.object({ 201 196 bar: z.optional(z.string()) 202 - }) 203 - ]))) 197 + })]))) 204 198 }); 205 199 206 200 /** ··· 305 299 z.null() 306 300 ]), 307 301 'foo_bar-enum': z.optional(z.enum([ 308 - 'Success', 309 - 'Warning', 310 - 'Error', 311 - 'ØÆÅ字符串' 302 + "Success", 303 + "Warning", 304 + "Error", 305 + "ØÆÅ字符串" 312 306 ])) 313 307 }); 314 308 ··· 317 311 */ 318 312 export const zModelWithEnum = z.object({ 319 313 'foo_bar-enum': z.optional(z.enum([ 320 - 'Success', 321 - 'Warning', 322 - 'Error', 323 - 'ØÆÅ字符串' 314 + "Success", 315 + "Warning", 316 + "Error", 317 + "ØÆÅ字符串" 324 318 ])), 325 319 statusCode: z.optional(z.enum([ 326 - '100', 327 - '200 FOO', 328 - '300 FOO_BAR', 329 - '400 foo-bar', 330 - '500 foo.bar', 331 - '600 foo&bar' 320 + "100", 321 + "200 FOO", 322 + "300 FOO_BAR", 323 + "400 foo-bar", 324 + "500 foo.bar", 325 + "600 foo&bar" 332 326 ])), 333 327 bool: z.optional(z.literal(true)) 334 328 }); ··· 337 331 * This is a model with one enum with escaped name 338 332 */ 339 333 export const zModelWithEnumWithHyphen = z.object({ 340 - 'foo-bar-baz-qux': z.optional(z.enum([ 341 - '3.0' 342 - ])) 334 + 'foo-bar-baz-qux': z.optional(z.enum(["3.0"])) 343 335 }); 344 336 345 337 /** ··· 354 346 */ 355 347 export const zModelWithNestedEnums = z.object({ 356 348 dictionaryWithEnum: z.optional(z.record(z.string(), z.enum([ 357 - 'Success', 358 - 'Warning', 359 - 'Error' 349 + "Success", 350 + "Warning", 351 + "Error" 360 352 ]))), 361 353 dictionaryWithEnumFromDescription: z.optional(z.record(z.string(), z.int())), 362 354 arrayWithEnum: z.optional(z.array(z.enum([ 363 - 'Success', 364 - 'Warning', 365 - 'Error' 355 + "Success", 356 + "Warning", 357 + "Error" 366 358 ]))), 367 359 arrayWithDescription: z.optional(z.array(z.int())), 368 360 'foo_bar-enum': z.optional(z.enum([ 369 - 'Success', 370 - 'Warning', 371 - 'Error', 372 - 'ØÆÅ字符串' 361 + "Success", 362 + "Warning", 363 + "Error", 364 + "ØÆÅ字符串" 373 365 ])) 374 366 }); 375 367 ··· 490 482 */ 491 483 export const zCompositionWithNestedAnyAndTypeNull = z.object({ 492 484 propA: z.optional(z.union([ 493 - z.array(z.union([ 494 - zModelWithDictionary, 495 - z.null() 496 - ])), 497 - z.array(z.union([ 498 - zModelWithArray, 499 - z.null() 500 - ])) 485 + z.array(z.union([zModelWithDictionary, z.null()])), 486 + z.array(z.union([zModelWithArray, z.null()])) 501 487 ])) 502 488 }); 503 489 504 - export const z3eNum1Период = z.enum([ 505 - 'Bird', 506 - 'Dog' 507 - ]); 490 + export const z3eNum1Период = z.enum(["Bird", "Dog"]); 508 491 509 492 export const zConstValue = z.literal("ConstValue"); 510 493 ··· 513 496 */ 514 497 export const zCompositionWithNestedAnyOfAndNull = z.object({ 515 498 propA: z.optional(z.union([ 516 - z.array(z.union([ 517 - z3eNum1Период, 518 - zConstValue 519 - ])), 499 + z.array(z.union([z3eNum1Период, zConstValue])), 520 500 z.null() 521 501 ])) 522 502 }); ··· 562 542 export const zCompositionWithOneOfAndComplexArrayDictionary = z.object({ 563 543 propA: z.optional(z.union([ 564 544 z.boolean(), 565 - z.record(z.string(), z.array(z.union([ 566 - z.number(), 567 - z.string() 568 - ]))) 545 + z.record(z.string(), z.array(z.union([z.number(), z.string()]))) 569 546 ])) 570 547 }); 571 548 ··· 766 743 767 744 export const zNestedAnyOfArraysNullable = z.object({ 768 745 nullableArray: z.optional(z.union([ 769 - z.array(z.union([ 770 - z.string(), 771 - z.boolean() 772 - ])), 746 + z.array(z.union([z.string(), z.boolean()])), 773 747 z.null() 774 748 ])) 775 749 }); ··· 795 769 796 770 export const zModelWithOneOfEnum = z.union([ 797 771 z.object({ 798 - foo: z.enum([ 799 - 'Bar' 800 - ]) 772 + foo: z.enum(["Bar"]) 801 773 }), 802 774 z.object({ 803 - foo: z.enum([ 804 - 'Baz' 805 - ]) 775 + foo: z.enum(["Baz"]) 806 776 }), 807 777 z.object({ 808 - foo: z.enum([ 809 - 'Qux' 810 - ]) 778 + foo: z.enum(["Qux"]) 811 779 }), 812 780 z.object({ 813 781 content: z.iso.datetime(), 814 - foo: z.enum([ 815 - 'Quux' 816 - ]) 782 + foo: z.enum(["Quux"]) 817 783 }), 818 784 z.object({ 819 - content: z.tuple([ 820 - z.iso.datetime(), 821 - z.string() 822 - ]), 823 - foo: z.enum([ 824 - 'Corge' 825 - ]) 785 + content: z.tuple([z.iso.datetime(), z.string()]), 786 + foo: z.enum(["Corge"]) 826 787 }) 827 788 ]); 828 789 829 - export const zModelWithNestedArrayEnumsDataFoo = z.enum([ 830 - 'foo', 831 - 'bar' 832 - ]); 790 + export const zModelWithNestedArrayEnumsDataFoo = z.enum(["foo", "bar"]); 833 791 834 - export const zModelWithNestedArrayEnumsDataBar = z.enum([ 835 - 'baz', 836 - 'qux' 837 - ]); 792 + export const zModelWithNestedArrayEnumsDataBar = z.enum(["baz", "qux"]); 838 793 839 794 export const zModelWithNestedArrayEnumsData = z.object({ 840 795 foo: z.optional(z.array(zModelWithNestedArrayEnumsDataFoo)), ··· 864 819 propWithNumber: z.optional(z.array(z.number())) 865 820 }); 866 821 867 - export const zModelWithConstantSizeArray = z.tuple([ 868 - z.number(), 869 - z.number() 870 - ]); 822 + export const zModelWithConstantSizeArray = z.tuple([z.number(), z.number()]); 871 823 872 824 export const zModelWithAnyOfConstantSizeArray = z.tuple([ 873 825 z.union([ ··· 911 863 ]) 912 864 ]); 913 865 914 - export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([ 915 - z.intersection(z.number(), z.string()), 916 - z.intersection(z.number(), z.string()) 917 - ]); 866 + export const zModelWithAnyOfConstantSizeArrayAndIntersect = z.tuple([z.intersection(z.number(), z.string()), z.intersection(z.number(), z.string())]); 918 867 919 868 export const zModelWithNumericEnumUnion = z.object({ 920 869 value: z.optional(z.union([ ··· 965 914 */ 966 915 export const zImport = z.string(); 967 916 968 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([ 969 - z.union([ 917 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = z.tuple([z.union([ 970 918 z.number(), 971 919 zImport 972 - ]), 973 - z.union([ 920 + ]), z.union([ 974 921 z.number(), 975 922 zImport 976 - ]) 977 - ]); 923 + ])]); 978 924 979 925 export const zSchemaWithFormRestrictedKeys = z.object({ 980 926 description: z.optional(z.string()), ··· 1132 1078 propWithNumber: z.optional(z.array(z.number())) 1133 1079 }); 1134 1080 1135 - export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([ 1136 - z.union([ 1081 + export const zModelWithAnyOfConstantSizeArrayWithNSizeAndOptionsWritable = z.tuple([z.union([ 1137 1082 z.number(), 1138 1083 zImport 1139 - ]), 1140 - z.union([ 1084 + ]), z.union([ 1141 1085 z.number(), 1142 1086 zImport 1143 - ]) 1144 - ]); 1087 + ])]); 1145 1088 1146 1089 export const zAdditionalPropertiesUnknownIssueWritable = z.record(z.string(), z.union([ 1147 1090 z.string(), ··· 1467 1410 path: z.optional(z.never()), 1468 1411 query: z.optional(z.object({ 1469 1412 parameterString: z.optional(z.union([ 1470 - z.string().default('Hello World!'), 1413 + z.string().default("Hello World!"), 1471 1414 z.null() 1472 - ])).default('Hello World!'), 1415 + ])).default("Hello World!"), 1473 1416 parameterNumber: z.optional(z.union([ 1474 1417 z.number().default(123), 1475 1418 z.null() ··· 1479 1422 z.null() 1480 1423 ])).default(true), 1481 1424 parameterEnum: z.optional(z.enum([ 1482 - 'Success', 1483 - 'Warning', 1484 - 'Error' 1425 + "Success", 1426 + "Warning", 1427 + "Error" 1485 1428 ])), 1486 1429 parameterModel: z.optional(z.union([ 1487 - zModelWithString.default({ 1488 - prop: 'Hello World!' 1489 - }), 1430 + zModelWithString.default({ prop: "Hello World!" }), 1490 1431 z.null() 1491 1432 ])) 1492 1433 })) ··· 1496 1437 body: z.optional(z.never()), 1497 1438 path: z.optional(z.never()), 1498 1439 query: z.optional(z.object({ 1499 - parameterString: z.optional(z.string()).default('Hello World!'), 1440 + parameterString: z.optional(z.string()).default("Hello World!"), 1500 1441 parameterNumber: z.optional(z.number()).default(123), 1501 1442 parameterBoolean: z.optional(z.boolean()).default(true), 1502 1443 parameterEnum: z.optional(z.enum([ 1503 - 'Success', 1504 - 'Warning', 1505 - 'Error' 1444 + "Success", 1445 + "Warning", 1446 + "Error" 1506 1447 ])), 1507 - parameterModel: z.optional(zModelWithString).default({ 1508 - prop: 'Hello World!' 1509 - }) 1448 + parameterModel: z.optional(zModelWithString).default({ prop: "Hello World!" }) 1510 1449 })) 1511 1450 }); 1512 1451 ··· 1514 1453 body: z.optional(z.never()), 1515 1454 path: z.optional(z.never()), 1516 1455 query: z.object({ 1517 - parameterOptionalStringWithDefault: z.optional(z.string()).default('Hello World!'), 1518 - parameterOptionalStringWithEmptyDefault: z.optional(z.string()).default(''), 1456 + parameterOptionalStringWithDefault: z.optional(z.string()).default("Hello World!"), 1457 + parameterOptionalStringWithEmptyDefault: z.optional(z.string()).default(""), 1519 1458 parameterOptionalStringWithNoDefault: z.optional(z.string()), 1520 - parameterStringWithDefault: z.string().default('Hello World!'), 1521 - parameterStringWithEmptyDefault: z.string().default(''), 1459 + parameterStringWithDefault: z.string().default("Hello World!"), 1460 + parameterStringWithEmptyDefault: z.string().default(""), 1522 1461 parameterStringWithNoDefault: z.string(), 1523 1462 parameterStringNullableWithNoDefault: z.optional(z.union([ 1524 1463 z.string(), ··· 1666 1605 query: z.object({ 1667 1606 parameterNumber: z.number().default(123), 1668 1607 parameterString: z.union([ 1669 - z.string().default('default'), 1608 + z.string().default("default"), 1670 1609 z.null() 1671 - ]).default('default'), 1610 + ]).default("default"), 1672 1611 parameterBoolean: z.union([ 1673 1612 z.boolean().default(true), 1674 1613 z.null() ··· 1789 1728 ]), 1790 1729 enabled: z.optional(z.boolean()).default(true), 1791 1730 type: z.enum([ 1792 - 'Monkey', 1793 - 'Horse', 1794 - 'Bird' 1731 + "Monkey", 1732 + "Horse", 1733 + "Bird" 1795 1734 ]), 1796 1735 listOfModels: z.optional(z.union([ 1797 1736 z.array(zModelWithString),
+7 -13
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/defaults-with-ref-and-anyof/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod'; 4 4 5 - export const zAudioFormat = z.enum([ 6 - 'pcm_16bit_44.1khz', 7 - 'pcm_16bit_24khz' 8 - ]); 5 + export const zAudioFormat = z.enum(["pcm_16bit_44.1khz", "pcm_16bit_24khz"]); 9 6 10 7 export const zLanguage = z.enum([ 11 - 'en', 12 - 'es', 13 - 'fr' 8 + "en", 9 + "es", 10 + "fr" 14 11 ]); 15 12 16 13 export const zNestedConfig = z.object({ 17 - model: z.string().default('gpt-4'), 14 + model: z.string().default("gpt-4"), 18 15 temperature: z.number().default(1) 19 16 }); 20 17 21 18 export const zTestSchema = z.object({ 22 19 primitiveDefault: z.number().default(42), 23 - refWithPrimitiveDefault: zAudioFormat.default('pcm_16bit_44.1khz'), 24 - refWithObjectDefault: zNestedConfig.default({ 25 - model: 'gpt-4', 26 - temperature: 1 27 - }), 20 + refWithPrimitiveDefault: zAudioFormat.default("pcm_16bit_44.1khz"), 21 + refWithObjectDefault: zNestedConfig.default({ model: "gpt-4", temperature: 1 }), 28 22 anyOfWithNullDefault: z.union([ 29 23 z.number(), 30 24 z.null()
+3 -12
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/enum-null/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod'; 4 4 5 - export const zFoo = z.nullable(z.enum([ 6 - 'foo', 7 - 'bar' 8 - ])); 5 + export const zFoo = z.nullable(z.enum(["foo", "bar"])); 9 6 10 - export const zBar = z.enum([ 11 - 'foo', 12 - 'bar' 13 - ]); 7 + export const zBar = z.enum(["foo", "bar"]); 14 8 15 - export const zBaz = z.enum([ 16 - 'foo', 17 - 'bar' 18 - ]); 9 + export const zBaz = z.enum(["foo", "bar"]);
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/schema-const/zod.gen.ts
··· 11 11 z.literal(1), 12 12 z.literal(2), 13 13 z.literal(3), 14 - z.literal('foo'), 14 + z.literal("foo"), 15 15 z.literal(true) 16 16 ])), 17 17 corge: z.optional(z.record(z.string(), z.unknown())),
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-dates/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export const zQux = z.record(z.string(), z.object({ 8 8 qux: z.optional(z.string())
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-metadata/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export const zQux = z.record(z.string(), z.object({ 8 8 qux: z.optional(z.string())
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-types/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export type BazZodType = z.infer<typeof zBaz>; 8 8
+4 -7
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-union-merge/zod.gen.ts
··· 22 22 23 23 export const zCatDetails = z.object({ 24 24 furLength: z.enum([ 25 - 'short', 26 - 'medium', 27 - 'long' 25 + "short", 26 + "medium", 27 + "long" 28 28 ]), 29 29 purrs: z.boolean() 30 30 }); ··· 32 32 export const zPetStore = z.object({ 33 33 animals: z.array(z.object({ 34 34 name: z.string(), 35 - type: z.optional(z.enum([ 36 - 'dog', 37 - 'cat' 38 - ])), 35 + type: z.optional(z.enum(["dog", "cat"])), 39 36 details: z.union([ 40 37 zDogDetails, 41 38 zCatDetails
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators/zod.gen.ts
··· 2 2 3 3 import { z } from 'zod'; 4 4 5 - export const zBaz = z.string().regex(/foo\nbar/).readonly().default('baz'); 5 + export const zBaz = z.string().regex(/foo\nbar/).readonly().default("baz"); 6 6 7 7 export const zQux = z.record(z.string(), z.object({ 8 8 qux: z.optional(z.string())
+54 -56
packages/openapi-ts/src/plugins/zod/constants.ts
··· 1 - import { tsc } from '~/tsc'; 2 - 3 1 // TODO: this is inaccurate, it combines identifiers for all supported versions 4 2 export const identifiers = { 5 - ZodMiniOptional: tsc.identifier({ text: 'ZodMiniOptional' }), 6 - ZodOptional: tsc.identifier({ text: 'ZodOptional' }), 7 - _default: tsc.identifier({ text: '_default' }), 8 - and: tsc.identifier({ text: 'and' }), 9 - array: tsc.identifier({ text: 'array' }), 10 - bigint: tsc.identifier({ text: 'bigint' }), 11 - boolean: tsc.identifier({ text: 'boolean' }), 12 - check: tsc.identifier({ text: 'check' }), 13 - coerce: tsc.identifier({ text: 'coerce' }), 14 - date: tsc.identifier({ text: 'date' }), 15 - datetime: tsc.identifier({ text: 'datetime' }), 16 - default: tsc.identifier({ text: 'default' }), 17 - describe: tsc.identifier({ text: 'describe' }), 18 - email: tsc.identifier({ text: 'email' }), 19 - enum: tsc.identifier({ text: 'enum' }), 20 - globalRegistry: tsc.identifier({ text: 'globalRegistry' }), 21 - gt: tsc.identifier({ text: 'gt' }), 22 - gte: tsc.identifier({ text: 'gte' }), 23 - infer: tsc.identifier({ text: 'infer' }), 24 - int: tsc.identifier({ text: 'int' }), 25 - intersection: tsc.identifier({ text: 'intersection' }), 26 - ip: tsc.identifier({ text: 'ip' }), 27 - ipv4: tsc.identifier({ text: 'ipv4' }), 28 - ipv6: tsc.identifier({ text: 'ipv6' }), 29 - iso: tsc.identifier({ text: 'iso' }), 30 - lazy: tsc.identifier({ text: 'lazy' }), 31 - length: tsc.identifier({ text: 'length' }), 32 - literal: tsc.identifier({ text: 'literal' }), 33 - lt: tsc.identifier({ text: 'lt' }), 34 - lte: tsc.identifier({ text: 'lte' }), 35 - max: tsc.identifier({ text: 'max' }), 36 - maxLength: tsc.identifier({ text: 'maxLength' }), 37 - min: tsc.identifier({ text: 'min' }), 38 - minLength: tsc.identifier({ text: 'minLength' }), 39 - never: tsc.identifier({ text: 'never' }), 40 - null: tsc.identifier({ text: 'null' }), 41 - nullable: tsc.identifier({ text: 'nullable' }), 42 - number: tsc.identifier({ text: 'number' }), 43 - object: tsc.identifier({ text: 'object' }), 44 - optional: tsc.identifier({ text: 'optional' }), 45 - parseAsync: tsc.identifier({ text: 'parseAsync' }), 46 - readonly: tsc.identifier({ text: 'readonly' }), 47 - record: tsc.identifier({ text: 'record' }), 48 - regex: tsc.identifier({ text: 'regex' }), 49 - register: tsc.identifier({ text: 'register' }), 50 - string: tsc.identifier({ text: 'string' }), 51 - time: tsc.identifier({ text: 'time' }), 52 - tuple: tsc.identifier({ text: 'tuple' }), 53 - undefined: tsc.identifier({ text: 'undefined' }), 54 - union: tsc.identifier({ text: 'union' }), 55 - unknown: tsc.identifier({ text: 'unknown' }), 56 - url: tsc.identifier({ text: 'url' }), 57 - uuid: tsc.identifier({ text: 'uuid' }), 58 - void: tsc.identifier({ text: 'void' }), 3 + ZodMiniOptional: 'ZodMiniOptional', 4 + ZodOptional: 'ZodOptional', 5 + _default: '_default', 6 + and: 'and', 7 + array: 'array', 8 + bigint: 'bigint', 9 + boolean: 'boolean', 10 + check: 'check', 11 + coerce: 'coerce', 12 + date: 'date', 13 + datetime: 'datetime', 14 + default: 'default', 15 + describe: 'describe', 16 + email: 'email', 17 + enum: 'enum', 18 + globalRegistry: 'globalRegistry', 19 + gt: 'gt', 20 + gte: 'gte', 21 + infer: 'infer', 22 + int: 'int', 23 + intersection: 'intersection', 24 + ip: 'ip', 25 + ipv4: 'ipv4', 26 + ipv6: 'ipv6', 27 + iso: 'iso', 28 + lazy: 'lazy', 29 + length: 'length', 30 + literal: 'literal', 31 + lt: 'lt', 32 + lte: 'lte', 33 + max: 'max', 34 + maxLength: 'maxLength', 35 + min: 'min', 36 + minLength: 'minLength', 37 + never: 'never', 38 + null: 'null', 39 + nullable: 'nullable', 40 + number: 'number', 41 + object: 'object', 42 + optional: 'optional', 43 + parseAsync: 'parseAsync', 44 + readonly: 'readonly', 45 + record: 'record', 46 + regex: 'regex', 47 + register: 'register', 48 + string: 'string', 49 + time: 'time', 50 + tuple: 'tuple', 51 + undefined: 'undefined', 52 + union: 'union', 53 + unknown: 'unknown', 54 + url: 'url', 55 + uuid: 'uuid', 56 + void: 'void', 59 57 };
+11 -19
packages/openapi-ts/src/plugins/zod/mini/plugin.ts
··· 48 48 }; 49 49 const refSymbol = plugin.referenceSymbol(query); 50 50 if (plugin.isSymbolRegistered(query)) { 51 - ast.expression = $(refSymbol.placeholder).$render(); 51 + ast.expression = $(refSymbol.placeholder); 52 52 } else { 53 53 ast.expression = $(z.placeholder) 54 54 .attr(identifiers.lazy) 55 - .call($.func().returns('any').do($(refSymbol.placeholder).return())) 56 - .$render(); 55 + .call($.func().returns('any').do($(refSymbol.placeholder).return())); 57 56 ast.hasLazyExpression = true; 58 57 state.hasLazyExpression.value = true; 59 58 } ··· 67 66 ast.hasLazyExpression = typeAst.hasLazyExpression; 68 67 69 68 if (plugin.config.metadata && schema.description) { 70 - ast.expression = $(ast.expression) 69 + ast.expression = ast.expression 71 70 .attr(identifiers.register) 72 71 .call( 73 72 $(z.placeholder).attr(identifiers.globalRegistry), 74 73 $.object() 75 74 .pretty() 76 75 .prop('description', $.literal(schema.description)), 77 - ) 78 - .$render(); 76 + ); 79 77 } 80 78 } else if (schema.items) { 81 79 schema = deduplicateSchema({ schema }); ··· 103 101 ) { 104 102 ast.expression = $(z.placeholder) 105 103 .attr(identifiers.intersection) 106 - .call(...itemSchemas.map((schema) => schema.expression)) 107 - .$render(); 104 + .call(...itemSchemas.map((schema) => schema.expression)); 108 105 } else { 109 106 ast.expression = itemSchemas[0]!.expression; 110 107 itemSchemas.slice(1).forEach((schema) => { ··· 115 112 schema.hasLazyExpression 116 113 ? $(z.placeholder) 117 114 .attr(identifiers.lazy) 118 - .call($.func().do($(schema.expression).return())) 115 + .call($.func().do(schema.expression.return())) 119 116 : schema.expression, 120 - ) 121 - .$render(); 117 + ); 122 118 }); 123 119 } 124 120 } else { ··· 128 124 $.array() 129 125 .pretty() 130 126 .elements(...itemSchemas.map((schema) => schema.expression)), 131 - ) 132 - .$render(); 127 + ); 133 128 } 134 129 } else { 135 130 ast = irSchemaToAst({ plugin, schema, state }); ··· 150 145 if (schema.accessScope === 'read') { 151 146 ast.expression = $(z.placeholder) 152 147 .attr(identifiers.readonly) 153 - .call(ast.expression) 154 - .$render(); 148 + .call(ast.expression); 155 149 } 156 150 157 151 if (optional) { 158 152 ast.expression = $(z.placeholder) 159 153 .attr(identifiers.optional) 160 - .call(ast.expression) 161 - .$render(); 154 + .call(ast.expression); 162 155 ast.typeName = identifiers.ZodMiniOptional; 163 156 } 164 157 ··· 171 164 if (callParameter) { 172 165 ast.expression = $(z.placeholder) 173 166 .attr(identifiers._default) 174 - .call(ast.expression, callParameter) 175 - .$render(); 167 + .call(ast.expression, callParameter); 176 168 } 177 169 } 178 170 }
+38 -90
packages/openapi-ts/src/plugins/zod/mini/toAst/array.ts
··· 1 - import type ts from 'typescript'; 2 - 3 1 import { deduplicateSchema } from '~/ir/schema'; 4 2 import type { SchemaWithType } from '~/plugins'; 5 3 import { toRef } from '~/plugins/shared/utils/refs'; 6 - import { tsc } from '~/tsc'; 4 + import { $ } from '~/ts-dsl'; 7 5 8 6 import { identifiers } from '../../constants'; 9 7 import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; ··· 24 22 25 23 const result: Partial<Omit<Ast, 'typeName'>> = {}; 26 24 27 - const functionName = tsc.propertyAccessExpression({ 28 - expression: z.placeholder, 29 - name: identifiers.array, 30 - }); 25 + const functionName = $(z.placeholder).attr(identifiers.array); 31 26 32 27 if (!schema.items) { 33 - result.expression = tsc.callExpression({ 34 - functionName, 35 - parameters: [ 36 - unknownToAst({ 37 - plugin, 38 - schema: { 39 - type: 'unknown', 40 - }, 41 - state, 42 - }).expression, 43 - ], 44 - }); 28 + result.expression = functionName.call( 29 + unknownToAst({ 30 + plugin, 31 + schema: { 32 + type: 'unknown', 33 + }, 34 + state, 35 + }).expression, 36 + ); 45 37 } else { 46 38 schema = deduplicateSchema({ schema }); 47 39 ··· 62 54 }); 63 55 64 56 if (itemExpressions.length === 1) { 65 - result.expression = tsc.callExpression({ 66 - functionName, 67 - parameters: itemExpressions, 68 - }); 57 + result.expression = functionName.call(...itemExpressions); 69 58 } else { 70 59 if (schema.logicalOperator === 'and') { 71 60 const firstSchema = schema.items![0]!; 72 61 // we want to add an intersection, but not every schema can use the same API. 73 62 // if the first item contains another array or not an object, we cannot use 74 63 // `.intersection()` as that does not exist on `.union()` and non-object schemas. 75 - let intersectionExpression: ts.Expression; 64 + let intersectionExpression: ReturnType<typeof $.expr | typeof $.call>; 76 65 if ( 77 66 firstSchema.logicalOperator === 'or' || 78 67 (firstSchema.type && firstSchema.type !== 'object') 79 68 ) { 80 - intersectionExpression = tsc.callExpression({ 81 - functionName: tsc.propertyAccessExpression({ 82 - expression: z.placeholder, 83 - name: identifiers.intersection, 84 - }), 85 - parameters: itemExpressions, 86 - }); 69 + intersectionExpression = $(z.placeholder) 70 + .attr(identifiers.intersection) 71 + .call(...itemExpressions); 87 72 } else { 88 73 intersectionExpression = itemExpressions[0]!; 89 74 for (let i = 1; i < itemExpressions.length; i++) { 90 - intersectionExpression = tsc.callExpression({ 91 - functionName: tsc.propertyAccessExpression({ 92 - expression: z.placeholder, 93 - name: identifiers.intersection, 94 - }), 95 - parameters: [intersectionExpression, itemExpressions[i]!], 96 - }); 75 + intersectionExpression = $(z.placeholder) 76 + .attr(identifiers.intersection) 77 + .call(intersectionExpression, itemExpressions[i]); 97 78 } 98 79 } 99 80 100 - result.expression = tsc.callExpression({ 101 - functionName, 102 - parameters: [intersectionExpression], 103 - }); 81 + result.expression = functionName.call(intersectionExpression); 104 82 } else { 105 - result.expression = tsc.callExpression({ 106 - functionName: tsc.propertyAccessExpression({ 107 - expression: z.placeholder, 108 - name: identifiers.array, 109 - }), 110 - parameters: [ 111 - tsc.callExpression({ 112 - functionName: tsc.propertyAccessExpression({ 113 - expression: z.placeholder, 114 - name: identifiers.union, 115 - }), 116 - parameters: [ 117 - tsc.arrayLiteralExpression({ 118 - elements: itemExpressions, 119 - }), 120 - ], 121 - }), 122 - ], 123 - }); 83 + result.expression = $(z.placeholder) 84 + .attr(identifiers.array) 85 + .call( 86 + $(z.placeholder) 87 + .attr(identifiers.union) 88 + .call($.array(...itemExpressions)), 89 + ); 124 90 } 125 91 } 126 92 } 127 93 128 - const checks: Array<ts.Expression> = []; 94 + const checks: Array<ReturnType<typeof $.call>> = []; 129 95 130 96 if (schema.minItems === schema.maxItems && schema.minItems !== undefined) { 131 97 checks.push( 132 - tsc.callExpression({ 133 - functionName: tsc.propertyAccessExpression({ 134 - expression: z.placeholder, 135 - name: identifiers.length, 136 - }), 137 - parameters: [tsc.valueToExpression({ value: schema.minItems })], 138 - }), 98 + $(z.placeholder).attr(identifiers.length).call($.toExpr(schema.minItems)), 139 99 ); 140 100 } else { 141 101 if (schema.minItems !== undefined) { 142 102 checks.push( 143 - tsc.callExpression({ 144 - functionName: tsc.propertyAccessExpression({ 145 - expression: z.placeholder, 146 - name: identifiers.minLength, 147 - }), 148 - parameters: [tsc.valueToExpression({ value: schema.minItems })], 149 - }), 103 + $(z.placeholder) 104 + .attr(identifiers.minLength) 105 + .call($.toExpr(schema.minItems)), 150 106 ); 151 107 } 152 108 153 109 if (schema.maxItems !== undefined) { 154 110 checks.push( 155 - tsc.callExpression({ 156 - functionName: tsc.propertyAccessExpression({ 157 - expression: z.placeholder, 158 - name: identifiers.maxLength, 159 - }), 160 - parameters: [tsc.valueToExpression({ value: schema.maxItems })], 161 - }), 111 + $(z.placeholder) 112 + .attr(identifiers.maxLength) 113 + .call($.toExpr(schema.maxItems)), 162 114 ); 163 115 } 164 116 } 165 117 166 118 if (checks.length) { 167 - result.expression = tsc.callExpression({ 168 - functionName: tsc.propertyAccessExpression({ 169 - expression: result.expression, 170 - name: identifiers.check, 171 - }), 172 - parameters: checks, 173 - }); 119 + result.expression = result.expression 120 + .attr(identifiers.check) 121 + .call(...checks); 174 122 } 175 123 176 124 return result as Omit<Ast, 'typeName'>;
+2 -2
packages/openapi-ts/src/plugins/zod/mini/toAst/boolean.ts
··· 22 22 chain = $(z.placeholder) 23 23 .attr(identifiers.literal) 24 24 .call($.literal(schema.const)); 25 - result.expression = chain.$render(); 25 + result.expression = chain; 26 26 return result as Omit<Ast, 'typeName'>; 27 27 } 28 28 29 29 chain = $(z.placeholder).attr(identifiers.boolean).call(); 30 - result.expression = chain.$render(); 30 + result.expression = chain; 31 31 return result as Omit<Ast, 'typeName'>; 32 32 };
+20 -64
packages/openapi-ts/src/plugins/zod/mini/toAst/enum.ts
··· 1 - import type ts from 'typescript'; 2 - 3 1 import type { SchemaWithType } from '~/plugins'; 4 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 5 3 6 4 import { identifiers } from '../../constants'; 7 5 import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; ··· 21 19 22 20 const result: Partial<Omit<Ast, 'typeName'>> = {}; 23 21 24 - const enumMembers: Array<ts.LiteralExpression> = []; 25 - const literalMembers: Array<ts.CallExpression> = []; 22 + const enumMembers: Array<ReturnType<typeof $.literal>> = []; 23 + const literalMembers: Array<ReturnType<typeof $.call>> = []; 26 24 27 25 let isNullable = false; 28 26 let allStrings = true; ··· 30 28 for (const item of schema.items ?? []) { 31 29 // Zod supports string, number, and boolean enums 32 30 if (item.type === 'string' && typeof item.const === 'string') { 33 - const stringLiteral = tsc.stringLiteral({ 34 - text: item.const, 35 - }); 36 - enumMembers.push(stringLiteral); 31 + const literal = $.literal(item.const); 32 + enumMembers.push(literal); 37 33 literalMembers.push( 38 - tsc.callExpression({ 39 - functionName: tsc.propertyAccessExpression({ 40 - expression: z.placeholder, 41 - name: identifiers.literal, 42 - }), 43 - parameters: [stringLiteral], 44 - }), 34 + $(z.placeholder).attr(identifiers.literal).call(literal), 45 35 ); 46 36 } else if ( 47 37 (item.type === 'number' || item.type === 'integer') && 48 38 typeof item.const === 'number' 49 39 ) { 50 40 allStrings = false; 51 - const numberLiteral = tsc.ots.number(item.const); 41 + const literal = $.literal(item.const); 52 42 literalMembers.push( 53 - tsc.callExpression({ 54 - functionName: tsc.propertyAccessExpression({ 55 - expression: z.placeholder, 56 - name: identifiers.literal, 57 - }), 58 - parameters: [numberLiteral], 59 - }), 43 + $(z.placeholder).attr(identifiers.literal).call(literal), 60 44 ); 61 45 } else if (item.type === 'boolean' && typeof item.const === 'boolean') { 62 46 allStrings = false; 63 - const booleanLiteral = tsc.ots.boolean(item.const); 47 + const literal = $.literal(item.const); 64 48 literalMembers.push( 65 - tsc.callExpression({ 66 - functionName: tsc.propertyAccessExpression({ 67 - expression: z.placeholder, 68 - name: identifiers.literal, 69 - }), 70 - parameters: [booleanLiteral], 71 - }), 49 + $(z.placeholder).attr(identifiers.literal).call(literal), 72 50 ); 73 51 } else if (item.type === 'null' || item.const === null) { 74 52 isNullable = true; ··· 87 65 88 66 // Use z.enum() for pure string enums, z.union() for mixed or non-string types 89 67 if (allStrings && enumMembers.length > 0) { 90 - result.expression = tsc.callExpression({ 91 - functionName: tsc.propertyAccessExpression({ 92 - expression: z.placeholder, 93 - name: identifiers.enum, 94 - }), 95 - parameters: [ 96 - tsc.arrayLiteralExpression({ 97 - elements: enumMembers, 98 - multiLine: false, 99 - }), 100 - ], 101 - }); 68 + result.expression = $(z.placeholder) 69 + .attr(identifiers.enum) 70 + .call($.array(...enumMembers)); 102 71 } else if (literalMembers.length === 1) { 103 72 // For single-member unions, use the member directly instead of wrapping in z.union() 104 - result.expression = literalMembers[0]; 73 + result.expression = literalMembers[0]!; 105 74 } else { 106 - result.expression = tsc.callExpression({ 107 - functionName: tsc.propertyAccessExpression({ 108 - expression: z.placeholder, 109 - name: identifiers.union, 110 - }), 111 - parameters: [ 112 - tsc.arrayLiteralExpression({ 113 - elements: literalMembers, 114 - multiLine: literalMembers.length > 3, 115 - }), 116 - ], 117 - }); 75 + result.expression = $(z.placeholder) 76 + .attr(identifiers.union) 77 + .call($.array(...literalMembers)); 118 78 } 119 79 120 80 if (isNullable) { 121 - result.expression = tsc.callExpression({ 122 - functionName: tsc.propertyAccessExpression({ 123 - expression: z.placeholder, 124 - name: identifiers.nullable, 125 - }), 126 - parameters: [result.expression], 127 - }); 81 + result.expression = $(z.placeholder) 82 + .attr(identifiers.nullable) 83 + .call(result.expression); 128 84 } 129 85 130 86 return result as Omit<Ast, 'typeName'>;
+2 -7
packages/openapi-ts/src/plugins/zod/mini/toAst/never.ts
··· 1 1 import type { SchemaWithType } from '~/plugins'; 2 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 3 3 4 4 import { identifiers } from '../../constants'; 5 5 import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; ··· 14 14 resource: 'zod.z', 15 15 }); 16 16 const result: Partial<Omit<Ast, 'typeName'>> = {}; 17 - result.expression = tsc.callExpression({ 18 - functionName: tsc.propertyAccessExpression({ 19 - expression: z.placeholder, 20 - name: identifiers.never, 21 - }), 22 - }); 17 + result.expression = $(z.placeholder).attr(identifiers.never).call(); 23 18 return result as Omit<Ast, 'typeName'>; 24 19 };
+2 -7
packages/openapi-ts/src/plugins/zod/mini/toAst/null.ts
··· 1 1 import type { SchemaWithType } from '~/plugins'; 2 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 3 3 4 4 import { identifiers } from '../../constants'; 5 5 import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; ··· 14 14 resource: 'zod.z', 15 15 }); 16 16 const result: Partial<Omit<Ast, 'typeName'>> = {}; 17 - result.expression = tsc.callExpression({ 18 - functionName: tsc.propertyAccessExpression({ 19 - expression: z.placeholder, 20 - name: identifiers.null, 21 - }), 22 - }); 17 + result.expression = $(z.placeholder).attr(identifiers.null).call(); 23 18 return result as Omit<Ast, 'typeName'>; 24 19 };
+24 -70
packages/openapi-ts/src/plugins/zod/mini/toAst/number.ts
··· 1 - import type ts from 'typescript'; 2 - 3 1 import type { SchemaWithType } from '~/plugins'; 4 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 5 3 6 4 import { identifiers } from '../../constants'; 7 5 import { numberParameter } from '../../shared/numbers'; ··· 24 22 25 23 if (typeof schema.const === 'number') { 26 24 // TODO: parser - handle bigint constants 27 - result.expression = tsc.callExpression({ 28 - functionName: tsc.propertyAccessExpression({ 29 - expression: z.placeholder, 30 - name: identifiers.literal, 31 - }), 32 - parameters: [tsc.ots.number(schema.const)], 33 - }); 25 + result.expression = $(z.placeholder) 26 + .attr(identifiers.literal) 27 + .call($.literal(schema.const)); 34 28 return result as Omit<Ast, 'typeName'>; 35 29 } 36 30 37 - result.expression = tsc.callExpression({ 38 - functionName: isBigInt 39 - ? tsc.propertyAccessExpression({ 40 - expression: tsc.propertyAccessExpression({ 41 - expression: z.placeholder, 42 - name: identifiers.coerce, 43 - }), 44 - name: identifiers.bigint, 45 - }) 46 - : tsc.propertyAccessExpression({ 47 - expression: z.placeholder, 48 - name: identifiers.number, 49 - }), 50 - }); 31 + result.expression = isBigInt 32 + ? $(z.placeholder).attr(identifiers.coerce).attr(identifiers.bigint).call() 33 + : $(z.placeholder).attr(identifiers.number).call(); 51 34 52 35 if (!isBigInt && schema.type === 'integer') { 53 - result.expression = tsc.callExpression({ 54 - functionName: tsc.propertyAccessExpression({ 55 - expression: z.placeholder, 56 - name: identifiers.int, 57 - }), 58 - }); 36 + result.expression = $(z.placeholder).attr(identifiers.int).call(); 59 37 } 60 38 61 - const checks: Array<ts.Expression> = []; 39 + const checks: Array<ReturnType<typeof $.call>> = []; 62 40 63 41 if (schema.exclusiveMinimum !== undefined) { 64 42 checks.push( 65 - tsc.callExpression({ 66 - functionName: tsc.propertyAccessExpression({ 67 - expression: z.placeholder, 68 - name: identifiers.gt, 69 - }), 70 - parameters: [ 71 - numberParameter({ isBigInt, value: schema.exclusiveMinimum }), 72 - ], 73 - }), 43 + $(z.placeholder) 44 + .attr(identifiers.gt) 45 + .call(numberParameter({ isBigInt, value: schema.exclusiveMinimum })), 74 46 ); 75 47 } else if (schema.minimum !== undefined) { 76 48 checks.push( 77 - tsc.callExpression({ 78 - functionName: tsc.propertyAccessExpression({ 79 - expression: z.placeholder, 80 - name: identifiers.gte, 81 - }), 82 - parameters: [numberParameter({ isBigInt, value: schema.minimum })], 83 - }), 49 + $(z.placeholder) 50 + .attr(identifiers.gte) 51 + .call(numberParameter({ isBigInt, value: schema.minimum })), 84 52 ); 85 53 } 86 54 87 55 if (schema.exclusiveMaximum !== undefined) { 88 56 checks.push( 89 - tsc.callExpression({ 90 - functionName: tsc.propertyAccessExpression({ 91 - expression: z.placeholder, 92 - name: identifiers.lt, 93 - }), 94 - parameters: [ 95 - numberParameter({ isBigInt, value: schema.exclusiveMaximum }), 96 - ], 97 - }), 57 + $(z.placeholder) 58 + .attr(identifiers.lt) 59 + .call(numberParameter({ isBigInt, value: schema.exclusiveMaximum })), 98 60 ); 99 61 } else if (schema.maximum !== undefined) { 100 62 checks.push( 101 - tsc.callExpression({ 102 - functionName: tsc.propertyAccessExpression({ 103 - expression: z.placeholder, 104 - name: identifiers.lte, 105 - }), 106 - parameters: [numberParameter({ isBigInt, value: schema.maximum })], 107 - }), 63 + $(z.placeholder) 64 + .attr(identifiers.lte) 65 + .call(numberParameter({ isBigInt, value: schema.maximum })), 108 66 ); 109 67 } 110 68 111 69 if (checks.length) { 112 - result.expression = tsc.callExpression({ 113 - functionName: tsc.propertyAccessExpression({ 114 - expression: result.expression, 115 - name: identifiers.check, 116 - }), 117 - parameters: checks, 118 - }); 70 + result.expression = result.expression 71 + .attr(identifiers.check) 72 + .call(...checks); 119 73 } 120 74 121 75 return result as Omit<Ast, 'typeName'>;
+3 -5
packages/openapi-ts/src/plugins/zod/mini/toAst/object.ts
··· 1 - import type ts from 'typescript'; 2 - 3 1 import type { SchemaWithType } from '~/plugins'; 4 2 import { toRef } from '~/plugins/shared/utils/refs'; 5 3 import { $ } from '~/ts-dsl'; ··· 60 58 } 61 59 62 60 if (propertyAst.hasLazyExpression) { 63 - shape.getter(name, $(propertyAst.expression).return()); 61 + shape.getter(name, propertyAst.expression.return()); 64 62 } else { 65 63 shape.prop(name, propertyAst.expression); 66 64 } 67 65 } 68 66 69 - let additional: ts.Expression | null | undefined; 67 + let additional: ReturnType<typeof $.call | typeof $.expr> | null | undefined; 70 68 if ( 71 69 schema.additionalProperties && 72 70 (!schema.properties || !Object.keys(schema.properties).length) ··· 93 91 }; 94 92 const resolver = plugin.config['~resolvers']?.object?.base; 95 93 const chain = resolver?.(args) ?? defaultObjectBaseResolver(args); 96 - result.expression = chain.$render(); 94 + result.expression = chain; 97 95 98 96 return result as Omit<Ast, 'typeName'>; 99 97 };
+2 -2
packages/openapi-ts/src/plugins/zod/mini/toAst/string.ts
··· 72 72 chain = $(z.placeholder) 73 73 .attr(identifiers.literal) 74 74 .call($.literal(schema.const)); 75 - result.expression = chain.$render(); 75 + result.expression = chain; 76 76 return result as Omit<Ast, 'typeName'>; 77 77 } 78 78 ··· 121 121 chain = chain.attr(identifiers.check).call(...checks); 122 122 } 123 123 124 - result.expression = chain.$render(); 124 + result.expression = chain; 125 125 return result as Omit<Ast, 'typeName'>; 126 126 };
+9 -33
packages/openapi-ts/src/plugins/zod/mini/toAst/tuple.ts
··· 1 - import type ts from 'typescript'; 2 - 3 1 import type { SchemaWithType } from '~/plugins'; 4 2 import { toRef } from '~/plugins/shared/utils/refs'; 5 - import { tsc } from '~/tsc'; 3 + import { $ } from '~/ts-dsl'; 6 4 7 5 import { identifiers } from '../../constants'; 8 6 import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; ··· 24 22 25 23 if (schema.const && Array.isArray(schema.const)) { 26 24 const tupleElements = schema.const.map((value) => 27 - tsc.callExpression({ 28 - functionName: tsc.propertyAccessExpression({ 29 - expression: z.placeholder, 30 - name: identifiers.literal, 31 - }), 32 - parameters: [tsc.valueToExpression({ value })], 33 - }), 25 + $(z.placeholder).attr(identifiers.literal).call($.toExpr(value)), 34 26 ); 35 - result.expression = tsc.callExpression({ 36 - functionName: tsc.propertyAccessExpression({ 37 - expression: z.placeholder, 38 - name: identifiers.tuple, 39 - }), 40 - parameters: [ 41 - tsc.arrayLiteralExpression({ 42 - elements: tupleElements, 43 - }), 44 - ], 45 - }); 27 + result.expression = $(z.placeholder) 28 + .attr(identifiers.tuple) 29 + .call($.array(...tupleElements)); 46 30 return result as Omit<Ast, 'typeName'>; 47 31 } 48 32 49 - const tupleElements: Array<ts.Expression> = []; 33 + const tupleElements: Array<ReturnType<typeof $.call | typeof $.expr>> = []; 50 34 51 35 if (schema.items) { 52 36 schema.items.forEach((item, index) => { ··· 65 49 }); 66 50 } 67 51 68 - result.expression = tsc.callExpression({ 69 - functionName: tsc.propertyAccessExpression({ 70 - expression: z.placeholder, 71 - name: identifiers.tuple, 72 - }), 73 - parameters: [ 74 - tsc.arrayLiteralExpression({ 75 - elements: tupleElements, 76 - }), 77 - ], 78 - }); 52 + result.expression = $(z.placeholder) 53 + .attr(identifiers.tuple) 54 + .call($.array(...tupleElements)); 79 55 80 56 return result as Omit<Ast, 'typeName'>; 81 57 };
+2 -7
packages/openapi-ts/src/plugins/zod/mini/toAst/undefined.ts
··· 1 1 import type { SchemaWithType } from '~/plugins'; 2 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 3 3 4 4 import { identifiers } from '../../constants'; 5 5 import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; ··· 14 14 resource: 'zod.z', 15 15 }); 16 16 const result: Partial<Omit<Ast, 'typeName'>> = {}; 17 - result.expression = tsc.callExpression({ 18 - functionName: tsc.propertyAccessExpression({ 19 - expression: z.placeholder, 20 - name: identifiers.undefined, 21 - }), 22 - }); 17 + result.expression = $(z.placeholder).attr(identifiers.undefined).call(); 23 18 return result as Omit<Ast, 'typeName'>; 24 19 };
+2 -7
packages/openapi-ts/src/plugins/zod/mini/toAst/unknown.ts
··· 1 1 import type { SchemaWithType } from '~/plugins'; 2 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 3 3 4 4 import { identifiers } from '../../constants'; 5 5 import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; ··· 14 14 resource: 'zod.z', 15 15 }); 16 16 const result: Partial<Omit<Ast, 'typeName'>> = {}; 17 - result.expression = tsc.callExpression({ 18 - functionName: tsc.propertyAccessExpression({ 19 - expression: z.placeholder, 20 - name: identifiers.unknown, 21 - }), 22 - }); 17 + result.expression = $(z.placeholder).attr(identifiers.unknown).call(); 23 18 return result as Omit<Ast, 'typeName'>; 24 19 };
+2 -7
packages/openapi-ts/src/plugins/zod/mini/toAst/void.ts
··· 1 1 import type { SchemaWithType } from '~/plugins'; 2 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 3 3 4 4 import { identifiers } from '../../constants'; 5 5 import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; ··· 14 14 resource: 'zod.z', 15 15 }); 16 16 const result: Partial<Omit<Ast, 'typeName'>> = {}; 17 - result.expression = tsc.callExpression({ 18 - functionName: tsc.propertyAccessExpression({ 19 - expression: z.placeholder, 20 - name: identifiers.void, 21 - }), 22 - }); 17 + result.expression = $(z.placeholder).attr(identifiers.void).call(); 23 18 return result as Omit<Ast, 'typeName'>; 24 19 };
+5 -10
packages/openapi-ts/src/plugins/zod/shared/numbers.ts
··· 1 - import type ts from 'typescript'; 2 - 3 - import { tsc } from '~/tsc'; 1 + import { $ } from '~/ts-dsl'; 4 2 5 3 export const numberParameter = ({ 6 4 isBigInt, ··· 8 6 }: { 9 7 isBigInt: boolean; 10 8 value: unknown; 11 - }): ts.Expression | undefined => { 12 - const expression = tsc.valueToExpression({ value }); 9 + }): ReturnType<typeof $.call> | ReturnType<typeof $.toExpr> | undefined => { 10 + const expr = $.toExpr(value); 13 11 14 12 if ( 15 13 isBigInt && ··· 18 16 typeof value === 'string' || 19 17 typeof value === 'boolean') 20 18 ) { 21 - return tsc.callExpression({ 22 - functionName: 'BigInt', 23 - parameters: [expression], 24 - }); 19 + return $('BigInt').call(expr); 25 20 } 26 21 27 - return expression; 22 + return expr; 28 23 };
+2 -1
packages/openapi-ts/src/plugins/zod/shared/types.d.ts
··· 3 3 4 4 import type { IR } from '~/ir/types'; 5 5 import type { ToRefs } from '~/plugins'; 6 + import type { $ } from '~/ts-dsl'; 6 7 7 8 import type { ZodPlugin } from '../types'; 8 9 9 10 export type Ast = { 10 - expression: ts.Expression; 11 + expression: ReturnType<typeof $.expr | typeof $.call>; 11 12 hasLazyExpression?: boolean; 12 13 typeName?: string | ts.Identifier; 13 14 };
+1 -1
packages/openapi-ts/src/plugins/zod/types.d.ts
··· 767 767 768 768 export type ObjectBaseResolverArgs = SharedResolverArgs & { 769 769 /** Null = never */ 770 - additional?: ts.Expression | null; 770 + additional?: ReturnType<typeof $.call | typeof $.expr> | null; 771 771 schema: IR.SchemaObject; 772 772 shape: ReturnType<typeof $.object>; 773 773 };
+11 -25
packages/openapi-ts/src/plugins/zod/v3/plugin.ts
··· 48 48 }; 49 49 const refSymbol = plugin.referenceSymbol(query); 50 50 if (plugin.isSymbolRegistered(query)) { 51 - ast.expression = $(refSymbol.placeholder).$render(); 51 + ast.expression = $(refSymbol.placeholder); 52 52 } else { 53 53 ast.expression = $(z.placeholder) 54 54 .attr(identifiers.lazy) 55 - .call($.func().do($(refSymbol.placeholder).return())) 56 - .$render(); 55 + .call($.func().do($(refSymbol.placeholder).return())); 57 56 ast.hasLazyExpression = true; 58 57 state.hasLazyExpression.value = true; 59 58 } ··· 67 66 ast.typeName = typeAst.anyType; 68 67 69 68 if (plugin.config.metadata && schema.description) { 70 - ast.expression = $(ast.expression) 69 + ast.expression = ast.expression 71 70 .attr(identifiers.describe) 72 - .call($.literal(schema.description)) 73 - .$render(); 71 + .call($.literal(schema.description)); 74 72 } 75 73 } else if (schema.items) { 76 74 schema = deduplicateSchema({ schema }); ··· 99 97 ) { 100 98 ast.expression = $(z.placeholder) 101 99 .attr(identifiers.intersection) 102 - .call(...itemTypes) 103 - .$render(); 100 + .call(...itemTypes); 104 101 } else { 105 102 ast.expression = itemTypes[0]; 106 103 itemTypes.slice(1).forEach((item) => { 107 - ast.expression = $(ast.expression!) 108 - .attr(identifiers.and) 109 - .call(item) 110 - .$render(); 104 + ast.expression = ast.expression!.attr(identifiers.and).call(item); 111 105 }); 112 106 } 113 107 } else { ··· 117 111 $.array() 118 112 .pretty() 119 113 .elements(...itemTypes), 120 - ) 121 - .$render(); 114 + ); 122 115 } 123 116 } else { 124 117 ast = irSchemaToAst({ plugin, schema, state }); ··· 138 131 139 132 if (ast.expression) { 140 133 if (schema.accessScope === 'read') { 141 - ast.expression = $(ast.expression) 142 - .attr(identifiers.readonly) 143 - .call() 144 - .$render(); 134 + ast.expression = ast.expression.attr(identifiers.readonly).call(); 145 135 } 146 136 147 137 if (optional) { 148 - ast.expression = $(ast.expression) 149 - .attr(identifiers.optional) 150 - .call() 151 - .$render(); 138 + ast.expression = ast.expression.attr(identifiers.optional).call(); 152 139 } 153 140 154 141 if (schema.default !== undefined) { ··· 158 145 value: schema.default, 159 146 }); 160 147 if (callParameter) { 161 - ast.expression = $(ast.expression) 148 + ast.expression = ast.expression 162 149 .attr(identifiers.default) 163 - .call(callParameter) 164 - .$render(); 150 + .call(callParameter); 165 151 } 166 152 } 167 153 }
+37 -83
packages/openapi-ts/src/plugins/zod/v3/toAst/array.ts
··· 1 - import type ts from 'typescript'; 2 - 3 1 import { deduplicateSchema } from '~/ir/schema'; 4 2 import type { SchemaWithType } from '~/plugins'; 5 3 import { toRef } from '~/plugins/shared/utils/refs'; 6 - import { tsc } from '~/tsc'; 4 + import { $ } from '~/ts-dsl'; 7 5 8 6 import { identifiers } from '../../constants'; 9 7 import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; ··· 24 22 resource: 'zod.z', 25 23 }); 26 24 27 - const functionName = tsc.propertyAccessExpression({ 28 - expression: z.placeholder, 29 - name: identifiers.array, 30 - }); 25 + const functionName = $(z.placeholder).attr(identifiers.array); 31 26 32 - let arrayExpression: ts.CallExpression | undefined; 27 + let arrayExpression: ReturnType<typeof $.call> | undefined; 33 28 let hasLazyExpression = false; 34 29 35 30 if (!schema.items) { 36 - arrayExpression = tsc.callExpression({ 37 - functionName, 38 - parameters: [ 39 - unknownToAst({ 40 - plugin, 41 - schema: { 42 - type: 'unknown', 43 - }, 44 - state, 45 - }), 46 - ], 47 - }); 31 + arrayExpression = functionName.call( 32 + unknownToAst({ 33 + plugin, 34 + schema: { 35 + type: 'unknown', 36 + }, 37 + state, 38 + }), 39 + ); 48 40 } else { 49 41 schema = deduplicateSchema({ schema }); 50 42 ··· 65 57 }); 66 58 67 59 if (itemExpressions.length === 1) { 68 - arrayExpression = tsc.callExpression({ 69 - functionName, 70 - parameters: itemExpressions, 71 - }); 60 + arrayExpression = functionName.call(...itemExpressions); 72 61 } else { 73 62 if (schema.logicalOperator === 'and') { 74 63 const firstSchema = schema.items![0]!; 75 64 // we want to add an intersection, but not every schema can use the same API. 76 65 // if the first item contains another array or not an object, we cannot use 77 66 // `.and()` as that does not exist on `.union()` and non-object schemas. 78 - let intersectionExpression: ts.Expression; 67 + let intersectionExpression: ReturnType<typeof $.call | typeof $.expr>; 79 68 if ( 80 69 firstSchema.logicalOperator === 'or' || 81 70 (firstSchema.type && firstSchema.type !== 'object') 82 71 ) { 83 - intersectionExpression = tsc.callExpression({ 84 - functionName: tsc.propertyAccessExpression({ 85 - expression: z.placeholder, 86 - name: identifiers.intersection, 87 - }), 88 - parameters: itemExpressions, 89 - }); 72 + intersectionExpression = $(z.placeholder) 73 + .attr(identifiers.intersection) 74 + .call(...itemExpressions); 90 75 } else { 91 76 intersectionExpression = itemExpressions[0]!; 92 77 for (let i = 1; i < itemExpressions.length; i++) { 93 - intersectionExpression = tsc.callExpression({ 94 - functionName: tsc.propertyAccessExpression({ 95 - expression: intersectionExpression, 96 - name: identifiers.and, 97 - }), 98 - parameters: [itemExpressions[i]!], 99 - }); 78 + intersectionExpression = intersectionExpression 79 + .attr(identifiers.and) 80 + .call(itemExpressions[i]); 100 81 } 101 82 } 102 83 103 - arrayExpression = tsc.callExpression({ 104 - functionName, 105 - parameters: [intersectionExpression], 106 - }); 84 + arrayExpression = functionName.call(intersectionExpression); 107 85 } else { 108 - arrayExpression = tsc.callExpression({ 109 - functionName: tsc.propertyAccessExpression({ 110 - expression: z.placeholder, 111 - name: identifiers.array, 112 - }), 113 - parameters: [ 114 - tsc.callExpression({ 115 - functionName: tsc.propertyAccessExpression({ 116 - expression: z.placeholder, 117 - name: identifiers.union, 118 - }), 119 - parameters: [ 120 - tsc.arrayLiteralExpression({ 121 - elements: itemExpressions, 122 - }), 123 - ], 124 - }), 125 - ], 126 - }); 86 + arrayExpression = $(z.placeholder) 87 + .attr(identifiers.array) 88 + .call( 89 + $(z.placeholder) 90 + .attr(identifiers.union) 91 + .call($.array(...itemExpressions)), 92 + ); 127 93 } 128 94 } 129 95 } 130 96 131 97 if (schema.minItems === schema.maxItems && schema.minItems !== undefined) { 132 - arrayExpression = tsc.callExpression({ 133 - functionName: tsc.propertyAccessExpression({ 134 - expression: arrayExpression, 135 - name: identifiers.length, 136 - }), 137 - parameters: [tsc.valueToExpression({ value: schema.minItems })], 138 - }); 98 + arrayExpression = arrayExpression 99 + .attr(identifiers.length) 100 + .call($.toExpr(schema.minItems)); 139 101 } else { 140 102 if (schema.minItems !== undefined) { 141 - arrayExpression = tsc.callExpression({ 142 - functionName: tsc.propertyAccessExpression({ 143 - expression: arrayExpression, 144 - name: identifiers.min, 145 - }), 146 - parameters: [tsc.valueToExpression({ value: schema.minItems })], 147 - }); 103 + arrayExpression = arrayExpression 104 + .attr(identifiers.min) 105 + .call($.toExpr(schema.minItems)); 148 106 } 149 107 150 108 if (schema.maxItems !== undefined) { 151 - arrayExpression = tsc.callExpression({ 152 - functionName: tsc.propertyAccessExpression({ 153 - expression: arrayExpression, 154 - name: identifiers.max, 155 - }), 156 - parameters: [tsc.valueToExpression({ value: schema.maxItems })], 157 - }); 109 + arrayExpression = arrayExpression 110 + .attr(identifiers.max) 111 + .call($.toExpr(schema.maxItems)); 158 112 } 159 113 } 160 114
+3 -5
packages/openapi-ts/src/plugins/zod/v3/toAst/boolean.ts
··· 1 - import type ts from 'typescript'; 2 - 3 1 import type { SchemaWithType } from '~/plugins'; 4 2 import { $ } from '~/ts-dsl'; 5 3 ··· 11 9 schema, 12 10 }: IrSchemaToAstOptions & { 13 11 schema: SchemaWithType<'boolean'>; 14 - }): ts.CallExpression => { 12 + }): ReturnType<typeof $.call> => { 15 13 let chain: ReturnType<typeof $.call>; 16 14 17 15 const z = plugin.referenceSymbol({ ··· 23 21 chain = $(z.placeholder) 24 22 .attr(identifiers.literal) 25 23 .call($.literal(schema.const)); 26 - return chain.$render(); 24 + return chain; 27 25 } 28 26 29 27 chain = $(z.placeholder).attr(identifiers.boolean).call(); 30 - return chain.$render(); 28 + return chain; 31 29 };
+19 -64
packages/openapi-ts/src/plugins/zod/v3/toAst/enum.ts
··· 1 - import type ts from 'typescript'; 2 - 3 1 import type { SchemaWithType } from '~/plugins'; 4 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 5 3 6 4 import { identifiers } from '../../constants'; 7 5 import type { IrSchemaToAstOptions } from '../../shared/types'; ··· 13 11 state, 14 12 }: IrSchemaToAstOptions & { 15 13 schema: SchemaWithType<'enum'>; 16 - }): ts.CallExpression => { 14 + }): ReturnType<typeof $.call> => { 17 15 const z = plugin.referenceSymbol({ 18 16 category: 'external', 19 17 resource: 'zod.z', 20 18 }); 21 19 22 - const enumMembers: Array<ts.LiteralExpression> = []; 23 - const literalMembers: Array<ts.CallExpression> = []; 20 + const enumMembers: Array<ReturnType<typeof $.literal>> = []; 21 + const literalMembers: Array<ReturnType<typeof $.call>> = []; 24 22 25 23 let isNullable = false; 26 24 let allStrings = true; ··· 28 26 for (const item of schema.items ?? []) { 29 27 // Zod supports string, number, and boolean enums 30 28 if (item.type === 'string' && typeof item.const === 'string') { 31 - const stringLiteral = tsc.stringLiteral({ 32 - text: item.const, 33 - }); 34 - enumMembers.push(stringLiteral); 29 + const literal = $.literal(item.const); 30 + enumMembers.push(literal); 35 31 literalMembers.push( 36 - tsc.callExpression({ 37 - functionName: tsc.propertyAccessExpression({ 38 - expression: z.placeholder, 39 - name: identifiers.literal, 40 - }), 41 - parameters: [stringLiteral], 42 - }), 32 + $(z.placeholder).attr(identifiers.literal).call(literal), 43 33 ); 44 34 } else if ( 45 35 (item.type === 'number' || item.type === 'integer') && 46 36 typeof item.const === 'number' 47 37 ) { 48 38 allStrings = false; 49 - const numberLiteral = tsc.ots.number(item.const); 39 + const literal = $.literal(item.const); 50 40 literalMembers.push( 51 - tsc.callExpression({ 52 - functionName: tsc.propertyAccessExpression({ 53 - expression: z.placeholder, 54 - name: identifiers.literal, 55 - }), 56 - parameters: [numberLiteral], 57 - }), 41 + $(z.placeholder).attr(identifiers.literal).call(literal), 58 42 ); 59 43 } else if (item.type === 'boolean' && typeof item.const === 'boolean') { 60 44 allStrings = false; 61 - const booleanLiteral = tsc.ots.boolean(item.const); 45 + const literal = $.literal(item.const); 62 46 literalMembers.push( 63 - tsc.callExpression({ 64 - functionName: tsc.propertyAccessExpression({ 65 - expression: z.placeholder, 66 - name: identifiers.literal, 67 - }), 68 - parameters: [booleanLiteral], 69 - }), 47 + $(z.placeholder).attr(identifiers.literal).call(literal), 70 48 ); 71 49 } else if (item.type === 'null' || item.const === null) { 72 50 isNullable = true; ··· 84 62 } 85 63 86 64 // Use z.enum() for pure string enums, z.union() for mixed or non-string types 87 - let enumExpression: ts.CallExpression; 65 + let enumExpression: ReturnType<typeof $.call>; 88 66 if (allStrings && enumMembers.length > 0) { 89 - enumExpression = tsc.callExpression({ 90 - functionName: tsc.propertyAccessExpression({ 91 - expression: z.placeholder, 92 - name: identifiers.enum, 93 - }), 94 - parameters: [ 95 - tsc.arrayLiteralExpression({ 96 - elements: enumMembers, 97 - multiLine: false, 98 - }), 99 - ], 100 - }); 67 + enumExpression = $(z.placeholder) 68 + .attr(identifiers.enum) 69 + .call($.array(...enumMembers)); 101 70 } else if (literalMembers.length === 1) { 102 71 // For single-member unions, use the member directly instead of wrapping in z.union() 103 72 enumExpression = literalMembers[0]!; 104 73 } else { 105 - enumExpression = tsc.callExpression({ 106 - functionName: tsc.propertyAccessExpression({ 107 - expression: z.placeholder, 108 - name: identifiers.union, 109 - }), 110 - parameters: [ 111 - tsc.arrayLiteralExpression({ 112 - elements: literalMembers, 113 - multiLine: literalMembers.length > 3, 114 - }), 115 - ], 116 - }); 74 + enumExpression = $(z.placeholder) 75 + .attr(identifiers.union) 76 + .call($.array(...literalMembers)); 117 77 } 118 78 119 79 if (isNullable) { 120 - enumExpression = tsc.callExpression({ 121 - functionName: tsc.propertyAccessExpression({ 122 - expression: enumExpression, 123 - name: identifiers.nullable, 124 - }), 125 - }); 80 + enumExpression = enumExpression.attr(identifiers.nullable).call(); 126 81 } 127 82 128 83 return enumExpression;
+2 -7
packages/openapi-ts/src/plugins/zod/v3/toAst/never.ts
··· 1 1 import type { SchemaWithType } from '~/plugins'; 2 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 3 3 4 4 import { identifiers } from '../../constants'; 5 5 import type { IrSchemaToAstOptions } from '../../shared/types'; ··· 13 13 category: 'external', 14 14 resource: 'zod.z', 15 15 }); 16 - const expression = tsc.callExpression({ 17 - functionName: tsc.propertyAccessExpression({ 18 - expression: z.placeholder, 19 - name: identifiers.never, 20 - }), 21 - }); 16 + const expression = $(z.placeholder).attr(identifiers.never).call(); 22 17 return expression; 23 18 };
+2 -7
packages/openapi-ts/src/plugins/zod/v3/toAst/null.ts
··· 1 1 import type { SchemaWithType } from '~/plugins'; 2 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 3 3 4 4 import { identifiers } from '../../constants'; 5 5 import type { IrSchemaToAstOptions } from '../../shared/types'; ··· 13 13 category: 'external', 14 14 resource: 'zod.z', 15 15 }); 16 - const expression = tsc.callExpression({ 17 - functionName: tsc.propertyAccessExpression({ 18 - expression: z.placeholder, 19 - name: identifiers.null, 20 - }), 21 - }); 16 + const expression = $(z.placeholder).attr(identifiers.null).call(); 22 17 return expression; 23 18 };
+20 -60
packages/openapi-ts/src/plugins/zod/v3/toAst/number.ts
··· 1 1 import type { SchemaWithType } from '~/plugins'; 2 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 3 3 4 4 import { identifiers } from '../../constants'; 5 5 import { numberParameter } from '../../shared/numbers'; ··· 20 20 21 21 if (typeof schema.const === 'number') { 22 22 // TODO: parser - handle bigint constants 23 - const expression = tsc.callExpression({ 24 - functionName: tsc.propertyAccessExpression({ 25 - expression: z.placeholder, 26 - name: identifiers.literal, 27 - }), 28 - parameters: [tsc.ots.number(schema.const)], 29 - }); 23 + const expression = $(z.placeholder) 24 + .attr(identifiers.literal) 25 + .call($.literal(schema.const)); 30 26 return expression; 31 27 } 32 28 33 - let numberExpression = tsc.callExpression({ 34 - functionName: isBigInt 35 - ? tsc.propertyAccessExpression({ 36 - expression: tsc.propertyAccessExpression({ 37 - expression: z.placeholder, 38 - name: identifiers.coerce, 39 - }), 40 - name: identifiers.bigint, 41 - }) 42 - : tsc.propertyAccessExpression({ 43 - expression: z.placeholder, 44 - name: identifiers.number, 45 - }), 46 - }); 29 + let numberExpression = isBigInt 30 + ? $(z.placeholder).attr(identifiers.coerce).attr(identifiers.bigint).call() 31 + : $(z.placeholder).attr(identifiers.number).call(); 47 32 48 33 if (!isBigInt && schema.type === 'integer') { 49 - numberExpression = tsc.callExpression({ 50 - functionName: tsc.propertyAccessExpression({ 51 - expression: numberExpression, 52 - name: identifiers.int, 53 - }), 54 - }); 34 + numberExpression = numberExpression.attr(identifiers.int).call(); 55 35 } 56 36 57 37 if (schema.exclusiveMinimum !== undefined) { 58 - numberExpression = tsc.callExpression({ 59 - functionName: tsc.propertyAccessExpression({ 60 - expression: numberExpression, 61 - name: identifiers.gt, 62 - }), 63 - parameters: [ 64 - numberParameter({ isBigInt, value: schema.exclusiveMinimum }), 65 - ], 66 - }); 38 + numberExpression = numberExpression 39 + .attr(identifiers.gt) 40 + .call(numberParameter({ isBigInt, value: schema.exclusiveMinimum })); 67 41 } else if (schema.minimum !== undefined) { 68 - numberExpression = tsc.callExpression({ 69 - functionName: tsc.propertyAccessExpression({ 70 - expression: numberExpression, 71 - name: identifiers.gte, 72 - }), 73 - parameters: [numberParameter({ isBigInt, value: schema.minimum })], 74 - }); 42 + numberExpression = numberExpression 43 + .attr(identifiers.gte) 44 + .call(numberParameter({ isBigInt, value: schema.minimum })); 75 45 } 76 46 77 47 if (schema.exclusiveMaximum !== undefined) { 78 - numberExpression = tsc.callExpression({ 79 - functionName: tsc.propertyAccessExpression({ 80 - expression: numberExpression, 81 - name: identifiers.lt, 82 - }), 83 - parameters: [ 84 - numberParameter({ isBigInt, value: schema.exclusiveMaximum }), 85 - ], 86 - }); 48 + numberExpression = numberExpression 49 + .attr(identifiers.lt) 50 + .call(numberParameter({ isBigInt, value: schema.exclusiveMaximum })); 87 51 } else if (schema.maximum !== undefined) { 88 - numberExpression = tsc.callExpression({ 89 - functionName: tsc.propertyAccessExpression({ 90 - expression: numberExpression, 91 - name: identifiers.lte, 92 - }), 93 - parameters: [numberParameter({ isBigInt, value: schema.maximum })], 94 - }); 52 + numberExpression = numberExpression 53 + .attr(identifiers.lte) 54 + .call(numberParameter({ isBigInt, value: schema.maximum })); 95 55 } 96 56 97 57 return numberExpression;
+2 -4
packages/openapi-ts/src/plugins/zod/v3/toAst/object.ts
··· 1 - import type ts from 'typescript'; 2 - 3 1 import type { SchemaWithType } from '~/plugins'; 4 2 import { toRef } from '~/plugins/shared/utils/refs'; 5 3 import { $ } from '~/ts-dsl'; ··· 61 59 shape.prop(name, propertyExpression.expression); 62 60 } 63 61 64 - let additional: ts.Expression | null | undefined; 62 + let additional: ReturnType<typeof $.call | typeof $.expr> | null | undefined; 65 63 const result: Partial<Omit<Ast, 'typeName'>> = {}; 66 64 if ( 67 65 schema.additionalProperties && ··· 89 87 }; 90 88 const resolver = plugin.config['~resolvers']?.object?.base; 91 89 const chain = resolver?.(args) ?? defaultObjectBaseResolver(args); 92 - result.expression = chain.$render(); 90 + result.expression = chain; 93 91 94 92 return { 95 93 anyType: 'AnyZodObject',
+3 -5
packages/openapi-ts/src/plugins/zod/v3/toAst/string.ts
··· 1 - import type ts from 'typescript'; 2 - 3 1 import type { SchemaWithType } from '~/plugins'; 4 2 import { $ } from '~/ts-dsl'; 5 3 ··· 48 46 schema, 49 47 }: IrSchemaToAstOptions & { 50 48 schema: SchemaWithType<'string'>; 51 - }): ts.CallExpression => { 49 + }): ReturnType<typeof $.call> => { 52 50 let chain: ReturnType<typeof $.call>; 53 51 54 52 const z = plugin.referenceSymbol({ ··· 60 58 chain = $(z.placeholder) 61 59 .attr(identifiers.literal) 62 60 .call($.literal(schema.const)); 63 - return chain.$render(); 61 + return chain; 64 62 } 65 63 66 64 chain = $(z.placeholder).attr(identifiers.string).call(); ··· 88 86 chain = chain.attr(identifiers.regex).call($.regexp(schema.pattern)); 89 87 } 90 88 91 - return chain.$render(); 89 + return chain; 92 90 };
+10 -33
packages/openapi-ts/src/plugins/zod/v3/toAst/tuple.ts
··· 1 - import type ts from 'typescript'; 2 - 3 1 import type { SchemaWithType } from '~/plugins'; 4 2 import { toRef } from '~/plugins/shared/utils/refs'; 5 - import { tsc } from '~/tsc'; 3 + import { $ } from '~/ts-dsl'; 6 4 7 5 import { identifiers } from '../../constants'; 8 6 import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; ··· 26 24 27 25 if (schema.const && Array.isArray(schema.const)) { 28 26 const tupleElements = schema.const.map((value) => 29 - tsc.callExpression({ 30 - functionName: tsc.propertyAccessExpression({ 31 - expression: z.placeholder, 32 - name: identifiers.literal, 33 - }), 34 - parameters: [tsc.valueToExpression({ value })], 35 - }), 27 + $(z.placeholder).attr(identifiers.literal).call($.toExpr(value)), 36 28 ); 37 - const expression = tsc.callExpression({ 38 - functionName: tsc.propertyAccessExpression({ 39 - expression: z.placeholder, 40 - name: identifiers.tuple, 41 - }), 42 - parameters: [ 43 - tsc.arrayLiteralExpression({ 44 - elements: tupleElements, 45 - }), 46 - ], 47 - }); 29 + const expression = $(z.placeholder) 30 + .attr(identifiers.tuple) 31 + .call($.array(...tupleElements)); 48 32 return { 49 33 expression, 50 34 hasLazyExpression, 51 35 }; 52 36 } 53 37 54 - const tupleElements: Array<ts.Expression> = []; 38 + const tupleElements: Array<ReturnType<typeof $.call | typeof $.expr>> = []; 55 39 56 40 if (schema.items) { 57 41 schema.items.forEach((item, index) => { ··· 70 54 }); 71 55 } 72 56 73 - const expression = tsc.callExpression({ 74 - functionName: tsc.propertyAccessExpression({ 75 - expression: z.placeholder, 76 - name: identifiers.tuple, 77 - }), 78 - parameters: [ 79 - tsc.arrayLiteralExpression({ 80 - elements: tupleElements, 81 - }), 82 - ], 83 - }); 57 + const expression = $(z.placeholder) 58 + .attr(identifiers.tuple) 59 + .call($.array(...tupleElements)); 60 + 84 61 return { 85 62 expression, 86 63 hasLazyExpression,
+2 -7
packages/openapi-ts/src/plugins/zod/v3/toAst/undefined.ts
··· 1 1 import type { SchemaWithType } from '~/plugins'; 2 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 3 3 4 4 import { identifiers } from '../../constants'; 5 5 import type { IrSchemaToAstOptions } from '../../shared/types'; ··· 13 13 category: 'external', 14 14 resource: 'zod.z', 15 15 }); 16 - const expression = tsc.callExpression({ 17 - functionName: tsc.propertyAccessExpression({ 18 - expression: z.placeholder, 19 - name: identifiers.undefined, 20 - }), 21 - }); 16 + const expression = $(z.placeholder).attr(identifiers.undefined).call(); 22 17 return expression; 23 18 };
+2 -7
packages/openapi-ts/src/plugins/zod/v3/toAst/unknown.ts
··· 1 1 import type { SchemaWithType } from '~/plugins'; 2 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 3 3 4 4 import { identifiers } from '../../constants'; 5 5 import type { IrSchemaToAstOptions } from '../../shared/types'; ··· 13 13 category: 'external', 14 14 resource: 'zod.z', 15 15 }); 16 - const expression = tsc.callExpression({ 17 - functionName: tsc.propertyAccessExpression({ 18 - expression: z.placeholder, 19 - name: identifiers.unknown, 20 - }), 21 - }); 16 + const expression = $(z.placeholder).attr(identifiers.unknown).call(); 22 17 return expression; 23 18 };
+2 -7
packages/openapi-ts/src/plugins/zod/v3/toAst/void.ts
··· 1 1 import type { SchemaWithType } from '~/plugins'; 2 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 3 3 4 4 import { identifiers } from '../../constants'; 5 5 import type { IrSchemaToAstOptions } from '../../shared/types'; ··· 13 13 category: 'external', 14 14 resource: 'zod.z', 15 15 }); 16 - const expression = tsc.callExpression({ 17 - functionName: tsc.propertyAccessExpression({ 18 - expression: z.placeholder, 19 - name: identifiers.void, 20 - }), 21 - }); 16 + const expression = $(z.placeholder).attr(identifiers.void).call(); 22 17 return expression; 23 18 };
+14 -24
packages/openapi-ts/src/plugins/zod/v4/plugin.ts
··· 48 48 }; 49 49 const refSymbol = plugin.referenceSymbol(query); 50 50 if (plugin.isSymbolRegistered(query)) { 51 - ast.expression = $(refSymbol.placeholder).$render(); 51 + ast.expression = $(refSymbol.placeholder); 52 52 } else { 53 53 ast.expression = $(z.placeholder) 54 54 .attr(identifiers.lazy) 55 - .call($.func().returns('any').do($(refSymbol.placeholder).return())) 56 - .$render(); 55 + .call($.func().returns('any').do($(refSymbol.placeholder).return())); 57 56 ast.hasLazyExpression = true; 58 57 state.hasLazyExpression.value = true; 59 58 } ··· 67 66 ast.hasLazyExpression = typeAst.hasLazyExpression; 68 67 69 68 if (plugin.config.metadata && schema.description) { 70 - ast.expression = $(ast.expression) 69 + ast.expression = ast.expression 71 70 .attr(identifiers.register) 72 71 .call( 73 72 $(z.placeholder).attr(identifiers.globalRegistry), 74 73 $.object() 75 74 .pretty() 76 75 .prop('description', $.literal(schema.description)), 77 - ) 78 - .$render(); 76 + ); 79 77 } 80 78 } else if (schema.items) { 81 79 schema = deduplicateSchema({ schema }); ··· 103 101 ) { 104 102 ast.expression = $(z.placeholder) 105 103 .attr(identifiers.intersection) 106 - .call(...itemSchemas.map((schema) => schema.expression)) 107 - .$render(); 104 + .call(...itemSchemas.map((schema) => schema.expression)); 108 105 } else { 109 106 ast.expression = itemSchemas[0]!.expression; 110 107 itemSchemas.slice(1).forEach((schema) => { 111 - ast.expression = $(ast.expression!) 112 - .attr(identifiers.and) 108 + ast.expression = ast 109 + .expression!.attr(identifiers.and) 113 110 .call( 114 111 schema.hasLazyExpression 115 112 ? $(z.placeholder) 116 113 .attr(identifiers.lazy) 117 - .call($.func().do($.return(schema.expression))) 114 + .call($.func().do(schema.expression.return())) 118 115 : schema.expression, 119 - ) 120 - .$render(); 116 + ); 121 117 }); 122 118 } 123 119 } else { ··· 127 123 $.array() 128 124 .pretty() 129 125 .elements(...itemSchemas.map((schema) => schema.expression)), 130 - ) 131 - .$render(); 126 + ); 132 127 } 133 128 } else { 134 129 ast = irSchemaToAst({ ··· 151 146 152 147 if (ast.expression) { 153 148 if (schema.accessScope === 'read') { 154 - ast.expression = $(ast.expression) 155 - .attr(identifiers.readonly) 156 - .call() 157 - .$render(); 149 + ast.expression = ast.expression.attr(identifiers.readonly).call(); 158 150 } 159 151 160 152 if (optional) { 161 153 ast.expression = $(z.placeholder) 162 154 .attr(identifiers.optional) 163 - .call(ast.expression) 164 - .$render(); 155 + .call(ast.expression); 165 156 ast.typeName = identifiers.ZodOptional; 166 157 } 167 158 ··· 172 163 value: schema.default, 173 164 }); 174 165 if (callParameter) { 175 - ast.expression = $(ast.expression) 166 + ast.expression = ast.expression 176 167 .attr(identifiers.default) 177 - .call(callParameter) 178 - .$render(); 168 + .call(callParameter); 179 169 } 180 170 } 181 171 }
+36 -82
packages/openapi-ts/src/plugins/zod/v4/toAst/array.ts
··· 1 - import type ts from 'typescript'; 2 - 3 1 import { deduplicateSchema } from '~/ir/schema'; 4 2 import type { SchemaWithType } from '~/plugins'; 5 3 import { toRef } from '~/plugins/shared/utils/refs'; 6 - import { tsc } from '~/tsc'; 4 + import { $ } from '~/ts-dsl'; 7 5 8 6 import { identifiers } from '../../constants'; 9 7 import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; ··· 24 22 resource: 'zod.z', 25 23 }); 26 24 27 - const functionName = tsc.propertyAccessExpression({ 28 - expression: z.placeholder, 29 - name: identifiers.array, 30 - }); 25 + const functionName = $(z.placeholder).attr(identifiers.array); 31 26 32 27 if (!schema.items) { 33 - result.expression = tsc.callExpression({ 34 - functionName, 35 - parameters: [ 36 - unknownToAst({ 37 - plugin, 38 - schema: { 39 - type: 'unknown', 40 - }, 41 - state, 42 - }).expression, 43 - ], 44 - }); 28 + result.expression = functionName.call( 29 + unknownToAst({ 30 + plugin, 31 + schema: { 32 + type: 'unknown', 33 + }, 34 + state, 35 + }).expression, 36 + ); 45 37 } else { 46 38 schema = deduplicateSchema({ schema }); 47 39 ··· 62 54 }); 63 55 64 56 if (itemExpressions.length === 1) { 65 - result.expression = tsc.callExpression({ 66 - functionName, 67 - parameters: itemExpressions, 68 - }); 57 + result.expression = functionName.call(...itemExpressions); 69 58 } else { 70 59 if (schema.logicalOperator === 'and') { 71 60 const firstSchema = schema.items![0]!; 72 61 // we want to add an intersection, but not every schema can use the same API. 73 62 // if the first item contains another array or not an object, we cannot use 74 63 // `.and()` as that does not exist on `.union()` and non-object schemas. 75 - let intersectionExpression: ts.Expression; 64 + let intersectionExpression: ReturnType<typeof $.call | typeof $.expr>; 76 65 if ( 77 66 firstSchema.logicalOperator === 'or' || 78 67 (firstSchema.type && firstSchema.type !== 'object') 79 68 ) { 80 - intersectionExpression = tsc.callExpression({ 81 - functionName: tsc.propertyAccessExpression({ 82 - expression: z.placeholder, 83 - name: identifiers.intersection, 84 - }), 85 - parameters: itemExpressions, 86 - }); 69 + intersectionExpression = $(z.placeholder) 70 + .attr(identifiers.intersection) 71 + .call(...itemExpressions); 87 72 } else { 88 73 intersectionExpression = itemExpressions[0]!; 89 74 for (let i = 1; i < itemExpressions.length; i++) { 90 - intersectionExpression = tsc.callExpression({ 91 - functionName: tsc.propertyAccessExpression({ 92 - expression: intersectionExpression, 93 - name: identifiers.and, 94 - }), 95 - parameters: [itemExpressions[i]!], 96 - }); 75 + intersectionExpression = intersectionExpression 76 + .attr(identifiers.and) 77 + .call(itemExpressions[i]); 97 78 } 98 79 } 99 80 100 - result.expression = tsc.callExpression({ 101 - functionName, 102 - parameters: [intersectionExpression], 103 - }); 81 + result.expression = functionName.call(intersectionExpression); 104 82 } else { 105 - result.expression = tsc.callExpression({ 106 - functionName: tsc.propertyAccessExpression({ 107 - expression: z.placeholder, 108 - name: identifiers.array, 109 - }), 110 - parameters: [ 111 - tsc.callExpression({ 112 - functionName: tsc.propertyAccessExpression({ 113 - expression: z.placeholder, 114 - name: identifiers.union, 115 - }), 116 - parameters: [ 117 - tsc.arrayLiteralExpression({ 118 - elements: itemExpressions, 119 - }), 120 - ], 121 - }), 122 - ], 123 - }); 83 + result.expression = $(z.placeholder) 84 + .attr(identifiers.array) 85 + .call( 86 + $(z.placeholder) 87 + .attr(identifiers.union) 88 + .call($.array(...itemExpressions)), 89 + ); 124 90 } 125 91 } 126 92 } 127 93 128 94 if (schema.minItems === schema.maxItems && schema.minItems !== undefined) { 129 - result.expression = tsc.callExpression({ 130 - functionName: tsc.propertyAccessExpression({ 131 - expression: result.expression, 132 - name: identifiers.length, 133 - }), 134 - parameters: [tsc.valueToExpression({ value: schema.minItems })], 135 - }); 95 + result.expression = result.expression 96 + .attr(identifiers.length) 97 + .call($.toExpr(schema.minItems)); 136 98 } else { 137 99 if (schema.minItems !== undefined) { 138 - result.expression = tsc.callExpression({ 139 - functionName: tsc.propertyAccessExpression({ 140 - expression: result.expression, 141 - name: identifiers.min, 142 - }), 143 - parameters: [tsc.valueToExpression({ value: schema.minItems })], 144 - }); 100 + result.expression = result.expression 101 + .attr(identifiers.min) 102 + .call($.toExpr(schema.minItems)); 145 103 } 146 104 147 105 if (schema.maxItems !== undefined) { 148 - result.expression = tsc.callExpression({ 149 - functionName: tsc.propertyAccessExpression({ 150 - expression: result.expression, 151 - name: identifiers.max, 152 - }), 153 - parameters: [tsc.valueToExpression({ value: schema.maxItems })], 154 - }); 106 + result.expression = result.expression 107 + .attr(identifiers.max) 108 + .call($.toExpr(schema.maxItems)); 155 109 } 156 110 } 157 111
+2 -2
packages/openapi-ts/src/plugins/zod/v4/toAst/boolean.ts
··· 22 22 chain = $(z.placeholder) 23 23 .attr(identifiers.literal) 24 24 .call($.literal(schema.const)); 25 - result.expression = chain.$render(); 25 + result.expression = chain; 26 26 return result as Omit<Ast, 'typeName'>; 27 27 } 28 28 29 29 chain = $(z.placeholder).attr(identifiers.boolean).call(); 30 - result.expression = chain.$render(); 30 + result.expression = chain; 31 31 return result as Omit<Ast, 'typeName'>; 32 32 };
+20 -64
packages/openapi-ts/src/plugins/zod/v4/toAst/enum.ts
··· 1 - import type ts from 'typescript'; 2 - 3 1 import type { SchemaWithType } from '~/plugins'; 4 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 5 3 6 4 import { identifiers } from '../../constants'; 7 5 import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; ··· 21 19 resource: 'zod.z', 22 20 }); 23 21 24 - const enumMembers: Array<ts.LiteralExpression> = []; 25 - const literalMembers: Array<ts.CallExpression> = []; 22 + const enumMembers: Array<ReturnType<typeof $.literal>> = []; 23 + const literalMembers: Array<ReturnType<typeof $.call>> = []; 26 24 27 25 let isNullable = false; 28 26 let allStrings = true; ··· 30 28 for (const item of schema.items ?? []) { 31 29 // Zod supports string, number, and boolean enums 32 30 if (item.type === 'string' && typeof item.const === 'string') { 33 - const stringLiteral = tsc.stringLiteral({ 34 - text: item.const, 35 - }); 36 - enumMembers.push(stringLiteral); 31 + const literal = $.literal(item.const); 32 + enumMembers.push(literal); 37 33 literalMembers.push( 38 - tsc.callExpression({ 39 - functionName: tsc.propertyAccessExpression({ 40 - expression: z.placeholder, 41 - name: identifiers.literal, 42 - }), 43 - parameters: [stringLiteral], 44 - }), 34 + $(z.placeholder).attr(identifiers.literal).call(literal), 45 35 ); 46 36 } else if ( 47 37 (item.type === 'number' || item.type === 'integer') && 48 38 typeof item.const === 'number' 49 39 ) { 50 40 allStrings = false; 51 - const numberLiteral = tsc.ots.number(item.const); 41 + const literal = $.literal(item.const); 52 42 literalMembers.push( 53 - tsc.callExpression({ 54 - functionName: tsc.propertyAccessExpression({ 55 - expression: z.placeholder, 56 - name: identifiers.literal, 57 - }), 58 - parameters: [numberLiteral], 59 - }), 43 + $(z.placeholder).attr(identifiers.literal).call(literal), 60 44 ); 61 45 } else if (item.type === 'boolean' && typeof item.const === 'boolean') { 62 46 allStrings = false; 63 - const booleanLiteral = tsc.ots.boolean(item.const); 47 + const literal = $.literal(item.const); 64 48 literalMembers.push( 65 - tsc.callExpression({ 66 - functionName: tsc.propertyAccessExpression({ 67 - expression: z.placeholder, 68 - name: identifiers.literal, 69 - }), 70 - parameters: [booleanLiteral], 71 - }), 49 + $(z.placeholder).attr(identifiers.literal).call(literal), 72 50 ); 73 51 } else if (item.type === 'null' || item.const === null) { 74 52 isNullable = true; ··· 87 65 88 66 // Use z.enum() for pure string enums, z.union() for mixed or non-string types 89 67 if (allStrings && enumMembers.length > 0) { 90 - result.expression = tsc.callExpression({ 91 - functionName: tsc.propertyAccessExpression({ 92 - expression: z.placeholder, 93 - name: identifiers.enum, 94 - }), 95 - parameters: [ 96 - tsc.arrayLiteralExpression({ 97 - elements: enumMembers, 98 - multiLine: false, 99 - }), 100 - ], 101 - }); 68 + result.expression = $(z.placeholder) 69 + .attr(identifiers.enum) 70 + .call($.array(...enumMembers)); 102 71 } else if (literalMembers.length === 1) { 103 72 // For single-member unions, use the member directly instead of wrapping in z.union() 104 - result.expression = literalMembers[0]; 73 + result.expression = literalMembers[0]!; 105 74 } else { 106 - result.expression = tsc.callExpression({ 107 - functionName: tsc.propertyAccessExpression({ 108 - expression: z.placeholder, 109 - name: identifiers.union, 110 - }), 111 - parameters: [ 112 - tsc.arrayLiteralExpression({ 113 - elements: literalMembers, 114 - multiLine: literalMembers.length > 3, 115 - }), 116 - ], 117 - }); 75 + result.expression = $(z.placeholder) 76 + .attr(identifiers.union) 77 + .call($.array(...literalMembers)); 118 78 } 119 79 120 80 if (isNullable) { 121 - result.expression = tsc.callExpression({ 122 - functionName: tsc.propertyAccessExpression({ 123 - expression: z.placeholder, 124 - name: identifiers.nullable, 125 - }), 126 - parameters: [result.expression], 127 - }); 81 + result.expression = $(z.placeholder) 82 + .attr(identifiers.nullable) 83 + .call(result.expression); 128 84 } 129 85 130 86 return result as Omit<Ast, 'typeName'>;
+2 -7
packages/openapi-ts/src/plugins/zod/v4/toAst/never.ts
··· 1 1 import type { SchemaWithType } from '~/plugins'; 2 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 3 3 4 4 import { identifiers } from '../../constants'; 5 5 import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; ··· 14 14 category: 'external', 15 15 resource: 'zod.z', 16 16 }); 17 - result.expression = tsc.callExpression({ 18 - functionName: tsc.propertyAccessExpression({ 19 - expression: z.placeholder, 20 - name: identifiers.never, 21 - }), 22 - }); 17 + result.expression = $(z.placeholder).attr(identifiers.never).call(); 23 18 return result as Omit<Ast, 'typeName'>; 24 19 };
+2 -7
packages/openapi-ts/src/plugins/zod/v4/toAst/null.ts
··· 1 1 import type { SchemaWithType } from '~/plugins'; 2 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 3 3 4 4 import { identifiers } from '../../constants'; 5 5 import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; ··· 14 14 category: 'external', 15 15 resource: 'zod.z', 16 16 }); 17 - result.expression = tsc.callExpression({ 18 - functionName: tsc.propertyAccessExpression({ 19 - expression: z.placeholder, 20 - name: identifiers.null, 21 - }), 22 - }); 17 + result.expression = $(z.placeholder).attr(identifiers.null).call(); 23 18 return result as Omit<Ast, 'typeName'>; 24 19 };
+20 -60
packages/openapi-ts/src/plugins/zod/v4/toAst/number.ts
··· 1 1 import type { SchemaWithType } from '~/plugins'; 2 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 3 3 4 4 import { identifiers } from '../../constants'; 5 5 import { numberParameter } from '../../shared/numbers'; ··· 22 22 23 23 if (typeof schema.const === 'number') { 24 24 // TODO: parser - handle bigint constants 25 - result.expression = tsc.callExpression({ 26 - functionName: tsc.propertyAccessExpression({ 27 - expression: z.placeholder, 28 - name: identifiers.literal, 29 - }), 30 - parameters: [tsc.ots.number(schema.const)], 31 - }); 25 + result.expression = $(z.placeholder) 26 + .attr(identifiers.literal) 27 + .call($.literal(schema.const)); 32 28 return result as Omit<Ast, 'typeName'>; 33 29 } 34 30 35 - result.expression = tsc.callExpression({ 36 - functionName: isBigInt 37 - ? tsc.propertyAccessExpression({ 38 - expression: tsc.propertyAccessExpression({ 39 - expression: z.placeholder, 40 - name: identifiers.coerce, 41 - }), 42 - name: identifiers.bigint, 43 - }) 44 - : tsc.propertyAccessExpression({ 45 - expression: z.placeholder, 46 - name: identifiers.number, 47 - }), 48 - }); 31 + result.expression = isBigInt 32 + ? $(z.placeholder).attr(identifiers.coerce).attr(identifiers.bigint).call() 33 + : $(z.placeholder).attr(identifiers.number).call(); 49 34 50 35 if (!isBigInt && schema.type === 'integer') { 51 - result.expression = tsc.callExpression({ 52 - functionName: tsc.propertyAccessExpression({ 53 - expression: z.placeholder, 54 - name: identifiers.int, 55 - }), 56 - }); 36 + result.expression = $(z.placeholder).attr(identifiers.int).call(); 57 37 } 58 38 59 39 if (schema.exclusiveMinimum !== undefined) { 60 - result.expression = tsc.callExpression({ 61 - functionName: tsc.propertyAccessExpression({ 62 - expression: result.expression, 63 - name: identifiers.gt, 64 - }), 65 - parameters: [ 66 - numberParameter({ isBigInt, value: schema.exclusiveMinimum }), 67 - ], 68 - }); 40 + result.expression = result.expression 41 + .attr(identifiers.gt) 42 + .call(numberParameter({ isBigInt, value: schema.exclusiveMinimum })); 69 43 } else if (schema.minimum !== undefined) { 70 - result.expression = tsc.callExpression({ 71 - functionName: tsc.propertyAccessExpression({ 72 - expression: result.expression, 73 - name: identifiers.gte, 74 - }), 75 - parameters: [numberParameter({ isBigInt, value: schema.minimum })], 76 - }); 44 + result.expression = result.expression 45 + .attr(identifiers.gte) 46 + .call(numberParameter({ isBigInt, value: schema.minimum })); 77 47 } 78 48 79 49 if (schema.exclusiveMaximum !== undefined) { 80 - result.expression = tsc.callExpression({ 81 - functionName: tsc.propertyAccessExpression({ 82 - expression: result.expression, 83 - name: identifiers.lt, 84 - }), 85 - parameters: [ 86 - numberParameter({ isBigInt, value: schema.exclusiveMaximum }), 87 - ], 88 - }); 50 + result.expression = result.expression 51 + .attr(identifiers.lt) 52 + .call(numberParameter({ isBigInt, value: schema.exclusiveMaximum })); 89 53 } else if (schema.maximum !== undefined) { 90 - result.expression = tsc.callExpression({ 91 - functionName: tsc.propertyAccessExpression({ 92 - expression: result.expression, 93 - name: identifiers.lte, 94 - }), 95 - parameters: [numberParameter({ isBigInt, value: schema.maximum })], 96 - }); 54 + result.expression = result.expression 55 + .attr(identifiers.lte) 56 + .call(numberParameter({ isBigInt, value: schema.maximum })); 97 57 } 98 58 99 59 return result as Omit<Ast, 'typeName'>;
+3 -5
packages/openapi-ts/src/plugins/zod/v4/toAst/object.ts
··· 1 - import type ts from 'typescript'; 2 - 3 1 import type { SchemaWithType } from '~/plugins'; 4 2 import { toRef } from '~/plugins/shared/utils/refs'; 5 3 import { $ } from '~/ts-dsl'; ··· 60 58 } 61 59 62 60 if (propertyAst.hasLazyExpression) { 63 - shape.getter(name, $(propertyAst.expression).return()); 61 + shape.getter(name, propertyAst.expression.return()); 64 62 } else { 65 63 shape.prop(name, propertyAst.expression); 66 64 } 67 65 } 68 66 69 - let additional: ts.Expression | null | undefined; 67 + let additional: ReturnType<typeof $.call | typeof $.expr> | null | undefined; 70 68 if ( 71 69 schema.additionalProperties && 72 70 (!schema.properties || !Object.keys(schema.properties).length) ··· 93 91 }; 94 92 const resolver = plugin.config['~resolvers']?.object?.base; 95 93 const chain = resolver?.(args) ?? defaultObjectBaseResolver(args); 96 - result.expression = chain.$render(); 94 + result.expression = chain; 97 95 98 96 // Return with typeName for circular references 99 97 if (result.hasLazyExpression) {
+2 -2
packages/openapi-ts/src/plugins/zod/v4/toAst/string.ts
··· 72 72 chain = $(z.placeholder) 73 73 .attr(identifiers.literal) 74 74 .call($.literal(schema.const)); 75 - result.expression = chain.$render(); 75 + result.expression = chain; 76 76 return result as Omit<Ast, 'typeName'>; 77 77 } 78 78 ··· 101 101 chain = chain.attr(identifiers.regex).call($.regexp(schema.pattern)); 102 102 } 103 103 104 - result.expression = chain.$render(); 104 + result.expression = chain; 105 105 return result as Omit<Ast, 'typeName'>; 106 106 };
+9 -33
packages/openapi-ts/src/plugins/zod/v4/toAst/tuple.ts
··· 1 - import type ts from 'typescript'; 2 - 3 1 import type { SchemaWithType } from '~/plugins'; 4 2 import { toRef } from '~/plugins/shared/utils/refs'; 5 - import { tsc } from '~/tsc'; 3 + import { $ } from '~/ts-dsl'; 6 4 7 5 import { identifiers } from '../../constants'; 8 6 import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; ··· 24 22 25 23 if (schema.const && Array.isArray(schema.const)) { 26 24 const tupleElements = schema.const.map((value) => 27 - tsc.callExpression({ 28 - functionName: tsc.propertyAccessExpression({ 29 - expression: z.placeholder, 30 - name: identifiers.literal, 31 - }), 32 - parameters: [tsc.valueToExpression({ value })], 33 - }), 25 + $(z.placeholder).attr(identifiers.literal).call($.toExpr(value)), 34 26 ); 35 - result.expression = tsc.callExpression({ 36 - functionName: tsc.propertyAccessExpression({ 37 - expression: z.placeholder, 38 - name: identifiers.tuple, 39 - }), 40 - parameters: [ 41 - tsc.arrayLiteralExpression({ 42 - elements: tupleElements, 43 - }), 44 - ], 45 - }); 27 + result.expression = $(z.placeholder) 28 + .attr(identifiers.tuple) 29 + .call($.array(...tupleElements)); 46 30 return result as Omit<Ast, 'typeName'>; 47 31 } 48 32 49 - const tupleElements: Array<ts.Expression> = []; 33 + const tupleElements: Array<ReturnType<typeof $.call | typeof $.expr>> = []; 50 34 51 35 if (schema.items) { 52 36 schema.items.forEach((item, index) => { ··· 65 49 }); 66 50 } 67 51 68 - result.expression = tsc.callExpression({ 69 - functionName: tsc.propertyAccessExpression({ 70 - expression: z.placeholder, 71 - name: identifiers.tuple, 72 - }), 73 - parameters: [ 74 - tsc.arrayLiteralExpression({ 75 - elements: tupleElements, 76 - }), 77 - ], 78 - }); 52 + result.expression = $(z.placeholder) 53 + .attr(identifiers.tuple) 54 + .call($.array(...tupleElements)); 79 55 80 56 return result as Omit<Ast, 'typeName'>; 81 57 };
+2 -7
packages/openapi-ts/src/plugins/zod/v4/toAst/undefined.ts
··· 1 1 import type { SchemaWithType } from '~/plugins'; 2 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 3 3 4 4 import { identifiers } from '../../constants'; 5 5 import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; ··· 14 14 category: 'external', 15 15 resource: 'zod.z', 16 16 }); 17 - result.expression = tsc.callExpression({ 18 - functionName: tsc.propertyAccessExpression({ 19 - expression: z.placeholder, 20 - name: identifiers.undefined, 21 - }), 22 - }); 17 + result.expression = $(z.placeholder).attr(identifiers.undefined).call(); 23 18 return result as Omit<Ast, 'typeName'>; 24 19 };
+2 -7
packages/openapi-ts/src/plugins/zod/v4/toAst/unknown.ts
··· 1 1 import type { SchemaWithType } from '~/plugins'; 2 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 3 3 4 4 import { identifiers } from '../../constants'; 5 5 import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; ··· 14 14 category: 'external', 15 15 resource: 'zod.z', 16 16 }); 17 - result.expression = tsc.callExpression({ 18 - functionName: tsc.propertyAccessExpression({ 19 - expression: z.placeholder, 20 - name: identifiers.unknown, 21 - }), 22 - }); 17 + result.expression = $(z.placeholder).attr(identifiers.unknown).call(); 23 18 return result as Omit<Ast, 'typeName'>; 24 19 };
+2 -7
packages/openapi-ts/src/plugins/zod/v4/toAst/void.ts
··· 1 1 import type { SchemaWithType } from '~/plugins'; 2 - import { tsc } from '~/tsc'; 2 + import { $ } from '~/ts-dsl'; 3 3 4 4 import { identifiers } from '../../constants'; 5 5 import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; ··· 14 14 category: 'external', 15 15 resource: 'zod.z', 16 16 }); 17 - result.expression = tsc.callExpression({ 18 - functionName: tsc.propertyAccessExpression({ 19 - expression: z.placeholder, 20 - name: identifiers.void, 21 - }), 22 - }); 17 + result.expression = $(z.placeholder).attr(identifiers.void).call(); 23 18 return result as Omit<Ast, 'typeName'>; 24 19 };
+7 -3
packages/openapi-ts/src/ts-dsl/array.ts
··· 13 13 | { expr: MaybeTsDsl<ts.Expression>; kind: 'spread' } 14 14 > = []; 15 15 16 + constructor( 17 + ...exprs: Array<string | number | boolean | MaybeTsDsl<ts.Expression>> 18 + ) { 19 + super(); 20 + this.elements(...exprs); 21 + } 22 + 16 23 /** Adds a single array element. */ 17 24 element(expr: string | number | boolean | MaybeTsDsl<ts.Expression>): this { 18 25 const node = ··· 44 51 $render(): ts.ArrayLiteralExpression { 45 52 const elements = this._elements.map((item) => { 46 53 const node = this.$node(item.expr); 47 - if (!ts.isExpression(node)) { 48 - throw new Error('Invalid array element: must be an expression.'); 49 - } 50 54 return item.kind === 'spread' 51 55 ? ts.factory.createSpreadElement(node) 52 56 : node;
+7 -4
packages/openapi-ts/src/ts-dsl/as.ts
··· 1 1 /* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */ 2 2 import ts from 'typescript'; 3 3 4 - import type { MaybeTsDsl, TypeTsDsl, WithString } from './base'; 4 + import type { MaybeTsDsl, TypeTsDsl } from './base'; 5 5 import { TsDsl } from './base'; 6 6 import { mixin } from './mixins/apply'; 7 7 import { ExprMixin, registerLazyAccessAsFactory } from './mixins/expr'; 8 8 9 9 export class AsTsDsl extends TsDsl<ts.AsExpression> { 10 - private expr: MaybeTsDsl<WithString>; 11 - private type: WithString<TypeTsDsl>; 10 + private expr: string | MaybeTsDsl<ts.Expression>; 11 + private type: string | TypeTsDsl; 12 12 13 - constructor(expr: MaybeTsDsl<WithString>, type: WithString<TypeTsDsl>) { 13 + constructor( 14 + expr: string | MaybeTsDsl<ts.Expression>, 15 + type: string | TypeTsDsl, 16 + ) { 14 17 super(); 15 18 this.expr = expr; 16 19 this.type = type;
+7 -7
packages/openapi-ts/src/ts-dsl/attr.ts
··· 1 1 /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ 2 2 import ts from 'typescript'; 3 3 4 - import type { MaybeTsDsl, WithString } from './base'; 4 + import type { MaybeTsDsl } from './base'; 5 5 import { TsDsl } from './base'; 6 6 import { mixin } from './mixins/apply'; 7 7 import { AssignmentMixin } from './mixins/assignment'; ··· 12 12 export class AttrTsDsl extends TsDsl< 13 13 ts.PropertyAccessExpression | ts.ElementAccessExpression 14 14 > { 15 - private left: MaybeTsDsl<WithString>; 16 - private right: WithString<ts.MemberName> | number; 15 + private left: string | MaybeTsDsl<ts.Expression>; 16 + private right: string | ts.MemberName | number; 17 17 18 18 constructor( 19 - left: MaybeTsDsl<WithString>, 20 - right: WithString<ts.MemberName> | number, 19 + left: string | MaybeTsDsl<ts.Expression>, 20 + right: string | ts.MemberName | number, 21 21 ) { 22 22 super(); 23 23 this.left = left; ··· 43 43 return ts.factory.createPropertyAccessChain( 44 44 leftNode, 45 45 ts.factory.createToken(ts.SyntaxKind.QuestionDotToken), 46 - this.$expr(this.right), 46 + this.$maybeId(this.right), 47 47 ); 48 48 } 49 49 return ts.factory.createPropertyAccessExpression( 50 50 leftNode, 51 - this.$expr(this.right), 51 + this.$maybeId(this.right), 52 52 ); 53 53 } 54 54 }
+3 -3
packages/openapi-ts/src/ts-dsl/await.ts
··· 1 1 /* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */ 2 2 import ts from 'typescript'; 3 3 4 - import type { MaybeTsDsl, WithString } from './base'; 4 + import type { MaybeTsDsl } from './base'; 5 5 import { TsDsl } from './base'; 6 6 import { mixin } from './mixins/apply'; 7 7 import { ExprMixin, registerLazyAccessAwaitFactory } from './mixins/expr'; 8 8 9 9 export class AwaitTsDsl extends TsDsl<ts.AwaitExpression> { 10 - private _awaitExpr: MaybeTsDsl<WithString>; 10 + private _awaitExpr: string | MaybeTsDsl<ts.Expression>; 11 11 12 - constructor(expr: MaybeTsDsl<WithString>) { 12 + constructor(expr: string | MaybeTsDsl<ts.Expression>) { 13 13 super(); 14 14 this._awaitExpr = expr; 15 15 }
+41 -44
packages/openapi-ts/src/ts-dsl/base.ts
··· 2 2 3 3 export type MaybeArray<T> = T | ReadonlyArray<T>; 4 4 5 - export type WithStatement<T = ts.Expression> = T | ts.Statement; 6 - 7 - export type WithString<T = ts.Expression> = T | string; 8 - 9 5 export interface ITsDsl<T extends ts.Node = ts.Node> { 10 6 $render(): T; 11 7 } ··· 13 9 export abstract class TsDsl<T extends ts.Node = ts.Node> implements ITsDsl<T> { 14 10 abstract $render(): T; 15 11 16 - protected $expr<T>(expr: WithString<T>): T { 17 - return typeof expr === 'string' 18 - ? (ts.factory.createIdentifier(expr) as T) 19 - : expr; 12 + protected $id(text: string): ts.Identifier { 13 + return ts.factory.createIdentifier(text); 20 14 } 21 15 22 16 /** Conditionally applies a callback to this builder. */ ··· 94 88 return this; 95 89 } 96 90 97 - protected $node<I>(input: I): NodeOfMaybe<I> { 98 - if (input === undefined) { 91 + protected $maybeId<T extends string | ts.Expression>( 92 + expr: T, 93 + ): T extends string ? ts.Identifier : T { 94 + return ( 95 + typeof expr === 'string' ? this.$id(expr) : expr 96 + ) as T extends string ? ts.Identifier : T; 97 + } 98 + 99 + protected $node<I>(value: I): NodeOfMaybe<I> { 100 + if (value === undefined) { 99 101 return undefined as NodeOfMaybe<I>; 100 102 } 101 - if (typeof input === 'string') { 102 - return this.$expr(input) as NodeOfMaybe<I>; 103 + if (typeof value === 'string') { 104 + return this.$id(value) as NodeOfMaybe<I>; 103 105 } 104 - if (typeof input === 'boolean') { 105 - return ( 106 - input ? ts.factory.createTrue() : ts.factory.createFalse() 107 - ) as NodeOfMaybe<I>; 108 - } 109 - if (input instanceof Array) { 110 - return input.map((item) => this._render(item)) as NodeOfMaybe<I>; 106 + if (value instanceof Array) { 107 + return value.map((item) => this._render(item)) as NodeOfMaybe<I>; 111 108 } 112 - return this._render(input as any) as NodeOfMaybe<I>; 109 + return this._render(value as any) as NodeOfMaybe<I>; 113 110 } 114 111 115 112 protected $stmt( 116 - input: MaybeArray<MaybeTsDsl<WithString<WithStatement>>>, 113 + value: MaybeArray<string | MaybeTsDsl<ts.Expression | ts.Statement>>, 117 114 ): ReadonlyArray<ts.Statement> { 118 - const arr = input instanceof Array ? input : [input]; 115 + const arr = value instanceof Array ? value : [value]; 119 116 return arr.map((item) => { 120 117 const node = 121 - typeof item === 'string' ? this.$expr(item) : this._render(item as any); 118 + typeof item === 'string' ? this.$id(item) : this._render(item); 122 119 return ts.isExpression(node) 123 120 ? ts.factory.createExpressionStatement(node) 124 - : (node as ts.Statement); 121 + : node; 125 122 }); 126 123 } 127 124 128 125 protected $type<I>( 129 - input: I, 126 + value: I, 130 127 args?: ReadonlyArray<ts.TypeNode>, 131 128 ): TypeOfMaybe<I> { 132 - if (input === undefined) { 129 + if (value === undefined) { 133 130 return undefined as TypeOfMaybe<I>; 134 131 } 135 - if (typeof input === 'string') { 136 - return ts.factory.createTypeReferenceNode(input, args) as TypeOfMaybe<I>; 132 + if (typeof value === 'string') { 133 + return ts.factory.createTypeReferenceNode(value, args) as TypeOfMaybe<I>; 137 134 } 138 - if (typeof input === 'boolean') { 139 - const literal = input 135 + if (typeof value === 'boolean') { 136 + const literal = value 140 137 ? ts.factory.createTrue() 141 138 : ts.factory.createFalse(); 142 139 return ts.factory.createLiteralTypeNode(literal) as TypeOfMaybe<I>; 143 140 } 144 - if (typeof input === 'number') { 141 + if (typeof value === 'number') { 145 142 return ts.factory.createLiteralTypeNode( 146 - ts.factory.createNumericLiteral(input), 143 + ts.factory.createNumericLiteral(value), 147 144 ) as TypeOfMaybe<I>; 148 145 } 149 - if (input instanceof Array) { 150 - return input.map((item) => this.$type(item, args)) as TypeOfMaybe<I>; 146 + if (value instanceof Array) { 147 + return value.map((item) => this.$type(item, args)) as TypeOfMaybe<I>; 151 148 } 152 - return this._render(input as any) as TypeOfMaybe<I>; 149 + return this._render(value as any) as TypeOfMaybe<I>; 153 150 } 154 151 155 - private _render<T extends ts.Node>(value: MaybeTsDsl<T>): T { 156 - return (value instanceof TsDsl ? value.$render() : value) as T; 152 + private _render<I>(value: I): I extends TsDsl<infer N> ? N : I { 153 + return ( 154 + value instanceof TsDsl ? value.$render() : value 155 + ) as I extends TsDsl<infer N> ? N : I; 157 156 } 158 157 } 159 158 ··· 166 165 ? ReadonlyArray<U extends TsDsl<infer N> ? N : U> 167 166 : I extends string 168 167 ? ts.Expression 169 - : I extends boolean 170 - ? ts.Expression 171 - : I extends TsDsl<infer N> 172 - ? N 173 - : I extends ts.Node 174 - ? I 175 - : never; 168 + : I extends TsDsl<infer N> 169 + ? N 170 + : I extends ts.Node 171 + ? I 172 + : never; 176 173 177 174 export type MaybeTsDsl<T> = 178 175 // if T includes string
+5 -5
packages/openapi-ts/src/ts-dsl/binary.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import type { MaybeTsDsl, WithString } from './base'; 3 + import type { MaybeTsDsl } from './base'; 4 4 import { TsDsl } from './base'; 5 5 6 6 type Operator = ··· 22 22 | '||'; 23 23 24 24 export class BinaryTsDsl extends TsDsl<ts.BinaryExpression> { 25 - private left: MaybeTsDsl<WithString>; 25 + private left: string | MaybeTsDsl<ts.Expression>; 26 26 private operator: Operator | ts.BinaryOperator; 27 - private right: MaybeTsDsl<WithString>; 27 + private right: string | MaybeTsDsl<ts.Expression>; 28 28 29 29 constructor( 30 - left: MaybeTsDsl<WithString>, 30 + left: string | MaybeTsDsl<ts.Expression>, 31 31 operator: Operator | ts.BinaryOperator, 32 - right: MaybeTsDsl<WithString>, 32 + right: string | MaybeTsDsl<ts.Expression>, 33 33 ) { 34 34 super(); 35 35 this.left = left;
+4 -4
packages/openapi-ts/src/ts-dsl/call.ts
··· 1 1 /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ 2 2 import ts from 'typescript'; 3 3 4 - import type { MaybeTsDsl, WithString } from './base'; 4 + import type { MaybeTsDsl } from './base'; 5 5 import { TsDsl } from './base'; 6 6 import { mixin } from './mixins/apply'; 7 7 import { ArgsMixin } from './mixins/args'; ··· 9 9 import { TypeArgsMixin } from './mixins/type-args'; 10 10 11 11 export class CallTsDsl extends TsDsl<ts.CallExpression> { 12 - private _callee: MaybeTsDsl<WithString>; 12 + private _callee: string | MaybeTsDsl<ts.Expression>; 13 13 14 14 constructor( 15 - callee: MaybeTsDsl<WithString>, 16 - ...args: ReadonlyArray<MaybeTsDsl<WithString> | undefined> 15 + callee: string | MaybeTsDsl<ts.Expression>, 16 + ...args: ReadonlyArray<string | MaybeTsDsl<ts.Expression> | undefined> 17 17 ) { 18 18 super(); 19 19 this._callee = callee;
+4 -4
packages/openapi-ts/src/ts-dsl/class.ts
··· 1 1 /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ 2 2 import ts from 'typescript'; 3 3 4 - import type { MaybeTsDsl, WithString } from './base'; 4 + import type { MaybeTsDsl } from './base'; 5 5 import { TsDsl } from './base'; 6 6 import { FieldTsDsl } from './field'; 7 7 import { InitTsDsl } from './init'; ··· 37 37 } 38 38 39 39 /** Adds a base class to extend from. */ 40 - extends(base?: WithString | false | null): this { 40 + extends(base?: string | ts.Expression | false | null): this { 41 41 if (!base) return this; 42 42 this.heritageClauses.push( 43 43 ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [ 44 44 ts.factory.createExpressionWithTypeArguments( 45 - this.$expr(base), 45 + this.$maybeId(base), 46 46 undefined, 47 47 ), 48 48 ]), ··· 82 82 const body = this.$node(this.body) as ReadonlyArray<ts.ClassElement>; 83 83 return ts.factory.createClassDeclaration( 84 84 [...this.$decorators(), ...this.modifiers.list()], 85 - this.$expr(this.name), 85 + this.name, 86 86 this.$generics(), 87 87 this.heritageClauses, 88 88 body,
+6 -6
packages/openapi-ts/src/ts-dsl/decorator.ts
··· 1 1 /* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */ 2 2 import ts from 'typescript'; 3 3 4 - import type { MaybeTsDsl, WithString } from './base'; 4 + import type { MaybeTsDsl } from './base'; 5 5 import { TsDsl } from './base'; 6 6 import { mixin } from './mixins/apply'; 7 7 import { ArgsMixin } from './mixins/args'; 8 8 9 9 export class DecoratorTsDsl extends TsDsl<ts.Decorator> { 10 - private name: WithString; 10 + private name: string | ts.Expression; 11 11 12 12 constructor( 13 - name: WithString, 14 - ...args: ReadonlyArray<MaybeTsDsl<WithString>> 13 + name: string | ts.Expression, 14 + ...args: ReadonlyArray<string | MaybeTsDsl<ts.Expression>> 15 15 ) { 16 16 super(); 17 17 this.name = name; ··· 23 23 return ts.factory.createDecorator( 24 24 args.length 25 25 ? ts.factory.createCallExpression( 26 - this.$expr(this.name), 26 + this.$maybeId(this.name), 27 27 undefined, 28 28 args, 29 29 ) 30 - : this.$expr(this.name), 30 + : this.$maybeId(this.name), 31 31 ); 32 32 } 33 33 }
+3 -3
packages/openapi-ts/src/ts-dsl/expr.ts
··· 1 1 /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ 2 2 import type ts from 'typescript'; 3 3 4 - import type { MaybeTsDsl, WithString } from './base'; 4 + import type { MaybeTsDsl } from './base'; 5 5 import { TsDsl } from './base'; 6 6 import { mixin } from './mixins/apply'; 7 7 import { ExprMixin } from './mixins/expr'; ··· 11 11 import { TypeOfExprTsDsl } from './typeof'; 12 12 13 13 export class ExprTsDsl extends TsDsl<ts.Expression> { 14 - private _exprInput: MaybeTsDsl<WithString>; 14 + private _exprInput: string | MaybeTsDsl<ts.Expression>; 15 15 16 - constructor(id: MaybeTsDsl<WithString>) { 16 + constructor(id: string | MaybeTsDsl<ts.Expression>) { 17 17 super(); 18 18 this._exprInput = id; 19 19 }
+1 -1
packages/openapi-ts/src/ts-dsl/field.ts
··· 37 37 $render(): ts.PropertyDeclaration { 38 38 return ts.factory.createPropertyDeclaration( 39 39 [...this.$decorators(), ...this.modifiers.list()], 40 - this.$expr(this.name), 40 + this.name, 41 41 undefined, 42 42 this.$type(this._type), 43 43 this.$value(),
+1 -1
packages/openapi-ts/src/ts-dsl/func.ts
··· 96 96 return ts.factory.createFunctionExpression( 97 97 [...this.modifiers.list()], 98 98 undefined, 99 - this.$expr(this.name), 99 + this.name, 100 100 this.$generics(), 101 101 this.$params(), 102 102 this.$type(this._returns),
+4 -4
packages/openapi-ts/src/ts-dsl/if.ts
··· 1 1 /* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */ 2 2 import ts from 'typescript'; 3 3 4 - import type { MaybeTsDsl, WithString } from './base'; 4 + import type { MaybeTsDsl } from './base'; 5 5 import { TsDsl } from './base'; 6 6 import { mixin } from './mixins/apply'; 7 7 import { DoMixin } from './mixins/do'; 8 8 9 9 export class IfTsDsl extends TsDsl<ts.IfStatement> { 10 - private _condition?: MaybeTsDsl<WithString>; 10 + private _condition?: string | MaybeTsDsl<ts.Expression>; 11 11 private _else?: ReadonlyArray<MaybeTsDsl<ts.Statement>>; 12 12 13 - constructor(condition?: MaybeTsDsl<WithString>) { 13 + constructor(condition?: string | MaybeTsDsl<ts.Expression>) { 14 14 super(); 15 15 if (condition) this.condition(condition); 16 16 } 17 17 18 - condition(condition: MaybeTsDsl<WithString>): this { 18 + condition(condition: string | MaybeTsDsl<ts.Expression>): this { 19 19 this._condition = condition; 20 20 return this; 21 21 }
+16 -4
packages/openapi-ts/src/ts-dsl/index.ts
··· 18 18 import { MethodTsDsl } from './method'; 19 19 import { NewTsDsl } from './new'; 20 20 import { NewlineTsDsl } from './newline'; 21 - import { NotTsDsl } from './not'; 22 21 import { NoteTsDsl } from './note'; 23 22 import { ObjectTsDsl } from './object'; 24 23 import { ParamTsDsl } from './param'; 25 24 import { PatternTsDsl } from './pattern'; 25 + import { PrefixTsDsl } from './prefix'; 26 26 import { RegExpTsDsl } from './regexp'; 27 27 import { ReturnTsDsl } from './return'; 28 28 import { SetterTsDsl } from './setter'; ··· 41 41 import { TypeQueryTsDsl } from './type/query'; 42 42 import { TypeTupleTsDsl } from './type/tuple'; 43 43 import { TypeOfExprTsDsl } from './typeof'; 44 + import { toExpr } from './utils'; 44 45 import { VarTsDsl } from './var'; 45 46 46 47 const base = { ··· 131 132 method: (...args: ConstructorParameters<typeof MethodTsDsl>) => 132 133 new MethodTsDsl(...args), 133 134 135 + /** Creates a negation expression (`-x`). */ 136 + neg: (...args: ConstructorParameters<typeof PrefixTsDsl>) => 137 + new PrefixTsDsl(...args).neg(), 138 + 134 139 /** Creates a new expression (e.g. `new ClassName()`). */ 135 140 new: (...args: ConstructorParameters<typeof NewTsDsl>) => 136 141 new NewTsDsl(...args), ··· 139 144 newline: (...args: ConstructorParameters<typeof NewlineTsDsl>) => 140 145 new NewlineTsDsl(...args), 141 146 142 - /** Creates a logical NOT expression (e.g. `!expr`). */ 143 - not: (...args: ConstructorParameters<typeof NotTsDsl>) => 144 - new NotTsDsl(...args), 147 + /** Creates a logical NOT expression (`!x`). */ 148 + not: (...args: ConstructorParameters<typeof PrefixTsDsl>) => 149 + new PrefixTsDsl(...args).not(), 145 150 146 151 /** Creates a block comment (/* ... *\/). */ 147 152 note: (...args: ConstructorParameters<typeof NoteTsDsl>) => ··· 158 163 /** Creates a pattern for destructuring or matching. */ 159 164 pattern: (...args: ConstructorParameters<typeof PatternTsDsl>) => 160 165 new PatternTsDsl(...args), 166 + 167 + /** Creates a prefix unary expression (e.g. `-x`, `!x`, `~x`). */ 168 + prefix: (...args: ConstructorParameters<typeof PrefixTsDsl>) => 169 + new PrefixTsDsl(...args), 161 170 162 171 /** Creates a regular expression literal (e.g. `/foo/gi`). */ 163 172 regexp: (...args: ConstructorParameters<typeof RegExpTsDsl>) => ··· 182 191 /** Creates a throw statement. */ 183 192 throw: (...args: ConstructorParameters<typeof ThrowTsDsl>) => 184 193 new ThrowTsDsl(...args), 194 + 195 + /** Converts a runtime value into a corresponding expression node. */ 196 + toExpr: (...args: Parameters<typeof toExpr>) => toExpr(...args), 185 197 186 198 /** Creates a basic type reference or type expression (e.g. Foo or Foo<T>). */ 187 199 type: Object.assign(
+16 -11
packages/openapi-ts/src/ts-dsl/literal.ts
··· 1 1 import ts from 'typescript'; 2 2 3 3 import { TsDsl } from './base'; 4 + import { PrefixTsDsl } from './prefix'; 4 5 5 6 export class LiteralTsDsl extends TsDsl<ts.LiteralTypeNode['literal']> { 6 - private value: string | number | boolean; 7 + private value: string | number | boolean | null; 7 8 8 - constructor(value: string | number | boolean) { 9 + constructor(value: string | number | boolean | null) { 9 10 super(); 10 11 this.value = value; 11 12 } 12 13 13 14 $render(): ts.LiteralTypeNode['literal'] { 14 - switch (typeof this.value) { 15 - case 'boolean': 16 - return this.value ? ts.factory.createTrue() : ts.factory.createFalse(); 17 - case 'number': 18 - return ts.factory.createNumericLiteral(this.value); 19 - case 'string': 20 - return ts.factory.createStringLiteral(this.value); 21 - default: 22 - throw new Error(`Unsupported literal: ${String(this.value)}`); 15 + if (typeof this.value === 'boolean') { 16 + return this.value ? ts.factory.createTrue() : ts.factory.createFalse(); 17 + } 18 + if (typeof this.value === 'number') { 19 + const expr = ts.factory.createNumericLiteral(Math.abs(this.value)); 20 + return this.value < 0 ? this.$node(new PrefixTsDsl(expr).neg()) : expr; 21 + } 22 + if (typeof this.value === 'string') { 23 + return ts.factory.createStringLiteral(this.value); 24 + } 25 + if (this.value === null) { 26 + return ts.factory.createNull(); 23 27 } 28 + throw new Error(`Unsupported literal: ${String(this.value)}`); 24 29 } 25 30 }
+1 -1
packages/openapi-ts/src/ts-dsl/method.ts
··· 42 42 return ts.factory.createMethodDeclaration( 43 43 [...this.$decorators(), ...this.modifiers.list()], 44 44 undefined, 45 - this.$expr(this.name), 45 + this.name, 46 46 this.questionToken, 47 47 this.$generics(), 48 48 this.$params(),
+5 -5
packages/openapi-ts/src/ts-dsl/mixins/args.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 - import type { MaybeTsDsl, WithString } from '../base'; 3 + import type { MaybeTsDsl } from '../base'; 4 4 import { TsDsl } from '../base'; 5 5 6 6 /** 7 7 * Adds `.arg()` and `.args()` for managing expression arguments in call-like nodes. 8 8 */ 9 9 export class ArgsMixin extends TsDsl { 10 - private _args?: Array<MaybeTsDsl<WithString>>; 10 + private _args?: Array<string | MaybeTsDsl<ts.Expression>>; 11 11 12 12 /** Adds a single expression argument. */ 13 - arg(arg: MaybeTsDsl<WithString>): this { 13 + arg(arg: string | MaybeTsDsl<ts.Expression>): this { 14 14 (this._args ??= []).push(arg); 15 15 return this; 16 16 } 17 17 18 18 /** Adds one or more expression arguments. */ 19 - args(...args: ReadonlyArray<MaybeTsDsl<WithString>>): this { 19 + args(...args: ReadonlyArray<string | MaybeTsDsl<ts.Expression>>): this { 20 20 (this._args ??= []).push(...args); 21 21 return this; 22 22 } ··· 24 24 /** Renders the arguments into an array of `Expression`s. */ 25 25 protected $args(): ReadonlyArray<ts.Expression> { 26 26 if (!this._args) return []; 27 - return this.$node(this._args).map((arg) => this.$expr(arg)); 27 + return this.$node(this._args).map((arg) => this.$maybeId(arg)); 28 28 } 29 29 30 30 $render(): ts.Node {
+5 -3
packages/openapi-ts/src/ts-dsl/mixins/assignment.ts
··· 1 - import type { MaybeTsDsl, WithString } from '../base'; 1 + import type ts from 'typescript'; 2 + 3 + import type { MaybeTsDsl } from '../base'; 2 4 import { BinaryTsDsl } from '../binary'; 3 5 4 6 export class AssignmentMixin { 5 7 /** Creates an assignment expression (e.g. `this = expr`). */ 6 8 assign( 7 - this: MaybeTsDsl<WithString>, 8 - expr: MaybeTsDsl<WithString>, 9 + this: string | MaybeTsDsl<ts.Expression>, 10 + expr: string | MaybeTsDsl<ts.Expression>, 9 11 ): BinaryTsDsl { 10 12 return new BinaryTsDsl(this, '=', expr); 11 13 }
+3 -3
packages/openapi-ts/src/ts-dsl/mixins/decorator.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 - import type { MaybeTsDsl, WithString } from '../base'; 3 + import type { MaybeTsDsl } from '../base'; 4 4 import { TsDsl } from '../base'; 5 5 import { DecoratorTsDsl } from '../decorator'; 6 6 ··· 9 9 10 10 /** Adds a decorator (e.g. `@sealed({ in: 'root' })`). */ 11 11 decorator( 12 - name: WithString, 13 - ...args: ReadonlyArray<MaybeTsDsl<WithString>> 12 + name: string | ts.Expression, 13 + ...args: ReadonlyArray<string | MaybeTsDsl<ts.Expression>> 14 14 ): this { 15 15 (this.decorators ??= []).push(new DecoratorTsDsl(name, ...args)); 16 16 return this;
+3 -3
packages/openapi-ts/src/ts-dsl/mixins/do.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 - import type { MaybeTsDsl, WithStatement } from '../base'; 3 + import type { MaybeTsDsl } from '../base'; 4 4 import { TsDsl } from '../base'; 5 5 6 6 /** 7 7 * Adds `.do()` for appending statements or expressions to a body. 8 8 */ 9 9 export class DoMixin extends TsDsl { 10 - private _do?: Array<MaybeTsDsl<WithStatement>>; 10 + private _do?: Array<MaybeTsDsl<ts.Expression | ts.Statement>>; 11 11 12 12 /** Adds one or more expressions/statements to the body. */ 13 - do(...items: ReadonlyArray<MaybeTsDsl<WithStatement>>): this { 13 + do(...items: ReadonlyArray<MaybeTsDsl<ts.Expression | ts.Statement>>): this { 14 14 (this._do ??= []).push(...items); 15 15 return this; 16 16 }
+19 -16
packages/openapi-ts/src/ts-dsl/mixins/expr.ts
··· 3 3 import type { AsTsDsl } from '../as'; 4 4 import type { AttrTsDsl } from '../attr'; 5 5 import type { AwaitTsDsl } from '../await'; 6 - import type { MaybeTsDsl, TypeTsDsl, WithString } from '../base'; 6 + import type { MaybeTsDsl, TypeTsDsl } from '../base'; 7 7 import type { CallTsDsl } from '../call'; 8 8 import type { ReturnTsDsl } from '../return'; 9 9 ··· 15 15 */ 16 16 17 17 type AsFactory = ( 18 - expr: MaybeTsDsl<WithString>, 19 - type: WithString<TypeTsDsl>, 18 + expr: string | MaybeTsDsl<ts.Expression>, 19 + type: string | TypeTsDsl, 20 20 ) => AsTsDsl; 21 21 let asFactory: AsFactory | undefined; 22 22 /** Registers the Attr DSL factory after its module has finished evaluating. */ ··· 25 25 } 26 26 27 27 type AttrFactory = ( 28 - expr: MaybeTsDsl<WithString>, 29 - name: WithString<ts.MemberName> | number, 28 + expr: string | MaybeTsDsl<ts.Expression>, 29 + name: string | ts.MemberName | number, 30 30 ) => AttrTsDsl; 31 31 let attrFactory: AttrFactory | undefined; 32 32 /** Registers the Attr DSL factory after its module has finished evaluating. */ ··· 34 34 attrFactory = factory; 35 35 } 36 36 37 - type AwaitFactory = (expr: MaybeTsDsl<WithString>) => AwaitTsDsl; 37 + type AwaitFactory = (expr: string | MaybeTsDsl<ts.Expression>) => AwaitTsDsl; 38 38 let awaitFactory: AwaitFactory | undefined; 39 39 /** Registers the Await DSL factory after its module has finished evaluating. */ 40 40 export function registerLazyAccessAwaitFactory(factory: AwaitFactory): void { ··· 42 42 } 43 43 44 44 type CallFactory = ( 45 - expr: MaybeTsDsl<WithString>, 46 - args: ReadonlyArray<MaybeTsDsl<WithString> | undefined>, 45 + expr: string | MaybeTsDsl<ts.Expression>, 46 + args: ReadonlyArray<string | MaybeTsDsl<ts.Expression> | undefined>, 47 47 ) => CallTsDsl; 48 48 let callFactory: CallFactory | undefined; 49 49 /** Registers the Call DSL factory after its module has finished evaluating. */ ··· 51 51 callFactory = factory; 52 52 } 53 53 54 - type ReturnFactory = (expr: MaybeTsDsl<WithString>) => ReturnTsDsl; 54 + type ReturnFactory = (expr: string | MaybeTsDsl<ts.Expression>) => ReturnTsDsl; 55 55 let returnFactory: ReturnFactory | undefined; 56 56 /** Registers the Return DSL factory after its module has finished evaluating. */ 57 57 export function registerLazyAccessReturnFactory(factory: ReturnFactory): void { ··· 60 60 61 61 export class ExprMixin { 62 62 /** Creates an `as` type assertion expression (e.g. `value as Type`). */ 63 - as(this: MaybeTsDsl<WithString>, type: WithString<TypeTsDsl>): AsTsDsl { 63 + as( 64 + this: string | MaybeTsDsl<ts.Expression>, 65 + type: string | TypeTsDsl, 66 + ): AsTsDsl { 64 67 return asFactory!(this, type); 65 68 } 66 69 67 70 /** Accesses a property on the current expression (e.g. `this.foo`). */ 68 71 attr( 69 - this: MaybeTsDsl<WithString>, 70 - name: WithString<ts.MemberName> | number, 72 + this: string | MaybeTsDsl<ts.Expression>, 73 + name: string | ts.MemberName | number, 71 74 ): AttrTsDsl { 72 75 return attrFactory!(this, name); 73 76 } 74 77 75 78 /** Awaits the current expression (e.g. `await expr`). */ 76 - await(this: MaybeTsDsl<WithString>): AwaitTsDsl { 79 + await(this: string | MaybeTsDsl<ts.Expression>): AwaitTsDsl { 77 80 return awaitFactory!(this); 78 81 } 79 82 80 83 /** Calls the current expression (e.g. `fn(arg1, arg2)`). */ 81 84 call( 82 - this: MaybeTsDsl<WithString>, 83 - ...args: ReadonlyArray<MaybeTsDsl<WithString> | undefined> 85 + this: string | MaybeTsDsl<ts.Expression>, 86 + ...args: ReadonlyArray<string | MaybeTsDsl<ts.Expression> | undefined> 84 87 ): CallTsDsl { 85 88 return callFactory!(this, args); 86 89 } 87 90 88 91 /** Produces a `return` statement returning the current expression. */ 89 - return(this: MaybeTsDsl<WithString>): ReturnTsDsl { 92 + return(this: string | MaybeTsDsl<ts.Expression>): ReturnTsDsl { 90 93 return returnFactory!(this); 91 94 } 92 95 }
+63 -16
packages/openapi-ts/src/ts-dsl/mixins/operator.ts
··· 1 - import type { MaybeTsDsl, WithString } from '../base'; 1 + import type ts from 'typescript'; 2 + 3 + import type { MaybeTsDsl } from '../base'; 2 4 import { BinaryTsDsl } from '../binary'; 3 5 4 6 export class OperatorMixin { 5 7 /** Logical AND — `this && expr` */ 6 - and(this: MaybeTsDsl<WithString>, expr: MaybeTsDsl<WithString>) { 8 + and( 9 + this: string | MaybeTsDsl<ts.Expression>, 10 + expr: string | MaybeTsDsl<ts.Expression>, 11 + ) { 7 12 return new BinaryTsDsl(this, '&&', expr); 8 13 } 9 14 /** Nullish coalescing — `this ?? expr` */ 10 - coalesce(this: MaybeTsDsl<WithString>, expr: MaybeTsDsl<WithString>) { 15 + coalesce( 16 + this: string | MaybeTsDsl<ts.Expression>, 17 + expr: string | MaybeTsDsl<ts.Expression>, 18 + ) { 11 19 return new BinaryTsDsl(this, '??', expr); 12 20 } 13 21 /** Division — `this / expr` */ 14 - div(this: MaybeTsDsl<WithString>, expr: MaybeTsDsl<WithString>) { 22 + div( 23 + this: string | MaybeTsDsl<ts.Expression>, 24 + expr: string | MaybeTsDsl<ts.Expression>, 25 + ) { 15 26 return new BinaryTsDsl(this, '/', expr); 16 27 } 17 28 /** Strict equality — `this === expr` */ 18 - eq(this: MaybeTsDsl<WithString>, expr: MaybeTsDsl<WithString>) { 29 + eq( 30 + this: string | MaybeTsDsl<ts.Expression>, 31 + expr: string | MaybeTsDsl<ts.Expression>, 32 + ) { 19 33 return new BinaryTsDsl(this, '===', expr); 20 34 } 21 35 /** Greater than — `this > expr` */ 22 - gt(this: MaybeTsDsl<WithString>, expr: MaybeTsDsl<WithString>) { 36 + gt( 37 + this: string | MaybeTsDsl<ts.Expression>, 38 + expr: string | MaybeTsDsl<ts.Expression>, 39 + ) { 23 40 return new BinaryTsDsl(this, '>', expr); 24 41 } 25 42 /** Greater than or equal — `this >= expr` */ 26 - gte(this: MaybeTsDsl<WithString>, expr: MaybeTsDsl<WithString>) { 43 + gte( 44 + this: string | MaybeTsDsl<ts.Expression>, 45 + expr: string | MaybeTsDsl<ts.Expression>, 46 + ) { 27 47 return new BinaryTsDsl(this, '>=', expr); 28 48 } 29 49 /** Loose equality — `this == expr` */ 30 - looseEq(this: MaybeTsDsl<WithString>, expr: MaybeTsDsl<WithString>) { 50 + looseEq( 51 + this: string | MaybeTsDsl<ts.Expression>, 52 + expr: string | MaybeTsDsl<ts.Expression>, 53 + ) { 31 54 return new BinaryTsDsl(this, '==', expr); 32 55 } 33 56 /** Loose inequality — `this != expr` */ 34 - looseNeq(this: MaybeTsDsl<WithString>, expr: MaybeTsDsl<WithString>) { 57 + looseNeq( 58 + this: string | MaybeTsDsl<ts.Expression>, 59 + expr: string | MaybeTsDsl<ts.Expression>, 60 + ) { 35 61 return new BinaryTsDsl(this, '!=', expr); 36 62 } 37 63 /** Less than — `this < expr` */ 38 - lt(this: MaybeTsDsl<WithString>, expr: MaybeTsDsl<WithString>) { 64 + lt( 65 + this: string | MaybeTsDsl<ts.Expression>, 66 + expr: string | MaybeTsDsl<ts.Expression>, 67 + ) { 39 68 return new BinaryTsDsl(this, '<', expr); 40 69 } 41 70 /** Less than or equal — `this <= expr` */ 42 - lte(this: MaybeTsDsl<WithString>, expr: MaybeTsDsl<WithString>) { 71 + lte( 72 + this: string | MaybeTsDsl<ts.Expression>, 73 + expr: string | MaybeTsDsl<ts.Expression>, 74 + ) { 43 75 return new BinaryTsDsl(this, '<=', expr); 44 76 } 45 77 /** Subtraction — `this - expr` */ 46 - minus(this: MaybeTsDsl<WithString>, expr: MaybeTsDsl<WithString>) { 78 + minus( 79 + this: string | MaybeTsDsl<ts.Expression>, 80 + expr: string | MaybeTsDsl<ts.Expression>, 81 + ) { 47 82 return new BinaryTsDsl(this, '-', expr); 48 83 } 49 84 /** Strict inequality — `this !== expr` */ 50 - neq(this: MaybeTsDsl<WithString>, expr: MaybeTsDsl<WithString>) { 85 + neq( 86 + this: string | MaybeTsDsl<ts.Expression>, 87 + expr: string | MaybeTsDsl<ts.Expression>, 88 + ) { 51 89 return new BinaryTsDsl(this, '!==', expr); 52 90 } 53 91 /** Logical OR — `this || expr` */ 54 - or(this: MaybeTsDsl<WithString>, expr: MaybeTsDsl<WithString>) { 92 + or( 93 + this: string | MaybeTsDsl<ts.Expression>, 94 + expr: string | MaybeTsDsl<ts.Expression>, 95 + ) { 55 96 return new BinaryTsDsl(this, '||', expr); 56 97 } 57 98 /** Addition — `this + expr` */ 58 - plus(this: MaybeTsDsl<WithString>, expr: MaybeTsDsl<WithString>) { 99 + plus( 100 + this: string | MaybeTsDsl<ts.Expression>, 101 + expr: string | MaybeTsDsl<ts.Expression>, 102 + ) { 59 103 return new BinaryTsDsl(this, '+', expr); 60 104 } 61 105 /** Multiplication — `this * expr` */ 62 - times(this: MaybeTsDsl<WithString>, expr: MaybeTsDsl<WithString>) { 106 + times( 107 + this: string | MaybeTsDsl<ts.Expression>, 108 + expr: string | MaybeTsDsl<ts.Expression>, 109 + ) { 63 110 return new BinaryTsDsl(this, '*', expr); 64 111 } 65 112 }
+4 -4
packages/openapi-ts/src/ts-dsl/mixins/type-args.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 - import type { MaybeTsDsl, TypeOfTsDsl, TypeTsDsl, WithString } from '../base'; 3 + import type { MaybeTsDsl, TypeOfTsDsl, TypeTsDsl } from '../base'; 4 4 import { TsDsl } from '../base'; 5 5 6 6 export class TypeArgsMixin extends TsDsl { 7 - protected _generics?: Array<WithString<MaybeTsDsl<TypeOfTsDsl<TypeTsDsl>>>>; 7 + protected _generics?: Array<string | MaybeTsDsl<TypeOfTsDsl<TypeTsDsl>>>; 8 8 9 9 /** Adds a single type argument (e.g. `string` in `Foo<string>`). */ 10 - generic(arg: WithString<MaybeTsDsl<TypeOfTsDsl<TypeTsDsl>>>): this { 10 + generic(arg: string | MaybeTsDsl<TypeOfTsDsl<TypeTsDsl>>): this { 11 11 (this._generics ??= []).push(arg); 12 12 return this; 13 13 } 14 14 15 15 /** Adds type arguments (e.g. `Map<string, number>`). */ 16 16 generics( 17 - ...args: ReadonlyArray<WithString<MaybeTsDsl<TypeOfTsDsl<TypeTsDsl>>>> 17 + ...args: ReadonlyArray<string | MaybeTsDsl<TypeOfTsDsl<TypeTsDsl>>> 18 18 ): this { 19 19 this._generics = [...args]; 20 20 return this;
+3 -3
packages/openapi-ts/src/ts-dsl/mixins/value.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 - import type { MaybeTsDsl, WithString } from '../base'; 3 + import type { MaybeTsDsl } from '../base'; 4 4 import { TsDsl } from '../base'; 5 5 6 6 export class ValueMixin extends TsDsl { 7 - private value?: MaybeTsDsl<WithString>; 7 + private value?: string | MaybeTsDsl<ts.Expression>; 8 8 9 9 /** Sets the initializer expression (e.g. `= expr`). */ 10 - assign<T extends this>(this: T, expr: MaybeTsDsl<WithString>): T { 10 + assign<T extends this>(this: T, expr: string | MaybeTsDsl<ts.Expression>): T { 11 11 this.value = expr; 12 12 return this; 13 13 }
+4 -4
packages/openapi-ts/src/ts-dsl/new.ts
··· 1 1 /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */ 2 2 import ts from 'typescript'; 3 3 4 - import type { MaybeTsDsl, WithString } from './base'; 4 + import type { MaybeTsDsl } from './base'; 5 5 import { TsDsl } from './base'; 6 6 import { mixin } from './mixins/apply'; 7 7 import { ArgsMixin } from './mixins/args'; ··· 9 9 import { TypeArgsMixin } from './mixins/type-args'; 10 10 11 11 export class NewTsDsl extends TsDsl<ts.NewExpression> { 12 - private classExpr: MaybeTsDsl<WithString>; 12 + private classExpr: string | MaybeTsDsl<ts.Expression>; 13 13 14 14 constructor( 15 - classExpr: MaybeTsDsl<WithString>, 16 - ...args: ReadonlyArray<MaybeTsDsl<WithString>> 15 + classExpr: string | MaybeTsDsl<ts.Expression>, 16 + ...args: ReadonlyArray<string | MaybeTsDsl<ts.Expression>> 17 17 ) { 18 18 super(); 19 19 this.classExpr = classExpr;
-20
packages/openapi-ts/src/ts-dsl/not.ts
··· 1 - import ts from 'typescript'; 2 - 3 - import type { MaybeTsDsl, WithString } from './base'; 4 - import { TsDsl } from './base'; 5 - 6 - export class NotTsDsl extends TsDsl<ts.PrefixUnaryExpression> { 7 - private _notExpr: MaybeTsDsl<WithString>; 8 - 9 - constructor(expr: MaybeTsDsl<WithString>) { 10 - super(); 11 - this._notExpr = expr; 12 - } 13 - 14 - $render(): ts.PrefixUnaryExpression { 15 - return ts.factory.createPrefixUnaryExpression( 16 - ts.SyntaxKind.ExclamationToken, 17 - this.$node(this._notExpr), 18 - ); 19 - } 20 - }
+9 -9
packages/openapi-ts/src/ts-dsl/object.ts
··· 3 3 4 4 import { numberRegExp } from '~/utils/regexp'; 5 5 6 - import type { MaybeTsDsl, WithString } from './base'; 6 + import type { MaybeTsDsl } from './base'; 7 7 import { TsDsl } from './base'; 8 8 import { GetterTsDsl } from './getter'; 9 9 import { mixin } from './mixins/apply'; ··· 15 15 export class ObjectTsDsl extends TsDsl<ts.ObjectLiteralExpression> { 16 16 private props: Array< 17 17 | { 18 - expr: WithString<MaybeTsDsl<ts.Statement>>; 18 + expr: string | MaybeTsDsl<ts.Statement>; 19 19 kind: 'getter'; 20 20 name: string; 21 21 } 22 - | { expr: MaybeTsDsl<WithString>; kind: 'prop'; name: string } 22 + | { expr: string | MaybeTsDsl<ts.Expression>; kind: 'prop'; name: string } 23 23 | { 24 - expr: WithString<MaybeTsDsl<ts.Statement>>; 24 + expr: string | MaybeTsDsl<ts.Statement>; 25 25 kind: 'setter'; 26 26 name: string; 27 27 } 28 - | { expr: MaybeTsDsl<WithString>; kind: 'spread' } 28 + | { expr: string | MaybeTsDsl<ts.Expression>; kind: 'spread' } 29 29 > = []; 30 30 31 31 /** Adds a getter property (e.g. `{ get foo() { ... } }`). */ 32 - getter(name: string, expr: WithString<MaybeTsDsl<ts.Statement>>): this { 32 + getter(name: string, expr: string | MaybeTsDsl<ts.Statement>): this { 33 33 this.props.push({ expr, kind: 'getter', name }); 34 34 return this; 35 35 } ··· 45 45 } 46 46 47 47 /** Adds a property assignment. */ 48 - prop(name: string, expr: MaybeTsDsl<WithString>): this { 48 + prop(name: string, expr: string | MaybeTsDsl<ts.Expression>): this { 49 49 this.props.push({ expr, kind: 'prop', name }); 50 50 return this; 51 51 } 52 52 53 53 /** Adds a setter property (e.g. `{ set foo(v) { ... } }`). */ 54 - setter(name: string, expr: WithString<MaybeTsDsl<ts.Statement>>): this { 54 + setter(name: string, expr: string | MaybeTsDsl<ts.Statement>): this { 55 55 this.props.push({ expr, kind: 'setter', name }); 56 56 return this; 57 57 } 58 58 59 59 /** Adds a spread property (e.g. `{ ...options }`). */ 60 - spread(expr: MaybeTsDsl<WithString>): this { 60 + spread(expr: string | MaybeTsDsl<ts.Expression>): this { 61 61 this.props.push({ expr, kind: 'spread' }); 62 62 return this; 63 63 }
+56
packages/openapi-ts/src/ts-dsl/prefix.ts
··· 1 + import ts from 'typescript'; 2 + 3 + import type { MaybeTsDsl } from './base'; 4 + import { TsDsl } from './base'; 5 + 6 + export class PrefixTsDsl extends TsDsl<ts.PrefixUnaryExpression> { 7 + private _expr?: string | MaybeTsDsl<ts.Expression>; 8 + private _op?: ts.PrefixUnaryOperator; 9 + 10 + constructor( 11 + expr?: string | MaybeTsDsl<ts.Expression>, 12 + op?: ts.PrefixUnaryOperator, 13 + ) { 14 + super(); 15 + this._expr = expr; 16 + this._op = op; 17 + } 18 + 19 + /** Sets the operand (the expression being prefixed). */ 20 + expr(expr: string | MaybeTsDsl<ts.Expression>): this { 21 + this._expr = expr; 22 + return this; 23 + } 24 + 25 + /** Sets the operator to MinusToken for negation (`-`). */ 26 + neg(): this { 27 + this._op = ts.SyntaxKind.MinusToken; 28 + return this; 29 + } 30 + 31 + /** Sets the operator to ExclamationToken for logical NOT (`!`). */ 32 + not(): this { 33 + this._op = ts.SyntaxKind.ExclamationToken; 34 + return this; 35 + } 36 + 37 + /** Sets the operator (e.g. `ts.SyntaxKind.ExclamationToken` for `!`). */ 38 + op(op: ts.PrefixUnaryOperator): this { 39 + this._op = op; 40 + return this; 41 + } 42 + 43 + /** Renders the prefix unary expression node. */ 44 + $render(): ts.PrefixUnaryExpression { 45 + if (!this._expr) { 46 + throw new Error('Missing expression for prefix unary expression'); 47 + } 48 + if (!this._op) { 49 + throw new Error('Missing operator for prefix unary expression'); 50 + } 51 + return ts.factory.createPrefixUnaryExpression( 52 + this._op, 53 + this.$node(this._expr), 54 + ); 55 + } 56 + }
+3 -3
packages/openapi-ts/src/ts-dsl/return.ts
··· 1 1 /* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */ 2 2 import ts from 'typescript'; 3 3 4 - import type { MaybeTsDsl, WithString } from './base'; 4 + import type { MaybeTsDsl } from './base'; 5 5 import { TsDsl } from './base'; 6 6 import { mixin } from './mixins/apply'; 7 7 import { ExprMixin, registerLazyAccessReturnFactory } from './mixins/expr'; 8 8 9 9 export class ReturnTsDsl extends TsDsl<ts.ReturnStatement> { 10 - private _returnExpr?: MaybeTsDsl<WithString>; 10 + private _returnExpr?: string | MaybeTsDsl<ts.Expression>; 11 11 12 - constructor(expr?: MaybeTsDsl<WithString>) { 12 + constructor(expr?: string | MaybeTsDsl<ts.Expression>) { 13 13 super(); 14 14 this._returnExpr = expr; 15 15 }
+5 -5
packages/openapi-ts/src/ts-dsl/template.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import type { MaybeTsDsl, WithString } from './base'; 3 + import type { MaybeTsDsl } from './base'; 4 4 import { TsDsl } from './base'; 5 5 6 6 export class TemplateTsDsl extends TsDsl< 7 7 ts.TemplateExpression | ts.NoSubstitutionTemplateLiteral 8 8 > { 9 - private parts: Array<MaybeTsDsl<WithString>> = []; 9 + private parts: Array<string | MaybeTsDsl<ts.Expression>> = []; 10 10 11 - constructor(value?: MaybeTsDsl<WithString>) { 11 + constructor(value?: string | MaybeTsDsl<ts.Expression>) { 12 12 super(); 13 13 if (value !== undefined) this.add(value); 14 14 } 15 15 16 - add(value: MaybeTsDsl<WithString>): this { 16 + add(value: string | MaybeTsDsl<ts.Expression>): this { 17 17 this.parts.push(value); 18 18 return this; 19 19 } ··· 21 21 $render(): ts.TemplateExpression | ts.NoSubstitutionTemplateLiteral { 22 22 const parts = this.$node(this.parts); 23 23 24 - const normalized: Array<WithString> = []; 24 + const normalized: Array<string | ts.Expression> = []; 25 25 // merge consecutive string parts 26 26 for (let index = 0; index < parts.length; index++) { 27 27 const current = parts[index]!;
+8 -8
packages/openapi-ts/src/ts-dsl/ternary.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import type { MaybeTsDsl, WithString } from './base'; 3 + import type { MaybeTsDsl } from './base'; 4 4 import { TsDsl } from './base'; 5 5 6 6 export class TernaryTsDsl extends TsDsl<ts.ConditionalExpression> { 7 - private _condition?: MaybeTsDsl<WithString>; 8 - private _then?: MaybeTsDsl<WithString>; 9 - private _else?: MaybeTsDsl<WithString>; 7 + private _condition?: string | MaybeTsDsl<ts.Expression>; 8 + private _then?: string | MaybeTsDsl<ts.Expression>; 9 + private _else?: string | MaybeTsDsl<ts.Expression>; 10 10 11 - constructor(condition?: MaybeTsDsl<WithString>) { 11 + constructor(condition?: string | MaybeTsDsl<ts.Expression>) { 12 12 super(); 13 13 if (condition) this.condition(condition); 14 14 } 15 15 16 - condition(condition: MaybeTsDsl<WithString>) { 16 + condition(condition: string | MaybeTsDsl<ts.Expression>) { 17 17 this._condition = condition; 18 18 return this; 19 19 } 20 20 21 - do(expr: MaybeTsDsl<WithString>) { 21 + do(expr: string | MaybeTsDsl<ts.Expression>) { 22 22 this._then = expr; 23 23 return this; 24 24 } 25 25 26 - otherwise(expr: MaybeTsDsl<WithString>) { 26 + otherwise(expr: string | MaybeTsDsl<ts.Expression>) { 27 27 this._else = expr; 28 28 return this; 29 29 }
+5 -5
packages/openapi-ts/src/ts-dsl/throw.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import type { MaybeTsDsl, WithString } from './base'; 3 + import type { MaybeTsDsl } from './base'; 4 4 import { TsDsl } from './base'; 5 5 6 6 export class ThrowTsDsl extends TsDsl<ts.ThrowStatement> { 7 - private error: MaybeTsDsl<WithString>; 8 - private msg?: MaybeTsDsl<WithString>; 7 + private error: string | MaybeTsDsl<ts.Expression>; 8 + private msg?: string | MaybeTsDsl<ts.Expression>; 9 9 private useNew: boolean; 10 10 11 - constructor(error: MaybeTsDsl<WithString>, useNew = true) { 11 + constructor(error: string | MaybeTsDsl<ts.Expression>, useNew = true) { 12 12 super(); 13 13 this.error = error; 14 14 this.useNew = useNew; 15 15 } 16 16 17 - message(value: MaybeTsDsl<WithString>): this { 17 + message(value: string | MaybeTsDsl<ts.Expression>): this { 18 18 this.msg = value; 19 19 return this; 20 20 }
+3 -4
packages/openapi-ts/src/ts-dsl/type/and.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import type { WithString } from '../base'; 4 3 import { TypeTsDsl } from '../base'; 5 4 6 5 export class TypeAndTsDsl extends TypeTsDsl<ts.IntersectionTypeNode> { 7 - private _types: Array<WithString<ts.TypeNode> | TypeTsDsl> = []; 6 + private _types: Array<string | ts.TypeNode | TypeTsDsl> = []; 8 7 9 - constructor(...nodes: Array<WithString<ts.TypeNode> | TypeTsDsl>) { 8 + constructor(...nodes: Array<string | ts.TypeNode | TypeTsDsl>) { 10 9 super(); 11 10 this.types(...nodes); 12 11 } 13 12 14 - types(...nodes: Array<WithString<ts.TypeNode> | TypeTsDsl>): this { 13 + types(...nodes: Array<string | ts.TypeNode | TypeTsDsl>): this { 15 14 this._types.push(...nodes); 16 15 return this; 17 16 }
+11 -11
packages/openapi-ts/src/ts-dsl/type/attr.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import type { MaybeTsDsl, WithString } from '../base'; 3 + import type { MaybeTsDsl } from '../base'; 4 4 import { TsDsl } from '../base'; 5 5 6 6 export class TypeAttrTsDsl extends TsDsl<ts.QualifiedName> { 7 - private _base?: WithString<MaybeTsDsl<ts.EntityName>>; 8 - private right: WithString<ts.Identifier>; 7 + private _base?: string | MaybeTsDsl<ts.EntityName>; 8 + private right: string | ts.Identifier; 9 9 10 10 constructor( 11 - base: WithString<MaybeTsDsl<ts.EntityName>>, 12 - right: WithString<ts.Identifier>, 11 + base: string | MaybeTsDsl<ts.EntityName>, 12 + right: string | ts.Identifier, 13 13 ); 14 - constructor(right: WithString<ts.Identifier>); 14 + constructor(right: string | ts.Identifier); 15 15 constructor( 16 - baseOrRight: WithString<MaybeTsDsl<ts.EntityName>>, 17 - maybeRight?: WithString<ts.Identifier>, 16 + baseOrRight: string | MaybeTsDsl<ts.EntityName>, 17 + maybeRight?: string | ts.Identifier, 18 18 ) { 19 19 super(); 20 20 if (maybeRight) { ··· 22 22 this.right = maybeRight; 23 23 } else { 24 24 this.base(undefined); 25 - this.right = baseOrRight as WithString<ts.Identifier>; 25 + this.right = baseOrRight as string | ts.Identifier; 26 26 } 27 27 } 28 28 29 - base(base?: WithString<MaybeTsDsl<ts.EntityName>>): this { 29 + base(base?: string | MaybeTsDsl<ts.EntityName>): this { 30 30 this._base = base; 31 31 return this; 32 32 } ··· 39 39 if (!ts.isEntityName(left)) { 40 40 throw new Error('TypeAttrTsDsl: base must be an EntityName'); 41 41 } 42 - const right = this.$expr(this.right); 42 + const right = this.$maybeId(this.right); 43 43 return ts.factory.createQualifiedName(left, right); 44 44 } 45 45 }
+3 -4
packages/openapi-ts/src/ts-dsl/type/expr.ts
··· 1 1 /* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */ 2 2 import ts from 'typescript'; 3 3 4 - import type { WithString } from '../base'; 5 4 import { TypeTsDsl } from '../base'; 6 5 import { mixin } from '../mixins/apply'; 7 6 import { TypeArgsMixin } from '../mixins/type-args'; ··· 9 8 import { TypeIdxTsDsl } from './idx'; 10 9 11 10 export class TypeExprTsDsl extends TypeTsDsl<ts.TypeReferenceNode> { 12 - private _exprInput?: WithString<ts.Identifier> | TypeAttrTsDsl; 11 + private _exprInput?: string | ts.Identifier | TypeAttrTsDsl; 13 12 14 13 constructor(); 15 14 constructor(fn: (t: TypeExprTsDsl) => void); ··· 29 28 } 30 29 31 30 /** Accesses a nested type (e.g. `Foo.Bar`). */ 32 - attr(right: WithString<ts.Identifier> | TypeAttrTsDsl): this { 31 + attr(right: string | ts.Identifier | TypeAttrTsDsl): this { 33 32 this._exprInput = 34 33 right instanceof TypeAttrTsDsl 35 34 ? right.base(this._exprInput) ··· 38 37 } 39 38 40 39 /** Creates an indexed-access type (e.g. `Foo<T>[K]`). */ 41 - idx(index: WithString<ts.TypeNode> | number): TypeIdxTsDsl { 40 + idx(index: string | ts.TypeNode | number): TypeIdxTsDsl { 42 41 return new TypeIdxTsDsl(this, index); 43 42 } 44 43
+7 -7
packages/openapi-ts/src/ts-dsl/type/idx.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import type { MaybeTsDsl, WithString } from '../base'; 3 + import type { MaybeTsDsl } from '../base'; 4 4 import { TypeTsDsl } from '../base'; 5 5 6 6 export class TypeIdxTsDsl extends TypeTsDsl<ts.IndexedAccessTypeNode> { 7 - private _base: WithString<MaybeTsDsl<ts.TypeNode>>; 8 - private _index: WithString<MaybeTsDsl<ts.TypeNode>> | number; 7 + private _base: string | MaybeTsDsl<ts.TypeNode>; 8 + private _index: string | MaybeTsDsl<ts.TypeNode> | number; 9 9 10 10 constructor( 11 - base: WithString<MaybeTsDsl<ts.TypeNode>>, 12 - index: WithString<MaybeTsDsl<ts.TypeNode>> | number, 11 + base: string | MaybeTsDsl<ts.TypeNode>, 12 + index: string | MaybeTsDsl<ts.TypeNode> | number, 13 13 ) { 14 14 super(); 15 15 this._base = base; 16 16 this._index = index; 17 17 } 18 18 19 - base(base: WithString<MaybeTsDsl<ts.TypeNode>>): this { 19 + base(base: string | MaybeTsDsl<ts.TypeNode>): this { 20 20 this._base = base; 21 21 return this; 22 22 } 23 23 24 - index(index: WithString<MaybeTsDsl<ts.TypeNode>> | number): this { 24 + index(index: string | MaybeTsDsl<ts.TypeNode> | number): this { 25 25 this._index = index; 26 26 return this; 27 27 }
+3 -4
packages/openapi-ts/src/ts-dsl/type/object.ts
··· 1 1 /* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */ 2 2 import ts from 'typescript'; 3 3 4 - import type { WithString } from '../base'; 5 4 import { TypeTsDsl } from '../base'; 6 5 import { mixin } from '../mixins/apply'; 7 6 import { OptionalMixin } from '../mixins/optional'; ··· 23 22 24 23 class TypePropTsDsl extends TypeTsDsl<ts.TypeElement> { 25 24 private name: string; 26 - private typeInput?: WithString<ts.TypeNode>; 25 + private typeInput?: string | ts.TypeNode; 27 26 28 27 constructor(name: string, fn: (p: TypePropTsDsl) => void) { 29 28 super(); ··· 32 31 } 33 32 34 33 /** Sets the property type. */ 35 - type(type: WithString<ts.TypeNode>): this { 34 + type(type: string | ts.TypeNode): this { 36 35 this.typeInput = type; 37 36 return this; 38 37 } ··· 44 43 } 45 44 return ts.factory.createPropertySignature( 46 45 undefined, 47 - this.$expr(this.name), 46 + this.name, 48 47 this.questionToken, 49 48 this.$type(this.typeInput), 50 49 );
+3 -4
packages/openapi-ts/src/ts-dsl/type/or.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import type { WithString } from '../base'; 4 3 import { TypeTsDsl } from '../base'; 5 4 6 5 export class TypeOrTsDsl extends TypeTsDsl<ts.UnionTypeNode> { 7 - private _types: Array<WithString<ts.TypeNode> | TypeTsDsl> = []; 6 + private _types: Array<string | ts.TypeNode | TypeTsDsl> = []; 8 7 9 - constructor(...nodes: Array<WithString<ts.TypeNode> | TypeTsDsl>) { 8 + constructor(...nodes: Array<string | ts.TypeNode | TypeTsDsl>) { 10 9 super(); 11 10 this.types(...nodes); 12 11 } 13 12 14 - types(...nodes: Array<WithString<ts.TypeNode> | TypeTsDsl>): this { 13 + types(...nodes: Array<string | ts.TypeNode | TypeTsDsl>): this { 15 14 this._types.push(...nodes); 16 15 return this; 17 16 }
+8 -8
packages/openapi-ts/src/ts-dsl/type/param.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import type { MaybeTsDsl, WithString } from '../base'; 3 + import type { MaybeTsDsl } from '../base'; 4 4 import { TypeTsDsl } from '../base'; 5 5 6 6 export class TypeParamTsDsl extends TypeTsDsl<ts.TypeParameterDeclaration> { 7 - protected name?: WithString<ts.Identifier>; 8 - protected constraint?: WithString<MaybeTsDsl<TypeTsDsl>> | boolean; 9 - protected defaultValue?: WithString<MaybeTsDsl<TypeTsDsl>> | boolean; 7 + protected name?: string | ts.Identifier; 8 + protected constraint?: string | MaybeTsDsl<TypeTsDsl> | boolean; 9 + protected defaultValue?: string | MaybeTsDsl<TypeTsDsl> | boolean; 10 10 11 11 constructor( 12 - name?: WithString<ts.Identifier>, 12 + name?: string | ts.Identifier, 13 13 fn?: (name: TypeParamTsDsl) => void, 14 14 ) { 15 15 super(); ··· 17 17 fn?.(this); 18 18 } 19 19 20 - default(value: WithString<MaybeTsDsl<TypeTsDsl>> | boolean): this { 20 + default(value: string | MaybeTsDsl<TypeTsDsl> | boolean): this { 21 21 this.defaultValue = value; 22 22 return this; 23 23 } 24 24 25 - extends(constraint: WithString<MaybeTsDsl<TypeTsDsl>> | boolean): this { 25 + extends(constraint: string | MaybeTsDsl<TypeTsDsl> | boolean): this { 26 26 this.constraint = constraint; 27 27 return this; 28 28 } ··· 31 31 if (!this.name) throw new Error('Missing type name'); 32 32 return ts.factory.createTypeParameterDeclaration( 33 33 undefined, 34 - this.$expr(this.name), 34 + this.$maybeId(this.name), 35 35 this.$type(this.constraint), 36 36 this.$type(this.defaultValue), 37 37 );
+3 -3
packages/openapi-ts/src/ts-dsl/type/query.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import type { MaybeTsDsl, WithString } from '../base'; 3 + import type { MaybeTsDsl } from '../base'; 4 4 import { TypeTsDsl } from '../base'; 5 5 6 6 export class TypeQueryTsDsl extends TypeTsDsl<ts.TypeQueryNode> { 7 - private expr: MaybeTsDsl<WithString>; 7 + private expr: string | MaybeTsDsl<ts.Expression>; 8 8 9 - constructor(expr: MaybeTsDsl<WithString>) { 9 + constructor(expr: string | MaybeTsDsl<ts.Expression>) { 10 10 super(); 11 11 this.expr = expr; 12 12 }
+3 -4
packages/openapi-ts/src/ts-dsl/type/tuple.ts
··· 1 1 import ts from 'typescript'; 2 2 3 - import type { WithString } from '../base'; 4 3 import { TypeTsDsl } from '../base'; 5 4 6 5 export class TypeTupleTsDsl extends TypeTsDsl<ts.TupleTypeNode> { 7 - private _elements: Array<WithString<ts.TypeNode> | TypeTsDsl> = []; 6 + private _elements: Array<string | ts.TypeNode | TypeTsDsl> = []; 8 7 9 - constructor(...nodes: Array<WithString<ts.TypeNode> | TypeTsDsl>) { 8 + constructor(...nodes: Array<string | ts.TypeNode | TypeTsDsl>) { 10 9 super(); 11 10 this.elements(...nodes); 12 11 } 13 12 14 - elements(...types: Array<WithString<ts.TypeNode> | TypeTsDsl>): this { 13 + elements(...types: Array<string | ts.TypeNode | TypeTsDsl>): this { 15 14 this._elements.push(...types); 16 15 return this; 17 16 }
+3 -3
packages/openapi-ts/src/ts-dsl/typeof.ts
··· 1 1 /* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */ 2 2 import ts from 'typescript'; 3 3 4 - import type { MaybeTsDsl, WithString } from './base'; 4 + import type { MaybeTsDsl } from './base'; 5 5 import { TsDsl } from './base'; 6 6 import { mixin } from './mixins/apply'; 7 7 import { OperatorMixin } from './mixins/operator'; 8 8 9 9 export class TypeOfExprTsDsl extends TsDsl<ts.TypeOfExpression> { 10 - private _expr: MaybeTsDsl<WithString>; 10 + private _expr: string | MaybeTsDsl<ts.Expression>; 11 11 12 - constructor(expr: MaybeTsDsl<WithString>) { 12 + constructor(expr: string | MaybeTsDsl<ts.Expression>) { 13 13 super(); 14 14 this._expr = expr; 15 15 }
+39
packages/openapi-ts/src/ts-dsl/utils.ts
··· 1 + import type ts from 'typescript'; 2 + 3 + import { ArrayTsDsl } from './array'; 4 + import { TsDsl } from './base'; 5 + import { LiteralTsDsl } from './literal'; 6 + import { ObjectTsDsl } from './object'; 7 + 8 + export const toExpr = (value: unknown): TsDsl<ts.Expression> | undefined => { 9 + if (value instanceof TsDsl) { 10 + return value; 11 + } 12 + 13 + if (value === null) { 14 + return new LiteralTsDsl(value); 15 + } 16 + 17 + if ( 18 + typeof value === 'number' || 19 + typeof value === 'boolean' || 20 + typeof value === 'string' 21 + ) { 22 + return new LiteralTsDsl(value); 23 + } 24 + 25 + if (value instanceof Array) { 26 + return new ArrayTsDsl(...value.map((v) => toExpr(v) ?? v)); 27 + } 28 + 29 + if (typeof value === 'object') { 30 + const obj = new ObjectTsDsl(); 31 + for (const [key, val] of Object.entries(value)) { 32 + const expr = toExpr(val); 33 + if (expr) obj.prop(key, expr); 34 + } 35 + return obj; 36 + } 37 + 38 + return; 39 + };