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 #3560 from hey-api/docs/hooks-get-name

docs: add getName hook docs

authored by

Lubos and committed by
GitHub
072b5d39 0a9bb68c

+76 -5
+1 -1
docs/openapi-ts/configuration/output.md
··· 307 307 ``` 308 308 <!-- prettier-ignore-end --> 309 309 310 - You can skip processing by adding the output path to the tool’s ignore file (for example `.eslintignore` or `.prettierignore`). 310 + You can skip processing by adding the output path to the tool's ignore file (for example `.eslintignore` or `.prettierignore`). 311 311 312 312 ## Name Conflicts 313 313
+75 -4
docs/openapi-ts/configuration/parser.md
··· 550 550 input: 'hey-api/backend', // sign up at app.heyapi.dev 551 551 output: 'src/client', 552 552 parser: { 553 - hooks: {}, // configure global hooks here // [!code ++] 553 + hooks: {}, // configure global hooks // [!code ++] 554 554 }, 555 555 }; 556 556 ``` ··· 562 562 plugins: [ 563 563 { 564 564 name: '@tanstack/react-query', 565 - '~hooks': {}, // configure plugin hooks here // [!code ++] 565 + '~hooks': {}, // configure plugin hooks // [!code ++] 566 566 }, 567 567 ], 568 568 }; ··· 651 651 parser: { 652 652 hooks: { 653 653 symbols: { 654 - getFilePath: (symbol) => { 654 + getFilePath: (symbol) => { // [!code ++] 655 655 if (symbol.name) { // [!code ++] 656 656 return symbol.name[0]?.toLowerCase(); // [!code ++] 657 657 } // [!code ++] 658 + }, // [!code ++] 659 + }, 660 + }, 661 + }, 662 + }; 663 + ``` 664 + <!-- prettier-ignore-end --> 665 + 666 + Most plugins expose configuration options that allow you to rename many of the generated symbols. If you need even more control, use the `getName()` hook. 667 + 668 + #### Example: Enum naming 669 + 670 + By default, generated enums use the same name for both the type and the runtime value. 671 + 672 + ::: code-group 673 + 674 + ```ts [example] 675 + export const Flags = { 676 + ALPHA: 'alpha', 677 + BETA: 'beta', 678 + } as const; 679 + 680 + export type Flags = (typeof Flags)[keyof typeof Flags]; 681 + ``` 682 + 683 + ```js [config] 684 + export default { 685 + input: 'hey-api/backend', // sign up at app.heyapi.dev 686 + output: 'src/client', 687 + plugins: [ 688 + { 689 + enums: 'javascript', 690 + name: '@hey-api/typescript', 691 + }, 692 + ], 693 + }; 694 + ``` 695 + 696 + ::: 697 + 698 + While this code works perfectly fine due to TypeScript's declaration merging, let's say we want to use a different name for the type. We can accomplish this with the `getName()` hook. 699 + 700 + ::: code-group 701 + 702 + ```ts [example] 703 + export const Flags = { 704 + ALPHA: 'alpha', 705 + BETA: 'beta', 706 + } as const; 707 + 708 + export type FlagsType = (typeof Flags)[keyof typeof Flags]; // [!code ++] 709 + ``` 710 + 711 + <!-- prettier-ignore-start --> 712 + ```js [config] 713 + export default { 714 + input: 'hey-api/backend', // sign up at app.heyapi.dev 715 + output: 'src/client', 716 + plugins: [ 717 + { 718 + enums: 'javascript', 719 + name: '@hey-api/typescript', 720 + '~hooks': { 721 + symbols: { 722 + getName({ meta, name, schema }) { // [!code ++] 723 + if (schema?.type === 'enum' && meta.category === 'type') { // [!code ++] 724 + return `${name}Type`; // [!code ++] 725 + } // [!code ++] 726 + }, // [!code ++] 658 727 }, 659 728 }, 660 729 }, 661 - }, 730 + ], 662 731 }; 663 732 ``` 664 733 <!-- prettier-ignore-end --> 734 + 735 + ::: 665 736 666 737 <!--@include: ../../partials/examples.md--> 667 738 <!--@include: ../../partials/sponsors.md-->