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 #1697 from hey-api/fix/export-from-index

fix: add ability to export any plugin output from index.ts

authored by

Lubos and committed by
GitHub
933472ad de799171

+155 -12
+5
.changeset/clever-plums-return.md
··· 1 + --- 2 + '@hey-api/openapi-ts': patch 3 + --- 4 + 5 + fix: add exportFromIndex option to all plugins
+1 -1
docs/openapi-ts/custom-plugin.md
··· 94 94 By default, your plugin output won't be re-exported from the `index.ts` file. To enable this feature, add `exportFromIndex: true` to your `config.ts` file. 95 95 96 96 ::: warning 97 - Re-exporting your plugin from `index.ts` may result in broken output due to naming conflicts. Ensure your exported identifiers are unique. 97 + Re-exporting your plugin from index file may result in broken output due to naming conflicts. Ensure your exported identifiers are unique. 98 98 ::: 99 99 100 100 ## Handler
+46 -3
docs/openapi-ts/output.md
··· 45 45 46 46 ::: 47 47 48 - We recommend importing artifacts from their files to avoid ambiguity, but we leave this choice up to you. 48 + ### Disable index file 49 + 50 + We recommend importing artifacts from their respective files to avoid ambiguity, but we leave this choice up to you. 49 51 50 52 ```ts 51 - import type { Pet } from './client'; // 👎 // [!code --] 52 - import type { Pet } from './client/types.gen'; // 👍 // [!code ++] 53 + import type { Pet } from './client'; 54 + // or 55 + import type { Pet } from './client/types.gen'; 56 + ``` 57 + 58 + If you're not importing artifacts from the index file, you can skip generating it altogether by setting the `output.indexFile` option to `false`. 59 + 60 + ```js 61 + import { defaultPlugins } from '@hey-api/openapi-ts'; 62 + 63 + export default { 64 + input: 'path/to/openapi.json', 65 + output: { 66 + indexFile: false, // [!code ++] 67 + path: 'src/client', 68 + }, 69 + plugins: ['@hey-api/client-fetch'], 70 + }; 71 + ``` 72 + 73 + ### Re-export more files 74 + 75 + You can choose which files should be re-exported by setting the `exportFromIndex` option to `true` on any plugin. For example, here's how you would re-export [Zod](/openapi-ts/plugins/zod) plugin exports. 76 + 77 + ```js 78 + import { defaultPlugins } from '@hey-api/openapi-ts'; 79 + 80 + export default { 81 + input: 'path/to/openapi.json', 82 + output: 'src/client', 83 + plugins: [ 84 + ...defaultPlugins, 85 + '@hey-api/client-fetch', 86 + { 87 + exportFromIndex: true, // [!code ++] 88 + name: 'zod', 89 + }, 90 + ], 91 + }; 53 92 ``` 93 + 94 + ::: warning 95 + Re-exporting additional files from index file may result in broken output due to naming conflicts. 96 + ::: 54 97 55 98 ## Client 56 99
+1
packages/openapi-ts/src/plugins/@hey-api/client-core/config.ts
··· 3 3 _tags: ['client'], 4 4 baseUrl: true, 5 5 bundle: false, 6 + exportFromIndex: false, 6 7 output: 'client', 7 8 } as const;
+7
packages/openapi-ts/src/plugins/@hey-api/client-core/types.d.ts
··· 43 43 */ 44 44 bundle?: boolean; 45 45 /** 46 + * Should the exports from the generated files be re-exported in the index 47 + * barrel file? 48 + * 49 + * @default false 50 + */ 51 + exportFromIndex?: boolean; 52 + /** 46 53 * Name of the generated file. 47 54 * 48 55 * @default 'client'
+1
packages/openapi-ts/src/plugins/@hey-api/schemas/config.ts
··· 6 6 export const defaultConfig: Plugin.Config<Config> = { 7 7 _handler: handler, 8 8 _handlerLegacy: handlerLegacy, 9 + exportFromIndex: false, 9 10 name: '@hey-api/schemas', 10 11 nameBuilder: (name) => `${name}Schema`, 11 12 output: 'schemas',
+7
packages/openapi-ts/src/plugins/@hey-api/schemas/types.d.ts
··· 9 9 10 10 export interface Config extends Plugin.Name<'@hey-api/schemas'> { 11 11 /** 12 + * Should the exports from the generated files be re-exported in the index 13 + * barrel file? 14 + * 15 + * @default false 16 + */ 17 + exportFromIndex?: boolean; 18 + /** 12 19 * Customise the schema name. By default, `{{name}}Schema` is used. `name` is a 13 20 * valid JavaScript/TypeScript identifier, e.g. if your schema name is 14 21 * "Foo-Bar", `name` value would be "FooBar".
+7
packages/openapi-ts/src/plugins/@hey-api/sdk/types.d.ts
··· 40 40 */ 41 41 client?: PluginClientNames | boolean; 42 42 /** 43 + * Should the exports from the generated files be re-exported in the index 44 + * barrel file? 45 + * 46 + * @default true 47 + */ 48 + exportFromIndex?: boolean; 49 + /** 43 50 * @deprecated 44 51 * 45 52 * **This feature works only with the legacy parser**
+1
packages/openapi-ts/src/plugins/@hey-api/transformers/config.ts
··· 10 10 _tags: ['transformer'], 11 11 bigInt: true, 12 12 dates: true, 13 + exportFromIndex: false, 13 14 name: '@hey-api/transformers', 14 15 output: 'transformers', 15 16 };
+7
packages/openapi-ts/src/plugins/@hey-api/transformers/types.d.ts
··· 14 14 */ 15 15 dates?: boolean; 16 16 /** 17 + * Should the exports from the generated files be re-exported in the index 18 + * barrel file? 19 + * 20 + * @default false 21 + */ 22 + exportFromIndex?: boolean; 23 + /** 17 24 * Name of the generated file. 18 25 * 19 26 * @default 'transformers'
+7
packages/openapi-ts/src/plugins/@hey-api/typescript/types.d.ts
··· 18 18 */ 19 19 enumsCase?: StringCase; 20 20 /** 21 + * Should the exports from the generated files be re-exported in the index 22 + * barrel file? 23 + * 24 + * @default true 25 + */ 26 + exportFromIndex?: boolean; 27 + /** 21 28 * By default, inline enums (enums not defined as reusable components in 22 29 * the input file) are generated as inlined union types. You can set 23 30 * `exportInlineEnums` to `true` to treat inline enums as reusable components.
+1
packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/config.ts
··· 7 7 _dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 8 8 _handler: handler, 9 9 _handlerLegacy: handlerLegacy, 10 + exportFromIndex: false, 10 11 infiniteQueryOptions: true, 11 12 mutationOptions: true, 12 13 name: '@tanstack/angular-query-experimental',
+7
packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/types.d.ts
··· 3 3 export interface Config 4 4 extends Plugin.Name<'@tanstack/angular-query-experimental'> { 5 5 /** 6 + * Should the exports from the generated files be re-exported in the index 7 + * barrel file? 8 + * 9 + * @default false 10 + */ 11 + exportFromIndex?: boolean; 12 + /** 6 13 * Generate {@link https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions `infiniteQueryOptions()`} helpers? These will be generated from GET and POST requests where a pagination parameter is detected. 7 14 * 8 15 * @default true
+1
packages/openapi-ts/src/plugins/@tanstack/react-query/config.ts
··· 7 7 _dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 8 8 _handler: handler, 9 9 _handlerLegacy: handlerLegacy, 10 + exportFromIndex: false, 10 11 infiniteQueryOptions: true, 11 12 mutationOptions: true, 12 13 name: '@tanstack/react-query',
+7
packages/openapi-ts/src/plugins/@tanstack/react-query/types.d.ts
··· 2 2 3 3 export interface Config extends Plugin.Name<'@tanstack/react-query'> { 4 4 /** 5 + * Should the exports from the generated files be re-exported in the index 6 + * barrel file? 7 + * 8 + * @default false 9 + */ 10 + exportFromIndex?: boolean; 11 + /** 5 12 * Generate {@link https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions `infiniteQueryOptions()`} helpers? These will be generated from GET and POST requests where a pagination parameter is detected. 6 13 * 7 14 * @default true
+1
packages/openapi-ts/src/plugins/@tanstack/solid-query/config.ts
··· 7 7 _dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 8 8 _handler: handler, 9 9 _handlerLegacy: handlerLegacy, 10 + exportFromIndex: false, 10 11 infiniteQueryOptions: true, 11 12 mutationOptions: true, 12 13 name: '@tanstack/solid-query',
+7
packages/openapi-ts/src/plugins/@tanstack/solid-query/types.d.ts
··· 2 2 3 3 export interface Config extends Plugin.Name<'@tanstack/solid-query'> { 4 4 /** 5 + * Should the exports from the generated files be re-exported in the index 6 + * barrel file? 7 + * 8 + * @default false 9 + */ 10 + exportFromIndex?: boolean; 11 + /** 5 12 * Generate `createInfiniteQuery()` helpers? These will be generated from GET and POST requests where a pagination parameter is detected. 6 13 * 7 14 * @default true
+1
packages/openapi-ts/src/plugins/@tanstack/svelte-query/config.ts
··· 7 7 _dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 8 8 _handler: handler, 9 9 _handlerLegacy: handlerLegacy, 10 + exportFromIndex: false, 10 11 infiniteQueryOptions: true, 11 12 mutationOptions: true, 12 13 name: '@tanstack/svelte-query',
+7
packages/openapi-ts/src/plugins/@tanstack/svelte-query/types.d.ts
··· 2 2 3 3 export interface Config extends Plugin.Name<'@tanstack/svelte-query'> { 4 4 /** 5 + * Should the exports from the generated files be re-exported in the index 6 + * barrel file? 7 + * 8 + * @default false 9 + */ 10 + exportFromIndex?: boolean; 11 + /** 5 12 * Generate `createInfiniteQuery()` helpers? These will be generated from GET and POST requests where a pagination parameter is detected. 6 13 * 7 14 * @default true
+1
packages/openapi-ts/src/plugins/@tanstack/vue-query/config.ts
··· 7 7 _dependencies: ['@hey-api/sdk', '@hey-api/typescript'], 8 8 _handler: handler, 9 9 _handlerLegacy: handlerLegacy, 10 + exportFromIndex: false, 10 11 infiniteQueryOptions: true, 11 12 mutationOptions: true, 12 13 name: '@tanstack/vue-query',
+7
packages/openapi-ts/src/plugins/@tanstack/vue-query/types.d.ts
··· 2 2 3 3 export interface Config extends Plugin.Name<'@tanstack/vue-query'> { 4 4 /** 5 + * Should the exports from the generated files be re-exported in the index 6 + * barrel file? 7 + * 8 + * @default false 9 + */ 10 + exportFromIndex?: boolean; 11 + /** 5 12 * Generate {@link https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions `infiniteQueryOptions()`} helpers? These will be generated from GET and POST requests where a pagination parameter is detected. 6 13 * 7 14 * @default true
+1
packages/openapi-ts/src/plugins/fastify/config.ts
··· 6 6 _dependencies: ['@hey-api/typescript'], 7 7 _handler: handler, 8 8 _handlerLegacy: () => {}, 9 + exportFromIndex: false, 9 10 name: 'fastify', 10 11 output: 'fastify', 11 12 };
+7
packages/openapi-ts/src/plugins/fastify/types.d.ts
··· 2 2 3 3 export interface Config extends Plugin.Name<'fastify'> { 4 4 /** 5 + * Should the exports from the generated files be re-exported in the index 6 + * barrel file? 7 + * 8 + * @default false 9 + */ 10 + exportFromIndex?: boolean; 11 + /** 5 12 * Name of the generated file. 6 13 * 7 14 * @default 'fastify'
+1
packages/openapi-ts/src/plugins/zod/config.ts
··· 6 6 _handler: handler, 7 7 _handlerLegacy: () => {}, 8 8 _tags: ['validator'], 9 + exportFromIndex: false, 9 10 name: 'zod', 10 11 output: 'zod', 11 12 };
+7
packages/openapi-ts/src/plugins/zod/types.d.ts
··· 3 3 4 4 export interface Config extends Plugin.Name<'zod'> { 5 5 /** 6 + * Should the exports from the generated files be re-exported in the index 7 + * barrel file? 8 + * 9 + * @default false 10 + */ 11 + exportFromIndex?: boolean; 12 + /** 6 13 * Customise the Zod schema name. By default, `z{{name}}` is used, 7 14 * where `name` is a definition name or an operation name. 8 15 */
+9 -8
packages/openapi-ts/test/openapi-ts.config.ts
··· 27 27 path: path.resolve(__dirname, 'generated', 'sample'), 28 28 }, 29 29 plugins: [ 30 - 'legacy/xhr', 31 30 // @ts-ignore 32 - // { 33 - // baseUrl: false, 34 - // // bundle: true, 35 - // name: '@hey-api/client-fetch', 36 - // strictBaseUrl: true, 37 - // }, 31 + { 32 + baseUrl: false, 33 + // bundle: true, 34 + exportFromIndex: true, 35 + name: '@hey-api/client-fetch', 36 + strictBaseUrl: true, 37 + }, 38 38 // @ts-ignore 39 39 { 40 40 // name: '@hey-api/schemas', ··· 81 81 }, 82 82 // @ts-ignore 83 83 { 84 - // name: 'zod', 84 + exportFromIndex: true, 85 + name: 'zod', 85 86 }, 86 87 ], 87 88 // useOptions: false,