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

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #2226 from hey-api/feat/valibot-config

feat(valibot): single schema per request

authored by

Lubos and committed by
GitHub
aea5dbd2 df037451

+2038 -1399
+25
.changeset/dry-suits-destroy.md
··· 1 + --- 2 + '@hey-api/openapi-ts': minor 3 + --- 4 + 5 + feat(valibot): generate a single schema for requests 6 + 7 + ### Single Valibot schema per request 8 + 9 + Previously, we generated a separate schema for each endpoint parameter and request body. In v0.76.0, a single request schema is generated for the whole endpoint. It may contain a request body, parameters, and headers. 10 + 11 + ```ts 12 + const vData = v.object({ 13 + body: v.optional(v.object({ 14 + foo: v.optional(v.string()), 15 + bar: v.optional(v.union([v.number(), v.null()])), 16 + })), 17 + headers: v.optional(v.never()), 18 + path: v.object({ 19 + baz: v.string(), 20 + }), 21 + query: v.optional(v.never()), 22 + }); 23 + ``` 24 + 25 + If you need to access individual fields, you can do so using the [`.entries`](https://valibot.dev/api/object/) API. For example, we can get the request body schema with `vData.entries.body`.
+5
.changeset/six-birds-peel.md
··· 1 + --- 2 + '@hey-api/openapi-ts': patch 3 + --- 4 + 5 + fix(valibot): add `metadata` option to generate additional metadata for documentation, code generation, AI structured outputs, form validation, and other purposes
+24
docs/openapi-ts/migrating.md
··· 27 27 28 28 This config option is deprecated and will be removed. 29 29 30 + ## v0.76.0 31 + 32 + ### Single Valibot schema per request 33 + 34 + Previously, we generated a separate schema for each endpoint parameter and request body. In v0.76.0, a single request schema is generated for the whole endpoint. It may contain a request body, parameters, and headers. 35 + 36 + ```ts 37 + const vData = v.object({ 38 + body: v.optional( 39 + v.object({ 40 + foo: v.optional(v.string()), 41 + bar: v.optional(v.union([v.number(), v.null()])), 42 + }), 43 + ), 44 + headers: v.optional(v.never()), 45 + path: v.object({ 46 + baz: v.string(), 47 + }), 48 + query: v.optional(v.never()), 49 + }); 50 + ``` 51 + 52 + If you need to access individual fields, you can do so using the [`.entries`](https://valibot.dev/api/object/) API. For example, we can get the request body schema with `vData.entries.body`. 53 + 30 54 ## v0.75.0 31 55 32 56 ### Updated TanStack Query options
+51 -28
docs/openapi-ts/plugins/valibot.md
··· 26 26 ## Features 27 27 28 28 - seamless integration with `@hey-api/openapi-ts` ecosystem 29 - - Valibot schemas for request payloads, parameters, and responses 29 + - Valibot schemas for requests, responses, and reusable definitions 30 30 31 31 ## Installation 32 32 33 33 In your [configuration](/openapi-ts/get-started), add `valibot` to your plugins and you'll be ready to generate Valibot artifacts. :tada: 34 34 35 35 ```js 36 - import { defaultPlugins } from '@hey-api/openapi-ts'; 37 - 38 36 export default { 39 37 input: 'https://get.heyapi.dev/hey-api/backend', 40 38 output: 'src/client', 41 39 plugins: [ 42 - ...defaultPlugins, 40 + // ...other plugins 43 41 'valibot', // [!code ++] 44 42 ], 45 43 }; ··· 50 48 To automatically validate response data in your SDKs, set `sdk.validator` to `true`. 51 49 52 50 ```js 53 - import { defaultPlugins } from '@hey-api/openapi-ts'; 54 - 55 51 export default { 56 52 input: 'https://get.heyapi.dev/hey-api/backend', 57 53 output: 'src/client', 58 54 plugins: [ 59 - ...defaultPlugins, 55 + // ...other plugins 60 56 'valibot', 61 57 { 62 58 name: '@hey-api/sdk', // [!code ++] ··· 70 66 71 67 The Valibot plugin will generate the following artifacts, depending on the input specification. 72 68 69 + ## Requests 70 + 71 + A single request schema is generated for each endpoint. It may contain a request body, parameters, and headers. 72 + 73 + ```ts 74 + const vData = v.object({ 75 + body: v.optional( 76 + v.object({ 77 + foo: v.optional(v.string()), 78 + bar: v.optional(v.union([v.number(), v.null()])), 79 + }), 80 + ), 81 + headers: v.optional(v.never()), 82 + path: v.object({ 83 + baz: v.string(), 84 + }), 85 + query: v.optional(v.never()), 86 + }); 87 + ``` 88 + 89 + ::: tip 90 + If you need to access individual fields, you can do so using the [`.entries`](https://valibot.dev/api/object/) API. For example, we can get the request body schema with `vData.entries.body`. 91 + ::: 92 + 93 + You can customize the naming and casing pattern for requests using the `requests.name` and `requests.case` options. 94 + 73 95 ## Responses 74 96 75 97 A single Valibot schema is generated for all endpoint's responses. If the endpoint describes multiple responses, the generated schema is a union of all possible response shapes. ··· 85 107 ]); 86 108 ``` 87 109 88 - ## Request Bodies 110 + You can customize the naming and casing pattern for responses using the `responses.name` and `responses.case` options. 89 111 90 - If an endpoint describes a request body, we will generate a Valibot schema representing its shape. 112 + ## Definitions 91 113 92 - ```ts 93 - const vData = v.object({ 94 - foo: v.optional(v.string()), 95 - bar: v.optional(v.union([v.number(), v.null()])), 96 - }); 97 - ``` 98 - 99 - ## Parameters 100 - 101 - A separate Valibot schema is generated for every request parameter. 114 + A Valibot schema is generated for every reusable definition from your input. 102 115 103 116 ```ts 104 - const vParameterFoo = v.pipe(v.number(), v.integer()); 117 + const vFoo = v.pipe(v.number(), v.integer()); 105 118 106 - const vParameterBar = v.string(); 119 + const vBar = v.object({ 120 + bar: v.optional(v.array(v.pipe(v.number(), v.integer()))), 121 + }); 107 122 ``` 108 123 109 - ## Schemas 124 + You can customize the naming and casing pattern for definitions using the `definitions.name` and `definitions.case` options. 110 125 111 - A separate Valibot schema is generated for every reusable schema. 126 + ## Metadata 112 127 113 - ```ts 114 - const vFoo = v.pipe(v.number(), v.integer()); 128 + It's often useful to associate a schema with some additional [metadata](https://valibot.dev/api/metadata/) for documentation, code generation, AI structured outputs, form validation, and other purposes. If this is your use case, you can set `metadata` to `true` to generate additional metadata about schemas. 115 129 116 - const vBar = v.object({ 117 - bar: v.optional(v.union([v.array(v.unknown()), v.null()])), 118 - }); 130 + ```js 131 + export default { 132 + input: 'https://get.heyapi.dev/hey-api/backend', 133 + output: 'src/client', 134 + plugins: [ 135 + // ...other plugins 136 + { 137 + metadata: true, // [!code ++] 138 + name: 'valibot', 139 + }, 140 + ], 141 + }; 119 142 ``` 120 143 121 144 <!--@include: ../../examples.md-->
+4 -1
packages/openapi-ts-tests/test/3.1.x.test.ts
··· 734 734 input: 'validators.yaml', 735 735 output: 'validators-metadata', 736 736 plugins: [ 737 - 'valibot', 737 + { 738 + metadata: true, 739 + name: 'valibot', 740 + }, 738 741 { 739 742 metadata: true, 740 743 name: 'zod',
+7
packages/openapi-ts-tests/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts
··· 12 12 foo: v.pipe(v.number(), v.integer()) 13 13 }); 14 14 15 + export const vPostFooData = v.object({ 16 + body: v.optional(v.never()), 17 + headers: v.optional(v.never()), 18 + path: v.optional(v.never()), 19 + query: v.optional(v.never()) 20 + }); 21 + 15 22 /** 16 23 * OK 17 24 */
+304 -258
packages/openapi-ts-tests/test/__snapshots__/2.0.x/plugins/valibot/default/valibot.gen.ts
··· 398 398 reference_code: v.optional(v.string()) 399 399 }); 400 400 401 - /** 402 - * Testing multiline comments in string: First line 403 - * Second line 404 - * 405 - * Fourth line 406 - */ 407 - export const vCallWithDescriptionsParameterParameterWithBreaks = v.string(); 401 + export const vServiceWithEmptyTagData = v.object({ 402 + body: v.optional(v.never()), 403 + headers: v.optional(v.never()), 404 + path: v.optional(v.never()), 405 + query: v.optional(v.never()) 406 + }); 408 407 409 - /** 410 - * Testing backticks in string: `backticks` and ```multiple backticks``` should work 411 - */ 412 - export const vCallWithDescriptionsParameterParameterWithBackticks = v.string(); 408 + export const vPatchApiVbyApiVersionNoTagData = v.object({ 409 + body: v.optional(v.never()), 410 + headers: v.optional(v.never()), 411 + path: v.optional(v.never()), 412 + query: v.optional(v.never()) 413 + }); 413 414 414 - /** 415 - * Testing slashes in string: \backwards\\\ and /forwards/// should work 416 - */ 417 - export const vCallWithDescriptionsParameterParameterWithSlashes = v.string(); 415 + export const vFooWowData = v.object({ 416 + body: v.optional(v.never()), 417 + headers: v.optional(v.never()), 418 + path: v.optional(v.never()), 419 + query: v.optional(v.never()) 420 + }); 418 421 419 - /** 420 - * Testing expression placeholders in string: ${expression} should work 421 - */ 422 - export const vCallWithDescriptionsParameterParameterWithExpressionPlaceholders = v.string(); 422 + export const vDeleteCallWithoutParametersAndResponseData = v.object({ 423 + body: v.optional(v.never()), 424 + headers: v.optional(v.never()), 425 + path: v.optional(v.never()), 426 + query: v.optional(v.never()) 427 + }); 423 428 424 - /** 425 - * Testing quotes in string: 'single quote''' and "double quotes""" should work 426 - */ 427 - export const vCallWithDescriptionsParameterParameterWithQuotes = v.string(); 429 + export const vGetCallWithoutParametersAndResponseData = v.object({ 430 + body: v.optional(v.never()), 431 + headers: v.optional(v.never()), 432 + path: v.optional(v.never()), 433 + query: v.optional(v.never()) 434 + }); 428 435 429 - /** 430 - * Testing reserved characters in string: * inline * and ** inline ** should work 431 - */ 432 - export const vCallWithDescriptionsParameterParameterWithReservedCharacters = v.string(); 436 + export const vHeadCallWithoutParametersAndResponseData = v.object({ 437 + body: v.optional(v.never()), 438 + headers: v.optional(v.never()), 439 + path: v.optional(v.never()), 440 + query: v.optional(v.never()) 441 + }); 433 442 434 - /** 435 - * This is the parameter that goes into the header 436 - */ 437 - export const vCallWithParametersParameterParameterHeader = v.string(); 443 + export const vOptionsCallWithoutParametersAndResponseData = v.object({ 444 + body: v.optional(v.never()), 445 + headers: v.optional(v.never()), 446 + path: v.optional(v.never()), 447 + query: v.optional(v.never()) 448 + }); 438 449 439 - /** 440 - * This is the parameter that goes into the path 441 - */ 442 - export const vCallWithParametersParameterParameterPath = v.string(); 450 + export const vPatchCallWithoutParametersAndResponseData = v.object({ 451 + body: v.optional(v.never()), 452 + headers: v.optional(v.never()), 453 + path: v.optional(v.never()), 454 + query: v.optional(v.never()) 455 + }); 443 456 444 - /** 445 - * api-version should be required in standalone clients 446 - */ 447 - export const vCallWithParametersParameterApiVersion = v.string(); 457 + export const vPostCallWithoutParametersAndResponseData = v.object({ 458 + body: v.optional(v.never()), 459 + headers: v.optional(v.never()), 460 + path: v.optional(v.never()), 461 + query: v.optional(v.never()) 462 + }); 448 463 449 - /** 450 - * This is the parameter that goes into the query params 451 - */ 452 - export const vCallWithParametersParameterParameterQuery = v.string(); 464 + export const vPutCallWithoutParametersAndResponseData = v.object({ 465 + body: v.optional(v.never()), 466 + headers: v.optional(v.never()), 467 + path: v.optional(v.never()), 468 + query: v.optional(v.never()) 469 + }); 453 470 454 - /** 455 - * This is the parameter that goes into the request header 456 - */ 457 - export const vCallWithWeirdParameterNamesParameterParameterHeader = v.string(); 471 + export const vCallWithDescriptionsData = v.object({ 472 + body: v.optional(v.never()), 473 + headers: v.optional(v.never()), 474 + path: v.optional(v.never()), 475 + query: v.optional(v.object({ 476 + parameterWithBreaks: v.optional(v.string()), 477 + parameterWithBackticks: v.optional(v.string()), 478 + parameterWithSlashes: v.optional(v.string()), 479 + parameterWithExpressionPlaceholders: v.optional(v.string()), 480 + parameterWithQuotes: v.optional(v.string()), 481 + parameterWithReservedCharacters: v.optional(v.string()) 482 + })) 483 + }); 458 484 459 - /** 460 - * This is the parameter that goes into the path 461 - */ 462 - export const vCallWithWeirdParameterNamesParameterParameterPath1 = v.string(); 485 + export const vCallWithParametersData = v.object({ 486 + body: v.optional(v.never()), 487 + headers: v.object({ 488 + parameterHeader: v.string() 489 + }), 490 + path: v.object({ 491 + parameterPath: v.string(), 492 + 'api-version': v.string() 493 + }), 494 + query: v.object({ 495 + parameterQuery: v.string() 496 + }) 497 + }); 463 498 464 - /** 465 - * This is the parameter that goes into the path 466 - */ 467 - export const vCallWithWeirdParameterNamesParameterParameterPath2 = v.string(); 468 - 469 - /** 470 - * This is the parameter that goes into the path 471 - */ 472 - export const vCallWithWeirdParameterNamesParameterParameterPath3 = v.string(); 473 - 474 - /** 475 - * api-version should be required in standalone clients 476 - */ 477 - export const vCallWithWeirdParameterNamesParameterApiVersion = v.string(); 478 - 479 - /** 480 - * This is the parameter with a reserved keyword 481 - */ 482 - export const vCallWithWeirdParameterNamesParameterDefault = v.string(); 483 - 484 - /** 485 - * This is the parameter that goes into the request query params 486 - */ 487 - export const vCallWithWeirdParameterNamesParameterParameterQuery = v.string(); 488 - 489 - /** 490 - * This is a simple string with default value 491 - */ 492 - export const vCallWithDefaultParametersParameterParameterString = v.optional(v.string(), 'Hello World!'); 493 - 494 - /** 495 - * This is a simple number with default value 496 - */ 497 - export const vCallWithDefaultParametersParameterParameterNumber = v.optional(v.number(), 123); 498 - 499 - /** 500 - * This is a simple boolean with default value 501 - */ 502 - export const vCallWithDefaultParametersParameterParameterBoolean = v.optional(v.boolean(), true); 503 - 504 - /** 505 - * This is a simple enum with default value 506 - */ 507 - export const vCallWithDefaultParametersParameterParameterEnum = v.picklist([ 508 - 'Success', 509 - 'Warning', 510 - 'Error' 511 - ]); 512 - 513 - /** 514 - * This is a model with one string property 515 - */ 516 - export const vCallWithDefaultParametersParameterParameterModel = v.optional(v.object({ 517 - prop: v.optional(v.string()) 518 - }), { 519 - prop: 'Hello World!' 499 + export const vCallWithWeirdParameterNamesData = v.object({ 500 + body: v.optional(v.never()), 501 + headers: v.object({ 502 + 'parameter.header': v.string() 503 + }), 504 + path: v.object({ 505 + 'parameter.path.1': v.optional(v.string()), 506 + 'parameter-path-2': v.optional(v.string()), 507 + 'PARAMETER-PATH-3': v.optional(v.string()), 508 + 'api-version': v.string() 509 + }), 510 + query: v.object({ 511 + default: v.optional(v.string()), 512 + 'parameter-query': v.string() 513 + }) 520 514 }); 521 515 522 - /** 523 - * This is a simple string that is optional with default value 524 - */ 525 - export const vCallWithDefaultOptionalParametersParameterParameterString = v.optional(v.string(), 'Hello World!'); 526 - 527 - /** 528 - * This is a simple number that is optional with default value 529 - */ 530 - export const vCallWithDefaultOptionalParametersParameterParameterNumber = v.optional(v.number(), 123); 531 - 532 - /** 533 - * This is a simple boolean that is optional with default value 534 - */ 535 - export const vCallWithDefaultOptionalParametersParameterParameterBoolean = v.optional(v.boolean(), true); 536 - 537 - /** 538 - * This is a simple enum that is optional with default value 539 - */ 540 - export const vCallWithDefaultOptionalParametersParameterParameterEnum = v.picklist([ 541 - 'Success', 542 - 'Warning', 543 - 'Error' 544 - ]); 516 + export const vCallWithDefaultParametersData = v.object({ 517 + body: v.optional(v.never()), 518 + headers: v.optional(v.never()), 519 + path: v.optional(v.never()), 520 + query: v.object({ 521 + parameterString: v.optional(v.string(), 'Hello World!'), 522 + parameterNumber: v.optional(v.number(), 123), 523 + parameterBoolean: v.optional(v.boolean(), true), 524 + parameterEnum: v.picklist([ 525 + 'Success', 526 + 'Warning', 527 + 'Error' 528 + ]), 529 + parameterModel: v.optional(v.object({ 530 + prop: v.optional(v.string()) 531 + }), { 532 + prop: 'Hello World!' 533 + }) 534 + }) 535 + }); 545 536 546 - /** 547 - * This is a optional string with default 548 - */ 549 - export const vCallToTestOrderOfParamsParameterParameterOptionalStringWithDefault = v.optional(v.string(), 'Hello World!'); 537 + export const vCallWithDefaultOptionalParametersData = v.object({ 538 + body: v.optional(v.never()), 539 + headers: v.optional(v.never()), 540 + path: v.optional(v.never()), 541 + query: v.optional(v.object({ 542 + parameterString: v.optional(v.string(), 'Hello World!'), 543 + parameterNumber: v.optional(v.number(), 123), 544 + parameterBoolean: v.optional(v.boolean(), true), 545 + parameterEnum: v.optional(v.picklist([ 546 + 'Success', 547 + 'Warning', 548 + 'Error' 549 + ])) 550 + })) 551 + }); 550 552 551 - /** 552 - * This is a optional string with empty default 553 - */ 554 - export const vCallToTestOrderOfParamsParameterParameterOptionalStringWithEmptyDefault = v.optional(v.string(), ''); 553 + export const vCallToTestOrderOfParamsData = v.object({ 554 + body: v.optional(v.never()), 555 + headers: v.optional(v.never()), 556 + path: v.optional(v.never()), 557 + query: v.object({ 558 + parameterOptionalStringWithDefault: v.optional(v.string(), 'Hello World!'), 559 + parameterOptionalStringWithEmptyDefault: v.optional(v.string(), ''), 560 + parameterOptionalStringWithNoDefault: v.optional(v.string()), 561 + parameterStringWithDefault: v.optional(v.string(), 'Hello World!'), 562 + parameterStringWithEmptyDefault: v.optional(v.string(), ''), 563 + parameterStringWithNoDefault: v.string(), 564 + parameterStringNullableWithNoDefault: v.optional(v.union([ 565 + v.string(), 566 + v.null() 567 + ])), 568 + parameterStringNullableWithDefault: v.optional(v.union([ 569 + v.string(), 570 + v.null() 571 + ]), null) 572 + }) 573 + }); 555 574 556 - /** 557 - * This is a optional string with no default 558 - */ 559 - export const vCallToTestOrderOfParamsParameterParameterOptionalStringWithNoDefault = v.string(); 575 + export const vDuplicateNameData = v.object({ 576 + body: v.optional(v.never()), 577 + headers: v.optional(v.never()), 578 + path: v.optional(v.never()), 579 + query: v.optional(v.never()) 580 + }); 560 581 561 - /** 562 - * This is a string with default 563 - */ 564 - export const vCallToTestOrderOfParamsParameterParameterStringWithDefault = v.optional(v.string(), 'Hello World!'); 582 + export const vDuplicateName2Data = v.object({ 583 + body: v.optional(v.never()), 584 + headers: v.optional(v.never()), 585 + path: v.optional(v.never()), 586 + query: v.optional(v.never()) 587 + }); 565 588 566 - /** 567 - * This is a string with empty default 568 - */ 569 - export const vCallToTestOrderOfParamsParameterParameterStringWithEmptyDefault = v.optional(v.string(), ''); 589 + export const vDuplicateName3Data = v.object({ 590 + body: v.optional(v.never()), 591 + headers: v.optional(v.never()), 592 + path: v.optional(v.never()), 593 + query: v.optional(v.never()) 594 + }); 570 595 571 - /** 572 - * This is a string with no default 573 - */ 574 - export const vCallToTestOrderOfParamsParameterParameterStringWithNoDefault = v.string(); 596 + export const vDuplicateName4Data = v.object({ 597 + body: v.optional(v.never()), 598 + headers: v.optional(v.never()), 599 + path: v.optional(v.never()), 600 + query: v.optional(v.never()) 601 + }); 575 602 576 - /** 577 - * This is a string that can be null with no default 578 - */ 579 - export const vCallToTestOrderOfParamsParameterParameterStringNullableWithNoDefault = v.union([ 580 - v.string(), 581 - v.null() 582 - ]); 603 + export const vCallWithNoContentResponseData = v.object({ 604 + body: v.optional(v.never()), 605 + headers: v.optional(v.never()), 606 + path: v.optional(v.never()), 607 + query: v.optional(v.never()) 608 + }); 583 609 584 - /** 585 - * This is a string that can be null with default 586 - */ 587 - export const vCallToTestOrderOfParamsParameterParameterStringNullableWithDefault = v.optional(v.union([ 588 - v.string(), 589 - v.null() 590 - ]), null); 610 + export const vCallWithResponseAndNoContentResponseData = v.object({ 611 + body: v.optional(v.never()), 612 + headers: v.optional(v.never()), 613 + path: v.optional(v.never()), 614 + query: v.optional(v.never()) 615 + }); 591 616 592 617 export const vCallWithResponseAndNoContentResponseResponse = v.union([ 593 618 v.number(), 594 619 v.unknown() 595 620 ]); 596 621 622 + export const vDummyAData = v.object({ 623 + body: v.optional(v.never()), 624 + headers: v.optional(v.never()), 625 + path: v.optional(v.never()), 626 + query: v.optional(v.never()) 627 + }); 628 + 629 + export const vDummyBData = v.object({ 630 + body: v.optional(v.never()), 631 + headers: v.optional(v.never()), 632 + path: v.optional(v.never()), 633 + query: v.optional(v.never()) 634 + }); 635 + 636 + export const vCallWithResponseData = v.object({ 637 + body: v.optional(v.never()), 638 + headers: v.optional(v.never()), 639 + path: v.optional(v.never()), 640 + query: v.optional(v.never()) 641 + }); 642 + 597 643 /** 598 644 * Message for default response 599 645 */ 600 646 export const vCallWithResponseResponse = vModelWithString; 601 647 648 + export const vCallWithDuplicateResponsesData = v.object({ 649 + body: v.optional(v.never()), 650 + headers: v.optional(v.never()), 651 + path: v.optional(v.never()), 652 + query: v.optional(v.never()) 653 + }); 654 + 602 655 /** 603 656 * Message for 201 response 604 657 */ 605 658 export const vCallWithDuplicateResponsesResponse = vModelWithString; 659 + 660 + export const vCallWithResponsesData = v.object({ 661 + body: v.optional(v.never()), 662 + headers: v.optional(v.never()), 663 + path: v.optional(v.never()), 664 + query: v.optional(v.never()) 665 + }); 606 666 607 667 export const vCallWithResponsesResponse = v.union([ 608 668 v.object({ ··· 614 674 vModelThatExtendsExtends 615 675 ]); 616 676 617 - /** 618 - * This is an array parameter that is sent as csv format (comma-separated values) 619 - */ 620 - export const vCollectionFormatParameterParameterArrayCsv = v.array(v.string()); 677 + export const vCollectionFormatData = v.object({ 678 + body: v.optional(v.never()), 679 + headers: v.optional(v.never()), 680 + path: v.optional(v.never()), 681 + query: v.object({ 682 + parameterArrayCSV: v.array(v.string()), 683 + parameterArraySSV: v.array(v.string()), 684 + parameterArrayTSV: v.array(v.string()), 685 + parameterArrayPipes: v.array(v.string()), 686 + parameterArrayMulti: v.array(v.string()) 687 + }) 688 + }); 621 689 622 - /** 623 - * This is an array parameter that is sent as ssv format (space-separated values) 624 - */ 625 - export const vCollectionFormatParameterParameterArraySsv = v.array(v.string()); 626 - 627 - /** 628 - * This is an array parameter that is sent as tsv format (tab-separated values) 629 - */ 630 - export const vCollectionFormatParameterParameterArrayTsv = v.array(v.string()); 631 - 632 - /** 633 - * This is an array parameter that is sent as pipes format (pipe-separated values) 634 - */ 635 - export const vCollectionFormatParameterParameterArrayPipes = v.array(v.string()); 636 - 637 - /** 638 - * This is an array parameter that is sent as multi format (multiple parameter instances) 639 - */ 640 - export const vCollectionFormatParameterParameterArrayMulti = v.array(v.string()); 641 - 642 - /** 643 - * This is a number parameter 644 - */ 645 - export const vTypesParameterId = v.pipe(v.number(), v.integer()); 646 - 647 - /** 648 - * This is a number parameter 649 - */ 650 - export const vTypesParameterParameterNumber = v.optional(v.number(), 123); 651 - 652 - /** 653 - * This is a string parameter 654 - */ 655 - export const vTypesParameterParameterString = v.optional(v.string(), 'default'); 656 - 657 - /** 658 - * This is a boolean parameter 659 - */ 660 - export const vTypesParameterParameterBoolean = v.optional(v.boolean(), true); 661 - 662 - /** 663 - * This is an array parameter 664 - */ 665 - export const vTypesParameterParameterArray = v.array(v.string()); 666 - 667 - /** 668 - * This is a dictionary parameter 669 - */ 670 - export const vTypesParameterParameterDictionary = v.object({}); 671 - 672 - /** 673 - * This is an enum parameter 674 - */ 675 - export const vTypesParameterParameterEnum = v.picklist([ 676 - 'Success', 677 - 'Warning', 678 - 'Error' 679 - ]); 690 + export const vTypesData = v.object({ 691 + body: v.optional(v.never()), 692 + headers: v.optional(v.never()), 693 + path: v.optional(v.object({ 694 + id: v.optional(v.pipe(v.number(), v.integer())) 695 + })), 696 + query: v.object({ 697 + parameterNumber: v.optional(v.number(), 123), 698 + parameterString: v.optional(v.string(), 'default'), 699 + parameterBoolean: v.optional(v.boolean(), true), 700 + parameterArray: v.array(v.string()), 701 + parameterDictionary: v.object({}), 702 + parameterEnum: v.picklist([ 703 + 'Success', 704 + 'Warning', 705 + 'Error' 706 + ]) 707 + }) 708 + }); 680 709 681 710 export const vTypesResponse = v.union([ 682 711 v.number(), ··· 685 714 v.object({}) 686 715 ]); 687 716 688 - /** 689 - * Parameter containing object 690 - */ 691 - export const vComplexTypesParameterParameterObject = v.object({ 692 - first: v.optional(v.object({ 693 - second: v.optional(v.object({ 694 - third: v.optional(v.string()) 695 - })) 696 - })) 697 - }); 698 - 699 - /** 700 - * This is a model with one string property 701 - */ 702 - export const vComplexTypesParameterParameterReference = v.object({ 703 - prop: v.optional(v.string()) 717 + export const vComplexTypesData = v.object({ 718 + body: v.optional(v.never()), 719 + headers: v.optional(v.never()), 720 + path: v.optional(v.never()), 721 + query: v.object({ 722 + parameterObject: v.object({ 723 + first: v.optional(v.object({ 724 + second: v.optional(v.object({ 725 + third: v.optional(v.string()) 726 + })) 727 + })) 728 + }), 729 + parameterReference: v.object({ 730 + prop: v.optional(v.string()) 731 + }) 732 + }) 704 733 }); 705 734 706 735 /** ··· 708 737 */ 709 738 export const vComplexTypesResponse = v.array(vModelWithString); 710 739 711 - /** 712 - * Status code to return 713 - */ 714 - export const vTestErrorCodeParameterStatus = v.string(); 740 + export const vCallWithResultFromHeaderData = v.object({ 741 + body: v.optional(v.never()), 742 + headers: v.optional(v.never()), 743 + path: v.optional(v.never()), 744 + query: v.optional(v.never()) 745 + }); 715 746 716 - /** 717 - * Dummy input param 718 - */ 719 - export const vNonAsciiæøåÆøÅöôêÊ字符串ParameterNonAsciiParamæøåÆøÅöôêÊ = v.pipe(v.number(), v.integer()); 747 + export const vTestErrorCodeData = v.object({ 748 + body: v.optional(v.never()), 749 + headers: v.optional(v.never()), 750 + path: v.optional(v.never()), 751 + query: v.object({ 752 + status: v.string() 753 + }) 754 + }); 755 + 756 + export const vNonAsciiæøåÆøÅöôêÊ字符串Data = v.object({ 757 + body: v.optional(v.never()), 758 + headers: v.optional(v.never()), 759 + path: v.optional(v.never()), 760 + query: v.object({ 761 + 'nonAsciiParamæøåÆØÅöôêÊ': v.pipe(v.number(), v.integer()) 762 + }) 763 + }); 720 764 721 765 /** 722 766 * Successful response 723 767 */ 724 768 export const vNonAsciiæøåÆøÅöôêÊ字符串Response = vNonAsciiStringæøåÆøÅöôêÊ字符串; 725 769 726 - /** 727 - * Body should not be unknown 728 - */ 729 - export const vPostApiVbyApiVersionBodyData = vParameterActivityParams; 770 + export const vPostApiVbyApiVersionBodyData = v.object({ 771 + body: vParameterActivityParams, 772 + headers: v.optional(v.never()), 773 + path: v.optional(v.never()), 774 + query: v.optional(v.never()) 775 + }); 730 776 731 777 /** 732 778 * OK
+7
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts
··· 12 12 foo: v.pipe(v.number(), v.integer()) 13 13 }); 14 14 15 + export const vPostFooData = v.object({ 16 + body: v.optional(v.never()), 17 + headers: v.optional(v.never()), 18 + path: v.optional(v.never()), 19 + query: v.optional(v.never()) 20 + }); 21 + 15 22 /** 16 23 * OK 17 24 */
+536 -493
packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts
··· 1070 1070 1071 1071 export const vSimpleFormData = vModelWithString; 1072 1072 1073 - export const vImportData = v.union([ 1074 - vModelWithReadOnlyAndWriteOnly, 1075 - vModelWithArrayReadOnlyAndWriteOnly 1076 - ]); 1073 + export const vExportData = v.object({ 1074 + body: v.optional(v.never()), 1075 + headers: v.optional(v.never()), 1076 + path: v.optional(v.never()), 1077 + query: v.optional(v.never()) 1078 + }); 1079 + 1080 + export const vPatchApiVbyApiVersionNoTagData = v.object({ 1081 + body: v.optional(v.never()), 1082 + headers: v.optional(v.never()), 1083 + path: v.optional(v.never()), 1084 + query: v.optional(v.never()) 1085 + }); 1086 + 1087 + export const vImportData = v.object({ 1088 + body: v.union([ 1089 + vModelWithReadOnlyAndWriteOnly, 1090 + vModelWithArrayReadOnlyAndWriteOnly 1091 + ]), 1092 + headers: v.optional(v.never()), 1093 + path: v.optional(v.never()), 1094 + query: v.optional(v.never()) 1095 + }); 1077 1096 1078 1097 export const vImportResponse = v.union([ 1079 1098 vModelFromZendesk, 1080 1099 vModelWithReadOnlyAndWriteOnly 1081 1100 ]); 1082 1101 1102 + export const vFooWowData = v.object({ 1103 + body: v.optional(v.never()), 1104 + headers: v.optional(v.never()), 1105 + path: v.optional(v.never()), 1106 + query: v.optional(v.never()) 1107 + }); 1108 + 1109 + export const vApiVVersionODataControllerCountData = v.object({ 1110 + body: v.optional(v.never()), 1111 + headers: v.optional(v.never()), 1112 + path: v.optional(v.never()), 1113 + query: v.optional(v.never()) 1114 + }); 1115 + 1083 1116 /** 1084 1117 * Success 1085 1118 */ 1086 1119 export const vApiVVersionODataControllerCountResponse = vModelFromZendesk; 1087 1120 1088 - /** 1089 - * foo in method 1090 - */ 1091 - export const vGetApiVbyApiVersionSimpleOperationParameterFooParam = v.string(); 1121 + export const vGetApiVbyApiVersionSimpleOperationData = v.object({ 1122 + body: v.optional(v.never()), 1123 + headers: v.optional(v.never()), 1124 + path: v.object({ 1125 + foo_param: v.string() 1126 + }), 1127 + query: v.optional(v.never()) 1128 + }); 1092 1129 1093 1130 /** 1094 1131 * Response is a simple number 1095 1132 */ 1096 1133 export const vGetApiVbyApiVersionSimpleOperationResponse = v.number(); 1097 1134 1098 - /** 1099 - * foo in method 1100 - */ 1101 - export const vDeleteFooParameterFooParam = v.string(); 1135 + export const vDeleteCallWithoutParametersAndResponseData = v.object({ 1136 + body: v.optional(v.never()), 1137 + headers: v.optional(v.never()), 1138 + path: v.optional(v.never()), 1139 + query: v.optional(v.never()) 1140 + }); 1102 1141 1103 - /** 1104 - * bar in method 1105 - */ 1106 - export const vDeleteFooParameterBarParam = v.string(); 1142 + export const vGetCallWithoutParametersAndResponseData = v.object({ 1143 + body: v.optional(v.never()), 1144 + headers: v.optional(v.never()), 1145 + path: v.optional(v.never()), 1146 + query: v.optional(v.never()) 1147 + }); 1107 1148 1108 - /** 1109 - * Parameter with illegal characters 1110 - */ 1111 - export const vDeleteFooParameterXFooBar = vModelWithString; 1149 + export const vHeadCallWithoutParametersAndResponseData = v.object({ 1150 + body: v.optional(v.never()), 1151 + headers: v.optional(v.never()), 1152 + path: v.optional(v.never()), 1153 + query: v.optional(v.never()) 1154 + }); 1112 1155 1113 - /** 1114 - * Testing multiline comments in string: First line 1115 - * Second line 1116 - * 1117 - * Fourth line 1118 - */ 1119 - export const vCallWithDescriptionsParameterParameterWithBreaks = v.string(); 1156 + export const vOptionsCallWithoutParametersAndResponseData = v.object({ 1157 + body: v.optional(v.never()), 1158 + headers: v.optional(v.never()), 1159 + path: v.optional(v.never()), 1160 + query: v.optional(v.never()) 1161 + }); 1120 1162 1121 - /** 1122 - * Testing backticks in string: `backticks` and ```multiple backticks``` should work 1123 - */ 1124 - export const vCallWithDescriptionsParameterParameterWithBackticks = v.string(); 1163 + export const vPatchCallWithoutParametersAndResponseData = v.object({ 1164 + body: v.optional(v.never()), 1165 + headers: v.optional(v.never()), 1166 + path: v.optional(v.never()), 1167 + query: v.optional(v.never()) 1168 + }); 1125 1169 1126 - /** 1127 - * Testing slashes in string: \backwards\\\ and /forwards/// should work 1128 - */ 1129 - export const vCallWithDescriptionsParameterParameterWithSlashes = v.string(); 1170 + export const vPostCallWithoutParametersAndResponseData = v.object({ 1171 + body: v.optional(v.never()), 1172 + headers: v.optional(v.never()), 1173 + path: v.optional(v.never()), 1174 + query: v.optional(v.never()) 1175 + }); 1130 1176 1131 - /** 1132 - * Testing expression placeholders in string: ${expression} should work 1133 - */ 1134 - export const vCallWithDescriptionsParameterParameterWithExpressionPlaceholders = v.string(); 1177 + export const vPutCallWithoutParametersAndResponseData = v.object({ 1178 + body: v.optional(v.never()), 1179 + headers: v.optional(v.never()), 1180 + path: v.optional(v.never()), 1181 + query: v.optional(v.never()) 1182 + }); 1135 1183 1136 - /** 1137 - * Testing quotes in string: 'single quote''' and "double quotes""" should work 1138 - */ 1139 - export const vCallWithDescriptionsParameterParameterWithQuotes = v.string(); 1184 + export const vDeleteFooData3 = v.object({ 1185 + body: v.optional(v.never()), 1186 + headers: v.object({ 1187 + 'x-Foo-Bar': vModelWithString 1188 + }), 1189 + path: v.object({ 1190 + foo_param: v.string(), 1191 + BarParam: v.string() 1192 + }), 1193 + query: v.optional(v.never()) 1194 + }); 1140 1195 1141 - /** 1142 - * Testing reserved characters in string: * inline * and ** inline ** should work 1143 - */ 1144 - export const vCallWithDescriptionsParameterParameterWithReservedCharacters = v.string(); 1196 + export const vCallWithDescriptionsData = v.object({ 1197 + body: v.optional(v.never()), 1198 + headers: v.optional(v.never()), 1199 + path: v.optional(v.never()), 1200 + query: v.optional(v.object({ 1201 + parameterWithBreaks: v.optional(v.string()), 1202 + parameterWithBackticks: v.optional(v.string()), 1203 + parameterWithSlashes: v.optional(v.string()), 1204 + parameterWithExpressionPlaceholders: v.optional(v.string()), 1205 + parameterWithQuotes: v.optional(v.string()), 1206 + parameterWithReservedCharacters: v.optional(v.string()) 1207 + })) 1208 + }); 1145 1209 1146 - /** 1147 - * This parameter is deprecated 1148 - * @deprecated 1149 - */ 1150 - export const vDeprecatedCallParameterParameter = v.union([ 1151 - vDeprecatedModel, 1152 - v.null() 1153 - ]); 1210 + export const vDeprecatedCallData = v.object({ 1211 + body: v.optional(v.never()), 1212 + headers: v.optional(v.object({ 1213 + parameter: v.union([ 1214 + vDeprecatedModel, 1215 + v.null() 1216 + ]) 1217 + })), 1218 + path: v.optional(v.never()), 1219 + query: v.optional(v.never()) 1220 + }); 1154 1221 1155 - /** 1156 - * This is the parameter that goes into the body 1157 - */ 1158 - export const vCallWithParametersData = v.union([ 1159 - v.object({}), 1160 - v.null() 1161 - ]); 1222 + export const vCallWithParametersData = v.object({ 1223 + body: v.union([ 1224 + v.object({}), 1225 + v.null() 1226 + ]), 1227 + headers: v.object({ 1228 + parameterHeader: v.union([ 1229 + v.string(), 1230 + v.null() 1231 + ]) 1232 + }), 1233 + path: v.object({ 1234 + parameterPath: v.union([ 1235 + v.string(), 1236 + v.null() 1237 + ]), 1238 + 'api-version': v.union([ 1239 + v.string(), 1240 + v.null() 1241 + ]) 1242 + }), 1243 + query: v.object({ 1244 + foo_ref_enum: v.optional(vModelWithNestedArrayEnumsDataFoo), 1245 + foo_all_of_enum: vModelWithNestedArrayEnumsDataFoo, 1246 + cursor: v.union([ 1247 + v.string(), 1248 + v.null() 1249 + ]) 1250 + }) 1251 + }); 1162 1252 1163 - /** 1164 - * This is the parameter that goes into the cookie 1165 - */ 1166 - export const vCallWithParametersParameterParameterCookie = v.union([ 1167 - v.string(), 1168 - v.null() 1169 - ]); 1253 + export const vCallWithWeirdParameterNamesData = v.object({ 1254 + body: v.union([ 1255 + vModelWithString, 1256 + v.null() 1257 + ]), 1258 + headers: v.object({ 1259 + 'parameter.header': v.union([ 1260 + v.string(), 1261 + v.null() 1262 + ]) 1263 + }), 1264 + path: v.object({ 1265 + 'parameter.path.1': v.optional(v.string()), 1266 + 'parameter-path-2': v.optional(v.string()), 1267 + 'PARAMETER-PATH-3': v.optional(v.string()), 1268 + 'api-version': v.union([ 1269 + v.string(), 1270 + v.null() 1271 + ]) 1272 + }), 1273 + query: v.object({ 1274 + default: v.optional(v.string()), 1275 + 'parameter-query': v.union([ 1276 + v.string(), 1277 + v.null() 1278 + ]) 1279 + }) 1280 + }); 1170 1281 1171 - /** 1172 - * This is the parameter that goes into the header 1173 - */ 1174 - export const vCallWithParametersParameterParameterHeader = v.union([ 1175 - v.string(), 1176 - v.null() 1177 - ]); 1282 + export const vGetCallWithOptionalParamData = v.object({ 1283 + body: vModelWithOneOfEnum, 1284 + headers: v.optional(v.never()), 1285 + path: v.optional(v.never()), 1286 + query: v.optional(v.object({ 1287 + page: v.optional(v.number()) 1288 + })) 1289 + }); 1178 1290 1179 - /** 1180 - * This is the parameter that goes into the path 1181 - */ 1182 - export const vCallWithParametersParameterParameterPath = v.union([ 1183 - v.string(), 1184 - v.null() 1185 - ]); 1186 - 1187 - /** 1188 - * api-version should be required in standalone clients 1189 - */ 1190 - export const vCallWithParametersParameterApiVersion = v.union([ 1191 - v.string(), 1192 - v.null() 1193 - ]); 1194 - 1195 - export const vCallWithParametersParameterFooRefEnum = vModelWithNestedArrayEnumsDataFoo; 1196 - 1197 - export const vCallWithParametersParameterFooAllOfEnum = vModelWithNestedArrayEnumsDataFoo; 1198 - 1199 - /** 1200 - * This is the parameter that goes into the query params 1201 - */ 1202 - export const vCallWithParametersParameterCursor = v.union([ 1203 - v.string(), 1204 - v.null() 1205 - ]); 1206 - 1207 - /** 1208 - * This is the parameter that goes into the body 1209 - */ 1210 - export const vCallWithWeirdParameterNamesData = v.union([ 1211 - vModelWithString, 1212 - v.null() 1213 - ]); 1214 - 1215 - /** 1216 - * This is the parameter that goes into the cookie 1217 - */ 1218 - export const vCallWithWeirdParameterNamesParameterParameterCookie = v.union([ 1219 - v.string(), 1220 - v.null() 1221 - ]); 1222 - 1223 - /** 1224 - * This is the parameter that goes into the request header 1225 - */ 1226 - export const vCallWithWeirdParameterNamesParameterParameterHeader = v.union([ 1227 - v.string(), 1228 - v.null() 1229 - ]); 1230 - 1231 - /** 1232 - * This is the parameter that goes into the path 1233 - */ 1234 - export const vCallWithWeirdParameterNamesParameterParameterPath1 = v.string(); 1235 - 1236 - /** 1237 - * This is the parameter that goes into the path 1238 - */ 1239 - export const vCallWithWeirdParameterNamesParameterParameterPath2 = v.string(); 1240 - 1241 - /** 1242 - * This is the parameter that goes into the path 1243 - */ 1244 - export const vCallWithWeirdParameterNamesParameterParameterPath3 = v.string(); 1245 - 1246 - /** 1247 - * api-version should be required in standalone clients 1248 - */ 1249 - export const vCallWithWeirdParameterNamesParameterApiVersion = v.union([ 1250 - v.string(), 1251 - v.null() 1252 - ]); 1253 - 1254 - /** 1255 - * This is the parameter with a reserved keyword 1256 - */ 1257 - export const vCallWithWeirdParameterNamesParameterDefault = v.string(); 1258 - 1259 - /** 1260 - * This is the parameter that goes into the request query params 1261 - */ 1262 - export const vCallWithWeirdParameterNamesParameterParameterQuery = v.union([ 1263 - v.string(), 1264 - v.null() 1265 - ]); 1266 - 1267 - /** 1268 - * This is a required parameter 1269 - */ 1270 - export const vGetCallWithOptionalParamData = vModelWithOneOfEnum; 1271 - 1272 - /** 1273 - * This is an optional parameter 1274 - */ 1275 - export const vGetCallWithOptionalParamParameterPage = v.number(); 1276 - 1277 - /** 1278 - * This is an optional parameter 1279 - */ 1280 1291 export const vPostCallWithOptionalParamData = v.object({ 1281 - offset: v.optional(v.union([ 1282 - v.number(), 1283 - v.null() 1284 - ])) 1292 + body: v.optional(v.object({ 1293 + offset: v.optional(v.union([ 1294 + v.number(), 1295 + v.null() 1296 + ])) 1297 + })), 1298 + headers: v.optional(v.never()), 1299 + path: v.optional(v.never()), 1300 + query: v.object({ 1301 + parameter: vPageable 1302 + }) 1285 1303 }); 1286 - 1287 - /** 1288 - * This is a required parameter 1289 - */ 1290 - export const vPostCallWithOptionalParamParameterParameter = vPageable; 1291 1304 1292 1305 export const vPostCallWithOptionalParamResponse = v.union([ 1293 1306 v.number(), 1294 1307 v.void() 1295 1308 ]); 1296 1309 1297 - /** 1298 - * A reusable request body 1299 - */ 1300 - export const vPostApiVbyApiVersionRequestBodyData = vSimpleRequestBody; 1310 + export const vPostApiVbyApiVersionRequestBodyData = v.object({ 1311 + body: v.optional(vSimpleRequestBody), 1312 + headers: v.optional(v.never()), 1313 + path: v.optional(v.never()), 1314 + query: v.optional(v.object({ 1315 + parameter: v.optional(v.string()) 1316 + })) 1317 + }); 1301 1318 1302 - /** 1303 - * This is a reusable parameter 1304 - */ 1305 - export const vPostApiVbyApiVersionRequestBodyParameterParameter = v.string(); 1319 + export const vPostApiVbyApiVersionFormDataData = v.object({ 1320 + body: v.optional(vSimpleFormData), 1321 + headers: v.optional(v.never()), 1322 + path: v.optional(v.never()), 1323 + query: v.optional(v.object({ 1324 + parameter: v.optional(v.string()) 1325 + })) 1326 + }); 1306 1327 1307 - /** 1308 - * A reusable request body 1309 - */ 1310 - export const vPostApiVbyApiVersionFormDataData = vSimpleFormData; 1328 + export const vCallWithDefaultParametersData = v.object({ 1329 + body: v.optional(v.never()), 1330 + headers: v.optional(v.never()), 1331 + path: v.optional(v.never()), 1332 + query: v.optional(v.object({ 1333 + parameterString: v.optional(v.union([ 1334 + v.optional(v.string(), 'Hello World!'), 1335 + v.null() 1336 + ]), 'Hello World!'), 1337 + parameterNumber: v.optional(v.union([ 1338 + v.optional(v.number(), 123), 1339 + v.null() 1340 + ]), 123), 1341 + parameterBoolean: v.optional(v.union([ 1342 + v.optional(v.boolean(), true), 1343 + v.null() 1344 + ]), true), 1345 + parameterEnum: v.optional(v.picklist([ 1346 + 'Success', 1347 + 'Warning', 1348 + 'Error' 1349 + ])), 1350 + parameterModel: v.optional(v.union([ 1351 + vModelWithString, 1352 + v.null() 1353 + ])) 1354 + })) 1355 + }); 1311 1356 1312 - /** 1313 - * This is a reusable parameter 1314 - */ 1315 - export const vPostApiVbyApiVersionFormDataParameterParameter = v.string(); 1357 + export const vCallWithDefaultOptionalParametersData = v.object({ 1358 + body: v.optional(v.never()), 1359 + headers: v.optional(v.never()), 1360 + path: v.optional(v.never()), 1361 + query: v.optional(v.object({ 1362 + parameterString: v.optional(v.string(), 'Hello World!'), 1363 + parameterNumber: v.optional(v.number(), 123), 1364 + parameterBoolean: v.optional(v.boolean(), true), 1365 + parameterEnum: v.optional(v.picklist([ 1366 + 'Success', 1367 + 'Warning', 1368 + 'Error' 1369 + ])), 1370 + parameterModel: v.optional(vModelWithString) 1371 + })) 1372 + }); 1316 1373 1317 - /** 1318 - * This is a simple string with default value 1319 - */ 1320 - export const vCallWithDefaultParametersParameterParameterString = v.optional(v.union([ 1321 - v.optional(v.string(), 'Hello World!'), 1322 - v.null() 1323 - ]), 'Hello World!'); 1374 + export const vCallToTestOrderOfParamsData = v.object({ 1375 + body: v.optional(v.never()), 1376 + headers: v.optional(v.never()), 1377 + path: v.optional(v.never()), 1378 + query: v.object({ 1379 + parameterOptionalStringWithDefault: v.optional(v.string(), 'Hello World!'), 1380 + parameterOptionalStringWithEmptyDefault: v.optional(v.string(), ''), 1381 + parameterOptionalStringWithNoDefault: v.optional(v.string()), 1382 + parameterStringWithDefault: v.optional(v.string(), 'Hello World!'), 1383 + parameterStringWithEmptyDefault: v.optional(v.string(), ''), 1384 + parameterStringWithNoDefault: v.string(), 1385 + parameterStringNullableWithNoDefault: v.optional(v.union([ 1386 + v.string(), 1387 + v.null() 1388 + ])), 1389 + parameterStringNullableWithDefault: v.optional(v.union([ 1390 + v.string(), 1391 + v.null() 1392 + ]), null) 1393 + }) 1394 + }); 1324 1395 1325 - /** 1326 - * This is a simple number with default value 1327 - */ 1328 - export const vCallWithDefaultParametersParameterParameterNumber = v.optional(v.union([ 1329 - v.optional(v.number(), 123), 1330 - v.null() 1331 - ]), 123); 1396 + export const vDuplicateNameData = v.object({ 1397 + body: v.optional(v.never()), 1398 + headers: v.optional(v.never()), 1399 + path: v.optional(v.never()), 1400 + query: v.optional(v.never()) 1401 + }); 1332 1402 1333 - /** 1334 - * This is a simple boolean with default value 1335 - */ 1336 - export const vCallWithDefaultParametersParameterParameterBoolean = v.optional(v.union([ 1337 - v.optional(v.boolean(), true), 1338 - v.null() 1339 - ]), true); 1403 + export const vDuplicateName2Data = v.object({ 1404 + body: v.optional(v.never()), 1405 + headers: v.optional(v.never()), 1406 + path: v.optional(v.never()), 1407 + query: v.optional(v.never()) 1408 + }); 1340 1409 1341 - /** 1342 - * This is a simple enum with default value 1343 - */ 1344 - export const vCallWithDefaultParametersParameterParameterEnum = v.picklist([ 1345 - 'Success', 1346 - 'Warning', 1347 - 'Error' 1348 - ]); 1410 + export const vDuplicateName3Data = v.object({ 1411 + body: v.optional(v.never()), 1412 + headers: v.optional(v.never()), 1413 + path: v.optional(v.never()), 1414 + query: v.optional(v.never()) 1415 + }); 1349 1416 1350 - /** 1351 - * This is a simple model with default value 1352 - */ 1353 - export const vCallWithDefaultParametersParameterParameterModel = v.union([ 1354 - vModelWithString, 1355 - v.null() 1356 - ]); 1417 + export const vDuplicateName4Data = v.object({ 1418 + body: v.optional(v.never()), 1419 + headers: v.optional(v.never()), 1420 + path: v.optional(v.never()), 1421 + query: v.optional(v.never()) 1422 + }); 1357 1423 1358 - /** 1359 - * This is a simple string that is optional with default value 1360 - */ 1361 - export const vCallWithDefaultOptionalParametersParameterParameterString = v.optional(v.string(), 'Hello World!'); 1362 - 1363 - /** 1364 - * This is a simple number that is optional with default value 1365 - */ 1366 - export const vCallWithDefaultOptionalParametersParameterParameterNumber = v.optional(v.number(), 123); 1367 - 1368 - /** 1369 - * This is a simple boolean that is optional with default value 1370 - */ 1371 - export const vCallWithDefaultOptionalParametersParameterParameterBoolean = v.optional(v.boolean(), true); 1372 - 1373 - /** 1374 - * This is a simple enum that is optional with default value 1375 - */ 1376 - export const vCallWithDefaultOptionalParametersParameterParameterEnum = v.picklist([ 1377 - 'Success', 1378 - 'Warning', 1379 - 'Error' 1380 - ]); 1381 - 1382 - /** 1383 - * This is a simple model that is optional with default value 1384 - */ 1385 - export const vCallWithDefaultOptionalParametersParameterParameterModel = vModelWithString; 1386 - 1387 - /** 1388 - * This is a optional string with default 1389 - */ 1390 - export const vCallToTestOrderOfParamsParameterParameterOptionalStringWithDefault = v.optional(v.string(), 'Hello World!'); 1391 - 1392 - /** 1393 - * This is a optional string with empty default 1394 - */ 1395 - export const vCallToTestOrderOfParamsParameterParameterOptionalStringWithEmptyDefault = v.optional(v.string(), ''); 1396 - 1397 - /** 1398 - * This is a optional string with no default 1399 - */ 1400 - export const vCallToTestOrderOfParamsParameterParameterOptionalStringWithNoDefault = v.string(); 1401 - 1402 - /** 1403 - * This is a string with default 1404 - */ 1405 - export const vCallToTestOrderOfParamsParameterParameterStringWithDefault = v.optional(v.string(), 'Hello World!'); 1406 - 1407 - /** 1408 - * This is a string with empty default 1409 - */ 1410 - export const vCallToTestOrderOfParamsParameterParameterStringWithEmptyDefault = v.optional(v.string(), ''); 1411 - 1412 - /** 1413 - * This is a string with no default 1414 - */ 1415 - export const vCallToTestOrderOfParamsParameterParameterStringWithNoDefault = v.string(); 1416 - 1417 - /** 1418 - * This is a string that can be null with no default 1419 - */ 1420 - export const vCallToTestOrderOfParamsParameterParameterStringNullableWithNoDefault = v.union([ 1421 - v.string(), 1422 - v.null() 1423 - ]); 1424 - 1425 - /** 1426 - * This is a string that can be null with default 1427 - */ 1428 - export const vCallToTestOrderOfParamsParameterParameterStringNullableWithDefault = v.optional(v.union([ 1429 - v.string(), 1430 - v.null() 1431 - ]), null); 1424 + export const vCallWithNoContentResponseData = v.object({ 1425 + body: v.optional(v.never()), 1426 + headers: v.optional(v.never()), 1427 + path: v.optional(v.never()), 1428 + query: v.optional(v.never()) 1429 + }); 1432 1430 1433 1431 /** 1434 1432 * Success 1435 1433 */ 1436 1434 export const vCallWithNoContentResponseResponse = v.void(); 1437 1435 1436 + export const vCallWithResponseAndNoContentResponseData = v.object({ 1437 + body: v.optional(v.never()), 1438 + headers: v.optional(v.never()), 1439 + path: v.optional(v.never()), 1440 + query: v.optional(v.never()) 1441 + }); 1442 + 1438 1443 export const vCallWithResponseAndNoContentResponseResponse = v.union([ 1439 1444 v.number(), 1440 1445 v.void() 1441 1446 ]); 1447 + 1448 + export const vDummyAData = v.object({ 1449 + body: v.optional(v.never()), 1450 + headers: v.optional(v.never()), 1451 + path: v.optional(v.never()), 1452 + query: v.optional(v.never()) 1453 + }); 1442 1454 1443 1455 export const vDummyAResponse = v400; 1444 1456 1457 + export const vDummyBData = v.object({ 1458 + body: v.optional(v.never()), 1459 + headers: v.optional(v.never()), 1460 + path: v.optional(v.never()), 1461 + query: v.optional(v.never()) 1462 + }); 1463 + 1445 1464 /** 1446 1465 * Success 1447 1466 */ 1448 1467 export const vDummyBResponse = v.void(); 1449 1468 1469 + export const vCallWithResponseData = v.object({ 1470 + body: v.optional(v.never()), 1471 + headers: v.optional(v.never()), 1472 + path: v.optional(v.never()), 1473 + query: v.optional(v.never()) 1474 + }); 1475 + 1450 1476 export const vCallWithResponseResponse = vImport; 1451 1477 1478 + export const vCallWithDuplicateResponsesData = v.object({ 1479 + body: v.optional(v.never()), 1480 + headers: v.optional(v.never()), 1481 + path: v.optional(v.never()), 1482 + query: v.optional(v.never()) 1483 + }); 1484 + 1452 1485 export const vCallWithDuplicateResponsesResponse = v.union([ 1453 1486 v.intersect([ 1454 1487 vModelWithBoolean, ··· 1457 1490 vModelWithString 1458 1491 ]); 1459 1492 1493 + export const vCallWithResponsesData = v.object({ 1494 + body: v.optional(v.never()), 1495 + headers: v.optional(v.never()), 1496 + path: v.optional(v.never()), 1497 + query: v.optional(v.never()) 1498 + }); 1499 + 1460 1500 export const vCallWithResponsesResponse = v.union([ 1461 1501 v.object({ 1462 1502 '@namespace.string': v.optional(v.pipe(v.string(), v.readonly())), ··· 1467 1507 vModelThatExtendsExtends 1468 1508 ]); 1469 1509 1470 - /** 1471 - * This is an array parameter that is sent as csv format (comma-separated values) 1472 - */ 1473 - export const vCollectionFormatParameterParameterArrayCsv = v.union([ 1474 - v.array(v.string()), 1475 - v.null() 1476 - ]); 1477 - 1478 - /** 1479 - * This is an array parameter that is sent as ssv format (space-separated values) 1480 - */ 1481 - export const vCollectionFormatParameterParameterArraySsv = v.union([ 1482 - v.array(v.string()), 1483 - v.null() 1484 - ]); 1485 - 1486 - /** 1487 - * This is an array parameter that is sent as tsv format (tab-separated values) 1488 - */ 1489 - export const vCollectionFormatParameterParameterArrayTsv = v.union([ 1490 - v.array(v.string()), 1491 - v.null() 1492 - ]); 1493 - 1494 - /** 1495 - * This is an array parameter that is sent as pipes format (pipe-separated values) 1496 - */ 1497 - export const vCollectionFormatParameterParameterArrayPipes = v.union([ 1498 - v.array(v.string()), 1499 - v.null() 1500 - ]); 1501 - 1502 - /** 1503 - * This is an array parameter that is sent as multi format (multiple parameter instances) 1504 - */ 1505 - export const vCollectionFormatParameterParameterArrayMulti = v.union([ 1506 - v.array(v.string()), 1507 - v.null() 1508 - ]); 1509 - 1510 - /** 1511 - * This is a number parameter 1512 - */ 1513 - export const vTypesParameterId = v.pipe(v.number(), v.integer()); 1514 - 1515 - /** 1516 - * This is a number parameter 1517 - */ 1518 - export const vTypesParameterParameterNumber = v.optional(v.number(), 123); 1519 - 1520 - /** 1521 - * This is a string parameter 1522 - */ 1523 - export const vTypesParameterParameterString = v.optional(v.union([ 1524 - v.optional(v.string(), 'default'), 1525 - v.null() 1526 - ]), 'default'); 1527 - 1528 - /** 1529 - * This is a boolean parameter 1530 - */ 1531 - export const vTypesParameterParameterBoolean = v.optional(v.union([ 1532 - v.optional(v.boolean(), true), 1533 - v.null() 1534 - ]), true); 1535 - 1536 - /** 1537 - * This is an object parameter 1538 - */ 1539 - export const vTypesParameterParameterObject = v.optional(v.union([ 1540 - v.object({}), 1541 - v.null() 1542 - ]), null); 1543 - 1544 - /** 1545 - * This is an array parameter 1546 - */ 1547 - export const vTypesParameterParameterArray = v.union([ 1548 - v.array(v.string()), 1549 - v.null() 1550 - ]); 1551 - 1552 - /** 1553 - * This is a dictionary parameter 1554 - */ 1555 - export const vTypesParameterParameterDictionary = v.union([ 1556 - v.object({}), 1557 - v.null() 1558 - ]); 1510 + export const vCollectionFormatData = v.object({ 1511 + body: v.optional(v.never()), 1512 + headers: v.optional(v.never()), 1513 + path: v.optional(v.never()), 1514 + query: v.object({ 1515 + parameterArrayCSV: v.union([ 1516 + v.array(v.string()), 1517 + v.null() 1518 + ]), 1519 + parameterArraySSV: v.union([ 1520 + v.array(v.string()), 1521 + v.null() 1522 + ]), 1523 + parameterArrayTSV: v.union([ 1524 + v.array(v.string()), 1525 + v.null() 1526 + ]), 1527 + parameterArrayPipes: v.union([ 1528 + v.array(v.string()), 1529 + v.null() 1530 + ]), 1531 + parameterArrayMulti: v.union([ 1532 + v.array(v.string()), 1533 + v.null() 1534 + ]) 1535 + }) 1536 + }); 1559 1537 1560 - /** 1561 - * This is an enum parameter 1562 - */ 1563 - export const vTypesParameterParameterEnum = v.picklist([ 1564 - 'Success', 1565 - 'Warning', 1566 - 'Error' 1567 - ]); 1538 + export const vTypesData = v.object({ 1539 + body: v.optional(v.never()), 1540 + headers: v.optional(v.never()), 1541 + path: v.optional(v.object({ 1542 + id: v.optional(v.pipe(v.number(), v.integer())) 1543 + })), 1544 + query: v.object({ 1545 + parameterNumber: v.optional(v.number(), 123), 1546 + parameterString: v.optional(v.union([ 1547 + v.optional(v.string(), 'default'), 1548 + v.null() 1549 + ]), 'default'), 1550 + parameterBoolean: v.optional(v.union([ 1551 + v.optional(v.boolean(), true), 1552 + v.null() 1553 + ]), true), 1554 + parameterObject: v.optional(v.union([ 1555 + v.object({}), 1556 + v.null() 1557 + ]), null), 1558 + parameterArray: v.union([ 1559 + v.array(v.string()), 1560 + v.null() 1561 + ]), 1562 + parameterDictionary: v.union([ 1563 + v.object({}), 1564 + v.null() 1565 + ]), 1566 + parameterEnum: v.picklist([ 1567 + 'Success', 1568 + 'Warning', 1569 + 'Error' 1570 + ]) 1571 + }) 1572 + }); 1568 1573 1569 1574 export const vTypesResponse = v.union([ 1570 1575 v.number(), ··· 1573 1578 v.object({}) 1574 1579 ]); 1575 1580 1576 - export const vUploadFileData = v.string(); 1577 - 1578 - /** 1579 - * api-version should be required in standalone clients 1580 - */ 1581 - export const vUploadFileParameterApiVersion = v.union([ 1582 - v.string(), 1583 - v.null() 1584 - ]); 1581 + export const vUploadFileData = v.object({ 1582 + body: v.string(), 1583 + headers: v.optional(v.never()), 1584 + path: v.object({ 1585 + 'api-version': v.union([ 1586 + v.string(), 1587 + v.null() 1588 + ]) 1589 + }), 1590 + query: v.optional(v.never()) 1591 + }); 1585 1592 1586 1593 export const vUploadFileResponse = v.boolean(); 1587 1594 1588 - export const vFileResponseParameterId = v.string(); 1589 - 1590 - /** 1591 - * api-version should be required in standalone clients 1592 - */ 1593 - export const vFileResponseParameterApiVersion = v.string(); 1595 + export const vFileResponseData = v.object({ 1596 + body: v.optional(v.never()), 1597 + headers: v.optional(v.never()), 1598 + path: v.object({ 1599 + id: v.string(), 1600 + 'api-version': v.string() 1601 + }), 1602 + query: v.optional(v.never()) 1603 + }); 1594 1604 1595 1605 /** 1596 1606 * Success 1597 1607 */ 1598 1608 export const vFileResponseResponse = v.string(); 1599 1609 1600 - /** 1601 - * Parameter containing object 1602 - */ 1603 - export const vComplexTypesParameterParameterObject = v.object({ 1604 - first: v.optional(v.object({ 1605 - second: v.optional(v.object({ 1606 - third: v.optional(v.string()) 1607 - })) 1608 - })) 1610 + export const vComplexTypesData = v.object({ 1611 + body: v.optional(v.never()), 1612 + headers: v.optional(v.never()), 1613 + path: v.optional(v.never()), 1614 + query: v.object({ 1615 + parameterObject: v.object({ 1616 + first: v.optional(v.object({ 1617 + second: v.optional(v.object({ 1618 + third: v.optional(v.string()) 1619 + })) 1620 + })) 1621 + }), 1622 + parameterReference: vModelWithString 1623 + }) 1609 1624 }); 1610 1625 1611 1626 /** 1612 - * Parameter containing reference 1613 - */ 1614 - export const vComplexTypesParameterParameterReference = vModelWithString; 1615 - 1616 - /** 1617 1627 * Successful response 1618 1628 */ 1619 1629 export const vComplexTypesResponse = v.array(vModelWithString); 1630 + 1631 + export const vMultipartResponseData = v.object({ 1632 + body: v.optional(v.never()), 1633 + headers: v.optional(v.never()), 1634 + path: v.optional(v.never()), 1635 + query: v.optional(v.never()) 1636 + }); 1620 1637 1621 1638 /** 1622 1639 * OK ··· 1630 1647 }); 1631 1648 1632 1649 export const vMultipartRequestData = v.object({ 1633 - content: v.optional(v.string()), 1634 - data: v.optional(v.union([ 1635 - vModelWithString, 1636 - v.null() 1637 - ])) 1650 + body: v.optional(v.object({ 1651 + content: v.optional(v.string()), 1652 + data: v.optional(v.union([ 1653 + vModelWithString, 1654 + v.null() 1655 + ])) 1656 + })), 1657 + headers: v.optional(v.never()), 1658 + path: v.optional(v.never()), 1659 + query: v.optional(v.never()) 1638 1660 }); 1639 1661 1640 1662 export const vComplexParamsData = v.object({ 1641 - key: v.pipe(v.union([ 1642 - v.pipe(v.pipe(v.string(), v.maxLength(64), v.regex(/^[a-zA-Z0-9_]*$/)), v.readonly()), 1643 - v.null() 1644 - ]), v.readonly()), 1645 - name: v.union([ 1646 - v.pipe(v.string(), v.maxLength(255)), 1647 - v.null() 1648 - ]), 1649 - enabled: v.optional(v.boolean(), true), 1650 - type: v.picklist([ 1651 - 'Monkey', 1652 - 'Horse', 1653 - 'Bird' 1654 - ]), 1655 - listOfModels: v.optional(v.union([ 1656 - v.array(vModelWithString), 1657 - v.null() 1658 - ])), 1659 - listOfStrings: v.optional(v.union([ 1660 - v.array(v.string()), 1661 - v.null() 1662 - ])), 1663 - parameters: v.union([ 1664 - vModelWithString, 1665 - vModelWithEnum, 1666 - vModelWithArray, 1667 - vModelWithDictionary 1668 - ]), 1669 - user: v.optional(v.pipe(v.object({ 1670 - id: v.optional(v.pipe(v.pipe(v.number(), v.integer()), v.readonly())), 1671 - name: v.optional(v.pipe(v.union([ 1672 - v.pipe(v.string(), v.readonly()), 1663 + body: v.optional(v.object({ 1664 + key: v.pipe(v.union([ 1665 + v.pipe(v.pipe(v.string(), v.maxLength(64), v.regex(/^[a-zA-Z0-9_]*$/)), v.readonly()), 1673 1666 v.null() 1674 - ]), v.readonly())) 1675 - }), v.readonly())) 1667 + ]), v.readonly()), 1668 + name: v.union([ 1669 + v.pipe(v.string(), v.maxLength(255)), 1670 + v.null() 1671 + ]), 1672 + enabled: v.optional(v.boolean(), true), 1673 + type: v.picklist([ 1674 + 'Monkey', 1675 + 'Horse', 1676 + 'Bird' 1677 + ]), 1678 + listOfModels: v.optional(v.union([ 1679 + v.array(vModelWithString), 1680 + v.null() 1681 + ])), 1682 + listOfStrings: v.optional(v.union([ 1683 + v.array(v.string()), 1684 + v.null() 1685 + ])), 1686 + parameters: v.union([ 1687 + vModelWithString, 1688 + vModelWithEnum, 1689 + vModelWithArray, 1690 + vModelWithDictionary 1691 + ]), 1692 + user: v.optional(v.pipe(v.object({ 1693 + id: v.optional(v.pipe(v.pipe(v.number(), v.integer()), v.readonly())), 1694 + name: v.optional(v.pipe(v.union([ 1695 + v.pipe(v.string(), v.readonly()), 1696 + v.null() 1697 + ]), v.readonly())) 1698 + }), v.readonly())) 1699 + })), 1700 + headers: v.optional(v.never()), 1701 + path: v.object({ 1702 + id: v.pipe(v.number(), v.integer()), 1703 + 'api-version': v.string() 1704 + }), 1705 + query: v.optional(v.never()) 1676 1706 }); 1677 1707 1678 - export const vComplexParamsParameterId = v.pipe(v.number(), v.integer()); 1679 - 1680 - /** 1681 - * api-version should be required in standalone clients 1682 - */ 1683 - export const vComplexParamsParameterApiVersion = v.string(); 1684 - 1685 1708 /** 1686 1709 * Success 1687 1710 */ 1688 1711 export const vComplexParamsResponse = vModelWithString; 1689 1712 1690 - /** 1691 - * Status code to return 1692 - */ 1693 - export const vTestErrorCodeParameterStatus = v.pipe(v.number(), v.integer()); 1713 + export const vCallWithResultFromHeaderData = v.object({ 1714 + body: v.optional(v.never()), 1715 + headers: v.optional(v.never()), 1716 + path: v.optional(v.never()), 1717 + query: v.optional(v.never()) 1718 + }); 1694 1719 1695 - /** 1696 - * Dummy input param 1697 - */ 1698 - export const vNonAsciiæøåÆøÅöôêÊ字符串ParameterNonAsciiParamæøåÆøÅöôêÊ = v.pipe(v.number(), v.integer()); 1720 + export const vTestErrorCodeData = v.object({ 1721 + body: v.optional(v.never()), 1722 + headers: v.optional(v.never()), 1723 + path: v.optional(v.never()), 1724 + query: v.object({ 1725 + status: v.pipe(v.number(), v.integer()) 1726 + }) 1727 + }); 1728 + 1729 + export const vNonAsciiæøåÆøÅöôêÊ字符串Data = v.object({ 1730 + body: v.optional(v.never()), 1731 + headers: v.optional(v.never()), 1732 + path: v.optional(v.never()), 1733 + query: v.object({ 1734 + 'nonAsciiParamæøåÆØÅöôêÊ': v.pipe(v.number(), v.integer()) 1735 + }) 1736 + }); 1699 1737 1700 1738 /** 1701 1739 * Successful response 1702 1740 */ 1703 1741 export const vNonAsciiæøåÆøÅöôêÊ字符串Response = v.array(vNonAsciiStringæøåÆøÅöôêÊ字符串); 1704 1742 1705 - export const vPutWithFormUrlEncodedData = vArrayWithStrings; 1743 + export const vPutWithFormUrlEncodedData = v.object({ 1744 + body: vArrayWithStrings, 1745 + headers: v.optional(v.never()), 1746 + path: v.optional(v.never()), 1747 + query: v.optional(v.never()) 1748 + });
+7
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts
··· 12 12 foo: v.pipe(v.number(), v.integer()) 13 13 }); 14 14 15 + export const vPostFooData = v.object({ 16 + body: v.optional(v.never()), 17 + headers: v.optional(v.never()), 18 + path: v.optional(v.never()), 19 + query: v.optional(v.never()) 20 + }); 21 + 15 22 /** 16 23 * OK 17 24 */
+540 -497
packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts
··· 1074 1074 */ 1075 1075 export const vSimpleFormData = vModelWithString; 1076 1076 1077 - export const vImportData = v.union([ 1078 - vModelWithReadOnlyAndWriteOnly, 1079 - vModelWithArrayReadOnlyAndWriteOnly 1080 - ]); 1077 + export const vExportData = v.object({ 1078 + body: v.optional(v.never()), 1079 + headers: v.optional(v.never()), 1080 + path: v.optional(v.never()), 1081 + query: v.optional(v.never()) 1082 + }); 1083 + 1084 + export const vPatchApiVbyApiVersionNoTagData = v.object({ 1085 + body: v.optional(v.never()), 1086 + headers: v.optional(v.never()), 1087 + path: v.optional(v.never()), 1088 + query: v.optional(v.never()) 1089 + }); 1090 + 1091 + export const vImportData = v.object({ 1092 + body: v.union([ 1093 + vModelWithReadOnlyAndWriteOnly, 1094 + vModelWithArrayReadOnlyAndWriteOnly 1095 + ]), 1096 + headers: v.optional(v.never()), 1097 + path: v.optional(v.never()), 1098 + query: v.optional(v.never()) 1099 + }); 1081 1100 1082 1101 export const vImportResponse = v.union([ 1083 1102 vModelFromZendesk, 1084 1103 vModelWithReadOnlyAndWriteOnly 1085 1104 ]); 1086 1105 1106 + export const vFooWowData = v.object({ 1107 + body: v.optional(v.never()), 1108 + headers: v.optional(v.never()), 1109 + path: v.optional(v.never()), 1110 + query: v.optional(v.never()) 1111 + }); 1112 + 1113 + export const vApiVVersionODataControllerCountData = v.object({ 1114 + body: v.optional(v.never()), 1115 + headers: v.optional(v.never()), 1116 + path: v.optional(v.never()), 1117 + query: v.optional(v.never()) 1118 + }); 1119 + 1087 1120 /** 1088 1121 * Success 1089 1122 */ 1090 1123 export const vApiVVersionODataControllerCountResponse = vModelFromZendesk; 1091 1124 1092 - /** 1093 - * foo in method 1094 - */ 1095 - export const vGetApiVbyApiVersionSimpleOperationParameterFooParam = v.union([ 1096 - v.string(), 1097 - v.pipe(v.string(), v.uuid()) 1098 - ]); 1125 + export const vGetApiVbyApiVersionSimpleOperationData = v.object({ 1126 + body: v.optional(v.never()), 1127 + headers: v.optional(v.never()), 1128 + path: v.object({ 1129 + foo_param: v.union([ 1130 + v.string(), 1131 + v.pipe(v.string(), v.uuid()) 1132 + ]) 1133 + }), 1134 + query: v.optional(v.never()) 1135 + }); 1099 1136 1100 1137 /** 1101 1138 * Response is a simple number 1102 1139 */ 1103 1140 export const vGetApiVbyApiVersionSimpleOperationResponse = v.number(); 1104 1141 1105 - /** 1106 - * foo in method 1107 - */ 1108 - export const vDeleteFooParameterFooParam = v.string(); 1142 + export const vDeleteCallWithoutParametersAndResponseData = v.object({ 1143 + body: v.optional(v.never()), 1144 + headers: v.optional(v.never()), 1145 + path: v.optional(v.never()), 1146 + query: v.optional(v.never()) 1147 + }); 1109 1148 1110 - /** 1111 - * bar in method 1112 - */ 1113 - export const vDeleteFooParameterBarParam = v.string(); 1149 + export const vGetCallWithoutParametersAndResponseData = v.object({ 1150 + body: v.optional(v.never()), 1151 + headers: v.optional(v.never()), 1152 + path: v.optional(v.never()), 1153 + query: v.optional(v.never()) 1154 + }); 1114 1155 1115 - /** 1116 - * Parameter with illegal characters 1117 - */ 1118 - export const vDeleteFooParameterXFooBar = vModelWithString; 1156 + export const vHeadCallWithoutParametersAndResponseData = v.object({ 1157 + body: v.optional(v.never()), 1158 + headers: v.optional(v.never()), 1159 + path: v.optional(v.never()), 1160 + query: v.optional(v.never()) 1161 + }); 1119 1162 1120 - /** 1121 - * Testing multiline comments in string: First line 1122 - * Second line 1123 - * 1124 - * Fourth line 1125 - */ 1126 - export const vCallWithDescriptionsParameterParameterWithBreaks = v.string(); 1163 + export const vOptionsCallWithoutParametersAndResponseData = v.object({ 1164 + body: v.optional(v.never()), 1165 + headers: v.optional(v.never()), 1166 + path: v.optional(v.never()), 1167 + query: v.optional(v.never()) 1168 + }); 1127 1169 1128 - /** 1129 - * Testing backticks in string: `backticks` and ```multiple backticks``` should work 1130 - */ 1131 - export const vCallWithDescriptionsParameterParameterWithBackticks = v.string(); 1170 + export const vPatchCallWithoutParametersAndResponseData = v.object({ 1171 + body: v.optional(v.never()), 1172 + headers: v.optional(v.never()), 1173 + path: v.optional(v.never()), 1174 + query: v.optional(v.never()) 1175 + }); 1132 1176 1133 - /** 1134 - * Testing slashes in string: \backwards\\\ and /forwards/// should work 1135 - */ 1136 - export const vCallWithDescriptionsParameterParameterWithSlashes = v.string(); 1177 + export const vPostCallWithoutParametersAndResponseData = v.object({ 1178 + body: v.optional(v.never()), 1179 + headers: v.optional(v.never()), 1180 + path: v.optional(v.never()), 1181 + query: v.optional(v.never()) 1182 + }); 1137 1183 1138 - /** 1139 - * Testing expression placeholders in string: ${expression} should work 1140 - */ 1141 - export const vCallWithDescriptionsParameterParameterWithExpressionPlaceholders = v.string(); 1184 + export const vPutCallWithoutParametersAndResponseData = v.object({ 1185 + body: v.optional(v.never()), 1186 + headers: v.optional(v.never()), 1187 + path: v.optional(v.never()), 1188 + query: v.optional(v.never()) 1189 + }); 1142 1190 1143 - /** 1144 - * Testing quotes in string: 'single quote''' and "double quotes""" should work 1145 - */ 1146 - export const vCallWithDescriptionsParameterParameterWithQuotes = v.string(); 1191 + export const vDeleteFooData3 = v.object({ 1192 + body: v.optional(v.never()), 1193 + headers: v.object({ 1194 + 'x-Foo-Bar': vModelWithString 1195 + }), 1196 + path: v.object({ 1197 + foo_param: v.string(), 1198 + BarParam: v.string() 1199 + }), 1200 + query: v.optional(v.never()) 1201 + }); 1147 1202 1148 - /** 1149 - * Testing reserved characters in string: * inline * and ** inline ** should work 1150 - */ 1151 - export const vCallWithDescriptionsParameterParameterWithReservedCharacters = v.string(); 1203 + export const vCallWithDescriptionsData = v.object({ 1204 + body: v.optional(v.never()), 1205 + headers: v.optional(v.never()), 1206 + path: v.optional(v.never()), 1207 + query: v.optional(v.object({ 1208 + parameterWithBreaks: v.optional(v.string()), 1209 + parameterWithBackticks: v.optional(v.string()), 1210 + parameterWithSlashes: v.optional(v.string()), 1211 + parameterWithExpressionPlaceholders: v.optional(v.string()), 1212 + parameterWithQuotes: v.optional(v.string()), 1213 + parameterWithReservedCharacters: v.optional(v.string()) 1214 + })) 1215 + }); 1152 1216 1153 - /** 1154 - * This parameter is deprecated 1155 - * @deprecated 1156 - */ 1157 - export const vDeprecatedCallParameterParameter = v.union([ 1158 - vDeprecatedModel, 1159 - v.null() 1160 - ]); 1217 + export const vDeprecatedCallData = v.object({ 1218 + body: v.optional(v.never()), 1219 + headers: v.optional(v.object({ 1220 + parameter: v.union([ 1221 + vDeprecatedModel, 1222 + v.null() 1223 + ]) 1224 + })), 1225 + path: v.optional(v.never()), 1226 + query: v.optional(v.never()) 1227 + }); 1161 1228 1162 - /** 1163 - * This is the parameter that goes into the body 1164 - */ 1165 - export const vCallWithParametersData = v.union([ 1166 - v.object({}), 1167 - v.null() 1168 - ]); 1229 + export const vCallWithParametersData = v.object({ 1230 + body: v.union([ 1231 + v.object({}), 1232 + v.null() 1233 + ]), 1234 + headers: v.object({ 1235 + parameterHeader: v.union([ 1236 + v.string(), 1237 + v.null() 1238 + ]) 1239 + }), 1240 + path: v.object({ 1241 + parameterPath: v.union([ 1242 + v.string(), 1243 + v.null() 1244 + ]), 1245 + 'api-version': v.union([ 1246 + v.string(), 1247 + v.null() 1248 + ]) 1249 + }), 1250 + query: v.object({ 1251 + foo_ref_enum: v.optional(vModelWithNestedArrayEnumsDataFoo), 1252 + foo_all_of_enum: vModelWithNestedArrayEnumsDataFoo, 1253 + cursor: v.union([ 1254 + v.string(), 1255 + v.null() 1256 + ]) 1257 + }) 1258 + }); 1169 1259 1170 - /** 1171 - * This is the parameter that goes into the cookie 1172 - */ 1173 - export const vCallWithParametersParameterParameterCookie = v.union([ 1174 - v.string(), 1175 - v.null() 1176 - ]); 1260 + export const vCallWithWeirdParameterNamesData = v.object({ 1261 + body: v.union([ 1262 + vModelWithString, 1263 + v.null() 1264 + ]), 1265 + headers: v.object({ 1266 + 'parameter.header': v.union([ 1267 + v.string(), 1268 + v.null() 1269 + ]) 1270 + }), 1271 + path: v.object({ 1272 + 'parameter.path.1': v.optional(v.string()), 1273 + 'parameter-path-2': v.optional(v.string()), 1274 + 'PARAMETER-PATH-3': v.optional(v.string()), 1275 + 'api-version': v.union([ 1276 + v.string(), 1277 + v.null() 1278 + ]) 1279 + }), 1280 + query: v.object({ 1281 + default: v.optional(v.string()), 1282 + 'parameter-query': v.union([ 1283 + v.string(), 1284 + v.null() 1285 + ]) 1286 + }) 1287 + }); 1177 1288 1178 - /** 1179 - * This is the parameter that goes into the header 1180 - */ 1181 - export const vCallWithParametersParameterParameterHeader = v.union([ 1182 - v.string(), 1183 - v.null() 1184 - ]); 1185 - 1186 - /** 1187 - * This is the parameter that goes into the path 1188 - */ 1189 - export const vCallWithParametersParameterParameterPath = v.union([ 1190 - v.string(), 1191 - v.null() 1192 - ]); 1193 - 1194 - /** 1195 - * api-version should be required in standalone clients 1196 - */ 1197 - export const vCallWithParametersParameterApiVersion = v.union([ 1198 - v.string(), 1199 - v.null() 1200 - ]); 1201 - 1202 - export const vCallWithParametersParameterFooRefEnum = vModelWithNestedArrayEnumsDataFoo; 1203 - 1204 - export const vCallWithParametersParameterFooAllOfEnum = vModelWithNestedArrayEnumsDataFoo; 1205 - 1206 - /** 1207 - * This is the parameter that goes into the query params 1208 - */ 1209 - export const vCallWithParametersParameterCursor = v.union([ 1210 - v.string(), 1211 - v.null() 1212 - ]); 1213 - 1214 - /** 1215 - * This is the parameter that goes into the body 1216 - */ 1217 - export const vCallWithWeirdParameterNamesData = v.union([ 1218 - vModelWithString, 1219 - v.null() 1220 - ]); 1221 - 1222 - /** 1223 - * This is the parameter that goes into the cookie 1224 - */ 1225 - export const vCallWithWeirdParameterNamesParameterParameterCookie = v.union([ 1226 - v.string(), 1227 - v.null() 1228 - ]); 1229 - 1230 - /** 1231 - * This is the parameter that goes into the request header 1232 - */ 1233 - export const vCallWithWeirdParameterNamesParameterParameterHeader = v.union([ 1234 - v.string(), 1235 - v.null() 1236 - ]); 1237 - 1238 - /** 1239 - * This is the parameter that goes into the path 1240 - */ 1241 - export const vCallWithWeirdParameterNamesParameterParameterPath1 = v.string(); 1242 - 1243 - /** 1244 - * This is the parameter that goes into the path 1245 - */ 1246 - export const vCallWithWeirdParameterNamesParameterParameterPath2 = v.string(); 1247 - 1248 - /** 1249 - * This is the parameter that goes into the path 1250 - */ 1251 - export const vCallWithWeirdParameterNamesParameterParameterPath3 = v.string(); 1252 - 1253 - /** 1254 - * api-version should be required in standalone clients 1255 - */ 1256 - export const vCallWithWeirdParameterNamesParameterApiVersion = v.union([ 1257 - v.string(), 1258 - v.null() 1259 - ]); 1260 - 1261 - /** 1262 - * This is the parameter with a reserved keyword 1263 - */ 1264 - export const vCallWithWeirdParameterNamesParameterDefault = v.string(); 1265 - 1266 - /** 1267 - * This is the parameter that goes into the request query params 1268 - */ 1269 - export const vCallWithWeirdParameterNamesParameterParameterQuery = v.union([ 1270 - v.string(), 1271 - v.null() 1272 - ]); 1289 + export const vGetCallWithOptionalParamData = v.object({ 1290 + body: vModelWithOneOfEnum, 1291 + headers: v.optional(v.never()), 1292 + path: v.optional(v.never()), 1293 + query: v.optional(v.object({ 1294 + page: v.optional(v.number()) 1295 + })) 1296 + }); 1273 1297 1274 - /** 1275 - * This is a required parameter 1276 - */ 1277 - export const vGetCallWithOptionalParamData = vModelWithOneOfEnum; 1278 - 1279 - /** 1280 - * This is an optional parameter 1281 - */ 1282 - export const vGetCallWithOptionalParamParameterPage = v.number(); 1283 - 1284 - /** 1285 - * This is an optional parameter 1286 - */ 1287 1298 export const vPostCallWithOptionalParamData = v.object({ 1288 - offset: v.optional(v.union([ 1289 - v.number(), 1290 - v.null() 1291 - ])) 1299 + body: v.optional(v.object({ 1300 + offset: v.optional(v.union([ 1301 + v.number(), 1302 + v.null() 1303 + ])) 1304 + })), 1305 + headers: v.optional(v.never()), 1306 + path: v.optional(v.never()), 1307 + query: v.object({ 1308 + parameter: vPageable 1309 + }) 1292 1310 }); 1293 1311 1294 - /** 1295 - * This is a required parameter 1296 - */ 1297 - export const vPostCallWithOptionalParamParameterParameter = vPageable; 1298 - 1299 1312 export const vPostCallWithOptionalParamResponse = v.union([ 1300 1313 v.number(), 1301 1314 v.void() 1302 1315 ]); 1303 1316 1304 - /** 1305 - * A reusable request body 1306 - */ 1307 - export const vPostApiVbyApiVersionRequestBodyData = vSimpleRequestBody; 1317 + export const vPostApiVbyApiVersionRequestBodyData = v.object({ 1318 + body: v.optional(vSimpleRequestBody), 1319 + headers: v.optional(v.never()), 1320 + path: v.optional(v.never()), 1321 + query: v.optional(v.object({ 1322 + parameter: v.optional(v.string()) 1323 + })) 1324 + }); 1308 1325 1309 - /** 1310 - * This is a reusable parameter 1311 - */ 1312 - export const vPostApiVbyApiVersionRequestBodyParameterParameter = v.string(); 1326 + export const vPostApiVbyApiVersionFormDataData = v.object({ 1327 + body: v.optional(vSimpleFormData), 1328 + headers: v.optional(v.never()), 1329 + path: v.optional(v.never()), 1330 + query: v.optional(v.object({ 1331 + parameter: v.optional(v.string()) 1332 + })) 1333 + }); 1313 1334 1314 - /** 1315 - * A reusable request body 1316 - */ 1317 - export const vPostApiVbyApiVersionFormDataData = vSimpleFormData; 1335 + export const vCallWithDefaultParametersData = v.object({ 1336 + body: v.optional(v.never()), 1337 + headers: v.optional(v.never()), 1338 + path: v.optional(v.never()), 1339 + query: v.optional(v.object({ 1340 + parameterString: v.optional(v.union([ 1341 + v.optional(v.string(), 'Hello World!'), 1342 + v.null() 1343 + ]), 'Hello World!'), 1344 + parameterNumber: v.optional(v.union([ 1345 + v.optional(v.number(), 123), 1346 + v.null() 1347 + ]), 123), 1348 + parameterBoolean: v.optional(v.union([ 1349 + v.optional(v.boolean(), true), 1350 + v.null() 1351 + ]), true), 1352 + parameterEnum: v.optional(v.picklist([ 1353 + 'Success', 1354 + 'Warning', 1355 + 'Error' 1356 + ])), 1357 + parameterModel: v.optional(v.union([ 1358 + vModelWithString, 1359 + v.null() 1360 + ])) 1361 + })) 1362 + }); 1318 1363 1319 - /** 1320 - * This is a reusable parameter 1321 - */ 1322 - export const vPostApiVbyApiVersionFormDataParameterParameter = v.string(); 1364 + export const vCallWithDefaultOptionalParametersData = v.object({ 1365 + body: v.optional(v.never()), 1366 + headers: v.optional(v.never()), 1367 + path: v.optional(v.never()), 1368 + query: v.optional(v.object({ 1369 + parameterString: v.optional(v.string(), 'Hello World!'), 1370 + parameterNumber: v.optional(v.number(), 123), 1371 + parameterBoolean: v.optional(v.boolean(), true), 1372 + parameterEnum: v.optional(v.picklist([ 1373 + 'Success', 1374 + 'Warning', 1375 + 'Error' 1376 + ])), 1377 + parameterModel: v.optional(vModelWithString) 1378 + })) 1379 + }); 1323 1380 1324 - /** 1325 - * This is a simple string with default value 1326 - */ 1327 - export const vCallWithDefaultParametersParameterParameterString = v.optional(v.union([ 1328 - v.optional(v.string(), 'Hello World!'), 1329 - v.null() 1330 - ]), 'Hello World!'); 1381 + export const vCallToTestOrderOfParamsData = v.object({ 1382 + body: v.optional(v.never()), 1383 + headers: v.optional(v.never()), 1384 + path: v.optional(v.never()), 1385 + query: v.object({ 1386 + parameterOptionalStringWithDefault: v.optional(v.string(), 'Hello World!'), 1387 + parameterOptionalStringWithEmptyDefault: v.optional(v.string(), ''), 1388 + parameterOptionalStringWithNoDefault: v.optional(v.string()), 1389 + parameterStringWithDefault: v.optional(v.string(), 'Hello World!'), 1390 + parameterStringWithEmptyDefault: v.optional(v.string(), ''), 1391 + parameterStringWithNoDefault: v.string(), 1392 + parameterStringNullableWithNoDefault: v.optional(v.union([ 1393 + v.string(), 1394 + v.null() 1395 + ])), 1396 + parameterStringNullableWithDefault: v.optional(v.union([ 1397 + v.string(), 1398 + v.null() 1399 + ]), null) 1400 + }) 1401 + }); 1331 1402 1332 - /** 1333 - * This is a simple number with default value 1334 - */ 1335 - export const vCallWithDefaultParametersParameterParameterNumber = v.optional(v.union([ 1336 - v.optional(v.number(), 123), 1337 - v.null() 1338 - ]), 123); 1403 + export const vDuplicateNameData = v.object({ 1404 + body: v.optional(v.never()), 1405 + headers: v.optional(v.never()), 1406 + path: v.optional(v.never()), 1407 + query: v.optional(v.never()) 1408 + }); 1339 1409 1340 - /** 1341 - * This is a simple boolean with default value 1342 - */ 1343 - export const vCallWithDefaultParametersParameterParameterBoolean = v.optional(v.union([ 1344 - v.optional(v.boolean(), true), 1345 - v.null() 1346 - ]), true); 1410 + export const vDuplicateName2Data = v.object({ 1411 + body: v.optional(v.never()), 1412 + headers: v.optional(v.never()), 1413 + path: v.optional(v.never()), 1414 + query: v.optional(v.never()) 1415 + }); 1347 1416 1348 - /** 1349 - * This is a simple enum with default value 1350 - */ 1351 - export const vCallWithDefaultParametersParameterParameterEnum = v.picklist([ 1352 - 'Success', 1353 - 'Warning', 1354 - 'Error' 1355 - ]); 1356 - 1357 - /** 1358 - * This is a simple model with default value 1359 - */ 1360 - export const vCallWithDefaultParametersParameterParameterModel = v.union([ 1361 - vModelWithString, 1362 - v.null() 1363 - ]); 1364 - 1365 - /** 1366 - * This is a simple string that is optional with default value 1367 - */ 1368 - export const vCallWithDefaultOptionalParametersParameterParameterString = v.optional(v.string(), 'Hello World!'); 1369 - 1370 - /** 1371 - * This is a simple number that is optional with default value 1372 - */ 1373 - export const vCallWithDefaultOptionalParametersParameterParameterNumber = v.optional(v.number(), 123); 1374 - 1375 - /** 1376 - * This is a simple boolean that is optional with default value 1377 - */ 1378 - export const vCallWithDefaultOptionalParametersParameterParameterBoolean = v.optional(v.boolean(), true); 1379 - 1380 - /** 1381 - * This is a simple enum that is optional with default value 1382 - */ 1383 - export const vCallWithDefaultOptionalParametersParameterParameterEnum = v.picklist([ 1384 - 'Success', 1385 - 'Warning', 1386 - 'Error' 1387 - ]); 1388 - 1389 - /** 1390 - * This is a simple model that is optional with default value 1391 - */ 1392 - export const vCallWithDefaultOptionalParametersParameterParameterModel = vModelWithString; 1393 - 1394 - /** 1395 - * This is a optional string with default 1396 - */ 1397 - export const vCallToTestOrderOfParamsParameterParameterOptionalStringWithDefault = v.optional(v.string(), 'Hello World!'); 1398 - 1399 - /** 1400 - * This is a optional string with empty default 1401 - */ 1402 - export const vCallToTestOrderOfParamsParameterParameterOptionalStringWithEmptyDefault = v.optional(v.string(), ''); 1403 - 1404 - /** 1405 - * This is a optional string with no default 1406 - */ 1407 - export const vCallToTestOrderOfParamsParameterParameterOptionalStringWithNoDefault = v.string(); 1408 - 1409 - /** 1410 - * This is a string with default 1411 - */ 1412 - export const vCallToTestOrderOfParamsParameterParameterStringWithDefault = v.optional(v.string(), 'Hello World!'); 1417 + export const vDuplicateName3Data = v.object({ 1418 + body: v.optional(v.never()), 1419 + headers: v.optional(v.never()), 1420 + path: v.optional(v.never()), 1421 + query: v.optional(v.never()) 1422 + }); 1413 1423 1414 - /** 1415 - * This is a string with empty default 1416 - */ 1417 - export const vCallToTestOrderOfParamsParameterParameterStringWithEmptyDefault = v.optional(v.string(), ''); 1424 + export const vDuplicateName4Data = v.object({ 1425 + body: v.optional(v.never()), 1426 + headers: v.optional(v.never()), 1427 + path: v.optional(v.never()), 1428 + query: v.optional(v.never()) 1429 + }); 1418 1430 1419 - /** 1420 - * This is a string with no default 1421 - */ 1422 - export const vCallToTestOrderOfParamsParameterParameterStringWithNoDefault = v.string(); 1423 - 1424 - /** 1425 - * This is a string that can be null with no default 1426 - */ 1427 - export const vCallToTestOrderOfParamsParameterParameterStringNullableWithNoDefault = v.union([ 1428 - v.string(), 1429 - v.null() 1430 - ]); 1431 - 1432 - /** 1433 - * This is a string that can be null with default 1434 - */ 1435 - export const vCallToTestOrderOfParamsParameterParameterStringNullableWithDefault = v.optional(v.union([ 1436 - v.string(), 1437 - v.null() 1438 - ]), null); 1431 + export const vCallWithNoContentResponseData = v.object({ 1432 + body: v.optional(v.never()), 1433 + headers: v.optional(v.never()), 1434 + path: v.optional(v.never()), 1435 + query: v.optional(v.never()) 1436 + }); 1439 1437 1440 1438 /** 1441 1439 * Success 1442 1440 */ 1443 1441 export const vCallWithNoContentResponseResponse = v.void(); 1444 1442 1443 + export const vCallWithResponseAndNoContentResponseData = v.object({ 1444 + body: v.optional(v.never()), 1445 + headers: v.optional(v.never()), 1446 + path: v.optional(v.never()), 1447 + query: v.optional(v.never()) 1448 + }); 1449 + 1445 1450 export const vCallWithResponseAndNoContentResponseResponse = v.union([ 1446 1451 v.number(), 1447 1452 v.void() 1448 1453 ]); 1449 1454 1455 + export const vDummyAData = v.object({ 1456 + body: v.optional(v.never()), 1457 + headers: v.optional(v.never()), 1458 + path: v.optional(v.never()), 1459 + query: v.optional(v.never()) 1460 + }); 1461 + 1450 1462 export const vDummyAResponse = v400; 1463 + 1464 + export const vDummyBData = v.object({ 1465 + body: v.optional(v.never()), 1466 + headers: v.optional(v.never()), 1467 + path: v.optional(v.never()), 1468 + query: v.optional(v.never()) 1469 + }); 1451 1470 1452 1471 /** 1453 1472 * Success 1454 1473 */ 1455 1474 export const vDummyBResponse = v.void(); 1456 1475 1476 + export const vCallWithResponseData = v.object({ 1477 + body: v.optional(v.never()), 1478 + headers: v.optional(v.never()), 1479 + path: v.optional(v.never()), 1480 + query: v.optional(v.never()) 1481 + }); 1482 + 1457 1483 export const vCallWithResponseResponse = vImport; 1458 1484 1485 + export const vCallWithDuplicateResponsesData = v.object({ 1486 + body: v.optional(v.never()), 1487 + headers: v.optional(v.never()), 1488 + path: v.optional(v.never()), 1489 + query: v.optional(v.never()) 1490 + }); 1491 + 1459 1492 export const vCallWithDuplicateResponsesResponse = v.union([ 1460 1493 v.intersect([ 1461 1494 vModelWithBoolean, ··· 1464 1497 vModelWithString 1465 1498 ]); 1466 1499 1500 + export const vCallWithResponsesData = v.object({ 1501 + body: v.optional(v.never()), 1502 + headers: v.optional(v.never()), 1503 + path: v.optional(v.never()), 1504 + query: v.optional(v.never()) 1505 + }); 1506 + 1467 1507 export const vCallWithResponsesResponse = v.union([ 1468 1508 v.object({ 1469 1509 '@namespace.string': v.optional(v.pipe(v.string(), v.readonly())), ··· 1474 1514 vModelThatExtendsExtends 1475 1515 ]); 1476 1516 1477 - /** 1478 - * This is an array parameter that is sent as csv format (comma-separated values) 1479 - */ 1480 - export const vCollectionFormatParameterParameterArrayCsv = v.union([ 1481 - v.array(v.string()), 1482 - v.null() 1483 - ]); 1484 - 1485 - /** 1486 - * This is an array parameter that is sent as ssv format (space-separated values) 1487 - */ 1488 - export const vCollectionFormatParameterParameterArraySsv = v.union([ 1489 - v.array(v.string()), 1490 - v.null() 1491 - ]); 1492 - 1493 - /** 1494 - * This is an array parameter that is sent as tsv format (tab-separated values) 1495 - */ 1496 - export const vCollectionFormatParameterParameterArrayTsv = v.union([ 1497 - v.array(v.string()), 1498 - v.null() 1499 - ]); 1500 - 1501 - /** 1502 - * This is an array parameter that is sent as pipes format (pipe-separated values) 1503 - */ 1504 - export const vCollectionFormatParameterParameterArrayPipes = v.union([ 1505 - v.array(v.string()), 1506 - v.null() 1507 - ]); 1508 - 1509 - /** 1510 - * This is an array parameter that is sent as multi format (multiple parameter instances) 1511 - */ 1512 - export const vCollectionFormatParameterParameterArrayMulti = v.union([ 1513 - v.array(v.string()), 1514 - v.null() 1515 - ]); 1516 - 1517 - /** 1518 - * This is a number parameter 1519 - */ 1520 - export const vTypesParameterId = v.pipe(v.number(), v.integer()); 1521 - 1522 - /** 1523 - * This is a number parameter 1524 - */ 1525 - export const vTypesParameterParameterNumber = v.optional(v.number(), 123); 1526 - 1527 - /** 1528 - * This is a string parameter 1529 - */ 1530 - export const vTypesParameterParameterString = v.optional(v.union([ 1531 - v.optional(v.string(), 'default'), 1532 - v.null() 1533 - ]), 'default'); 1534 - 1535 - /** 1536 - * This is a boolean parameter 1537 - */ 1538 - export const vTypesParameterParameterBoolean = v.optional(v.union([ 1539 - v.optional(v.boolean(), true), 1540 - v.null() 1541 - ]), true); 1542 - 1543 - /** 1544 - * This is an object parameter 1545 - */ 1546 - export const vTypesParameterParameterObject = v.optional(v.union([ 1547 - v.object({}), 1548 - v.null() 1549 - ]), null); 1550 - 1551 - /** 1552 - * This is an array parameter 1553 - */ 1554 - export const vTypesParameterParameterArray = v.union([ 1555 - v.array(v.string()), 1556 - v.null() 1557 - ]); 1558 - 1559 - /** 1560 - * This is a dictionary parameter 1561 - */ 1562 - export const vTypesParameterParameterDictionary = v.union([ 1563 - v.object({}), 1564 - v.null() 1565 - ]); 1517 + export const vCollectionFormatData = v.object({ 1518 + body: v.optional(v.never()), 1519 + headers: v.optional(v.never()), 1520 + path: v.optional(v.never()), 1521 + query: v.object({ 1522 + parameterArrayCSV: v.union([ 1523 + v.array(v.string()), 1524 + v.null() 1525 + ]), 1526 + parameterArraySSV: v.union([ 1527 + v.array(v.string()), 1528 + v.null() 1529 + ]), 1530 + parameterArrayTSV: v.union([ 1531 + v.array(v.string()), 1532 + v.null() 1533 + ]), 1534 + parameterArrayPipes: v.union([ 1535 + v.array(v.string()), 1536 + v.null() 1537 + ]), 1538 + parameterArrayMulti: v.union([ 1539 + v.array(v.string()), 1540 + v.null() 1541 + ]) 1542 + }) 1543 + }); 1566 1544 1567 - /** 1568 - * This is an enum parameter 1569 - */ 1570 - export const vTypesParameterParameterEnum = v.union([ 1571 - v.literal('Success'), 1572 - v.literal('Warning'), 1573 - v.literal('Error'), 1574 - v.null() 1575 - ]); 1545 + export const vTypesData = v.object({ 1546 + body: v.optional(v.never()), 1547 + headers: v.optional(v.never()), 1548 + path: v.optional(v.object({ 1549 + id: v.optional(v.pipe(v.number(), v.integer())) 1550 + })), 1551 + query: v.object({ 1552 + parameterNumber: v.optional(v.number(), 123), 1553 + parameterString: v.optional(v.union([ 1554 + v.optional(v.string(), 'default'), 1555 + v.null() 1556 + ]), 'default'), 1557 + parameterBoolean: v.optional(v.union([ 1558 + v.optional(v.boolean(), true), 1559 + v.null() 1560 + ]), true), 1561 + parameterObject: v.optional(v.union([ 1562 + v.object({}), 1563 + v.null() 1564 + ]), null), 1565 + parameterArray: v.union([ 1566 + v.array(v.string()), 1567 + v.null() 1568 + ]), 1569 + parameterDictionary: v.union([ 1570 + v.object({}), 1571 + v.null() 1572 + ]), 1573 + parameterEnum: v.union([ 1574 + v.literal('Success'), 1575 + v.literal('Warning'), 1576 + v.literal('Error'), 1577 + v.null() 1578 + ]) 1579 + }) 1580 + }); 1576 1581 1577 1582 export const vTypesResponse = v.union([ 1578 1583 v.number(), ··· 1581 1586 v.object({}) 1582 1587 ]); 1583 1588 1584 - export const vUploadFileData = v.string(); 1585 - 1586 - /** 1587 - * api-version should be required in standalone clients 1588 - */ 1589 - export const vUploadFileParameterApiVersion = v.union([ 1590 - v.string(), 1591 - v.null() 1592 - ]); 1589 + export const vUploadFileData = v.object({ 1590 + body: v.string(), 1591 + headers: v.optional(v.never()), 1592 + path: v.object({ 1593 + 'api-version': v.union([ 1594 + v.string(), 1595 + v.null() 1596 + ]) 1597 + }), 1598 + query: v.optional(v.never()) 1599 + }); 1593 1600 1594 1601 export const vUploadFileResponse = v.boolean(); 1595 1602 1596 - export const vFileResponseParameterId = v.string(); 1597 - 1598 - /** 1599 - * api-version should be required in standalone clients 1600 - */ 1601 - export const vFileResponseParameterApiVersion = v.string(); 1603 + export const vFileResponseData = v.object({ 1604 + body: v.optional(v.never()), 1605 + headers: v.optional(v.never()), 1606 + path: v.object({ 1607 + id: v.string(), 1608 + 'api-version': v.string() 1609 + }), 1610 + query: v.optional(v.never()) 1611 + }); 1602 1612 1603 1613 /** 1604 1614 * Success 1605 1615 */ 1606 1616 export const vFileResponseResponse = v.string(); 1607 1617 1608 - /** 1609 - * Parameter containing object 1610 - */ 1611 - export const vComplexTypesParameterParameterObject = v.object({ 1612 - first: v.optional(v.object({ 1613 - second: v.optional(v.object({ 1614 - third: v.optional(v.string()) 1615 - })) 1616 - })) 1618 + export const vComplexTypesData = v.object({ 1619 + body: v.optional(v.never()), 1620 + headers: v.optional(v.never()), 1621 + path: v.optional(v.never()), 1622 + query: v.object({ 1623 + parameterObject: v.object({ 1624 + first: v.optional(v.object({ 1625 + second: v.optional(v.object({ 1626 + third: v.optional(v.string()) 1627 + })) 1628 + })) 1629 + }), 1630 + parameterReference: vModelWithString 1631 + }) 1617 1632 }); 1618 1633 1619 1634 /** 1620 - * Parameter containing reference 1621 - */ 1622 - export const vComplexTypesParameterParameterReference = vModelWithString; 1623 - 1624 - /** 1625 1635 * Successful response 1626 1636 */ 1627 1637 export const vComplexTypesResponse = v.array(vModelWithString); 1628 1638 1639 + export const vMultipartResponseData = v.object({ 1640 + body: v.optional(v.never()), 1641 + headers: v.optional(v.never()), 1642 + path: v.optional(v.never()), 1643 + query: v.optional(v.never()) 1644 + }); 1645 + 1629 1646 /** 1630 1647 * OK 1631 1648 */ ··· 1638 1655 }); 1639 1656 1640 1657 export const vMultipartRequestData = v.object({ 1641 - content: v.optional(v.string()), 1642 - data: v.optional(v.union([ 1643 - vModelWithString, 1644 - v.null() 1645 - ])) 1658 + body: v.optional(v.object({ 1659 + content: v.optional(v.string()), 1660 + data: v.optional(v.union([ 1661 + vModelWithString, 1662 + v.null() 1663 + ])) 1664 + })), 1665 + headers: v.optional(v.never()), 1666 + path: v.optional(v.never()), 1667 + query: v.optional(v.never()) 1646 1668 }); 1647 1669 1648 1670 export const vComplexParamsData = v.object({ 1649 - key: v.pipe(v.union([ 1650 - v.pipe(v.pipe(v.string(), v.maxLength(64), v.regex(/^[a-zA-Z0-9_]*$/)), v.readonly()), 1651 - v.null() 1652 - ]), v.readonly()), 1653 - name: v.union([ 1654 - v.pipe(v.string(), v.maxLength(255)), 1655 - v.null() 1656 - ]), 1657 - enabled: v.optional(v.boolean(), true), 1658 - type: v.picklist([ 1659 - 'Monkey', 1660 - 'Horse', 1661 - 'Bird' 1662 - ]), 1663 - listOfModels: v.optional(v.union([ 1664 - v.array(vModelWithString), 1665 - v.null() 1666 - ])), 1667 - listOfStrings: v.optional(v.union([ 1668 - v.array(v.string()), 1669 - v.null() 1670 - ])), 1671 - parameters: v.union([ 1672 - vModelWithString, 1673 - vModelWithEnum, 1674 - vModelWithArray, 1675 - vModelWithDictionary 1676 - ]), 1677 - user: v.optional(v.pipe(v.object({ 1678 - id: v.optional(v.pipe(v.pipe(v.number(), v.integer()), v.readonly())), 1679 - name: v.optional(v.pipe(v.union([ 1680 - v.pipe(v.string(), v.readonly()), 1671 + body: v.optional(v.object({ 1672 + key: v.pipe(v.union([ 1673 + v.pipe(v.pipe(v.string(), v.maxLength(64), v.regex(/^[a-zA-Z0-9_]*$/)), v.readonly()), 1674 + v.null() 1675 + ]), v.readonly()), 1676 + name: v.union([ 1677 + v.pipe(v.string(), v.maxLength(255)), 1678 + v.null() 1679 + ]), 1680 + enabled: v.optional(v.boolean(), true), 1681 + type: v.picklist([ 1682 + 'Monkey', 1683 + 'Horse', 1684 + 'Bird' 1685 + ]), 1686 + listOfModels: v.optional(v.union([ 1687 + v.array(vModelWithString), 1688 + v.null() 1689 + ])), 1690 + listOfStrings: v.optional(v.union([ 1691 + v.array(v.string()), 1681 1692 v.null() 1682 - ]), v.readonly())) 1683 - }), v.readonly())) 1693 + ])), 1694 + parameters: v.union([ 1695 + vModelWithString, 1696 + vModelWithEnum, 1697 + vModelWithArray, 1698 + vModelWithDictionary 1699 + ]), 1700 + user: v.optional(v.pipe(v.object({ 1701 + id: v.optional(v.pipe(v.pipe(v.number(), v.integer()), v.readonly())), 1702 + name: v.optional(v.pipe(v.union([ 1703 + v.pipe(v.string(), v.readonly()), 1704 + v.null() 1705 + ]), v.readonly())) 1706 + }), v.readonly())) 1707 + })), 1708 + headers: v.optional(v.never()), 1709 + path: v.object({ 1710 + id: v.pipe(v.number(), v.integer()), 1711 + 'api-version': v.string() 1712 + }), 1713 + query: v.optional(v.never()) 1684 1714 }); 1685 1715 1686 - export const vComplexParamsParameterId = v.pipe(v.number(), v.integer()); 1687 - 1688 - /** 1689 - * api-version should be required in standalone clients 1690 - */ 1691 - export const vComplexParamsParameterApiVersion = v.string(); 1692 - 1693 1716 /** 1694 1717 * Success 1695 1718 */ 1696 1719 export const vComplexParamsResponse = vModelWithString; 1697 1720 1698 - /** 1699 - * Status code to return 1700 - */ 1701 - export const vTestErrorCodeParameterStatus = v.pipe(v.number(), v.integer()); 1721 + export const vCallWithResultFromHeaderData = v.object({ 1722 + body: v.optional(v.never()), 1723 + headers: v.optional(v.never()), 1724 + path: v.optional(v.never()), 1725 + query: v.optional(v.never()) 1726 + }); 1702 1727 1703 - /** 1704 - * Dummy input param 1705 - */ 1706 - export const vNonAsciiæøåÆøÅöôêÊ字符串ParameterNonAsciiParamæøåÆøÅöôêÊ = v.pipe(v.number(), v.integer()); 1728 + export const vTestErrorCodeData = v.object({ 1729 + body: v.optional(v.never()), 1730 + headers: v.optional(v.never()), 1731 + path: v.optional(v.never()), 1732 + query: v.object({ 1733 + status: v.pipe(v.number(), v.integer()) 1734 + }) 1735 + }); 1736 + 1737 + export const vNonAsciiæøåÆøÅöôêÊ字符串Data = v.object({ 1738 + body: v.optional(v.never()), 1739 + headers: v.optional(v.never()), 1740 + path: v.optional(v.never()), 1741 + query: v.object({ 1742 + 'nonAsciiParamæøåÆØÅöôêÊ': v.pipe(v.number(), v.integer()) 1743 + }) 1744 + }); 1707 1745 1708 1746 /** 1709 1747 * Successful response 1710 1748 */ 1711 1749 export const vNonAsciiæøåÆøÅöôêÊ字符串Response = v.array(vNonAsciiStringæøåÆøÅöôêÊ字符串); 1712 1750 1713 - export const vPutWithFormUrlEncodedData = vArrayWithStrings; 1751 + export const vPutWithFormUrlEncodedData = v.object({ 1752 + body: vArrayWithStrings, 1753 + headers: v.optional(v.never()), 1754 + path: v.optional(v.never()), 1755 + query: v.optional(v.never()) 1756 + });
+38 -23
packages/openapi-ts-tests/test/__snapshots__/3.1.x/validators-metadata/valibot.gen.ts
··· 5 5 /** 6 6 * This is Bar schema. 7 7 */ 8 - export const vBar: v.GenericSchema = v.object({ 8 + export const vBar: v.GenericSchema = v.pipe(v.object({ 9 9 foo: v.optional(v.lazy(() => { 10 10 return vFoo; 11 11 })) 12 - }); 12 + }), v.metadata({ 13 + description: 'This is Bar schema.' 14 + })); 13 15 14 16 /** 15 17 * This is Foo schema. 16 18 */ 17 19 export const vFoo: v.GenericSchema = v.optional(v.union([ 18 20 v.object({ 19 - foo: v.optional(v.pipe(v.string(), v.regex(/^\d{3}-\d{2}-\d{4}$/))), 21 + foo: v.optional(v.pipe(v.pipe(v.string(), v.regex(/^\d{3}-\d{2}-\d{4}$/)), v.metadata({ 22 + description: 'This is foo property.' 23 + }))), 20 24 bar: v.optional(vBar), 21 - baz: v.optional(v.array(v.lazy(() => { 25 + baz: v.optional(v.pipe(v.array(v.lazy(() => { 22 26 return vFoo; 27 + })), v.metadata({ 28 + description: 'This is baz property.' 23 29 }))), 24 - qux: v.optional(v.pipe(v.number(), v.integer(), v.gtValue(0)), 0) 30 + qux: v.optional(v.pipe(v.pipe(v.number(), v.integer(), v.gtValue(0)), v.metadata({ 31 + description: 'This is qux property.' 32 + })), 0) 25 33 }), 26 34 v.null() 27 35 ]), null); ··· 35 43 /** 36 44 * This is Foo parameter. 37 45 */ 38 - export const vFoo2 = v.string(); 46 + export const vFoo2 = v.pipe(v.string(), v.metadata({ 47 + description: 'This is Foo parameter.' 48 + })); 39 49 40 50 export const vFoo3 = v.object({ 41 51 foo: v.optional(vBar) 42 52 }); 43 53 44 54 export const vPatchFooData = v.object({ 45 - foo: v.optional(v.string()) 46 - }); 47 - 48 - /** 49 - * This is Foo parameter. 50 - */ 51 - export const vPatchFooParameterFoo = v.string(); 52 - 53 - export const vPatchFooParameterBar = vBar; 54 - 55 - export const vPatchFooParameterBaz = v.object({ 56 - baz: v.optional(v.string()) 55 + body: v.object({ 56 + foo: v.optional(v.string()) 57 + }), 58 + headers: v.optional(v.never()), 59 + path: v.optional(v.never()), 60 + query: v.optional(v.object({ 61 + foo: v.optional(v.pipe(v.string(), v.metadata({ 62 + description: 'This is Foo parameter.' 63 + }))), 64 + bar: v.optional(vBar), 65 + baz: v.optional(v.object({ 66 + baz: v.optional(v.string()) 67 + })), 68 + qux: v.optional(v.pipe(v.string(), v.isoDate())), 69 + quux: v.optional(v.pipe(v.string(), v.isoTimestamp())) 70 + })) 57 71 }); 58 72 59 - export const vPatchFooParameterQux = v.pipe(v.string(), v.isoDate()); 60 - 61 - export const vPatchFooParameterQuux = v.pipe(v.string(), v.isoTimestamp()); 62 - 63 - export const vPostFooData = vFoo3; 73 + export const vPostFooData = v.object({ 74 + body: vFoo3, 75 + headers: v.optional(v.never()), 76 + path: v.optional(v.never()), 77 + query: v.optional(v.never()) 78 + });
+20 -17
packages/openapi-ts-tests/test/__snapshots__/3.1.x/validators/valibot.gen.ts
··· 42 42 }); 43 43 44 44 export const vPatchFooData = v.object({ 45 - foo: v.optional(v.string()) 45 + body: v.object({ 46 + foo: v.optional(v.string()) 47 + }), 48 + headers: v.optional(v.never()), 49 + path: v.optional(v.never()), 50 + query: v.optional(v.object({ 51 + foo: v.optional(v.string()), 52 + bar: v.optional(vBar), 53 + baz: v.optional(v.object({ 54 + baz: v.optional(v.string()) 55 + })), 56 + qux: v.optional(v.pipe(v.string(), v.isoDate())), 57 + quux: v.optional(v.pipe(v.string(), v.isoTimestamp())) 58 + })) 46 59 }); 47 60 48 - /** 49 - * This is Foo parameter. 50 - */ 51 - export const vPatchFooParameterFoo = v.string(); 52 - 53 - export const vPatchFooParameterBar = vBar; 54 - 55 - export const vPatchFooParameterBaz = v.object({ 56 - baz: v.optional(v.string()) 57 - }); 58 - 59 - export const vPatchFooParameterQux = v.pipe(v.string(), v.isoDate()); 60 - 61 - export const vPatchFooParameterQuux = v.pipe(v.string(), v.isoTimestamp()); 62 - 63 - export const vPostFooData = vFoo3; 61 + export const vPostFooData = v.object({ 62 + body: vFoo3, 63 + headers: v.optional(v.never()), 64 + path: v.optional(v.never()), 65 + query: v.optional(v.never()) 66 + });
+13 -2
packages/openapi-ts-tests/test/openapi-ts.config.ts
··· 60 60 // 'invalid', 61 61 // 'servers-entry.yaml', 62 62 // ), 63 - path: path.resolve(__dirname, 'spec', '3.1.x', 'content-types.yaml'), 63 + path: path.resolve(__dirname, 'spec', '3.1.x', 'full.yaml'), 64 64 // path: path.resolve(__dirname, 'spec', 'v3-transforms.json'), 65 65 // path: 'http://localhost:4000/', 66 66 // path: 'https://get.heyapi.dev/', ··· 127 127 // throwOnError: true, 128 128 // transformer: '@hey-api/transformers', 129 129 transformer: true, 130 - validator: 'zod', 130 + validator: 'valibot', 131 131 }, 132 132 { 133 133 // bigInt: true, ··· 171 171 // }, 172 172 }, 173 173 { 174 + // case: 'SCREAMING_SNAKE_CASE', 174 175 // comments: false, 176 + definitions: 'z{{name}}Definition', 175 177 // exportFromIndex: true, 178 + metadata: true, 176 179 name: 'valibot', 180 + requests: { 181 + // case: 'SCREAMING_SNAKE_CASE', 182 + name: 'z{{name}}TestData', 183 + }, 184 + responses: { 185 + // case: 'snake_case', 186 + name: 'z{{name}}TestResponse', 187 + }, 177 188 }, 178 189 { 179 190 // case: 'snake_case',
+4 -9
packages/openapi-ts/src/plugins/@hey-api/sdk/validator.ts
··· 1 1 import { compiler } from '../../../compiler'; 2 2 import type { IR } from '../../../ir/types'; 3 - import { operationIrRef } from '../../shared/utils/ref'; 4 3 import type { Plugin } from '../../types'; 5 4 import { valibotId } from '../../valibot/constants'; 6 - import { nameTransformer } from '../../valibot/plugin'; 7 5 import { zodId } from '../../zod/plugin'; 8 6 import { sdkId } from './constants'; 9 7 import type { Config } from './types'; ··· 23 21 }) => { 24 22 const file = plugin.context.file({ id: sdkId })!; 25 23 24 + const responses = plugin.getPlugin('valibot')?.config.responses; 26 25 const identifierSchema = plugin.context.file({ id: valibotId })!.identifier({ 27 - $ref: operationIrRef({ 28 - case: 'camelCase', 29 - config: plugin.context.config, 30 - id: operation.id, 31 - type: 'response', 32 - }), 26 + // TODO: refactor for better cross-plugin compatibility 27 + $ref: `#/valibot-response/${operation.id}`, 33 28 // TODO: refactor to not have to define nameTransformer 34 - nameTransformer, 29 + nameTransformer: typeof responses === 'object' ? responses.name : undefined, 35 30 namespace: 'value', 36 31 }); 37 32
+44 -2
packages/openapi-ts/src/plugins/valibot/config.ts
··· 1 1 import { definePluginConfig } from '../shared/utils/config'; 2 2 import type { Plugin } from '../types'; 3 3 import { handler } from './plugin'; 4 - import type { Config } from './types'; 4 + import type { Config, ResolvedConfig } from './types'; 5 5 6 - export const defaultConfig: Plugin.Config<Config> = { 6 + export const defaultConfig: Plugin.Config<Config, ResolvedConfig> = { 7 7 config: { 8 + case: 'camelCase', 8 9 comments: true, 9 10 exportFromIndex: false, 11 + metadata: false, 10 12 }, 11 13 handler, 12 14 handlerLegacy: () => {}, 13 15 name: 'valibot', 14 16 output: 'valibot', 17 + resolveConfig: (plugin, context) => { 18 + plugin.config.definitions = context.valueToObject({ 19 + defaultValue: { 20 + case: plugin.config.case ?? 'camelCase', 21 + enabled: true, 22 + name: 'v{{name}}', 23 + }, 24 + mappers: { 25 + boolean: (enabled) => ({ enabled }), 26 + string: (name) => ({ enabled: true, name }), 27 + }, 28 + value: plugin.config.definitions, 29 + }); 30 + 31 + plugin.config.requests = context.valueToObject({ 32 + defaultValue: { 33 + case: plugin.config.case ?? 'camelCase', 34 + enabled: true, 35 + name: 'v{{name}}Data', 36 + }, 37 + mappers: { 38 + boolean: (enabled) => ({ enabled }), 39 + string: (name) => ({ enabled: true, name }), 40 + }, 41 + value: plugin.config.requests, 42 + }); 43 + 44 + plugin.config.responses = context.valueToObject({ 45 + defaultValue: { 46 + case: plugin.config.case ?? 'camelCase', 47 + enabled: true, 48 + name: 'v{{name}}Response', 49 + }, 50 + mappers: { 51 + boolean: (enabled) => ({ enabled }), 52 + string: (name) => ({ enabled: true, name }), 53 + }, 54 + value: plugin.config.responses, 55 + }); 56 + }, 15 57 tags: ['validator'], 16 58 }; 17 59
+180 -65
packages/openapi-ts/src/plugins/valibot/plugin.ts
··· 1 1 import ts from 'typescript'; 2 2 3 3 import { compiler } from '../../compiler'; 4 + import type { Identifier } from '../../generate/files'; 4 5 import { operationResponsesMap } from '../../ir/operation'; 6 + import { hasParameterGroupObjectRequired } from '../../ir/parameter'; 5 7 import { deduplicateSchema } from '../../ir/schema'; 6 8 import type { IR } from '../../ir/types'; 9 + import type { StringCase } from '../../types/config'; 7 10 import { numberRegExp } from '../../utils/regexp'; 8 - import { operationIrRef } from '../shared/utils/ref'; 9 11 import { createSchemaComment } from '../shared/utils/schema'; 10 12 import type { Plugin } from '../types'; 11 13 import { identifiers, valibotId } from './constants'; 12 - import type { Config } from './types'; 14 + import type { ResolvedConfig } from './types'; 13 15 14 16 interface SchemaWithType<T extends Required<IR.SchemaObject>['type']> 15 17 extends Omit<IR.SchemaObject, 'type'> { ··· 19 21 interface State { 20 22 circularReferenceTracker: Set<string>; 21 23 hasCircularReference: boolean; 24 + nameCase: StringCase; 25 + nameTransformer: string | ((name: string) => string); 22 26 } 23 - 24 - export const nameTransformer = (name: string) => `v-${name}`; 25 27 26 28 const pipesToExpression = (pipes: Array<ts.Expression>) => { 27 29 if (pipes.length === 1) { ··· 43 45 schema, 44 46 state, 45 47 }: { 46 - plugin: Plugin.Instance<Config>; 48 + plugin: Plugin.Instance<ResolvedConfig>; 47 49 schema: SchemaWithType<'array'>; 48 50 state: State; 49 51 }): ts.CallExpression => { ··· 369 371 schema, 370 372 state, 371 373 }: { 372 - plugin: Plugin.Instance<Config>; 374 + plugin: Plugin.Instance<ResolvedConfig>; 373 375 schema: SchemaWithType<'object'>; 374 376 state: State; 375 377 }): { ··· 601 603 schema, 602 604 state, 603 605 }: { 604 - plugin: Plugin.Instance<Config>; 606 + plugin: Plugin.Instance<ResolvedConfig>; 605 607 schema: SchemaWithType<'tuple'>; 606 608 state: State; 607 609 }) => { ··· 703 705 schema, 704 706 state, 705 707 }: { 706 - plugin: Plugin.Instance<Config>; 708 + plugin: Plugin.Instance<ResolvedConfig>; 707 709 schema: IR.SchemaObject; 708 710 state: State; 709 711 }): { ··· 797 799 state, 798 800 }: { 799 801 operation: IR.OperationObject; 800 - plugin: Plugin.Instance<Config>; 802 + plugin: Plugin.Instance<ResolvedConfig>; 801 803 state: State; 802 804 }) => { 803 - if (operation.body) { 805 + const file = plugin.context.file({ id: valibotId })!; 806 + 807 + if (plugin.config.requests.enabled) { 808 + const requiredProperties: Array<string> = []; 809 + if (operation.body?.required) { 810 + requiredProperties.push('body'); 811 + } 812 + 813 + const headersPropertyProperties: Record<string, IR.SchemaObject> = {}; 814 + const headersPropertyRequired: Array<string> = []; 815 + const pathPropertyProperties: Record<string, IR.SchemaObject> = {}; 816 + const pathPropertyRequired: Array<string> = []; 817 + const queryPropertyProperties: Record<string, IR.SchemaObject> = {}; 818 + const queryPropertyRequired: Array<string> = []; 819 + 820 + if (operation.parameters) { 821 + // TODO: add support for cookies 822 + 823 + if (operation.parameters.header) { 824 + if (hasParameterGroupObjectRequired(operation.parameters.path)) { 825 + requiredProperties.push('headers'); 826 + } 827 + 828 + for (const key in operation.parameters.header) { 829 + const parameter = operation.parameters.header[key]!; 830 + headersPropertyProperties[parameter.name] = parameter.schema; 831 + if (parameter.required) { 832 + headersPropertyRequired.push(parameter.name); 833 + } 834 + } 835 + } 836 + 837 + if (operation.parameters.path) { 838 + if (hasParameterGroupObjectRequired(operation.parameters.path)) { 839 + requiredProperties.push('path'); 840 + } 841 + 842 + for (const key in operation.parameters.path) { 843 + const parameter = operation.parameters.path[key]!; 844 + pathPropertyProperties[parameter.name] = parameter.schema; 845 + if (parameter.required) { 846 + pathPropertyRequired.push(parameter.name); 847 + } 848 + } 849 + } 850 + 851 + if (operation.parameters.query) { 852 + if (hasParameterGroupObjectRequired(operation.parameters.query)) { 853 + requiredProperties.push('query'); 854 + } 855 + 856 + for (const key in operation.parameters.query) { 857 + const parameter = operation.parameters.query[key]!; 858 + queryPropertyProperties[parameter.name] = parameter.schema; 859 + if (parameter.required) { 860 + queryPropertyRequired.push(parameter.name); 861 + } 862 + } 863 + } 864 + } 865 + 866 + const identifierData = file.identifier({ 867 + // TODO: refactor for better cross-plugin compatibility 868 + $ref: `#/valibot-data/${operation.id}`, 869 + case: plugin.config.requests.case, 870 + create: true, 871 + nameTransformer: plugin.config.requests.name, 872 + namespace: 'value', 873 + }); 804 874 schemaToValibotSchema({ 805 - $ref: operationIrRef({ 806 - case: 'camelCase', 807 - config: plugin.context.config, 808 - id: operation.id, 809 - type: 'data', 810 - }), 875 + // TODO: refactor for better cross-plugin compatibility 876 + $ref: `#/valibot-data/${operation.id}`, 877 + identifier: identifierData, 811 878 plugin, 812 - schema: operation.body.schema, 879 + schema: { 880 + properties: { 881 + body: operation.body 882 + ? operation.body.schema 883 + : { 884 + type: 'never', 885 + }, 886 + headers: Object.keys(headersPropertyProperties).length 887 + ? { 888 + properties: headersPropertyProperties, 889 + required: headersPropertyRequired, 890 + type: 'object', 891 + } 892 + : { 893 + type: 'never', 894 + }, 895 + path: Object.keys(pathPropertyProperties).length 896 + ? { 897 + properties: pathPropertyProperties, 898 + required: pathPropertyRequired, 899 + type: 'object', 900 + } 901 + : { 902 + type: 'never', 903 + }, 904 + query: Object.keys(queryPropertyProperties).length 905 + ? { 906 + properties: queryPropertyProperties, 907 + required: queryPropertyRequired, 908 + type: 'object', 909 + } 910 + : { 911 + type: 'never', 912 + }, 913 + }, 914 + required: requiredProperties, 915 + type: 'object', 916 + }, 813 917 state, 814 918 }); 815 919 } 816 920 817 - if (operation.parameters) { 818 - for (const type in operation.parameters) { 819 - const group = operation.parameters[type as keyof IR.ParametersObject]!; 820 - for (const key in group) { 821 - const parameter = group[key]!; 921 + if (plugin.config.responses.enabled) { 922 + if (operation.responses) { 923 + const { response } = operationResponsesMap(operation); 924 + 925 + if (response) { 926 + const identifierResponse = file.identifier({ 927 + // TODO: refactor for better cross-plugin compatibility 928 + $ref: `#/valibot-response/${operation.id}`, 929 + case: plugin.config.responses.case, 930 + create: true, 931 + nameTransformer: plugin.config.responses.name, 932 + namespace: 'value', 933 + }); 822 934 schemaToValibotSchema({ 823 - $ref: operationIrRef({ 824 - case: 'camelCase', 825 - config: plugin.context.config, 826 - id: operation.id, 827 - parameterId: parameter.name, 828 - type: 'parameter', 829 - }), 935 + // TODO: refactor for better cross-plugin compatibility 936 + $ref: `#/valibot-response/${operation.id}`, 937 + identifier: identifierResponse, 830 938 plugin, 831 - schema: parameter.schema, 939 + schema: response, 832 940 state, 833 941 }); 834 942 } 835 943 } 836 944 } 837 - 838 - if (operation.responses) { 839 - const { response } = operationResponsesMap(operation); 840 - 841 - if (response) { 842 - schemaToValibotSchema({ 843 - $ref: operationIrRef({ 844 - case: 'camelCase', 845 - config: plugin.context.config, 846 - id: operation.id, 847 - type: 'response', 848 - }), 849 - plugin, 850 - schema: response, 851 - state, 852 - }); 853 - } 854 - } 855 945 }; 856 946 857 947 const schemaToValibotSchema = ({ 858 948 $ref, 949 + identifier: _identifier, 859 950 optional, 860 951 plugin, 861 952 schema, ··· 865 956 * When $ref is supplied, a node will be emitted to the file. 866 957 */ 867 958 $ref?: string; 959 + identifier?: Identifier; 868 960 /** 869 961 * Accept `optional` to handle optional object properties. We can't handle 870 962 * this inside the object function because `.optional()` must come before 871 963 * `.default()` which is handled in this function. 872 964 */ 873 965 optional?: boolean; 874 - plugin: Plugin.Instance<Config>; 966 + plugin: Plugin.Instance<ResolvedConfig>; 875 967 schema: IR.SchemaObject; 876 968 state: State; 877 969 }): Array<ts.Expression> => { 878 970 const file = plugin.context.file({ id: valibotId })!; 879 971 880 972 let anyType: string | undefined; 881 - let identifier: ReturnType<typeof file.identifier> | undefined; 973 + let identifier: ReturnType<typeof file.identifier> | undefined = _identifier; 882 974 let pipes: Array<ts.Expression> = []; 883 975 884 976 if ($ref) { 885 977 state.circularReferenceTracker.add($ref); 886 978 887 - identifier = file.identifier({ 888 - $ref, 889 - create: true, 890 - nameTransformer, 891 - namespace: 'value', 892 - }); 979 + if (!identifier) { 980 + identifier = file.identifier({ 981 + $ref, 982 + case: state.nameCase, 983 + create: true, 984 + nameTransformer: state.nameTransformer, 985 + namespace: 'value', 986 + }); 987 + } 893 988 } 894 989 895 990 if (schema.$ref) { ··· 900 995 // this could be (maybe?) fixed by reshuffling the generation order 901 996 let identifierRef = file.identifier({ 902 997 $ref: schema.$ref, 903 - nameTransformer, 998 + case: state.nameCase, 999 + nameTransformer: state.nameTransformer, 904 1000 namespace: 'value', 905 1001 }); 906 1002 ··· 916 1012 917 1013 identifierRef = file.identifier({ 918 1014 $ref: schema.$ref, 919 - nameTransformer, 1015 + case: state.nameCase, 1016 + nameTransformer: state.nameTransformer, 920 1017 namespace: 'value', 921 1018 }); 922 1019 } ··· 947 1044 } 948 1045 } 949 1046 } else if (schema.type) { 950 - const valibotSchema = schemaTypeToValibotSchema({ 951 - plugin, 952 - schema, 953 - state, 954 - }); 1047 + const valibotSchema = schemaTypeToValibotSchema({ plugin, schema, state }); 955 1048 anyType = valibotSchema.anyType; 956 1049 pipes.push(valibotSchema.expression); 1050 + 1051 + if (plugin.config.metadata && schema.description) { 1052 + const expression = compiler.callExpression({ 1053 + functionName: compiler.propertyAccessExpression({ 1054 + expression: identifiers.v, 1055 + name: identifiers.actions.metadata, 1056 + }), 1057 + parameters: [ 1058 + compiler.objectExpression({ 1059 + obj: [ 1060 + { 1061 + key: 'description', 1062 + value: compiler.stringLiteral({ text: schema.description }), 1063 + }, 1064 + ], 1065 + }), 1066 + ], 1067 + }); 1068 + pipes.push(expression); 1069 + } 957 1070 } else if (schema.items) { 958 1071 schema = deduplicateSchema({ schema }); 959 1072 ··· 1087 1200 return pipes; 1088 1201 }; 1089 1202 1090 - export const handler: Plugin.Handler<Config> = ({ plugin }) => { 1203 + export const handler: Plugin.Handler<ResolvedConfig> = ({ plugin }) => { 1091 1204 const file = plugin.createFile({ 1092 1205 id: valibotId, 1093 - identifierCase: 'camelCase', 1206 + identifierCase: plugin.config.case, 1094 1207 path: plugin.output, 1095 1208 }); 1096 1209 ··· 1104 1217 const state: State = { 1105 1218 circularReferenceTracker: new Set(), 1106 1219 hasCircularReference: false, 1220 + nameCase: plugin.config.definitions.case, 1221 + nameTransformer: plugin.config.definitions.name, 1107 1222 }; 1108 1223 1109 1224 if (event.type === 'operation') {
+229 -4
packages/openapi-ts/src/plugins/valibot/types.d.ts
··· 1 - // import type { IR } from '../../ir/types'; 1 + import type { StringCase } from '../../types/config'; 2 2 import type { Plugin } from '../types'; 3 3 4 4 export interface Config extends Plugin.Name<'valibot'> { 5 + /** 6 + * The casing convention to use for generated names. 7 + * 8 + * @default 'camelCase' 9 + */ 10 + case?: StringCase; 5 11 /** 6 12 * Add comments from input to the generated Valibot schemas? 7 13 * ··· 9 15 */ 10 16 comments?: boolean; 11 17 /** 18 + * Configuration for reusable schema definitions. Controls generation of 19 + * shared Valibot schemas that can be referenced across requests and 20 + * responses. 21 + * 22 + * Can be: 23 + * - `boolean`: Shorthand for `{ enabled: boolean }` 24 + * - `string`: Shorthand for `{ enabled: true; name: string }` 25 + * - `object`: Full configuration object 26 + */ 27 + definitions?: 28 + | boolean 29 + | string 30 + | { 31 + /** 32 + * The casing convention to use for generated names. 33 + * 34 + * @default 'camelCase' 35 + */ 36 + case?: StringCase; 37 + /** 38 + * Whether to generate Valibot schemas for reusable definitions. 39 + * 40 + * @default true 41 + */ 42 + enabled?: boolean; 43 + /** 44 + * Custom naming pattern for generated schema names. The name variable is 45 + * obtained from the schema name. 46 + * 47 + * @default 'v{{name}}' 48 + */ 49 + name?: string | ((name: string) => string); 50 + }; 51 + /** 12 52 * Should the exports from the generated files be re-exported in the index 13 53 * barrel file? 14 54 * ··· 16 56 */ 17 57 exportFromIndex?: boolean; 18 58 /** 19 - * Customise the Valibot schema name. By default, `v{{name}}` is used, 20 - * where `name` is a definition name or an operation name. 59 + * Enable Valibot metadata support? It's often useful to associate a schema 60 + * with some additional metadata for documentation, code generation, AI 61 + * structured outputs, form validation, and other purposes. 62 + * 63 + * @default false 21 64 */ 22 - // nameBuilder?: (model: IR.OperationObject | IR.SchemaObject) => string; 65 + metadata?: boolean; 23 66 /** 24 67 * Name of the generated file. 25 68 * 26 69 * @default 'valibot' 27 70 */ 28 71 output?: string; 72 + /** 73 + * Configuration for request-specific Valibot schemas. 74 + * Controls generation of Valibot schemas for request bodies, query 75 + * parameters, path parameters, and headers. 76 + * 77 + * Can be: 78 + * - `boolean`: Shorthand for `{ enabled: boolean }` 79 + * - `string`: Shorthand for `{ enabled: true; name: string }` 80 + * - `object`: Full configuration object 81 + */ 82 + requests?: 83 + | boolean 84 + | string 85 + | { 86 + /** 87 + * The casing convention to use for generated names. 88 + * 89 + * @default 'camelCase' 90 + */ 91 + case?: StringCase; 92 + /** 93 + * Whether to generate Valibot schemas for request definitions. 94 + * 95 + * @default true 96 + */ 97 + enabled?: boolean; 98 + /** 99 + * Custom naming pattern for generated schema names. The name variable is 100 + * obtained from the operation name. 101 + * 102 + * @default 'v{{name}}Data' 103 + */ 104 + name?: string | ((name: string) => string); 105 + }; 106 + /** 107 + * Configuration for response-specific Valibot schemas. 108 + * Controls generation of Valibot schemas for response bodies, error 109 + * responses, and status codes. 110 + * 111 + * Can be: 112 + * - `boolean`: Shorthand for `{ enabled: boolean }` 113 + * - `string`: Shorthand for `{ enabled: true; name: string }` 114 + * - `object`: Full configuration object 115 + */ 116 + responses?: 117 + | boolean 118 + | string 119 + | { 120 + /** 121 + * The casing convention to use for generated names. 122 + * 123 + * @default 'camelCase' 124 + */ 125 + case?: StringCase; 126 + /** 127 + * Whether to generate Valibot schemas for response definitions. 128 + * 129 + * @default true 130 + */ 131 + enabled?: boolean; 132 + /** 133 + * Custom naming pattern for generated schema names. The name variable is 134 + * obtained from the operation name. 135 + * 136 + * @default 'v{{name}}Response' 137 + */ 138 + name?: string | ((name: string) => string); 139 + }; 140 + } 141 + 142 + export interface ResolvedConfig extends Plugin.Name<'valibot'> { 143 + /** 144 + * The casing convention to use for generated names. 145 + * 146 + * @default 'camelCase' 147 + */ 148 + case: StringCase; 149 + /** 150 + * Add comments from input to the generated Valibot schemas? 151 + * 152 + * @default true 153 + */ 154 + comments: boolean; 155 + /** 156 + * Configuration for reusable schema definitions. Controls generation of 157 + * shared Valibot schemas that can be referenced across requests and 158 + * responses. 159 + */ 160 + definitions: { 161 + /** 162 + * The casing convention to use for generated names. 163 + * 164 + * @default 'camelCase' 165 + */ 166 + case: StringCase; 167 + /** 168 + * Whether to generate Valibot schemas for reusable definitions. 169 + * 170 + * @default true 171 + */ 172 + enabled: boolean; 173 + /** 174 + * Custom naming pattern for generated schema names. The name variable is 175 + * obtained from the schema name. 176 + * 177 + * @default 'v{{name}}' 178 + */ 179 + name: string | ((name: string) => string); 180 + }; 181 + /** 182 + * Should the exports from the generated files be re-exported in the index 183 + * barrel file? 184 + * 185 + * @default false 186 + */ 187 + exportFromIndex: boolean; 188 + /** 189 + * Enable Valibot metadata support? It's often useful to associate a schema 190 + * with some additional metadata for documentation, code generation, AI 191 + * structured outputs, form validation, and other purposes. 192 + * 193 + * @default false 194 + */ 195 + metadata: boolean; 196 + /** 197 + * Name of the generated file. 198 + * 199 + * @default 'valibot' 200 + */ 201 + output: string; 202 + /** 203 + * Configuration for request-specific Valibot schemas. 204 + * Controls generation of Valibot schemas for request bodies, query 205 + * parameters, path parameters, and headers. 206 + */ 207 + requests: { 208 + /** 209 + * The casing convention to use for generated names. 210 + * 211 + * @default 'camelCase' 212 + */ 213 + case: StringCase; 214 + /** 215 + * Whether to generate Valibot schemas for request definitions. 216 + * 217 + * @default true 218 + */ 219 + enabled: boolean; 220 + /** 221 + * Custom naming pattern for generated schema names. The name variable is 222 + * obtained from the operation name. 223 + * 224 + * @default 'v{{name}}Data' 225 + */ 226 + name: string | ((name: string) => string); 227 + }; 228 + /** 229 + * Configuration for response-specific Valibot schemas. 230 + * Controls generation of Valibot schemas for response bodies, error 231 + * responses, and status codes. 232 + */ 233 + responses: { 234 + /** 235 + * The casing convention to use for generated names. 236 + * 237 + * @default 'camelCase' 238 + */ 239 + case: StringCase; 240 + /** 241 + * Whether to generate Valibot schemas for response definitions. 242 + * 243 + * @default true 244 + */ 245 + enabled: boolean; 246 + /** 247 + * Custom naming pattern for generated schema names. The name variable is 248 + * obtained from the operation name. 249 + * 250 + * @default 'v{{name}}Response' 251 + */ 252 + name: string | ((name: string) => string); 253 + }; 29 254 }