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 #2284 from hey-api/fix/typescript-name

fix(typescript): add name option

authored by

Lubos and committed by
GitHub
0a6fca5a 82738450

+3701 -5566
+7
.changeset/silent-donkeys-itch.md
··· 1 + --- 2 + '@hey-api/openapi-ts': minor 3 + --- 4 + 5 + ### Removed `typescript+namespace` enums mode 6 + 7 + Due to a simpler TypeScript plugin implementation, the `typescript+namespace` enums mode is no longer necessary. This mode was used in the past to group inline enums under the same namespace. With the latest changes, this behavior is no longer supported. You can either choose to ignore inline enums (default), or use the `enums` transform (added in v0.78.0) to convert them into reusable components which will get exported as usual.
+4
docs/openapi-ts/clients/axios.md
··· 222 222 223 223 You can use any of the approaches mentioned in [Configuration](#configuration), depending on how granular you want your custom instance to be. 224 224 225 + ## Config API 226 + 227 + You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@hey-api/client-axios/types.d.ts) interface. 228 + 225 229 <!--@include: ../../examples.md--> 226 230 <!--@include: ../../sponsors.md-->
+4
docs/openapi-ts/clients/fetch.md
··· 299 299 300 300 You can use any of the approaches mentioned in [Configuration](#configuration), depending on how granular you want your custom method to be. 301 301 302 + ## Config API 303 + 304 + You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@hey-api/client-fetch/types.d.ts) interface. 305 + 302 306 <!--@include: ../../examples.md--> 303 307 <!--@include: ../../sponsors.md-->
+4
docs/openapi-ts/clients/next-js.md
··· 286 286 287 287 You can use any of the approaches mentioned in [Configuration](#configuration), depending on how granular you want your custom method to be. 288 288 289 + ## Config API 290 + 291 + You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@hey-api/client-next/types.d.ts) interface. 292 + 289 293 <!--@include: ../../examples.md--> 290 294 <!--@include: ../../sponsors.md-->
+4
docs/openapi-ts/clients/nuxt.md
··· 248 248 249 249 You can use any of the approaches mentioned in [Configuration](#configuration), depending on how granular you want your custom method to be. 250 250 251 + ## Config API 252 + 253 + You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@hey-api/client-nuxt/types.d.ts) interface. 254 + 251 255 <!--@include: ../../examples.md--> 252 256 <!--@include: ../../sponsors.md-->
+6
docs/openapi-ts/migrating.md
··· 7 7 8 8 While we try to avoid breaking changes, sometimes it's unavoidable in order to offer you the latest features. This page lists changes that require updates to your code. If you run into a problem with migration, please [open an issue](https://github.com/hey-api/openapi-ts/issues). 9 9 10 + ## v0.79.0 11 + 12 + ### Removed `typescript+namespace` enums mode 13 + 14 + Due to a simpler TypeScript plugin implementation, the `typescript+namespace` enums mode is no longer necessary. This mode was used in the past to group inline enums under the same namespace. With the latest changes, this behavior is no longer supported. You can either choose to ignore inline enums (default), or use the `enums` transform (added in v0.78.0) to convert them into reusable components which will get exported as usual. 15 + 10 16 ## v0.78.0 11 17 12 18 ### Added `parser` options
+4
docs/openapi-ts/output/json-schema.md
··· 96 96 } 97 97 ``` 98 98 99 + ## Config API 100 + 101 + You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@hey-api/schemas/types.d.ts) interface. 102 + 99 103 <!--@include: ../../examples.md--> 100 104 <!--@include: ../../sponsors.md-->
+4
docs/openapi-ts/output/sdk.md
··· 224 224 225 225 Learn more about available validators on the [Validators](/openapi-ts/validators) page. 226 226 227 + ## Config API 228 + 229 + You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@hey-api/sdk/types.d.ts) interface. 230 + 227 231 <!--@include: ../../examples.md--> 228 232 <!--@include: ../../sponsors.md-->
+62 -40
docs/openapi-ts/output/typescript.md
··· 7 7 8 8 TypeScript interfaces are located in the `types.gen.ts` file. This is the only file that does not impact your bundle size and runtime performance. It will get discarded during build time, unless you configured to emit runtime [enums](#enums). 9 9 10 - This file contains three different categories of interfaces created from your input: 10 + ## Installation 11 11 12 - - reusable components 13 - - operation request, response, and error data 14 - - enums 12 + In your [configuration](/openapi-ts/get-started), add `@hey-api/typescript` to your plugins and you'll be ready to generate TypeScript artifacts. :tada: 15 13 16 - Depending on your input and configuration, some of these categories might be missing or differ in your output (and that's okay!). 14 + ```js 15 + export default { 16 + input: 'https://get.heyapi.dev/hey-api/backend', 17 + output: 'src/client', 18 + plugins: [ 19 + // ...other plugins 20 + '@hey-api/typescript', // [!code ++] 21 + ], 22 + }; 23 + ``` 17 24 18 - ::: code-group 25 + :::tip 26 + The `@hey-api/typescript` plugin might be implicitly added to your `plugins` if another plugin depends on it. 27 + ::: 28 + 29 + ## Output 30 + 31 + The TypeScript plugin will generate the following artifacts, depending on the input specification. 32 + 33 + ## Requests 19 34 20 - ```ts [types.gen.ts] 21 - export type Pet = { 22 - id?: number; 23 - name: string; 24 - }; 35 + A single request type is generated for each endpoint. It may contain a request body, parameters, and headers. 25 36 37 + ```ts 26 38 export type AddPetData = { 27 - body: Pet; 39 + body: { 40 + id?: number; 41 + name: string; 42 + }; 43 + path?: never; 44 + query?: never; 45 + url: '/pets'; 28 46 }; 29 - 30 - export type AddPetResponse = Pet; 31 47 ``` 32 48 33 - ::: 49 + You can customize the naming and casing pattern for `requests` schemas using the `.name` and `.case` options. 34 50 35 - Every generated interface inside `types.gen.ts` is exported. You can import individual exports in your application and use them as necessary. 51 + ## Responses 36 52 37 - ## Configuration 53 + A single type is generated for all endpoint's responses. 38 54 39 - You can modify the contents of `types.gen.ts` by configuring the `@hey-api/typescript` plugin. Note that you must specify the default plugins to preserve the default output. 55 + ```ts 56 + export type AddPetResponses = { 57 + 200: { 58 + id?: number; 59 + name: string; 60 + }; 61 + }; 40 62 41 - ```js 42 - import { defaultPlugins } from '@hey-api/openapi-ts'; 63 + export type AddPetResponse = AddPetResponses[keyof AddPetResponses]; 64 + ``` 43 65 44 - export default { 45 - input: 'https://get.heyapi.dev/hey-api/backend', 46 - output: 'src/client', 47 - plugins: [ 48 - ...defaultPlugins, 49 - { 50 - name: '@hey-api/typescript', 51 - // ...custom options // [!code ++] 52 - }, 53 - ], 66 + You can customize the naming and casing pattern for `responses` schemas using the `.name` and `.case` options. 67 + 68 + ## Definitions 69 + 70 + A type is generated for every reusable definition from your input. 71 + 72 + ```ts 73 + export type Pet = { 74 + id?: number; 75 + name: string; 54 76 }; 55 77 ``` 78 + 79 + You can customize the naming and casing pattern for `definitions` schemas using the `.name` and `.case` options. 56 80 57 81 ## Enums 58 82 59 - By default, `@hey-api/openapi-ts` will only emit enums as types. You may want to generate runtime artifacts. A good use case is iterating through possible field values without manually typing arrays. To emit runtime enums, set `enums` to a valid option. 83 + By default, `@hey-api/typescript` will emit enums only as types. You may want to generate runtime artifacts. A good use case is iterating through possible field values without manually typing arrays. To emit runtime enums, set `enums` to a valid option. 60 84 61 85 ::: code-group 62 86 63 87 ```js [disabled] 64 - import { defaultPlugins } from '@hey-api/openapi-ts'; 65 - 66 88 export default { 67 89 input: 'https://get.heyapi.dev/hey-api/backend', 68 90 output: 'src/client', 69 91 plugins: [ 70 - ...defaultPlugins, 92 + // ...other plugins 71 93 { 72 94 enums: false, // default // [!code ++] 73 95 name: '@hey-api/typescript', ··· 77 99 ``` 78 100 79 101 ```js [javascript] 80 - import { defaultPlugins } from '@hey-api/openapi-ts'; 81 - 82 102 export default { 83 103 input: 'https://get.heyapi.dev/hey-api/backend', 84 104 output: 'src/client', 85 105 plugins: [ 86 - ...defaultPlugins, 106 + // ...other plugins 87 107 { 88 108 enums: 'javascript', // [!code ++] 89 109 name: '@hey-api/typescript', ··· 93 113 ``` 94 114 95 115 ```js [typescript] 96 - import { defaultPlugins } from '@hey-api/openapi-ts'; 97 - 98 116 export default { 99 117 input: 'https://get.heyapi.dev/hey-api/backend', 100 118 output: 'src/client', 101 119 plugins: [ 102 - ...defaultPlugins, 120 + // ...other plugins 103 121 { 104 122 enums: 'typescript', // [!code ++] 105 123 name: '@hey-api/typescript', ··· 111 129 ::: 112 130 113 131 We recommend exporting enums as plain JavaScript objects. [TypeScript enums](https://www.typescriptlang.org/docs/handbook/enums.html) are not a type-level extension of JavaScript and pose [typing challenges](https://dev.to/ivanzm123/dont-use-enums-in-typescript-they-are-very-dangerous-57bh). 132 + 133 + ## Config API 134 + 135 + You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@hey-api/typescript/types.d.ts) interface. 114 136 115 137 <!--@include: ../../examples.md--> 116 138 <!--@include: ../../sponsors.md-->
+2 -2
docs/openapi-ts/plugins/custom.md
··· 33 33 ```ts [types.d.ts] 34 34 import type { DefinePlugin } from '@hey-api/openapi-ts'; 35 35 36 - export type Config = { 36 + export type UserConfig = { 37 37 /** 38 38 * Plugin name. Must be unique. 39 39 */ ··· 52 52 myOption?: boolean; 53 53 }; 54 54 55 - export type MyPlugin = DefinePlugin<Config>; 55 + export type MyPlugin = DefinePlugin<UserConfig>; 56 56 ``` 57 57 58 58 :::
+4
docs/openapi-ts/plugins/fastify.md
··· 75 75 fastify.register(glue, { serviceHandlers }); 76 76 ``` 77 77 78 + ## Config API 79 + 80 + You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/fastify/types.d.ts) interface. 81 + 78 82 <!--@include: ../../examples.md--> 79 83 <!--@include: ../../sponsors.md-->
+4
docs/openapi-ts/plugins/tanstack-query.md
··· 200 200 201 201 You can customize the naming and casing pattern for `mutationOptions` functions using the `.name` and `.case` options. 202 202 203 + ## Config API 204 + 205 + You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@tanstack/react-query/types.d.ts) interface. 206 + 203 207 <!--@include: ../../examples.md--> 204 208 <!--@include: ../../sponsors.md-->
+4
docs/openapi-ts/plugins/valibot.md
··· 142 142 }; 143 143 ``` 144 144 145 + ## Config API 146 + 147 + You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/valibot/types.d.ts) interface. 148 + 145 149 <!--@include: ../../examples.md--> 146 150 <!--@include: ../../sponsors.md-->
+4
docs/openapi-ts/plugins/zod.md
··· 142 142 }; 143 143 ``` 144 144 145 + ## Config API 146 + 147 + You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/zod/types.d.ts) interface. 148 + 145 149 <!--@include: ../../examples.md--> 146 150 <!--@include: ../../sponsors.md-->
+4
docs/openapi-ts/transformers.md
··· 139 139 140 140 ::: 141 141 142 + ## Config API 143 + 144 + You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@hey-api/transformers/types.d.ts) interface. 145 + 142 146 <!--@include: ../sponsors.md-->
+4 -22
packages/openapi-ts-tests/test/3.0.x.test.ts
··· 96 96 }, 97 97 { 98 98 config: createConfig({ 99 - input: 'case.json', 99 + input: 'case.yaml', 100 100 output: 'case-preserve', 101 101 plugins: [ 102 102 { ··· 109 109 }, 110 110 { 111 111 config: createConfig({ 112 - input: 'case.json', 112 + input: 'case.yaml', 113 113 output: 'case-PascalCase', 114 114 plugins: [ 115 115 { ··· 122 122 }, 123 123 { 124 124 config: createConfig({ 125 - input: 'case.json', 125 + input: 'case.yaml', 126 126 output: 'case-camelCase', 127 127 plugins: [ 128 128 { ··· 135 135 }, 136 136 { 137 137 config: createConfig({ 138 - input: 'case.json', 138 + input: 'case.yaml', 139 139 output: 'case-snake_case', 140 140 plugins: [ 141 141 { ··· 255 255 ], 256 256 }), 257 257 description: 'exports inline enums (TypeScript)', 258 - }, 259 - { 260 - config: createConfig({ 261 - input: 'enum-inline.json', 262 - output: 'enum-inline-typescript-namespace', 263 - parser: { 264 - transforms: { 265 - enums: 'root', 266 - }, 267 - }, 268 - plugins: [ 269 - { 270 - enums: 'typescript+namespace', 271 - name: '@hey-api/typescript', 272 - }, 273 - ], 274 - }), 275 - description: 'exports inline enums (TypeScript namespace)', 276 258 }, 277 259 { 278 260 config: createConfig({
+4 -22
packages/openapi-ts-tests/test/3.1.x.test.ts
··· 96 96 }, 97 97 { 98 98 config: createConfig({ 99 - input: 'case.json', 99 + input: 'case.yaml', 100 100 output: 'case-preserve', 101 101 plugins: [ 102 102 { ··· 109 109 }, 110 110 { 111 111 config: createConfig({ 112 - input: 'case.json', 112 + input: 'case.yaml', 113 113 output: 'case-PascalCase', 114 114 plugins: [ 115 115 { ··· 122 122 }, 123 123 { 124 124 config: createConfig({ 125 - input: 'case.json', 125 + input: 'case.yaml', 126 126 output: 'case-camelCase', 127 127 plugins: [ 128 128 { ··· 135 135 }, 136 136 { 137 137 config: createConfig({ 138 - input: 'case.json', 138 + input: 'case.yaml', 139 139 output: 'case-snake_case', 140 140 plugins: [ 141 141 { ··· 269 269 ], 270 270 }), 271 271 description: 'exports inline enums (TypeScript)', 272 - }, 273 - { 274 - config: createConfig({ 275 - input: 'enum-inline.yaml', 276 - output: 'enum-inline-typescript-namespace', 277 - parser: { 278 - transforms: { 279 - enums: 'root', 280 - }, 281 - }, 282 - plugins: [ 283 - { 284 - enums: 'typescript+namespace', 285 - name: '@hey-api/typescript', 286 - }, 287 - ], 288 - }), 289 - description: 'exports inline enums (TypeScript namespace)', 290 272 }, 291 273 { 292 274 config: createConfig({
+7 -13
packages/openapi-ts-tests/test/__snapshots__/2.0.x/enum-names-values-javascript-PascalCase/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export type _110 = '1-10' | '11-20'; 4 - 5 3 export const _110 = { 6 4 110: '1-10', 7 5 1120: '11-20' 8 6 } as const; 9 7 10 - export type MyFoo = 'myFoo' | 'myBar'; 8 + export type _110 = typeof _110[keyof typeof _110]; 11 9 12 10 export const MyFoo = { 13 11 MyFoo: 'myFoo', 14 12 MyBar: 'myBar' 15 13 } as const; 16 14 17 - export type MyFoo2 = 'MyFoo' | 'MyBar'; 15 + export type MyFoo = typeof MyFoo[keyof typeof MyFoo]; 18 16 19 17 export const MyFoo2 = { 20 18 MyFoo: 'MyFoo', 21 19 MyBar: 'MyBar' 22 20 } as const; 23 21 24 - export type Foo = 'foo' | 'bar' | '' | true | false; 22 + export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2]; 25 23 26 24 export const Foo = { 27 25 Foo: 'foo', ··· 31 29 False: false 32 30 } as const; 33 31 34 - export type Numbers = 100 | 200 | 300 | -100 | -200 | -300; 32 + export type Foo = typeof Foo[keyof typeof Foo]; 35 33 36 34 export const Numbers = { 37 35 100: 100, ··· 42 40 '-300': -300 43 41 } as const; 44 42 45 - export type Arrays = [ 46 - 'foo' 47 - ] | [ 48 - 'bar' 49 - ] | [ 50 - 'baz' 51 - ]; 43 + export type Numbers = typeof Numbers[keyof typeof Numbers]; 52 44 53 45 export const Arrays = { 54 46 0: ['foo'], 55 47 1: ['bar'], 56 48 2: ['baz'] 57 49 } as const; 50 + 51 + export type Arrays = typeof Arrays[keyof typeof Arrays]; 58 52 59 53 export type ClientOptions = { 60 54 baseUrl: string;
+7 -13
packages/openapi-ts-tests/test/__snapshots__/2.0.x/enum-names-values-javascript-SCREAMING_SNAKE_CASE/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export type _110 = '1-10' | '11-20'; 4 - 5 3 export const _110 = { 6 4 '1_10': '1-10', 7 5 '11_20': '11-20' 8 6 } as const; 9 7 10 - export type MyFoo = 'myFoo' | 'myBar'; 8 + export type _110 = typeof _110[keyof typeof _110]; 11 9 12 10 export const MyFoo = { 13 11 MY_FOO: 'myFoo', 14 12 MY_BAR: 'myBar' 15 13 } as const; 16 14 17 - export type MyFoo2 = 'MyFoo' | 'MyBar'; 15 + export type MyFoo = typeof MyFoo[keyof typeof MyFoo]; 18 16 19 17 export const MyFoo2 = { 20 18 MY_FOO: 'MyFoo', 21 19 MY_BAR: 'MyBar' 22 20 } as const; 23 21 24 - export type Foo = 'foo' | 'bar' | '' | true | false; 22 + export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2]; 25 23 26 24 export const Foo = { 27 25 FOO: 'foo', ··· 31 29 FALSE: false 32 30 } as const; 33 31 34 - export type Numbers = 100 | 200 | 300 | -100 | -200 | -300; 32 + export type Foo = typeof Foo[keyof typeof Foo]; 35 33 36 34 export const Numbers = { 37 35 100: 100, ··· 42 40 '-300': -300 43 41 } as const; 44 42 45 - export type Arrays = [ 46 - 'foo' 47 - ] | [ 48 - 'bar' 49 - ] | [ 50 - 'baz' 51 - ]; 43 + export type Numbers = typeof Numbers[keyof typeof Numbers]; 52 44 53 45 export const Arrays = { 54 46 0: ['foo'], 55 47 1: ['bar'], 56 48 2: ['baz'] 57 49 } as const; 50 + 51 + export type Arrays = typeof Arrays[keyof typeof Arrays]; 58 52 59 53 export type ClientOptions = { 60 54 baseUrl: string;
+7 -13
packages/openapi-ts-tests/test/__snapshots__/2.0.x/enum-names-values-javascript-camelCase/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export type _110 = '1-10' | '11-20'; 4 - 5 3 export const _110 = { 6 4 110: '1-10', 7 5 1120: '11-20' 8 6 } as const; 9 7 10 - export type MyFoo = 'myFoo' | 'myBar'; 8 + export type _110 = typeof _110[keyof typeof _110]; 11 9 12 10 export const MyFoo = { 13 11 myFoo: 'myFoo', 14 12 myBar: 'myBar' 15 13 } as const; 16 14 17 - export type MyFoo2 = 'MyFoo' | 'MyBar'; 15 + export type MyFoo = typeof MyFoo[keyof typeof MyFoo]; 18 16 19 17 export const MyFoo2 = { 20 18 myFoo: 'MyFoo', 21 19 myBar: 'MyBar' 22 20 } as const; 23 21 24 - export type Foo = 'foo' | 'bar' | '' | true | false; 22 + export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2]; 25 23 26 24 export const Foo = { 27 25 foo: 'foo', ··· 31 29 false: false 32 30 } as const; 33 31 34 - export type Numbers = 100 | 200 | 300 | -100 | -200 | -300; 32 + export type Foo = typeof Foo[keyof typeof Foo]; 35 33 36 34 export const Numbers = { 37 35 100: 100, ··· 42 40 '-300': -300 43 41 } as const; 44 42 45 - export type Arrays = [ 46 - 'foo' 47 - ] | [ 48 - 'bar' 49 - ] | [ 50 - 'baz' 51 - ]; 43 + export type Numbers = typeof Numbers[keyof typeof Numbers]; 52 44 53 45 export const Arrays = { 54 46 0: ['foo'], 55 47 1: ['bar'], 56 48 2: ['baz'] 57 49 } as const; 50 + 51 + export type Arrays = typeof Arrays[keyof typeof Arrays]; 58 52 59 53 export type ClientOptions = { 60 54 baseUrl: string;
+7 -13
packages/openapi-ts-tests/test/__snapshots__/2.0.x/enum-names-values-javascript-preserve/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export type _110 = '1-10' | '11-20'; 4 - 5 3 export const _110 = { 6 4 '1-10': '1-10', 7 5 '11-20': '11-20' 8 6 } as const; 9 7 10 - export type MyFoo = 'myFoo' | 'myBar'; 8 + export type _110 = typeof _110[keyof typeof _110]; 11 9 12 10 export const MyFoo = { 13 11 myFoo: 'myFoo', 14 12 myBar: 'myBar' 15 13 } as const; 16 14 17 - export type MyFoo2 = 'MyFoo' | 'MyBar'; 15 + export type MyFoo = typeof MyFoo[keyof typeof MyFoo]; 18 16 19 17 export const MyFoo2 = { 20 18 MyFoo: 'MyFoo', 21 19 MyBar: 'MyBar' 22 20 } as const; 23 21 24 - export type Foo = 'foo' | 'bar' | '' | true | false; 22 + export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2]; 25 23 26 24 export const Foo = { 27 25 foo: 'foo', ··· 31 29 false: false 32 30 } as const; 33 31 34 - export type Numbers = 100 | 200 | 300 | -100 | -200 | -300; 32 + export type Foo = typeof Foo[keyof typeof Foo]; 35 33 36 34 export const Numbers = { 37 35 100: 100, ··· 42 40 '-300': -300 43 41 } as const; 44 42 45 - export type Arrays = [ 46 - 'foo' 47 - ] | [ 48 - 'bar' 49 - ] | [ 50 - 'baz' 51 - ]; 43 + export type Numbers = typeof Numbers[keyof typeof Numbers]; 52 44 53 45 export const Arrays = { 54 46 0: ['foo'], 55 47 1: ['bar'], 56 48 2: ['baz'] 57 49 } as const; 50 + 51 + export type Arrays = typeof Arrays[keyof typeof Arrays]; 58 52 59 53 export type ClientOptions = { 60 54 baseUrl: string;
+7 -13
packages/openapi-ts-tests/test/__snapshots__/2.0.x/enum-names-values-javascript-snake_case/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export type _110 = '1-10' | '11-20'; 4 - 5 3 export const _110 = { 6 4 '1_10': '1-10', 7 5 '11_20': '11-20' 8 6 } as const; 9 7 10 - export type MyFoo = 'myFoo' | 'myBar'; 8 + export type _110 = typeof _110[keyof typeof _110]; 11 9 12 10 export const MyFoo = { 13 11 my_foo: 'myFoo', 14 12 my_bar: 'myBar' 15 13 } as const; 16 14 17 - export type MyFoo2 = 'MyFoo' | 'MyBar'; 15 + export type MyFoo = typeof MyFoo[keyof typeof MyFoo]; 18 16 19 17 export const MyFoo2 = { 20 18 my_foo: 'MyFoo', 21 19 my_bar: 'MyBar' 22 20 } as const; 23 21 24 - export type Foo = 'foo' | 'bar' | '' | true | false; 22 + export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2]; 25 23 26 24 export const Foo = { 27 25 foo: 'foo', ··· 31 29 false: false 32 30 } as const; 33 31 34 - export type Numbers = 100 | 200 | 300 | -100 | -200 | -300; 32 + export type Foo = typeof Foo[keyof typeof Foo]; 35 33 36 34 export const Numbers = { 37 35 100: 100, ··· 42 40 '-300': -300 43 41 } as const; 44 42 45 - export type Arrays = [ 46 - 'foo' 47 - ] | [ 48 - 'bar' 49 - ] | [ 50 - 'baz' 51 - ]; 43 + export type Numbers = typeof Numbers[keyof typeof Numbers]; 52 44 53 45 export const Arrays = { 54 46 0: ['foo'], 55 47 1: ['bar'], 56 48 2: ['baz'] 57 49 } as const; 50 + 51 + export type Arrays = typeof Arrays[keyof typeof Arrays]; 58 52 59 53 export type ClientOptions = { 60 54 baseUrl: string;
+3 -3
packages/openapi-ts-tests/test/__snapshots__/3.0.x/case-preserve/types.gen.ts
··· 51 51 */ 52 52 export type FooBar = string; 53 53 54 - export type GetFooData = { 54 + export type getFooData = { 55 55 body: Foo; 56 56 path?: never; 57 57 query: { ··· 71 71 url: '/foo'; 72 72 }; 73 73 74 - export type GetFooResponses = { 74 + export type getFooResponses = { 75 75 /** 76 76 * OK 77 77 */ ··· 82 82 201: _201; 83 83 }; 84 84 85 - export type GetFooResponse = GetFooResponses[keyof GetFooResponses]; 85 + export type getFooResponse = getFooResponses[keyof getFooResponses]; 86 86 87 87 export type ClientOptions = { 88 88 baseUrl: `${string}://${string}` | (string & {});
+2 -2
packages/openapi-ts-tests/test/__snapshots__/3.0.x/enum-inline-javascript/types.gen.ts
··· 4 4 type?: TypeEnum; 5 5 }; 6 6 7 - export type TypeEnum = 'foo' | 'bar'; 8 - 9 7 export const TypeEnum = { 10 8 FOO: 'foo', 11 9 BAR: 'bar' 12 10 } as const; 11 + 12 + export type TypeEnum = typeof TypeEnum[keyof typeof TypeEnum]; 13 13 14 14 export type ClientOptions = { 15 15 baseUrl: `${string}://${string}` | (string & {});
-2
packages/openapi-ts-tests/test/__snapshots__/3.0.x/enum-inline-typescript-namespace/index.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - export * from './types.gen';
-14
packages/openapi-ts-tests/test/__snapshots__/3.0.x/enum-inline-typescript-namespace/types.gen.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - export type Foo = { 4 - type?: TypeEnum; 5 - }; 6 - 7 - export enum TypeEnum { 8 - FOO = 'foo', 9 - BAR = 'bar' 10 - } 11 - 12 - export type ClientOptions = { 13 - baseUrl: `${string}://${string}` | (string & {}); 14 - };
+7 -13
packages/openapi-ts-tests/test/__snapshots__/3.0.x/enum-names-values-javascript-PascalCase/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export type _110 = '1-10' | '11-20'; 4 - 5 3 export const _110 = { 6 4 110: '1-10', 7 5 1120: '11-20' 8 6 } as const; 9 7 10 - export type MyFoo = 'myFoo' | 'myBar'; 8 + export type _110 = typeof _110[keyof typeof _110]; 11 9 12 10 export const MyFoo = { 13 11 MyFoo: 'myFoo', 14 12 MyBar: 'myBar' 15 13 } as const; 16 14 17 - export type MyFoo2 = 'MyFoo' | 'MyBar'; 15 + export type MyFoo = typeof MyFoo[keyof typeof MyFoo]; 18 16 19 17 export const MyFoo2 = { 20 18 MyFoo: 'MyFoo', 21 19 MyBar: 'MyBar' 22 20 } as const; 23 21 24 - export type Foo = 'foo' | 'bar' | null | '' | true | false; 22 + export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2]; 25 23 26 24 export const Foo = { 27 25 Foo: 'foo', ··· 32 30 False: false 33 31 } as const; 34 32 35 - export type Numbers = 100 | 200 | 300 | -100 | -200 | -300; 33 + export type Foo = typeof Foo[keyof typeof Foo]; 36 34 37 35 export const Numbers = { 38 36 100: 100, ··· 43 41 '-300': -300 44 42 } as const; 45 43 46 - export type Arrays = [ 47 - 'foo' 48 - ] | [ 49 - 'bar' 50 - ] | [ 51 - 'baz' 52 - ]; 44 + export type Numbers = typeof Numbers[keyof typeof Numbers]; 53 45 54 46 export const Arrays = { 55 47 0: ['foo'], 56 48 1: ['bar'], 57 49 2: ['baz'] 58 50 } as const; 51 + 52 + export type Arrays = typeof Arrays[keyof typeof Arrays]; 59 53 60 54 export type ClientOptions = { 61 55 baseUrl: `${string}://${string}` | (string & {});
+7 -13
packages/openapi-ts-tests/test/__snapshots__/3.0.x/enum-names-values-javascript-SCREAMING_SNAKE_CASE/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export type _110 = '1-10' | '11-20'; 4 - 5 3 export const _110 = { 6 4 '1_10': '1-10', 7 5 '11_20': '11-20' 8 6 } as const; 9 7 10 - export type MyFoo = 'myFoo' | 'myBar'; 8 + export type _110 = typeof _110[keyof typeof _110]; 11 9 12 10 export const MyFoo = { 13 11 MY_FOO: 'myFoo', 14 12 MY_BAR: 'myBar' 15 13 } as const; 16 14 17 - export type MyFoo2 = 'MyFoo' | 'MyBar'; 15 + export type MyFoo = typeof MyFoo[keyof typeof MyFoo]; 18 16 19 17 export const MyFoo2 = { 20 18 MY_FOO: 'MyFoo', 21 19 MY_BAR: 'MyBar' 22 20 } as const; 23 21 24 - export type Foo = 'foo' | 'bar' | null | '' | true | false; 22 + export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2]; 25 23 26 24 export const Foo = { 27 25 FOO: 'foo', ··· 32 30 FALSE: false 33 31 } as const; 34 32 35 - export type Numbers = 100 | 200 | 300 | -100 | -200 | -300; 33 + export type Foo = typeof Foo[keyof typeof Foo]; 36 34 37 35 export const Numbers = { 38 36 100: 100, ··· 43 41 '-300': -300 44 42 } as const; 45 43 46 - export type Arrays = [ 47 - 'foo' 48 - ] | [ 49 - 'bar' 50 - ] | [ 51 - 'baz' 52 - ]; 44 + export type Numbers = typeof Numbers[keyof typeof Numbers]; 53 45 54 46 export const Arrays = { 55 47 0: ['foo'], 56 48 1: ['bar'], 57 49 2: ['baz'] 58 50 } as const; 51 + 52 + export type Arrays = typeof Arrays[keyof typeof Arrays]; 59 53 60 54 export type ClientOptions = { 61 55 baseUrl: `${string}://${string}` | (string & {});
+7 -13
packages/openapi-ts-tests/test/__snapshots__/3.0.x/enum-names-values-javascript-camelCase/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export type _110 = '1-10' | '11-20'; 4 - 5 3 export const _110 = { 6 4 110: '1-10', 7 5 1120: '11-20' 8 6 } as const; 9 7 10 - export type MyFoo = 'myFoo' | 'myBar'; 8 + export type _110 = typeof _110[keyof typeof _110]; 11 9 12 10 export const MyFoo = { 13 11 myFoo: 'myFoo', 14 12 myBar: 'myBar' 15 13 } as const; 16 14 17 - export type MyFoo2 = 'MyFoo' | 'MyBar'; 15 + export type MyFoo = typeof MyFoo[keyof typeof MyFoo]; 18 16 19 17 export const MyFoo2 = { 20 18 myFoo: 'MyFoo', 21 19 myBar: 'MyBar' 22 20 } as const; 23 21 24 - export type Foo = 'foo' | 'bar' | null | '' | true | false; 22 + export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2]; 25 23 26 24 export const Foo = { 27 25 foo: 'foo', ··· 32 30 false: false 33 31 } as const; 34 32 35 - export type Numbers = 100 | 200 | 300 | -100 | -200 | -300; 33 + export type Foo = typeof Foo[keyof typeof Foo]; 36 34 37 35 export const Numbers = { 38 36 100: 100, ··· 43 41 '-300': -300 44 42 } as const; 45 43 46 - export type Arrays = [ 47 - 'foo' 48 - ] | [ 49 - 'bar' 50 - ] | [ 51 - 'baz' 52 - ]; 44 + export type Numbers = typeof Numbers[keyof typeof Numbers]; 53 45 54 46 export const Arrays = { 55 47 0: ['foo'], 56 48 1: ['bar'], 57 49 2: ['baz'] 58 50 } as const; 51 + 52 + export type Arrays = typeof Arrays[keyof typeof Arrays]; 59 53 60 54 export type ClientOptions = { 61 55 baseUrl: `${string}://${string}` | (string & {});
+7 -13
packages/openapi-ts-tests/test/__snapshots__/3.0.x/enum-names-values-javascript-ignore-null/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export type _110 = '1-10' | '11-20'; 4 - 5 3 export const _110 = { 6 4 '1-10': '1-10', 7 5 '11-20': '11-20' 8 6 } as const; 9 7 10 - export type MyFoo = 'myFoo' | 'myBar'; 8 + export type _110 = typeof _110[keyof typeof _110]; 11 9 12 10 export const MyFoo = { 13 11 myFoo: 'myFoo', 14 12 myBar: 'myBar' 15 13 } as const; 16 14 17 - export type MyFoo2 = 'MyFoo' | 'MyBar'; 15 + export type MyFoo = typeof MyFoo[keyof typeof MyFoo]; 18 16 19 17 export const MyFoo2 = { 20 18 MyFoo: 'MyFoo', 21 19 MyBar: 'MyBar' 22 20 } as const; 23 21 24 - export type Foo = 'foo' | 'bar' | null | '' | true | false; 22 + export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2]; 25 23 26 24 export const Foo = { 27 25 foo: 'foo', ··· 31 29 false: false 32 30 } as const; 33 31 34 - export type Numbers = 100 | 200 | 300 | -100 | -200 | -300; 32 + export type Foo = typeof Foo[keyof typeof Foo]; 35 33 36 34 export const Numbers = { 37 35 100: 100, ··· 42 40 '-300': -300 43 41 } as const; 44 42 45 - export type Arrays = [ 46 - 'foo' 47 - ] | [ 48 - 'bar' 49 - ] | [ 50 - 'baz' 51 - ]; 43 + export type Numbers = typeof Numbers[keyof typeof Numbers]; 52 44 53 45 export const Arrays = { 54 46 0: ['foo'], 55 47 1: ['bar'], 56 48 2: ['baz'] 57 49 } as const; 50 + 51 + export type Arrays = typeof Arrays[keyof typeof Arrays]; 58 52 59 53 export type ClientOptions = { 60 54 baseUrl: `${string}://${string}` | (string & {});
+7 -13
packages/openapi-ts-tests/test/__snapshots__/3.0.x/enum-names-values-javascript-preserve/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export type _110 = '1-10' | '11-20'; 4 - 5 3 export const _110 = { 6 4 '1-10': '1-10', 7 5 '11-20': '11-20' 8 6 } as const; 9 7 10 - export type MyFoo = 'myFoo' | 'myBar'; 8 + export type _110 = typeof _110[keyof typeof _110]; 11 9 12 10 export const MyFoo = { 13 11 myFoo: 'myFoo', 14 12 myBar: 'myBar' 15 13 } as const; 16 14 17 - export type MyFoo2 = 'MyFoo' | 'MyBar'; 15 + export type MyFoo = typeof MyFoo[keyof typeof MyFoo]; 18 16 19 17 export const MyFoo2 = { 20 18 MyFoo: 'MyFoo', 21 19 MyBar: 'MyBar' 22 20 } as const; 23 21 24 - export type Foo = 'foo' | 'bar' | null | '' | true | false; 22 + export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2]; 25 23 26 24 export const Foo = { 27 25 foo: 'foo', ··· 32 30 false: false 33 31 } as const; 34 32 35 - export type Numbers = 100 | 200 | 300 | -100 | -200 | -300; 33 + export type Foo = typeof Foo[keyof typeof Foo]; 36 34 37 35 export const Numbers = { 38 36 100: 100, ··· 43 41 '-300': -300 44 42 } as const; 45 43 46 - export type Arrays = [ 47 - 'foo' 48 - ] | [ 49 - 'bar' 50 - ] | [ 51 - 'baz' 52 - ]; 44 + export type Numbers = typeof Numbers[keyof typeof Numbers]; 53 45 54 46 export const Arrays = { 55 47 0: ['foo'], 56 48 1: ['bar'], 57 49 2: ['baz'] 58 50 } as const; 51 + 52 + export type Arrays = typeof Arrays[keyof typeof Arrays]; 59 53 60 54 export type ClientOptions = { 61 55 baseUrl: `${string}://${string}` | (string & {});
+7 -13
packages/openapi-ts-tests/test/__snapshots__/3.0.x/enum-names-values-javascript-snake_case/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export type _110 = '1-10' | '11-20'; 4 - 5 3 export const _110 = { 6 4 '1_10': '1-10', 7 5 '11_20': '11-20' 8 6 } as const; 9 7 10 - export type MyFoo = 'myFoo' | 'myBar'; 8 + export type _110 = typeof _110[keyof typeof _110]; 11 9 12 10 export const MyFoo = { 13 11 my_foo: 'myFoo', 14 12 my_bar: 'myBar' 15 13 } as const; 16 14 17 - export type MyFoo2 = 'MyFoo' | 'MyBar'; 15 + export type MyFoo = typeof MyFoo[keyof typeof MyFoo]; 18 16 19 17 export const MyFoo2 = { 20 18 my_foo: 'MyFoo', 21 19 my_bar: 'MyBar' 22 20 } as const; 23 21 24 - export type Foo = 'foo' | 'bar' | null | '' | true | false; 22 + export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2]; 25 23 26 24 export const Foo = { 27 25 foo: 'foo', ··· 32 30 false: false 33 31 } as const; 34 32 35 - export type Numbers = 100 | 200 | 300 | -100 | -200 | -300; 33 + export type Foo = typeof Foo[keyof typeof Foo]; 36 34 37 35 export const Numbers = { 38 36 100: 100, ··· 43 41 '-300': -300 44 42 } as const; 45 43 46 - export type Arrays = [ 47 - 'foo' 48 - ] | [ 49 - 'bar' 50 - ] | [ 51 - 'baz' 52 - ]; 44 + export type Numbers = typeof Numbers[keyof typeof Numbers]; 53 45 54 46 export const Arrays = { 55 47 0: ['foo'], 56 48 1: ['bar'], 57 49 2: ['baz'] 58 50 } as const; 51 + 52 + export type Arrays = typeof Arrays[keyof typeof Arrays]; 59 53 60 54 export type ClientOptions = { 61 55 baseUrl: `${string}://${string}` | (string & {});
+3 -3
packages/openapi-ts-tests/test/__snapshots__/3.1.x/case-preserve/types.gen.ts
··· 51 51 */ 52 52 export type FooBar = string; 53 53 54 - export type GetFooData = { 54 + export type getFooData = { 55 55 body: Foo; 56 56 path?: never; 57 57 query: { ··· 71 71 url: '/foo'; 72 72 }; 73 73 74 - export type GetFooResponses = { 74 + export type getFooResponses = { 75 75 /** 76 76 * OK 77 77 */ ··· 82 82 201: _201; 83 83 }; 84 84 85 - export type GetFooResponse = GetFooResponses[keyof GetFooResponses]; 85 + export type getFooResponse = getFooResponses[keyof getFooResponses]; 86 86 87 87 export type ClientOptions = { 88 88 baseUrl: `${string}://${string}` | (string & {});
+1 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/default/sdk.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 3 import { type Options as ClientOptions, type Composable, type TDataShape, type Client, formDataBodySerializer, urlSearchParamsBodySerializer } from './client'; 4 - import type { ExportData, PatchApiVbyApiVersionNoTagData, ImportData, ImportResponse, FooWowData, ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponse, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationResponse, GetApiVbyApiVersionSimpleOperationError, DeleteCallWithoutParametersAndResponseData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, OptionsCallWithoutParametersAndResponseData, PatchCallWithoutParametersAndResponseData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, DuplicateNameData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, CallWithNoContentResponseData, CallWithNoContentResponseResponse, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, DummyAData, DummyAResponse, DummyBData, DummyBResponse, CallWithResponseData, CallWithResponseResponse, CallWithDuplicateResponsesData, CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesError, CallWithResponsesData, CallWithResponsesResponse, CallWithResponsesError, CollectionFormatData, TypesData, TypesResponse, UploadFileData, UploadFileResponse, FileResponseData, FileResponseResponse, ComplexTypesData, ComplexTypesResponse, MultipartResponseData, MultipartResponseResponse, MultipartRequestData, ComplexParamsData, ComplexParamsResponse, CallWithResultFromHeaderData, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData } from './types.gen'; 4 + import type { ExportData, PatchApiVbyApiVersionNoTagData, ImportResponse, ImportData, FooWowData, ApiVVersionODataControllerCountResponse, ApiVVersionODataControllerCountData, GetApiVbyApiVersionSimpleOperationResponse, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, DeleteCallWithoutParametersAndResponseData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, OptionsCallWithoutParametersAndResponseData, PatchCallWithoutParametersAndResponseData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithOptionalParamData, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, DuplicateNameData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, CallWithNoContentResponseResponse, CallWithNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseAndNoContentResponseData, DummyAResponse, DummyAData, DummyBResponse, DummyBData, CallWithResponseResponse, CallWithResponseData, CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithResponsesResponse, CallWithResponsesData, CallWithResponsesError, CollectionFormatData, TypesResponse, TypesData, UploadFileResponse, UploadFileData, FileResponseResponse, FileResponseData, ComplexTypesResponse, ComplexTypesData, MultipartResponseResponse, MultipartResponseData, MultipartRequestData, ComplexParamsResponse, ComplexParamsData, CallWithResultFromHeaderData, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Response, NonAsciiæøåÆøÅöôêÊ字符串Data, PutWithFormUrlEncodedData } from './types.gen'; 5 5 import { client as _heyApiClient } from './client.gen'; 6 6 7 7 export type Options<TComposable extends Composable, TData extends TDataShape = TDataShape, ResT = unknown, DefaultT = undefined> = ClientOptions<TComposable, TData, ResT, DefaultT> & {
+1 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/sdk-client-optional/sdk.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 3 import { type Options as ClientOptions, type Composable, type TDataShape, type Client, formDataBodySerializer, urlSearchParamsBodySerializer } from './client'; 4 - import type { ExportData, PatchApiVbyApiVersionNoTagData, ImportData, ImportResponse, FooWowData, ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponse, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationResponse, GetApiVbyApiVersionSimpleOperationError, DeleteCallWithoutParametersAndResponseData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, OptionsCallWithoutParametersAndResponseData, PatchCallWithoutParametersAndResponseData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, DuplicateNameData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, CallWithNoContentResponseData, CallWithNoContentResponseResponse, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, DummyAData, DummyAResponse, DummyBData, DummyBResponse, CallWithResponseData, CallWithResponseResponse, CallWithDuplicateResponsesData, CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesError, CallWithResponsesData, CallWithResponsesResponse, CallWithResponsesError, CollectionFormatData, TypesData, TypesResponse, UploadFileData, UploadFileResponse, FileResponseData, FileResponseResponse, ComplexTypesData, ComplexTypesResponse, MultipartResponseData, MultipartResponseResponse, MultipartRequestData, ComplexParamsData, ComplexParamsResponse, CallWithResultFromHeaderData, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData } from './types.gen'; 4 + import type { ExportData, PatchApiVbyApiVersionNoTagData, ImportResponse, ImportData, FooWowData, ApiVVersionODataControllerCountResponse, ApiVVersionODataControllerCountData, GetApiVbyApiVersionSimpleOperationResponse, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, DeleteCallWithoutParametersAndResponseData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, OptionsCallWithoutParametersAndResponseData, PatchCallWithoutParametersAndResponseData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithOptionalParamData, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, DuplicateNameData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, CallWithNoContentResponseResponse, CallWithNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseAndNoContentResponseData, DummyAResponse, DummyAData, DummyBResponse, DummyBData, CallWithResponseResponse, CallWithResponseData, CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithResponsesResponse, CallWithResponsesData, CallWithResponsesError, CollectionFormatData, TypesResponse, TypesData, UploadFileResponse, UploadFileData, FileResponseResponse, FileResponseData, ComplexTypesResponse, ComplexTypesData, MultipartResponseResponse, MultipartResponseData, MultipartRequestData, ComplexParamsResponse, ComplexParamsData, CallWithResultFromHeaderData, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Response, NonAsciiæøåÆøÅöôêÊ字符串Data, PutWithFormUrlEncodedData } from './types.gen'; 5 5 import { client as _heyApiClient } from './client.gen'; 6 6 7 7 export type Options<TComposable extends Composable, TData extends TDataShape = TDataShape, ResT = unknown, DefaultT = undefined> = ClientOptions<TComposable, TData, ResT, DefaultT> & {
+1 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/sdk-client-required/sdk.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 3 import { type Options as ClientOptions, type Composable, type TDataShape, type Client, formDataBodySerializer, urlSearchParamsBodySerializer } from './client'; 4 - import type { ExportData, PatchApiVbyApiVersionNoTagData, ImportData, ImportResponse, FooWowData, ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponse, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationResponse, GetApiVbyApiVersionSimpleOperationError, DeleteCallWithoutParametersAndResponseData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, OptionsCallWithoutParametersAndResponseData, PatchCallWithoutParametersAndResponseData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, DuplicateNameData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, CallWithNoContentResponseData, CallWithNoContentResponseResponse, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, DummyAData, DummyAResponse, DummyBData, DummyBResponse, CallWithResponseData, CallWithResponseResponse, CallWithDuplicateResponsesData, CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesError, CallWithResponsesData, CallWithResponsesResponse, CallWithResponsesError, CollectionFormatData, TypesData, TypesResponse, UploadFileData, UploadFileResponse, FileResponseData, FileResponseResponse, ComplexTypesData, ComplexTypesResponse, MultipartResponseData, MultipartResponseResponse, MultipartRequestData, ComplexParamsData, ComplexParamsResponse, CallWithResultFromHeaderData, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData } from './types.gen'; 4 + import type { ExportData, PatchApiVbyApiVersionNoTagData, ImportResponse, ImportData, FooWowData, ApiVVersionODataControllerCountResponse, ApiVVersionODataControllerCountData, GetApiVbyApiVersionSimpleOperationResponse, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, DeleteCallWithoutParametersAndResponseData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, OptionsCallWithoutParametersAndResponseData, PatchCallWithoutParametersAndResponseData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithOptionalParamData, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, DuplicateNameData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, CallWithNoContentResponseResponse, CallWithNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseAndNoContentResponseData, DummyAResponse, DummyAData, DummyBResponse, DummyBData, CallWithResponseResponse, CallWithResponseData, CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithResponsesResponse, CallWithResponsesData, CallWithResponsesError, CollectionFormatData, TypesResponse, TypesData, UploadFileResponse, UploadFileData, FileResponseResponse, FileResponseData, ComplexTypesResponse, ComplexTypesData, MultipartResponseResponse, MultipartResponseData, MultipartRequestData, ComplexParamsResponse, ComplexParamsData, CallWithResultFromHeaderData, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Response, NonAsciiæøåÆøÅöôêÊ字符串Data, PutWithFormUrlEncodedData } from './types.gen'; 5 5 6 6 export type Options<TComposable extends Composable, TData extends TDataShape = TDataShape, ResT = unknown, DefaultT = undefined> = ClientOptions<TComposable, TData, ResT, DefaultT> & { 7 7 /**
+1 -1
packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/tsconfig-nodenext-sdk/sdk.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 3 import { type Options as ClientOptions, type Composable, type TDataShape, type Client, formDataBodySerializer, urlSearchParamsBodySerializer } from './client/index.js'; 4 - import type { ExportData, PatchApiVbyApiVersionNoTagData, ImportData, ImportResponse, FooWowData, ApiVVersionODataControllerCountData, ApiVVersionODataControllerCountResponse, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationResponse, GetApiVbyApiVersionSimpleOperationError, DeleteCallWithoutParametersAndResponseData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, OptionsCallWithoutParametersAndResponseData, PatchCallWithoutParametersAndResponseData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, DuplicateNameData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, CallWithNoContentResponseData, CallWithNoContentResponseResponse, CallWithResponseAndNoContentResponseData, CallWithResponseAndNoContentResponseResponse, DummyAData, DummyAResponse, DummyBData, DummyBResponse, CallWithResponseData, CallWithResponseResponse, CallWithDuplicateResponsesData, CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesError, CallWithResponsesData, CallWithResponsesResponse, CallWithResponsesError, CollectionFormatData, TypesData, TypesResponse, UploadFileData, UploadFileResponse, FileResponseData, FileResponseResponse, ComplexTypesData, ComplexTypesResponse, MultipartResponseData, MultipartResponseResponse, MultipartRequestData, ComplexParamsData, ComplexParamsResponse, CallWithResultFromHeaderData, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData } from './types.gen.js'; 4 + import type { ExportData, PatchApiVbyApiVersionNoTagData, ImportResponse, ImportData, FooWowData, ApiVVersionODataControllerCountResponse, ApiVVersionODataControllerCountData, GetApiVbyApiVersionSimpleOperationResponse, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, DeleteCallWithoutParametersAndResponseData, GetCallWithoutParametersAndResponseData, HeadCallWithoutParametersAndResponseData, OptionsCallWithoutParametersAndResponseData, PatchCallWithoutParametersAndResponseData, PostCallWithoutParametersAndResponseData, PutCallWithoutParametersAndResponseData, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostCallWithOptionalParamData, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, DuplicateNameData, DuplicateName2Data, DuplicateName3Data, DuplicateName4Data, CallWithNoContentResponseResponse, CallWithNoContentResponseData, CallWithResponseAndNoContentResponseResponse, CallWithResponseAndNoContentResponseData, DummyAResponse, DummyAData, DummyBResponse, DummyBData, CallWithResponseResponse, CallWithResponseData, CallWithDuplicateResponsesResponse, CallWithDuplicateResponsesData, CallWithDuplicateResponsesError, CallWithResponsesResponse, CallWithResponsesData, CallWithResponsesError, CollectionFormatData, TypesResponse, TypesData, UploadFileResponse, UploadFileData, FileResponseResponse, FileResponseData, ComplexTypesResponse, ComplexTypesData, MultipartResponseResponse, MultipartResponseData, MultipartRequestData, ComplexParamsResponse, ComplexParamsData, CallWithResultFromHeaderData, TestErrorCodeData, NonAsciiæøåÆøÅöôêÊ字符串Response, NonAsciiæøåÆøÅöôêÊ字符串Data, PutWithFormUrlEncodedData } from './types.gen.js'; 5 5 import { client as _heyApiClient } from './client.gen.js'; 6 6 7 7 export type Options<TComposable extends Composable, TData extends TDataShape = TDataShape, ResT = unknown, DefaultT = undefined> = ClientOptions<TComposable, TData, ResT, DefaultT> & {
+4 -4
packages/openapi-ts-tests/test/__snapshots__/3.1.x/enum-inline-javascript/types.gen.ts
··· 8 8 type?: Baz; 9 9 }; 10 10 11 - export type Baz = 'qux' | 'quux'; 12 - 13 11 export const Baz = { 14 12 QUX: 'qux', 15 13 QUUX: 'quux' 16 14 } as const; 17 15 18 - export type FooEnum = 'foo' | 'bar'; 16 + export type Baz = typeof Baz[keyof typeof Baz]; 19 17 20 18 export const FooEnum = { 21 19 FOO: 'foo', 22 20 BAR: 'bar' 23 21 } as const; 24 22 25 - export type FooEnum2 = 'baz'; 23 + export type FooEnum = typeof FooEnum[keyof typeof FooEnum]; 26 24 27 25 export const FooEnum2 = { 28 26 BAZ: 'baz' 29 27 } as const; 28 + 29 + export type FooEnum2 = typeof FooEnum2[keyof typeof FooEnum2]; 30 30 31 31 export type GetFooData = { 32 32 body?: never;
-2
packages/openapi-ts-tests/test/__snapshots__/3.1.x/enum-inline-typescript-namespace/index.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - export * from './types.gen';
-79
packages/openapi-ts-tests/test/__snapshots__/3.1.x/enum-inline-typescript-namespace/types.gen.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - export type Foo = { 4 - type?: FooEnum; 5 - }; 6 - 7 - export type Bar = { 8 - type?: Baz; 9 - }; 10 - 11 - export enum Baz { 12 - QUX = 'qux', 13 - QUUX = 'quux' 14 - } 15 - 16 - export enum FooEnum { 17 - FOO = 'foo', 18 - BAR = 'bar' 19 - } 20 - 21 - export enum FooEnum2 { 22 - BAZ = 'baz' 23 - } 24 - 25 - export type GetFooData = { 26 - body?: never; 27 - path?: never; 28 - query?: never; 29 - url: '/foo'; 30 - }; 31 - 32 - export type GetFooResponses = { 33 - /** 34 - * OK 35 - */ 36 - 200: { 37 - foo?: FooEnum; 38 - }; 39 - }; 40 - 41 - export type GetFooResponse = GetFooResponses[keyof GetFooResponses]; 42 - 43 - export type PostFooData = { 44 - body?: never; 45 - path?: never; 46 - query?: never; 47 - url: '/foo'; 48 - }; 49 - 50 - export type PostFooResponses = { 51 - /** 52 - * OK 53 - */ 54 - 200: { 55 - foo?: FooEnum2; 56 - }; 57 - }; 58 - 59 - export type PostFooResponse = PostFooResponses[keyof PostFooResponses]; 60 - 61 - export type PutFooData = { 62 - body?: never; 63 - path?: never; 64 - query?: never; 65 - url: '/foo'; 66 - }; 67 - 68 - export type PutFooResponses = { 69 - /** 70 - * OK 71 - */ 72 - 200: Baz; 73 - }; 74 - 75 - export type PutFooResponse = PutFooResponses[keyof PutFooResponses]; 76 - 77 - export type ClientOptions = { 78 - baseUrl: `${string}://${string}` | (string & {}); 79 - };
+7 -13
packages/openapi-ts-tests/test/__snapshots__/3.1.x/enum-names-values-javascript-PascalCase/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export type _110 = '1-10' | '11-20'; 4 - 5 3 export const _110 = { 6 4 110: '1-10', 7 5 1120: '11-20' 8 6 } as const; 9 7 10 - export type MyFoo = 'myFoo' | 'myBar'; 8 + export type _110 = typeof _110[keyof typeof _110]; 11 9 12 10 export const MyFoo = { 13 11 MyFoo: 'myFoo', 14 12 MyBar: 'myBar' 15 13 } as const; 16 14 17 - export type MyFoo2 = 'MyFoo' | 'MyBar'; 15 + export type MyFoo = typeof MyFoo[keyof typeof MyFoo]; 18 16 19 17 export const MyFoo2 = { 20 18 MyFoo: 'MyFoo', 21 19 MyBar: 'MyBar' 22 20 } as const; 23 21 24 - export type Foo = 'foo' | 'bar' | null | '' | true | false; 22 + export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2]; 25 23 26 24 export const Foo = { 27 25 Foo: 'foo', ··· 32 30 False: false 33 31 } as const; 34 32 35 - export type Numbers = 100 | 200 | 300 | -100 | -200 | -300; 33 + export type Foo = typeof Foo[keyof typeof Foo]; 36 34 37 35 export const Numbers = { 38 36 100: 100, ··· 43 41 '-300': -300 44 42 } as const; 45 43 46 - export type Arrays = [ 47 - 'foo' 48 - ] | [ 49 - 'bar' 50 - ] | [ 51 - 'baz' 52 - ]; 44 + export type Numbers = typeof Numbers[keyof typeof Numbers]; 53 45 54 46 export const Arrays = { 55 47 0: ['foo'], 56 48 1: ['bar'], 57 49 2: ['baz'] 58 50 } as const; 51 + 52 + export type Arrays = typeof Arrays[keyof typeof Arrays]; 59 53 60 54 export type MyFooRef = { 61 55 foo?: Array<MyFoo2>;
+7 -13
packages/openapi-ts-tests/test/__snapshots__/3.1.x/enum-names-values-javascript-SCREAMING_SNAKE_CASE/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export type _110 = '1-10' | '11-20'; 4 - 5 3 export const _110 = { 6 4 '1_10': '1-10', 7 5 '11_20': '11-20' 8 6 } as const; 9 7 10 - export type MyFoo = 'myFoo' | 'myBar'; 8 + export type _110 = typeof _110[keyof typeof _110]; 11 9 12 10 export const MyFoo = { 13 11 MY_FOO: 'myFoo', 14 12 MY_BAR: 'myBar' 15 13 } as const; 16 14 17 - export type MyFoo2 = 'MyFoo' | 'MyBar'; 15 + export type MyFoo = typeof MyFoo[keyof typeof MyFoo]; 18 16 19 17 export const MyFoo2 = { 20 18 MY_FOO: 'MyFoo', 21 19 MY_BAR: 'MyBar' 22 20 } as const; 23 21 24 - export type Foo = 'foo' | 'bar' | null | '' | true | false; 22 + export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2]; 25 23 26 24 export const Foo = { 27 25 FOO: 'foo', ··· 32 30 FALSE: false 33 31 } as const; 34 32 35 - export type Numbers = 100 | 200 | 300 | -100 | -200 | -300; 33 + export type Foo = typeof Foo[keyof typeof Foo]; 36 34 37 35 export const Numbers = { 38 36 100: 100, ··· 43 41 '-300': -300 44 42 } as const; 45 43 46 - export type Arrays = [ 47 - 'foo' 48 - ] | [ 49 - 'bar' 50 - ] | [ 51 - 'baz' 52 - ]; 44 + export type Numbers = typeof Numbers[keyof typeof Numbers]; 53 45 54 46 export const Arrays = { 55 47 0: ['foo'], 56 48 1: ['bar'], 57 49 2: ['baz'] 58 50 } as const; 51 + 52 + export type Arrays = typeof Arrays[keyof typeof Arrays]; 59 53 60 54 export type MyFooRef = { 61 55 foo?: Array<MyFoo2>;
+7 -13
packages/openapi-ts-tests/test/__snapshots__/3.1.x/enum-names-values-javascript-camelCase/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export type _110 = '1-10' | '11-20'; 4 - 5 3 export const _110 = { 6 4 110: '1-10', 7 5 1120: '11-20' 8 6 } as const; 9 7 10 - export type MyFoo = 'myFoo' | 'myBar'; 8 + export type _110 = typeof _110[keyof typeof _110]; 11 9 12 10 export const MyFoo = { 13 11 myFoo: 'myFoo', 14 12 myBar: 'myBar' 15 13 } as const; 16 14 17 - export type MyFoo2 = 'MyFoo' | 'MyBar'; 15 + export type MyFoo = typeof MyFoo[keyof typeof MyFoo]; 18 16 19 17 export const MyFoo2 = { 20 18 myFoo: 'MyFoo', 21 19 myBar: 'MyBar' 22 20 } as const; 23 21 24 - export type Foo = 'foo' | 'bar' | null | '' | true | false; 22 + export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2]; 25 23 26 24 export const Foo = { 27 25 foo: 'foo', ··· 32 30 false: false 33 31 } as const; 34 32 35 - export type Numbers = 100 | 200 | 300 | -100 | -200 | -300; 33 + export type Foo = typeof Foo[keyof typeof Foo]; 36 34 37 35 export const Numbers = { 38 36 100: 100, ··· 43 41 '-300': -300 44 42 } as const; 45 43 46 - export type Arrays = [ 47 - 'foo' 48 - ] | [ 49 - 'bar' 50 - ] | [ 51 - 'baz' 52 - ]; 44 + export type Numbers = typeof Numbers[keyof typeof Numbers]; 53 45 54 46 export const Arrays = { 55 47 0: ['foo'], 56 48 1: ['bar'], 57 49 2: ['baz'] 58 50 } as const; 51 + 52 + export type Arrays = typeof Arrays[keyof typeof Arrays]; 59 53 60 54 export type MyFooRef = { 61 55 foo?: Array<MyFoo2>;
+7 -13
packages/openapi-ts-tests/test/__snapshots__/3.1.x/enum-names-values-javascript-ignore-null/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export type _110 = '1-10' | '11-20'; 4 - 5 3 export const _110 = { 6 4 '1-10': '1-10', 7 5 '11-20': '11-20' 8 6 } as const; 9 7 10 - export type MyFoo = 'myFoo' | 'myBar'; 8 + export type _110 = typeof _110[keyof typeof _110]; 11 9 12 10 export const MyFoo = { 13 11 myFoo: 'myFoo', 14 12 myBar: 'myBar' 15 13 } as const; 16 14 17 - export type MyFoo2 = 'MyFoo' | 'MyBar'; 15 + export type MyFoo = typeof MyFoo[keyof typeof MyFoo]; 18 16 19 17 export const MyFoo2 = { 20 18 MyFoo: 'MyFoo', 21 19 MyBar: 'MyBar' 22 20 } as const; 23 21 24 - export type Foo = 'foo' | 'bar' | null | '' | true | false; 22 + export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2]; 25 23 26 24 export const Foo = { 27 25 foo: 'foo', ··· 31 29 false: false 32 30 } as const; 33 31 34 - export type Numbers = 100 | 200 | 300 | -100 | -200 | -300; 32 + export type Foo = typeof Foo[keyof typeof Foo]; 35 33 36 34 export const Numbers = { 37 35 100: 100, ··· 42 40 '-300': -300 43 41 } as const; 44 42 45 - export type Arrays = [ 46 - 'foo' 47 - ] | [ 48 - 'bar' 49 - ] | [ 50 - 'baz' 51 - ]; 43 + export type Numbers = typeof Numbers[keyof typeof Numbers]; 52 44 53 45 export const Arrays = { 54 46 0: ['foo'], 55 47 1: ['bar'], 56 48 2: ['baz'] 57 49 } as const; 50 + 51 + export type Arrays = typeof Arrays[keyof typeof Arrays]; 58 52 59 53 export type MyFooRef = { 60 54 foo?: Array<MyFoo2>;
+7 -13
packages/openapi-ts-tests/test/__snapshots__/3.1.x/enum-names-values-javascript-preserve/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export type _110 = '1-10' | '11-20'; 4 - 5 3 export const _110 = { 6 4 '1-10': '1-10', 7 5 '11-20': '11-20' 8 6 } as const; 9 7 10 - export type MyFoo = 'myFoo' | 'myBar'; 8 + export type _110 = typeof _110[keyof typeof _110]; 11 9 12 10 export const MyFoo = { 13 11 myFoo: 'myFoo', 14 12 myBar: 'myBar' 15 13 } as const; 16 14 17 - export type MyFoo2 = 'MyFoo' | 'MyBar'; 15 + export type MyFoo = typeof MyFoo[keyof typeof MyFoo]; 18 16 19 17 export const MyFoo2 = { 20 18 MyFoo: 'MyFoo', 21 19 MyBar: 'MyBar' 22 20 } as const; 23 21 24 - export type Foo = 'foo' | 'bar' | null | '' | true | false; 22 + export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2]; 25 23 26 24 export const Foo = { 27 25 foo: 'foo', ··· 32 30 false: false 33 31 } as const; 34 32 35 - export type Numbers = 100 | 200 | 300 | -100 | -200 | -300; 33 + export type Foo = typeof Foo[keyof typeof Foo]; 36 34 37 35 export const Numbers = { 38 36 100: 100, ··· 43 41 '-300': -300 44 42 } as const; 45 43 46 - export type Arrays = [ 47 - 'foo' 48 - ] | [ 49 - 'bar' 50 - ] | [ 51 - 'baz' 52 - ]; 44 + export type Numbers = typeof Numbers[keyof typeof Numbers]; 53 45 54 46 export const Arrays = { 55 47 0: ['foo'], 56 48 1: ['bar'], 57 49 2: ['baz'] 58 50 } as const; 51 + 52 + export type Arrays = typeof Arrays[keyof typeof Arrays]; 59 53 60 54 export type MyFooRef = { 61 55 foo?: Array<MyFoo2>;
+7 -13
packages/openapi-ts-tests/test/__snapshots__/3.1.x/enum-names-values-javascript-snake_case/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export type _110 = '1-10' | '11-20'; 4 - 5 3 export const _110 = { 6 4 '1_10': '1-10', 7 5 '11_20': '11-20' 8 6 } as const; 9 7 10 - export type MyFoo = 'myFoo' | 'myBar'; 8 + export type _110 = typeof _110[keyof typeof _110]; 11 9 12 10 export const MyFoo = { 13 11 my_foo: 'myFoo', 14 12 my_bar: 'myBar' 15 13 } as const; 16 14 17 - export type MyFoo2 = 'MyFoo' | 'MyBar'; 15 + export type MyFoo = typeof MyFoo[keyof typeof MyFoo]; 18 16 19 17 export const MyFoo2 = { 20 18 my_foo: 'MyFoo', 21 19 my_bar: 'MyBar' 22 20 } as const; 23 21 24 - export type Foo = 'foo' | 'bar' | null | '' | true | false; 22 + export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2]; 25 23 26 24 export const Foo = { 27 25 foo: 'foo', ··· 32 30 false: false 33 31 } as const; 34 32 35 - export type Numbers = 100 | 200 | 300 | -100 | -200 | -300; 33 + export type Foo = typeof Foo[keyof typeof Foo]; 36 34 37 35 export const Numbers = { 38 36 100: 100, ··· 43 41 '-300': -300 44 42 } as const; 45 43 46 - export type Arrays = [ 47 - 'foo' 48 - ] | [ 49 - 'bar' 50 - ] | [ 51 - 'baz' 52 - ]; 44 + export type Numbers = typeof Numbers[keyof typeof Numbers]; 53 45 54 46 export const Arrays = { 55 47 0: ['foo'], 56 48 1: ['bar'], 57 49 2: ['baz'] 58 50 } as const; 51 + 52 + export type Arrays = typeof Arrays[keyof typeof Arrays]; 59 53 60 54 export type MyFooRef = { 61 55 foo?: Array<MyFoo2>;
+23
packages/openapi-ts-tests/test/__snapshots__/test/generated/v2/types.gen.ts.snap
··· 282 282 bool?: boolean; 283 283 }; 284 284 285 + export namespace ModelWithEnum { 286 + /** 287 + * This is a simple enum with strings 288 + */ 289 + export enum test { 290 + SUCCESS = 'Success', 291 + WARNING = 'Warning', 292 + ERROR = 'Error', 293 + ØÆÅ字符串 = 'ØÆÅ字符串' 294 + } 295 + /** 296 + * These are the HTTP error code enums 297 + */ 298 + export enum statusCode { 299 + _100 = '100', 300 + _200_FOO = '200 FOO', 301 + _300_FOO_BAR = '300 FOO_BAR', 302 + _400_FOO_BAR = '400 foo-bar', 303 + _500_FOO_BAR = '500 foo.bar', 304 + _600_FOO_BAR = '600 foo&bar' 305 + } 306 + } 307 + 285 308 /** 286 309 * This is a model with one enum 287 310 */
+70 -58
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3/types.gen.ts.snap
··· 702 702 bool?: boolean; 703 703 }; 704 704 705 - /** 706 - * This is a simple enum with strings 707 - */ 708 - export type foo_bar_enum = 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 709 - 710 - /** 711 - * This is a simple enum with strings 712 - */ 713 - export const foo_bar_enum = { 714 - SUCCESS: 'Success', 715 - WARNING: 'Warning', 716 - ERROR: 'Error', 717 - 'ØÆÅ字符串': 'ØÆÅ字符串' 718 - } as const; 719 - 720 - /** 721 - * These are the HTTP error code enums 722 - */ 723 - export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; 724 - 725 - /** 726 - * These are the HTTP error code enums 727 - */ 728 - export const statusCode = { 729 - _100: '100', 730 - _200_FOO: '200 FOO', 731 - _300_FOO_BAR: '300 FOO_BAR', 732 - _400_FOO_BAR: '400 foo-bar', 733 - _500_FOO_BAR: '500 foo.bar', 734 - _600_FOO_BAR: '600 foo&bar' 735 - } as const; 705 + export namespace ModelWithEnum { 706 + /** 707 + * This is a simple enum with strings 708 + */ 709 + export enum foo_bar_enum { 710 + SUCCESS = 'Success', 711 + WARNING = 'Warning', 712 + ERROR = 'Error', 713 + ØÆÅ字符串 = 'ØÆÅ字符串' 714 + } 715 + /** 716 + * These are the HTTP error code enums 717 + */ 718 + export enum statusCode { 719 + _100 = '100', 720 + _200_FOO = '200 FOO', 721 + _300_FOO_BAR = '300 FOO_BAR', 722 + _400_FOO_BAR = '400 foo-bar', 723 + _500_FOO_BAR = '500 foo.bar', 724 + _600_FOO_BAR = '600 foo&bar' 725 + } 726 + } 736 727 737 728 /** 738 729 * This is a model with one enum ··· 751 742 'foo-bar-baz-qux'?: '3.0'; 752 743 }; 753 744 754 - export type foo_bar_baz_qux = '3.0'; 755 - 756 - export const foo_bar_baz_qux = { 757 - _3_0: '3.0' 758 - } as const; 745 + export namespace ModelWithEnumWithHyphen { 746 + export enum foo_bar_baz_qux { 747 + _3_0 = '3.0' 748 + } 749 + } 759 750 760 751 /** 761 752 * This is a model with one number property ··· 813 804 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 814 805 }; 815 806 807 + export namespace ModelWithNestedEnums { 808 + /** 809 + * This is a simple enum with strings 810 + */ 811 + export enum foo_bar_enum { 812 + SUCCESS = 'Success', 813 + WARNING = 'Warning', 814 + ERROR = 'Error', 815 + ØÆÅ字符串 = 'ØÆÅ字符串' 816 + } 817 + } 818 + 816 819 /** 817 820 * This is a model with one nested property 818 821 */ ··· 854 857 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 855 858 }; 856 859 860 + export namespace ModelWithNullableString { 861 + /** 862 + * This is a simple enum with strings 863 + */ 864 + export enum foo_bar_enum { 865 + SUCCESS = 'Success', 866 + WARNING = 'Warning', 867 + ERROR = 'Error', 868 + ØÆÅ字符串 = 'ØÆÅ字符串' 869 + } 870 + } 871 + 857 872 export type ModelWithNumericEnumUnion = { 858 873 /** 859 874 * Период ··· 861 876 value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; 862 877 }; 863 878 864 - /** 865 - * Период 866 - */ 867 - export type value = -10 | -1 | 0 | 1 | 3 | 6 | 12; 868 - 869 - /** 870 - * Период 871 - */ 872 - export const value = { 873 - '_-10': -10, 874 - '_-1': -1, 875 - '_0': 0, 876 - '_1': 1, 877 - '_3': 3, 878 - '_6': 6, 879 - '_12': 12 880 - } as const; 879 + export namespace ModelWithNumericEnumUnion { 880 + /** 881 + * Период 882 + */ 883 + export enum value { 884 + '_-10' = -10, 885 + '_-1' = -1, 886 + '_0' = 0, 887 + '_1' = 1, 888 + '_3' = 3, 889 + '_6' = 6, 890 + '_12' = 12 891 + } 892 + } 881 893 882 894 export type ModelWithOneOfAndProperties = (ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { 883 895 baz: (number) | null; ··· 901 913 foo: 'Corge'; 902 914 }; 903 915 904 - export type foo = 'Bar'; 905 - 906 - export const foo = { 907 - BAR: 'Bar' 908 - } as const; 916 + export namespace ModelWithOneOfEnum { 917 + export enum foo { 918 + BAR = 'Bar' 919 + } 920 + } 909 921 910 922 /** 911 923 * This is a model with ordered properties
+70 -15
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap
··· 632 632 bool?: boolean; 633 633 }; 634 634 635 - /** 636 - * This is a simple enum with strings 637 - */ 638 - export type foo_bar_enum = 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 639 - 640 - /** 641 - * These are the HTTP error code enums 642 - */ 643 - export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; 635 + export namespace ModelWithEnum { 636 + /** 637 + * This is a simple enum with strings 638 + */ 639 + export enum foo_bar_enum { 640 + SUCCESS = 'Success', 641 + WARNING = 'Warning', 642 + ERROR = 'Error', 643 + ØÆÅ字符串 = 'ØÆÅ字符串' 644 + } 645 + /** 646 + * These are the HTTP error code enums 647 + */ 648 + export enum statusCode { 649 + _100 = '100', 650 + _200_FOO = '200 FOO', 651 + _300_FOO_BAR = '300 FOO_BAR', 652 + _400_FOO_BAR = '400 foo-bar', 653 + _500_FOO_BAR = '500 foo.bar', 654 + _600_FOO_BAR = '600 foo&bar' 655 + } 656 + } 644 657 645 658 /** 646 659 * This is a model with one enum ··· 659 672 'foo-bar-baz-qux'?: '3.0'; 660 673 }; 661 674 662 - export type foo_bar_baz_qux = '3.0'; 675 + export namespace ModelWithEnumWithHyphen { 676 + export enum foo_bar_baz_qux { 677 + _3_0 = '3.0' 678 + } 679 + } 663 680 664 681 /** 665 682 * This is a model with one number property ··· 707 724 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 708 725 }; 709 726 727 + export namespace ModelWithNestedEnums { 728 + /** 729 + * This is a simple enum with strings 730 + */ 731 + export enum foo_bar_enum { 732 + SUCCESS = 'Success', 733 + WARNING = 'Warning', 734 + ERROR = 'Error', 735 + ØÆÅ字符串 = 'ØÆÅ字符串' 736 + } 737 + } 738 + 710 739 /** 711 740 * This is a model with one nested property 712 741 */ ··· 748 777 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 749 778 }; 750 779 780 + export namespace ModelWithNullableString { 781 + /** 782 + * This is a simple enum with strings 783 + */ 784 + export enum foo_bar_enum { 785 + SUCCESS = 'Success', 786 + WARNING = 'Warning', 787 + ERROR = 'Error', 788 + ØÆÅ字符串 = 'ØÆÅ字符串' 789 + } 790 + } 791 + 751 792 export type ModelWithNumericEnumUnion = { 752 793 /** 753 794 * Период ··· 755 796 value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; 756 797 }; 757 798 758 - /** 759 - * Период 760 - */ 761 - export type value = -10 | -1 | 0 | 1 | 3 | 6 | 12; 799 + export namespace ModelWithNumericEnumUnion { 800 + /** 801 + * Период 802 + */ 803 + export enum value { 804 + '_-10' = -10, 805 + '_-1' = -1, 806 + '_0' = 0, 807 + '_1' = 1, 808 + '_3' = 3, 809 + '_6' = 6, 810 + '_12' = 12 811 + } 812 + } 762 813 763 814 export type ModelWithOneOfAndProperties = (ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { 764 815 baz: (number) | null; ··· 782 833 foo: 'Corge'; 783 834 }; 784 835 785 - export type foo = 'Bar'; 836 + export namespace ModelWithOneOfEnum { 837 + export enum foo { 838 + BAR = 'Bar' 839 + } 840 + } 786 841 787 842 /** 788 843 * This is a model with ordered properties
+70 -15
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_angular_tree_shakeable/types.gen.ts.snap
··· 632 632 bool?: boolean; 633 633 }; 634 634 635 - /** 636 - * This is a simple enum with strings 637 - */ 638 - export type foo_bar_enum = 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 639 - 640 - /** 641 - * These are the HTTP error code enums 642 - */ 643 - export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; 635 + export namespace ModelWithEnum { 636 + /** 637 + * This is a simple enum with strings 638 + */ 639 + export enum foo_bar_enum { 640 + SUCCESS = 'Success', 641 + WARNING = 'Warning', 642 + ERROR = 'Error', 643 + ØÆÅ字符串 = 'ØÆÅ字符串' 644 + } 645 + /** 646 + * These are the HTTP error code enums 647 + */ 648 + export enum statusCode { 649 + _100 = '100', 650 + _200_FOO = '200 FOO', 651 + _300_FOO_BAR = '300 FOO_BAR', 652 + _400_FOO_BAR = '400 foo-bar', 653 + _500_FOO_BAR = '500 foo.bar', 654 + _600_FOO_BAR = '600 foo&bar' 655 + } 656 + } 644 657 645 658 /** 646 659 * This is a model with one enum ··· 659 672 'foo-bar-baz-qux'?: '3.0'; 660 673 }; 661 674 662 - export type foo_bar_baz_qux = '3.0'; 675 + export namespace ModelWithEnumWithHyphen { 676 + export enum foo_bar_baz_qux { 677 + _3_0 = '3.0' 678 + } 679 + } 663 680 664 681 /** 665 682 * This is a model with one number property ··· 707 724 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 708 725 }; 709 726 727 + export namespace ModelWithNestedEnums { 728 + /** 729 + * This is a simple enum with strings 730 + */ 731 + export enum foo_bar_enum { 732 + SUCCESS = 'Success', 733 + WARNING = 'Warning', 734 + ERROR = 'Error', 735 + ØÆÅ字符串 = 'ØÆÅ字符串' 736 + } 737 + } 738 + 710 739 /** 711 740 * This is a model with one nested property 712 741 */ ··· 748 777 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 749 778 }; 750 779 780 + export namespace ModelWithNullableString { 781 + /** 782 + * This is a simple enum with strings 783 + */ 784 + export enum foo_bar_enum { 785 + SUCCESS = 'Success', 786 + WARNING = 'Warning', 787 + ERROR = 'Error', 788 + ØÆÅ字符串 = 'ØÆÅ字符串' 789 + } 790 + } 791 + 751 792 export type ModelWithNumericEnumUnion = { 752 793 /** 753 794 * Период ··· 755 796 value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; 756 797 }; 757 798 758 - /** 759 - * Период 760 - */ 761 - export type value = -10 | -1 | 0 | 1 | 3 | 6 | 12; 799 + export namespace ModelWithNumericEnumUnion { 800 + /** 801 + * Период 802 + */ 803 + export enum value { 804 + '_-10' = -10, 805 + '_-1' = -1, 806 + '_0' = 0, 807 + '_1' = 1, 808 + '_3' = 3, 809 + '_6' = 6, 810 + '_12' = 12 811 + } 812 + } 762 813 763 814 export type ModelWithOneOfAndProperties = (ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { 764 815 baz: (number) | null; ··· 782 833 foo: 'Corge'; 783 834 }; 784 835 785 - export type foo = 'Bar'; 836 + export namespace ModelWithOneOfEnum { 837 + export enum foo { 838 + BAR = 'Bar' 839 + } 840 + } 786 841 787 842 /** 788 843 * This is a model with ordered properties
+70 -58
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_axios/types.gen.ts.snap
··· 702 702 bool?: boolean; 703 703 }; 704 704 705 - /** 706 - * This is a simple enum with strings 707 - */ 708 - export type foo_bar_enum = 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 709 - 710 - /** 711 - * This is a simple enum with strings 712 - */ 713 - export const foo_bar_enum = { 714 - SUCCESS: 'Success', 715 - WARNING: 'Warning', 716 - ERROR: 'Error', 717 - 'ØÆÅ字符串': 'ØÆÅ字符串' 718 - } as const; 719 - 720 - /** 721 - * These are the HTTP error code enums 722 - */ 723 - export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; 724 - 725 - /** 726 - * These are the HTTP error code enums 727 - */ 728 - export const statusCode = { 729 - _100: '100', 730 - _200_FOO: '200 FOO', 731 - _300_FOO_BAR: '300 FOO_BAR', 732 - _400_FOO_BAR: '400 foo-bar', 733 - _500_FOO_BAR: '500 foo.bar', 734 - _600_FOO_BAR: '600 foo&bar' 735 - } as const; 705 + export namespace ModelWithEnum { 706 + /** 707 + * This is a simple enum with strings 708 + */ 709 + export enum foo_bar_enum { 710 + SUCCESS = 'Success', 711 + WARNING = 'Warning', 712 + ERROR = 'Error', 713 + ØÆÅ字符串 = 'ØÆÅ字符串' 714 + } 715 + /** 716 + * These are the HTTP error code enums 717 + */ 718 + export enum statusCode { 719 + _100 = '100', 720 + _200_FOO = '200 FOO', 721 + _300_FOO_BAR = '300 FOO_BAR', 722 + _400_FOO_BAR = '400 foo-bar', 723 + _500_FOO_BAR = '500 foo.bar', 724 + _600_FOO_BAR = '600 foo&bar' 725 + } 726 + } 736 727 737 728 /** 738 729 * This is a model with one enum ··· 751 742 'foo-bar-baz-qux'?: '3.0'; 752 743 }; 753 744 754 - export type foo_bar_baz_qux = '3.0'; 755 - 756 - export const foo_bar_baz_qux = { 757 - _3_0: '3.0' 758 - } as const; 745 + export namespace ModelWithEnumWithHyphen { 746 + export enum foo_bar_baz_qux { 747 + _3_0 = '3.0' 748 + } 749 + } 759 750 760 751 /** 761 752 * This is a model with one number property ··· 813 804 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 814 805 }; 815 806 807 + export namespace ModelWithNestedEnums { 808 + /** 809 + * This is a simple enum with strings 810 + */ 811 + export enum foo_bar_enum { 812 + SUCCESS = 'Success', 813 + WARNING = 'Warning', 814 + ERROR = 'Error', 815 + ØÆÅ字符串 = 'ØÆÅ字符串' 816 + } 817 + } 818 + 816 819 /** 817 820 * This is a model with one nested property 818 821 */ ··· 854 857 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 855 858 }; 856 859 860 + export namespace ModelWithNullableString { 861 + /** 862 + * This is a simple enum with strings 863 + */ 864 + export enum foo_bar_enum { 865 + SUCCESS = 'Success', 866 + WARNING = 'Warning', 867 + ERROR = 'Error', 868 + ØÆÅ字符串 = 'ØÆÅ字符串' 869 + } 870 + } 871 + 857 872 export type ModelWithNumericEnumUnion = { 858 873 /** 859 874 * Период ··· 861 876 value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; 862 877 }; 863 878 864 - /** 865 - * Период 866 - */ 867 - export type value = -10 | -1 | 0 | 1 | 3 | 6 | 12; 868 - 869 - /** 870 - * Период 871 - */ 872 - export const value = { 873 - '_-10': -10, 874 - '_-1': -1, 875 - '_0': 0, 876 - '_1': 1, 877 - '_3': 3, 878 - '_6': 6, 879 - '_12': 12 880 - } as const; 879 + export namespace ModelWithNumericEnumUnion { 880 + /** 881 + * Период 882 + */ 883 + export enum value { 884 + '_-10' = -10, 885 + '_-1' = -1, 886 + '_0' = 0, 887 + '_1' = 1, 888 + '_3' = 3, 889 + '_6' = 6, 890 + '_12' = 12 891 + } 892 + } 881 893 882 894 export type ModelWithOneOfAndProperties = (ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { 883 895 baz: (number) | null; ··· 901 913 foo: 'Corge'; 902 914 }; 903 915 904 - export type foo = 'Bar'; 905 - 906 - export const foo = { 907 - BAR: 'Bar' 908 - } as const; 916 + export namespace ModelWithOneOfEnum { 917 + export enum foo { 918 + BAR = 'Bar' 919 + } 920 + } 909 921 910 922 /** 911 923 * This is a model with ordered properties
+70 -15
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap
··· 632 632 bool?: boolean; 633 633 }; 634 634 635 - /** 636 - * This is a simple enum with strings 637 - */ 638 - export type foo_bar_enum = 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 639 - 640 - /** 641 - * These are the HTTP error code enums 642 - */ 643 - export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; 635 + export namespace ModelWithEnum { 636 + /** 637 + * This is a simple enum with strings 638 + */ 639 + export enum foo_bar_enum { 640 + SUCCESS = 'Success', 641 + WARNING = 'Warning', 642 + ERROR = 'Error', 643 + ØÆÅ字符串 = 'ØÆÅ字符串' 644 + } 645 + /** 646 + * These are the HTTP error code enums 647 + */ 648 + export enum statusCode { 649 + _100 = '100', 650 + _200_FOO = '200 FOO', 651 + _300_FOO_BAR = '300 FOO_BAR', 652 + _400_FOO_BAR = '400 foo-bar', 653 + _500_FOO_BAR = '500 foo.bar', 654 + _600_FOO_BAR = '600 foo&bar' 655 + } 656 + } 644 657 645 658 /** 646 659 * This is a model with one enum ··· 659 672 'foo-bar-baz-qux'?: '3.0'; 660 673 }; 661 674 662 - export type foo_bar_baz_qux = '3.0'; 675 + export namespace ModelWithEnumWithHyphen { 676 + export enum foo_bar_baz_qux { 677 + _3_0 = '3.0' 678 + } 679 + } 663 680 664 681 /** 665 682 * This is a model with one number property ··· 707 724 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 708 725 }; 709 726 727 + export namespace ModelWithNestedEnums { 728 + /** 729 + * This is a simple enum with strings 730 + */ 731 + export enum foo_bar_enum { 732 + SUCCESS = 'Success', 733 + WARNING = 'Warning', 734 + ERROR = 'Error', 735 + ØÆÅ字符串 = 'ØÆÅ字符串' 736 + } 737 + } 738 + 710 739 /** 711 740 * This is a model with one nested property 712 741 */ ··· 748 777 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 749 778 }; 750 779 780 + export namespace ModelWithNullableString { 781 + /** 782 + * This is a simple enum with strings 783 + */ 784 + export enum foo_bar_enum { 785 + SUCCESS = 'Success', 786 + WARNING = 'Warning', 787 + ERROR = 'Error', 788 + ØÆÅ字符串 = 'ØÆÅ字符串' 789 + } 790 + } 791 + 751 792 export type ModelWithNumericEnumUnion = { 752 793 /** 753 794 * Период ··· 755 796 value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; 756 797 }; 757 798 758 - /** 759 - * Период 760 - */ 761 - export type value = -10 | -1 | 0 | 1 | 3 | 6 | 12; 799 + export namespace ModelWithNumericEnumUnion { 800 + /** 801 + * Период 802 + */ 803 + export enum value { 804 + '_-10' = -10, 805 + '_-1' = -1, 806 + '_0' = 0, 807 + '_1' = 1, 808 + '_3' = 3, 809 + '_6' = 6, 810 + '_12' = 12 811 + } 812 + } 762 813 763 814 export type ModelWithOneOfAndProperties = (ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { 764 815 baz: (number) | null; ··· 782 833 foo: 'Corge'; 783 834 }; 784 835 785 - export type foo = 'Bar'; 836 + export namespace ModelWithOneOfEnum { 837 + export enum foo { 838 + BAR = 'Bar' 839 + } 840 + } 786 841 787 842 /** 788 843 * This is a model with ordered properties
+70 -15
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_date/types.gen.ts.snap
··· 632 632 bool?: boolean; 633 633 }; 634 634 635 - /** 636 - * This is a simple enum with strings 637 - */ 638 - export type foo_bar_enum = 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 639 - 640 - /** 641 - * These are the HTTP error code enums 642 - */ 643 - export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; 635 + export namespace ModelWithEnum { 636 + /** 637 + * This is a simple enum with strings 638 + */ 639 + export enum foo_bar_enum { 640 + SUCCESS = 'Success', 641 + WARNING = 'Warning', 642 + ERROR = 'Error', 643 + ØÆÅ字符串 = 'ØÆÅ字符串' 644 + } 645 + /** 646 + * These are the HTTP error code enums 647 + */ 648 + export enum statusCode { 649 + _100 = '100', 650 + _200_FOO = '200 FOO', 651 + _300_FOO_BAR = '300 FOO_BAR', 652 + _400_FOO_BAR = '400 foo-bar', 653 + _500_FOO_BAR = '500 foo.bar', 654 + _600_FOO_BAR = '600 foo&bar' 655 + } 656 + } 644 657 645 658 /** 646 659 * This is a model with one enum ··· 659 672 'foo-bar-baz-qux'?: '3.0'; 660 673 }; 661 674 662 - export type foo_bar_baz_qux = '3.0'; 675 + export namespace ModelWithEnumWithHyphen { 676 + export enum foo_bar_baz_qux { 677 + _3_0 = '3.0' 678 + } 679 + } 663 680 664 681 /** 665 682 * This is a model with one number property ··· 707 724 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 708 725 }; 709 726 727 + export namespace ModelWithNestedEnums { 728 + /** 729 + * This is a simple enum with strings 730 + */ 731 + export enum foo_bar_enum { 732 + SUCCESS = 'Success', 733 + WARNING = 'Warning', 734 + ERROR = 'Error', 735 + ØÆÅ字符串 = 'ØÆÅ字符串' 736 + } 737 + } 738 + 710 739 /** 711 740 * This is a model with one nested property 712 741 */ ··· 748 777 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 749 778 }; 750 779 780 + export namespace ModelWithNullableString { 781 + /** 782 + * This is a simple enum with strings 783 + */ 784 + export enum foo_bar_enum { 785 + SUCCESS = 'Success', 786 + WARNING = 'Warning', 787 + ERROR = 'Error', 788 + ØÆÅ字符串 = 'ØÆÅ字符串' 789 + } 790 + } 791 + 751 792 export type ModelWithNumericEnumUnion = { 752 793 /** 753 794 * Период ··· 755 796 value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; 756 797 }; 757 798 758 - /** 759 - * Период 760 - */ 761 - export type value = -10 | -1 | 0 | 1 | 3 | 6 | 12; 799 + export namespace ModelWithNumericEnumUnion { 800 + /** 801 + * Период 802 + */ 803 + export enum value { 804 + '_-10' = -10, 805 + '_-1' = -1, 806 + '_0' = 0, 807 + '_1' = 1, 808 + '_3' = 3, 809 + '_6' = 6, 810 + '_12' = 12 811 + } 812 + } 762 813 763 814 export type ModelWithOneOfAndProperties = (ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { 764 815 baz: (number) | null; ··· 782 833 foo: 'Corge'; 783 834 }; 784 835 785 - export type foo = 'Bar'; 836 + export namespace ModelWithOneOfEnum { 837 + export enum foo { 838 + BAR = 'Bar' 839 + } 840 + } 786 841 787 842 /** 788 843 * This is a model with ordered properties
+66 -35
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap
··· 681 681 bool?: boolean; 682 682 }; 683 683 684 - /** 685 - * This is a simple enum with strings 686 - */ 687 - export enum foo_bar_enum { 688 - SUCCESS = 'Success', 689 - WARNING = 'Warning', 690 - ERROR = 'Error', 691 - ØÆÅ字符串 = 'ØÆÅ字符串' 692 - } 693 - 694 - /** 695 - * These are the HTTP error code enums 696 - */ 697 - export enum statusCode { 698 - _100 = '100', 699 - _200_FOO = '200 FOO', 700 - _300_FOO_BAR = '300 FOO_BAR', 701 - _400_FOO_BAR = '400 foo-bar', 702 - _500_FOO_BAR = '500 foo.bar', 703 - _600_FOO_BAR = '600 foo&bar' 684 + export namespace ModelWithEnum { 685 + /** 686 + * This is a simple enum with strings 687 + */ 688 + export enum foo_bar_enum { 689 + SUCCESS = 'Success', 690 + WARNING = 'Warning', 691 + ERROR = 'Error', 692 + ØÆÅ字符串 = 'ØÆÅ字符串' 693 + } 694 + /** 695 + * These are the HTTP error code enums 696 + */ 697 + export enum statusCode { 698 + _100 = '100', 699 + _200_FOO = '200 FOO', 700 + _300_FOO_BAR = '300 FOO_BAR', 701 + _400_FOO_BAR = '400 foo-bar', 702 + _500_FOO_BAR = '500 foo.bar', 703 + _600_FOO_BAR = '600 foo&bar' 704 + } 704 705 } 705 706 706 707 /** ··· 720 721 'foo-bar-baz-qux'?: '3.0'; 721 722 }; 722 723 723 - export enum foo_bar_baz_qux { 724 - _3_0 = '3.0' 724 + export namespace ModelWithEnumWithHyphen { 725 + export enum foo_bar_baz_qux { 726 + _3_0 = '3.0' 727 + } 725 728 } 726 729 727 730 /** ··· 776 779 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 777 780 }; 778 781 782 + export namespace ModelWithNestedEnums { 783 + /** 784 + * This is a simple enum with strings 785 + */ 786 + export enum foo_bar_enum { 787 + SUCCESS = 'Success', 788 + WARNING = 'Warning', 789 + ERROR = 'Error', 790 + ØÆÅ字符串 = 'ØÆÅ字符串' 791 + } 792 + } 793 + 779 794 /** 780 795 * This is a model with one nested property 781 796 */ ··· 817 832 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 818 833 }; 819 834 835 + export namespace ModelWithNullableString { 836 + /** 837 + * This is a simple enum with strings 838 + */ 839 + export enum foo_bar_enum { 840 + SUCCESS = 'Success', 841 + WARNING = 'Warning', 842 + ERROR = 'Error', 843 + ØÆÅ字符串 = 'ØÆÅ字符串' 844 + } 845 + } 846 + 820 847 export type ModelWithNumericEnumUnion = { 821 848 /** 822 849 * Период ··· 824 851 value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; 825 852 }; 826 853 827 - /** 828 - * Период 829 - */ 830 - export enum value { 831 - '_-10' = -10, 832 - '_-1' = -1, 833 - '_0' = 0, 834 - '_1' = 1, 835 - '_3' = 3, 836 - '_6' = 6, 837 - '_12' = 12 854 + export namespace ModelWithNumericEnumUnion { 855 + /** 856 + * Период 857 + */ 858 + export enum value { 859 + '_-10' = -10, 860 + '_-1' = -1, 861 + '_0' = 0, 862 + '_1' = 1, 863 + '_3' = 3, 864 + '_6' = 6, 865 + '_12' = 12 866 + } 838 867 } 839 868 840 869 export type ModelWithOneOfAndProperties = (ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { ··· 859 888 foo: 'Corge'; 860 889 }; 861 890 862 - export enum foo { 863 - BAR = 'Bar' 891 + export namespace ModelWithOneOfEnum { 892 + export enum foo { 893 + BAR = 'Bar' 894 + } 864 895 } 865 896 866 897 /**
-21
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_enums_typescript_namespace/core/ApiError.ts.snap
··· 1 - import type { ApiRequestOptions } from './ApiRequestOptions'; 2 - import type { ApiResult } from './ApiResult'; 3 - 4 - export class ApiError extends Error { 5 - public readonly url: string; 6 - public readonly status: number; 7 - public readonly statusText: string; 8 - public readonly body: unknown; 9 - public readonly request: ApiRequestOptions; 10 - 11 - constructor(request: ApiRequestOptions, response: ApiResult, message: string) { 12 - super(message); 13 - 14 - this.name = 'ApiError'; 15 - this.url = response.url; 16 - this.status = response.status; 17 - this.statusText = response.statusText; 18 - this.body = response.body; 19 - this.request = request; 20 - } 21 - }
-21
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_enums_typescript_namespace/core/ApiRequestOptions.ts.snap
··· 1 - export type ApiRequestOptions<T = unknown> = { 2 - readonly body?: any; 3 - readonly cookies?: Record<string, unknown>; 4 - readonly errors?: Record<number | string, string>; 5 - readonly formData?: Record<string, unknown> | any[] | Blob | File; 6 - readonly headers?: Record<string, unknown>; 7 - readonly mediaType?: string; 8 - readonly method: 9 - | 'DELETE' 10 - | 'GET' 11 - | 'HEAD' 12 - | 'OPTIONS' 13 - | 'PATCH' 14 - | 'POST' 15 - | 'PUT'; 16 - readonly path?: Record<string, unknown>; 17 - readonly query?: Record<string, unknown>; 18 - readonly responseHeader?: string; 19 - readonly responseTransformer?: (data: unknown) => Promise<T>; 20 - readonly url: string; 21 - };
-7
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_enums_typescript_namespace/core/ApiResult.ts.snap
··· 1 - export type ApiResult<TData = any> = { 2 - readonly body: TData; 3 - readonly ok: boolean; 4 - readonly status: number; 5 - readonly statusText: string; 6 - readonly url: string; 7 - };
-126
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_enums_typescript_namespace/core/CancelablePromise.ts.snap
··· 1 - export class CancelError extends Error { 2 - constructor(message: string) { 3 - super(message); 4 - this.name = 'CancelError'; 5 - } 6 - 7 - public get isCancelled(): boolean { 8 - return true; 9 - } 10 - } 11 - 12 - export interface OnCancel { 13 - readonly isResolved: boolean; 14 - readonly isRejected: boolean; 15 - readonly isCancelled: boolean; 16 - 17 - (cancelHandler: () => void): void; 18 - } 19 - 20 - export class CancelablePromise<T> implements Promise<T> { 21 - private _isResolved: boolean; 22 - private _isRejected: boolean; 23 - private _isCancelled: boolean; 24 - readonly cancelHandlers: (() => void)[]; 25 - readonly promise: Promise<T>; 26 - private _resolve?: (value: T | PromiseLike<T>) => void; 27 - private _reject?: (reason?: unknown) => void; 28 - 29 - constructor( 30 - executor: ( 31 - resolve: (value: T | PromiseLike<T>) => void, 32 - reject: (reason?: unknown) => void, 33 - onCancel: OnCancel 34 - ) => void 35 - ) { 36 - this._isResolved = false; 37 - this._isRejected = false; 38 - this._isCancelled = false; 39 - this.cancelHandlers = []; 40 - this.promise = new Promise<T>((resolve, reject) => { 41 - this._resolve = resolve; 42 - this._reject = reject; 43 - 44 - const onResolve = (value: T | PromiseLike<T>): void => { 45 - if (this._isResolved || this._isRejected || this._isCancelled) { 46 - return; 47 - } 48 - this._isResolved = true; 49 - if (this._resolve) this._resolve(value); 50 - }; 51 - 52 - const onReject = (reason?: unknown): void => { 53 - if (this._isResolved || this._isRejected || this._isCancelled) { 54 - return; 55 - } 56 - this._isRejected = true; 57 - if (this._reject) this._reject(reason); 58 - }; 59 - 60 - const onCancel = (cancelHandler: () => void): void => { 61 - if (this._isResolved || this._isRejected || this._isCancelled) { 62 - return; 63 - } 64 - this.cancelHandlers.push(cancelHandler); 65 - }; 66 - 67 - Object.defineProperty(onCancel, 'isResolved', { 68 - get: (): boolean => this._isResolved, 69 - }); 70 - 71 - Object.defineProperty(onCancel, 'isRejected', { 72 - get: (): boolean => this._isRejected, 73 - }); 74 - 75 - Object.defineProperty(onCancel, 'isCancelled', { 76 - get: (): boolean => this._isCancelled, 77 - }); 78 - 79 - return executor(onResolve, onReject, onCancel as OnCancel); 80 - }); 81 - } 82 - 83 - get [Symbol.toStringTag]() { 84 - return "Cancellable Promise"; 85 - } 86 - 87 - public then<TResult1 = T, TResult2 = never>( 88 - onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, 89 - onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null 90 - ): Promise<TResult1 | TResult2> { 91 - return this.promise.then(onFulfilled, onRejected); 92 - } 93 - 94 - public catch<TResult = never>( 95 - onRejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null 96 - ): Promise<T | TResult> { 97 - return this.promise.catch(onRejected); 98 - } 99 - 100 - public finally(onFinally?: (() => void) | null): Promise<T> { 101 - return this.promise.finally(onFinally); 102 - } 103 - 104 - public cancel(): void { 105 - if (this._isResolved || this._isRejected || this._isCancelled) { 106 - return; 107 - } 108 - this._isCancelled = true; 109 - if (this.cancelHandlers.length) { 110 - try { 111 - for (const cancelHandler of this.cancelHandlers) { 112 - cancelHandler(); 113 - } 114 - } catch (error) { 115 - console.warn('Cancellation threw an error', error); 116 - return; 117 - } 118 - } 119 - this.cancelHandlers.length = 0; 120 - if (this._reject) this._reject(new CancelError('Request aborted')); 121 - } 122 - 123 - public get isCancelled(): boolean { 124 - return this._isCancelled; 125 - } 126 - }
-56
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_enums_typescript_namespace/core/OpenAPI.ts.snap
··· 1 - import type { ApiRequestOptions } from './ApiRequestOptions'; 2 - 3 - type Headers = Record<string, string>; 4 - type Middleware<T> = (value: T) => T | Promise<T>; 5 - type Resolver<T> = (options: ApiRequestOptions<T>) => Promise<T>; 6 - 7 - export class Interceptors<T> { 8 - _fns: Middleware<T>[]; 9 - 10 - constructor() { 11 - this._fns = []; 12 - } 13 - 14 - eject(fn: Middleware<T>): void { 15 - const index = this._fns.indexOf(fn); 16 - if (index !== -1) { 17 - this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)]; 18 - } 19 - } 20 - 21 - use(fn: Middleware<T>): void { 22 - this._fns = [...this._fns, fn]; 23 - } 24 - } 25 - 26 - export type OpenAPIConfig = { 27 - BASE: string; 28 - CREDENTIALS: 'include' | 'omit' | 'same-origin'; 29 - ENCODE_PATH?: ((path: string) => string) | undefined; 30 - HEADERS?: Headers | Resolver<Headers> | undefined; 31 - PASSWORD?: string | Resolver<string> | undefined; 32 - TOKEN?: string | Resolver<string> | undefined; 33 - USERNAME?: string | Resolver<string> | undefined; 34 - VERSION: string; 35 - WITH_CREDENTIALS: boolean; 36 - interceptors: { 37 - request: Interceptors<RequestInit>; 38 - response: Interceptors<Response>; 39 - }; 40 - }; 41 - 42 - export const OpenAPI: OpenAPIConfig = { 43 - BASE: 'http://localhost:3000/base', 44 - CREDENTIALS: 'include', 45 - ENCODE_PATH: undefined, 46 - HEADERS: undefined, 47 - PASSWORD: undefined, 48 - TOKEN: undefined, 49 - USERNAME: undefined, 50 - VERSION: '1.0', 51 - WITH_CREDENTIALS: false, 52 - interceptors: { 53 - request: new Interceptors(), 54 - response: new Interceptors(), 55 - }, 56 - };
-350
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_enums_typescript_namespace/core/request.ts.snap
··· 1 - import { ApiError } from './ApiError'; 2 - import type { ApiRequestOptions } from './ApiRequestOptions'; 3 - import type { ApiResult } from './ApiResult'; 4 - import { CancelablePromise } from './CancelablePromise'; 5 - import type { OnCancel } from './CancelablePromise'; 6 - import type { OpenAPIConfig } from './OpenAPI'; 7 - 8 - export const isString = (value: unknown): value is string => { 9 - return typeof value === 'string'; 10 - }; 11 - 12 - export const isStringWithValue = (value: unknown): value is string => { 13 - return isString(value) && value !== ''; 14 - }; 15 - 16 - export const isBlob = (value: any): value is Blob => { 17 - return value instanceof Blob; 18 - }; 19 - 20 - export const isFormData = (value: unknown): value is FormData => { 21 - return value instanceof FormData; 22 - }; 23 - 24 - export const base64 = (str: string): string => { 25 - try { 26 - return btoa(str); 27 - } catch (err) { 28 - // @ts-ignore 29 - return Buffer.from(str).toString('base64'); 30 - } 31 - }; 32 - 33 - export const getQueryString = (params: Record<string, unknown>): string => { 34 - const qs: string[] = []; 35 - 36 - const append = (key: string, value: unknown) => { 37 - qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); 38 - }; 39 - 40 - const encodePair = (key: string, value: unknown) => { 41 - if (value === undefined || value === null) { 42 - return; 43 - } 44 - 45 - if (value instanceof Date) { 46 - append(key, value.toISOString()); 47 - } else if (Array.isArray(value)) { 48 - value.forEach(v => encodePair(key, v)); 49 - } else if (typeof value === 'object') { 50 - Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); 51 - } else { 52 - append(key, value); 53 - } 54 - }; 55 - 56 - Object.entries(params).forEach(([key, value]) => encodePair(key, value)); 57 - 58 - return qs.length ? `?${qs.join('&')}` : ''; 59 - }; 60 - 61 - const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => { 62 - const encoder = config.ENCODE_PATH || encodeURI; 63 - 64 - const path = options.url 65 - .replace('{api-version}', config.VERSION) 66 - .replace(/{(.*?)}/g, (substring: string, group: string) => { 67 - if (options.path?.hasOwnProperty(group)) { 68 - return encoder(String(options.path[group])); 69 - } 70 - return substring; 71 - }); 72 - 73 - const url = config.BASE + path; 74 - return options.query ? url + getQueryString(options.query) : url; 75 - }; 76 - 77 - export const getFormData = (options: ApiRequestOptions): FormData | undefined => { 78 - if (options.formData) { 79 - const formData = new FormData(); 80 - 81 - const process = (key: string, value: unknown) => { 82 - if (isString(value) || isBlob(value)) { 83 - formData.append(key, value); 84 - } else { 85 - formData.append(key, JSON.stringify(value)); 86 - } 87 - }; 88 - 89 - Object.entries(options.formData) 90 - .filter(([, value]) => value !== undefined && value !== null) 91 - .forEach(([key, value]) => { 92 - if (Array.isArray(value)) { 93 - value.forEach(v => process(key, v)); 94 - } else { 95 - process(key, value); 96 - } 97 - }); 98 - 99 - return formData; 100 - } 101 - return undefined; 102 - }; 103 - 104 - type Resolver<T> = (options: ApiRequestOptions<T>) => Promise<T>; 105 - 106 - export const resolve = async <T>(options: ApiRequestOptions<T>, resolver?: T | Resolver<T>): Promise<T | undefined> => { 107 - if (typeof resolver === 'function') { 108 - return (resolver as Resolver<T>)(options); 109 - } 110 - return resolver; 111 - }; 112 - 113 - export const getHeaders = async <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>): Promise<Headers> => { 114 - const [token, username, password, additionalHeaders] = await Promise.all([ 115 - // @ts-ignore 116 - resolve(options, config.TOKEN), 117 - // @ts-ignore 118 - resolve(options, config.USERNAME), 119 - // @ts-ignore 120 - resolve(options, config.PASSWORD), 121 - // @ts-ignore 122 - resolve(options, config.HEADERS), 123 - ]); 124 - 125 - const headers = Object.entries({ 126 - Accept: 'application/json', 127 - ...additionalHeaders, 128 - ...options.headers, 129 - }) 130 - .filter(([, value]) => value !== undefined && value !== null) 131 - .reduce((headers, [key, value]) => ({ 132 - ...headers, 133 - [key]: String(value), 134 - }), {} as Record<string, string>); 135 - 136 - if (isStringWithValue(token)) { 137 - headers['Authorization'] = `Bearer ${token}`; 138 - } 139 - 140 - if (isStringWithValue(username) && isStringWithValue(password)) { 141 - const credentials = base64(`${username}:${password}`); 142 - headers['Authorization'] = `Basic ${credentials}`; 143 - } 144 - 145 - if (options.body !== undefined) { 146 - if (options.mediaType) { 147 - headers['Content-Type'] = options.mediaType; 148 - } else if (isBlob(options.body)) { 149 - headers['Content-Type'] = options.body.type || 'application/octet-stream'; 150 - } else if (isString(options.body)) { 151 - headers['Content-Type'] = 'text/plain'; 152 - } else if (!isFormData(options.body)) { 153 - headers['Content-Type'] = 'application/json'; 154 - } 155 - } 156 - 157 - return new Headers(headers); 158 - }; 159 - 160 - export const getRequestBody = (options: ApiRequestOptions): unknown => { 161 - if (options.body !== undefined) { 162 - if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) { 163 - return JSON.stringify(options.body); 164 - } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) { 165 - return options.body; 166 - } else { 167 - return JSON.stringify(options.body); 168 - } 169 - } 170 - return undefined; 171 - }; 172 - 173 - export const sendRequest = async ( 174 - config: OpenAPIConfig, 175 - options: ApiRequestOptions, 176 - url: string, 177 - body: any, 178 - formData: FormData | undefined, 179 - headers: Headers, 180 - onCancel: OnCancel 181 - ): Promise<Response> => { 182 - const controller = new AbortController(); 183 - 184 - let request: RequestInit = { 185 - headers, 186 - body: body ?? formData, 187 - method: options.method, 188 - signal: controller.signal, 189 - }; 190 - 191 - if (config.WITH_CREDENTIALS) { 192 - request.credentials = config.CREDENTIALS; 193 - } 194 - 195 - for (const fn of config.interceptors.request._fns) { 196 - request = await fn(request); 197 - } 198 - 199 - onCancel(() => controller.abort()); 200 - 201 - return await fetch(url, request); 202 - }; 203 - 204 - export const getResponseHeader = (response: Response, responseHeader?: string): string | undefined => { 205 - if (responseHeader) { 206 - const content = response.headers.get(responseHeader); 207 - if (isString(content)) { 208 - return content; 209 - } 210 - } 211 - return undefined; 212 - }; 213 - 214 - export const getResponseBody = async (response: Response): Promise<unknown> => { 215 - if (response.status !== 204) { 216 - try { 217 - const contentType = response.headers.get('Content-Type'); 218 - if (contentType) { 219 - const binaryTypes = ['application/octet-stream', 'application/pdf', 'application/zip', 'audio/', 'image/', 'video/']; 220 - if (contentType.includes('application/json') || contentType.includes('+json')) { 221 - return await response.json(); 222 - } else if (binaryTypes.some(type => contentType.includes(type))) { 223 - return await response.blob(); 224 - } else if (contentType.includes('multipart/form-data')) { 225 - return await response.formData(); 226 - } else if (contentType.includes('text/')) { 227 - return await response.text(); 228 - } 229 - } 230 - } catch (error) { 231 - console.error(error); 232 - } 233 - } 234 - return undefined; 235 - }; 236 - 237 - export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => { 238 - const errors: Record<number, string> = { 239 - 400: 'Bad Request', 240 - 401: 'Unauthorized', 241 - 402: 'Payment Required', 242 - 403: 'Forbidden', 243 - 404: 'Not Found', 244 - 405: 'Method Not Allowed', 245 - 406: 'Not Acceptable', 246 - 407: 'Proxy Authentication Required', 247 - 408: 'Request Timeout', 248 - 409: 'Conflict', 249 - 410: 'Gone', 250 - 411: 'Length Required', 251 - 412: 'Precondition Failed', 252 - 413: 'Payload Too Large', 253 - 414: 'URI Too Long', 254 - 415: 'Unsupported Media Type', 255 - 416: 'Range Not Satisfiable', 256 - 417: 'Expectation Failed', 257 - 418: 'Im a teapot', 258 - 421: 'Misdirected Request', 259 - 422: 'Unprocessable Content', 260 - 423: 'Locked', 261 - 424: 'Failed Dependency', 262 - 425: 'Too Early', 263 - 426: 'Upgrade Required', 264 - 428: 'Precondition Required', 265 - 429: 'Too Many Requests', 266 - 431: 'Request Header Fields Too Large', 267 - 451: 'Unavailable For Legal Reasons', 268 - 500: 'Internal Server Error', 269 - 501: 'Not Implemented', 270 - 502: 'Bad Gateway', 271 - 503: 'Service Unavailable', 272 - 504: 'Gateway Timeout', 273 - 505: 'HTTP Version Not Supported', 274 - 506: 'Variant Also Negotiates', 275 - 507: 'Insufficient Storage', 276 - 508: 'Loop Detected', 277 - 510: 'Not Extended', 278 - 511: 'Network Authentication Required', 279 - ...options.errors, 280 - } 281 - 282 - const error = errors[result.status]; 283 - if (error) { 284 - throw new ApiError(options, result, error); 285 - } 286 - 287 - if (!result.ok) { 288 - const errorStatus = result.status ?? 'unknown'; 289 - const errorStatusText = result.statusText ?? 'unknown'; 290 - const errorBody = (() => { 291 - try { 292 - return JSON.stringify(result.body, null, 2); 293 - } catch (e) { 294 - return undefined; 295 - } 296 - })(); 297 - 298 - throw new ApiError(options, result, 299 - `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}` 300 - ); 301 - } 302 - }; 303 - 304 - /** 305 - * Request method 306 - * @param config The OpenAPI configuration object 307 - * @param options The request options from the service 308 - * @returns CancelablePromise<T> 309 - * @throws ApiError 310 - */ 311 - export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>): CancelablePromise<T> => { 312 - return new CancelablePromise(async (resolve, reject, onCancel) => { 313 - try { 314 - const url = getUrl(config, options); 315 - const formData = getFormData(options); 316 - const body = getRequestBody(options); 317 - const headers = await getHeaders(config, options); 318 - 319 - if (!onCancel.isCancelled) { 320 - let response = await sendRequest(config, options, url, body, formData, headers, onCancel); 321 - 322 - for (const fn of config.interceptors.response._fns) { 323 - response = await fn(response); 324 - } 325 - 326 - const responseBody = await getResponseBody(response); 327 - const responseHeader = getResponseHeader(response, options.responseHeader); 328 - 329 - let transformedBody = responseBody; 330 - if (options.responseTransformer && response.ok) { 331 - transformedBody = await options.responseTransformer(responseBody) 332 - } 333 - 334 - const result: ApiResult = { 335 - url, 336 - ok: response.ok, 337 - status: response.status, 338 - statusText: response.statusText, 339 - body: responseHeader ?? transformedBody, 340 - }; 341 - 342 - catchErrorCodes(options, result); 343 - 344 - resolve(result.body); 345 - } 346 - } catch (error) { 347 - reject(error); 348 - } 349 - }); 350 - };
-6
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_enums_typescript_namespace/index.ts.snap
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - export { ApiError } from './core/ApiError'; 3 - export { CancelablePromise, CancelError } from './core/CancelablePromise'; 4 - export { OpenAPI, type OpenAPIConfig } from './core/OpenAPI'; 5 - export * from './sdk.gen'; 6 - export * from './types.gen';
-890
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_enums_typescript_namespace/sdk.gen.ts.snap
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - import type { CancelablePromise } from './core/CancelablePromise'; 4 - import { OpenAPI } from './core/OpenAPI'; 5 - import { request as __request } from './core/request'; 6 - import type { CollectionFormatData, ComplexTypesData, ComplexTypesResponse, ComplexParamsData, ComplexParamsResponse, PatchApiNoTagResponse, ImportData, ImportResponse, FooWowResponse, GetApiSimpleOperationData, GetApiSimpleOperationResponse, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, DeprecatedCallData, CallWithDescriptionsData, TestErrorCodeData, TestErrorCodeResponse, FileResponseData, FileResponseResponse, PostApiFormDataData, CallWithResultFromHeaderResponse, MultipartRequestData, MultipartResponseResponse, DummyAResponse, DummyBResponse, CallWithNoContentResponseResponse, CallWithResponseAndNoContentResponseResponse, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData, DeleteFooData3, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamResponse, PostApiRequestBodyData, CallWithResponseResponse, CallWithDuplicateResponsesResponse, CallWithResponsesResponse, ApiVVersionODataControllerCountResponse, TypesData, TypesResponse, UploadFileData, UploadFileResponse } from './types.gen'; 7 - 8 - export class CollectionFormat { 9 - /** 10 - * @param data The data for the request. 11 - * @param data.parameterArrayCsv This is an array parameter that is sent as csv format (comma-separated values) 12 - * @param data.parameterArraySsv This is an array parameter that is sent as ssv format (space-separated values) 13 - * @param data.parameterArrayTsv This is an array parameter that is sent as tsv format (tab-separated values) 14 - * @param data.parameterArrayPipes This is an array parameter that is sent as pipes format (pipe-separated values) 15 - * @param data.parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) 16 - * @throws ApiError 17 - */ 18 - public static collectionFormat(data: CollectionFormatData): CancelablePromise<void> { 19 - return __request(OpenAPI, { 20 - method: 'GET', 21 - url: '/api/v{api-version}/collectionFormat', 22 - query: { 23 - parameterArrayCSV: data.parameterArrayCsv, 24 - parameterArraySSV: data.parameterArraySsv, 25 - parameterArrayTSV: data.parameterArrayTsv, 26 - parameterArrayPipes: data.parameterArrayPipes, 27 - parameterArrayMulti: data.parameterArrayMulti 28 - } 29 - }); 30 - } 31 - } 32 - 33 - export class Complex { 34 - /** 35 - * @param data The data for the request. 36 - * @param data.parameterObject Parameter containing object 37 - * @param data.parameterReference Parameter containing reference 38 - * @returns ModelWithString Successful response 39 - * @throws ApiError 40 - */ 41 - public static complexTypes(data: ComplexTypesData): CancelablePromise<ComplexTypesResponse> { 42 - return __request(OpenAPI, { 43 - method: 'GET', 44 - url: '/api/v{api-version}/complex', 45 - query: { 46 - parameterObject: data.parameterObject, 47 - parameterReference: data.parameterReference 48 - }, 49 - errors: { 50 - 400: '400 `server` error', 51 - 500: '500 server error' 52 - } 53 - }); 54 - } 55 - 56 - /** 57 - * @param data The data for the request. 58 - * @param data.id 59 - * @param data.requestBody 60 - * @returns ModelWithString Success 61 - * @throws ApiError 62 - */ 63 - public static complexParams(data: ComplexParamsData): CancelablePromise<ComplexParamsResponse> { 64 - return __request(OpenAPI, { 65 - method: 'PUT', 66 - url: '/api/v{api-version}/complex/{id}', 67 - path: { 68 - id: data.id 69 - }, 70 - body: data.requestBody, 71 - mediaType: 'application/json-patch+json' 72 - }); 73 - } 74 - } 75 - 76 - export class Default { 77 - /** 78 - * @throws ApiError 79 - */ 80 - public static export(): CancelablePromise<void> { 81 - return __request(OpenAPI, { 82 - method: 'GET', 83 - url: '/api/v{api-version}/no+tag' 84 - }); 85 - } 86 - 87 - /** 88 - * @returns unknown OK 89 - * @throws ApiError 90 - */ 91 - public static patchApiNoTag(): CancelablePromise<PatchApiNoTagResponse> { 92 - return __request(OpenAPI, { 93 - method: 'PATCH', 94 - url: '/api/v{api-version}/no+tag' 95 - }); 96 - } 97 - 98 - /** 99 - * @param data The data for the request. 100 - * @param data.requestBody 101 - * @returns Model_From_Zendesk Success 102 - * @returns ModelWithReadOnlyAndWriteOnly Default success response 103 - * @throws ApiError 104 - */ 105 - public static import(data: ImportData): CancelablePromise<ImportResponse> { 106 - return __request(OpenAPI, { 107 - method: 'POST', 108 - url: '/api/v{api-version}/no+tag', 109 - body: data.requestBody, 110 - mediaType: 'application/json' 111 - }); 112 - } 113 - 114 - /** 115 - * @returns unknown OK 116 - * @throws ApiError 117 - */ 118 - public static fooWow(): CancelablePromise<FooWowResponse> { 119 - return __request(OpenAPI, { 120 - method: 'PUT', 121 - url: '/api/v{api-version}/no+tag' 122 - }); 123 - } 124 - 125 - /** 126 - * @param data The data for the request. 127 - * @param data.fooParam foo in method 128 - * @returns number Response is a simple number 129 - * @throws ApiError 130 - */ 131 - public static getApiSimpleOperation(data: GetApiSimpleOperationData): CancelablePromise<GetApiSimpleOperationResponse> { 132 - return __request(OpenAPI, { 133 - method: 'GET', 134 - url: '/api/v{api-version}/simple:operation', 135 - path: { 136 - foo_param: data.fooParam 137 - }, 138 - errors: { 139 - default: 'Default error response' 140 - } 141 - }); 142 - } 143 - } 144 - 145 - export class Defaults { 146 - /** 147 - * @param data The data for the request. 148 - * @param data.parameterString This is a simple string with default value 149 - * @param data.parameterNumber This is a simple number with default value 150 - * @param data.parameterBoolean This is a simple boolean with default value 151 - * @param data.parameterEnum This is a simple enum with default value 152 - * @param data.parameterModel This is a simple model with default value 153 - * @throws ApiError 154 - */ 155 - public static callWithDefaultParameters(data: CallWithDefaultParametersData = {}): CancelablePromise<void> { 156 - return __request(OpenAPI, { 157 - method: 'GET', 158 - url: '/api/v{api-version}/defaults', 159 - query: { 160 - parameterString: data.parameterString, 161 - parameterNumber: data.parameterNumber, 162 - parameterBoolean: data.parameterBoolean, 163 - parameterEnum: data.parameterEnum, 164 - parameterModel: data.parameterModel 165 - } 166 - }); 167 - } 168 - 169 - /** 170 - * @param data The data for the request. 171 - * @param data.parameterString This is a simple string that is optional with default value 172 - * @param data.parameterNumber This is a simple number that is optional with default value 173 - * @param data.parameterBoolean This is a simple boolean that is optional with default value 174 - * @param data.parameterEnum This is a simple enum that is optional with default value 175 - * @param data.parameterModel This is a simple model that is optional with default value 176 - * @throws ApiError 177 - */ 178 - public static callWithDefaultOptionalParameters(data: CallWithDefaultOptionalParametersData = {}): CancelablePromise<void> { 179 - return __request(OpenAPI, { 180 - method: 'POST', 181 - url: '/api/v{api-version}/defaults', 182 - query: { 183 - parameterString: data.parameterString, 184 - parameterNumber: data.parameterNumber, 185 - parameterBoolean: data.parameterBoolean, 186 - parameterEnum: data.parameterEnum, 187 - parameterModel: data.parameterModel 188 - } 189 - }); 190 - } 191 - 192 - /** 193 - * @param data The data for the request. 194 - * @param data.parameterStringWithNoDefault This is a string with no default 195 - * @param data.parameterOptionalStringWithDefault This is a optional string with default 196 - * @param data.parameterOptionalStringWithEmptyDefault This is a optional string with empty default 197 - * @param data.parameterOptionalStringWithNoDefault This is a optional string with no default 198 - * @param data.parameterStringWithDefault This is a string with default 199 - * @param data.parameterStringWithEmptyDefault This is a string with empty default 200 - * @param data.parameterStringNullableWithNoDefault This is a string that can be null with no default 201 - * @param data.parameterStringNullableWithDefault This is a string that can be null with default 202 - * @throws ApiError 203 - */ 204 - public static callToTestOrderOfParams(data: CallToTestOrderOfParamsData): CancelablePromise<void> { 205 - return __request(OpenAPI, { 206 - method: 'PUT', 207 - url: '/api/v{api-version}/defaults', 208 - query: { 209 - parameterOptionalStringWithDefault: data.parameterOptionalStringWithDefault, 210 - parameterOptionalStringWithEmptyDefault: data.parameterOptionalStringWithEmptyDefault, 211 - parameterOptionalStringWithNoDefault: data.parameterOptionalStringWithNoDefault, 212 - parameterStringWithDefault: data.parameterStringWithDefault, 213 - parameterStringWithEmptyDefault: data.parameterStringWithEmptyDefault, 214 - parameterStringWithNoDefault: data.parameterStringWithNoDefault, 215 - parameterStringNullableWithNoDefault: data.parameterStringNullableWithNoDefault, 216 - parameterStringNullableWithDefault: data.parameterStringNullableWithDefault 217 - } 218 - }); 219 - } 220 - } 221 - 222 - export class Deprecated { 223 - /** 224 - * @deprecated 225 - * @param data The data for the request. 226 - * @param data.parameter This parameter is deprecated 227 - * @throws ApiError 228 - */ 229 - public static deprecatedCall(data: DeprecatedCallData): CancelablePromise<void> { 230 - return __request(OpenAPI, { 231 - method: 'POST', 232 - url: '/api/v{api-version}/parameters/deprecated', 233 - headers: { 234 - parameter: data.parameter 235 - } 236 - }); 237 - } 238 - } 239 - 240 - export class Descriptions { 241 - /** 242 - * @param data The data for the request. 243 - * @param data.parameterWithBreaks Testing multiline comments in string: First line 244 - * Second line 245 - * 246 - * Fourth line 247 - * @param data.parameterWithBackticks Testing backticks in string: `backticks` and ```multiple backticks``` should work 248 - * @param data.parameterWithSlashes Testing slashes in string: \backwards\\\ and /forwards/// should work 249 - * @param data.parameterWithExpressionPlaceholders Testing expression placeholders in string: ${expression} should work 250 - * @param data.parameterWithQuotes Testing quotes in string: 'single quote''' and "double quotes""" should work 251 - * @param data.parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work 252 - * @throws ApiError 253 - */ 254 - public static callWithDescriptions(data: CallWithDescriptionsData = {}): CancelablePromise<void> { 255 - return __request(OpenAPI, { 256 - method: 'POST', 257 - url: '/api/v{api-version}/descriptions/', 258 - query: { 259 - parameterWithBreaks: data.parameterWithBreaks, 260 - parameterWithBackticks: data.parameterWithBackticks, 261 - parameterWithSlashes: data.parameterWithSlashes, 262 - parameterWithExpressionPlaceholders: data.parameterWithExpressionPlaceholders, 263 - parameterWithQuotes: data.parameterWithQuotes, 264 - parameterWithReservedCharacters: data.parameterWithReservedCharacters 265 - } 266 - }); 267 - } 268 - } 269 - 270 - export class Duplicate { 271 - /** 272 - * @throws ApiError 273 - */ 274 - public static duplicateName(): CancelablePromise<void> { 275 - return __request(OpenAPI, { 276 - method: 'GET', 277 - url: '/api/v{api-version}/duplicate' 278 - }); 279 - } 280 - 281 - /** 282 - * @throws ApiError 283 - */ 284 - public static duplicateName1(): CancelablePromise<void> { 285 - return __request(OpenAPI, { 286 - method: 'POST', 287 - url: '/api/v{api-version}/duplicate' 288 - }); 289 - } 290 - 291 - /** 292 - * @throws ApiError 293 - */ 294 - public static duplicateName2(): CancelablePromise<void> { 295 - return __request(OpenAPI, { 296 - method: 'PUT', 297 - url: '/api/v{api-version}/duplicate' 298 - }); 299 - } 300 - 301 - /** 302 - * @throws ApiError 303 - */ 304 - public static duplicateName3(): CancelablePromise<void> { 305 - return __request(OpenAPI, { 306 - method: 'DELETE', 307 - url: '/api/v{api-version}/duplicate' 308 - }); 309 - } 310 - } 311 - 312 - export class Error { 313 - /** 314 - * @param data The data for the request. 315 - * @param data.status Status code to return 316 - * @returns unknown Custom message: Successful response 317 - * @throws ApiError 318 - */ 319 - public static testErrorCode(data: TestErrorCodeData): CancelablePromise<TestErrorCodeResponse> { 320 - return __request(OpenAPI, { 321 - method: 'POST', 322 - url: '/api/v{api-version}/error', 323 - query: { 324 - status: data.status 325 - }, 326 - errors: { 327 - 500: 'Custom message: Internal Server Error', 328 - 501: 'Custom message: Not Implemented', 329 - 502: 'Custom message: Bad Gateway', 330 - 503: 'Custom message: Service Unavailable' 331 - } 332 - }); 333 - } 334 - } 335 - 336 - export class FileResponse { 337 - /** 338 - * @param data The data for the request. 339 - * @param data.id 340 - * @returns binary Success 341 - * @throws ApiError 342 - */ 343 - public static fileResponse(data: FileResponseData): CancelablePromise<FileResponseResponse> { 344 - return __request(OpenAPI, { 345 - method: 'GET', 346 - url: '/api/v{api-version}/file/{id}', 347 - path: { 348 - id: data.id 349 - } 350 - }); 351 - } 352 - } 353 - 354 - export class FormData { 355 - /** 356 - * @param data The data for the request. 357 - * @param data.parameter This is a reusable parameter 358 - * @param data.formData A reusable request body 359 - * @throws ApiError 360 - */ 361 - public static postApiFormData(data: PostApiFormDataData = {}): CancelablePromise<void> { 362 - return __request(OpenAPI, { 363 - method: 'POST', 364 - url: '/api/v{api-version}/formData/', 365 - query: { 366 - parameter: data.parameter 367 - }, 368 - formData: data.formData, 369 - mediaType: 'multipart/form-data' 370 - }); 371 - } 372 - } 373 - 374 - export class Header { 375 - /** 376 - * @returns string Successful response 377 - * @throws ApiError 378 - */ 379 - public static callWithResultFromHeader(): CancelablePromise<CallWithResultFromHeaderResponse> { 380 - return __request(OpenAPI, { 381 - method: 'POST', 382 - url: '/api/v{api-version}/header', 383 - responseHeader: 'operation-location', 384 - errors: { 385 - 400: '400 server error', 386 - 500: '500 server error' 387 - } 388 - }); 389 - } 390 - } 391 - 392 - export class Multipart { 393 - /** 394 - * @param data The data for the request. 395 - * @param data.formData 396 - * @throws ApiError 397 - */ 398 - public static multipartRequest(data: MultipartRequestData = {}): CancelablePromise<void> { 399 - return __request(OpenAPI, { 400 - method: 'POST', 401 - url: '/api/v{api-version}/multipart', 402 - formData: data.formData, 403 - mediaType: 'multipart/form-data' 404 - }); 405 - } 406 - 407 - /** 408 - * @returns unknown OK 409 - * @throws ApiError 410 - */ 411 - public static multipartResponse(): CancelablePromise<MultipartResponseResponse> { 412 - return __request(OpenAPI, { 413 - method: 'GET', 414 - url: '/api/v{api-version}/multipart' 415 - }); 416 - } 417 - } 418 - 419 - export class MultipleTags1 { 420 - /** 421 - * @returns _400 422 - * @throws ApiError 423 - */ 424 - public static dummyA(): CancelablePromise<DummyAResponse> { 425 - return __request(OpenAPI, { 426 - method: 'GET', 427 - url: '/api/v{api-version}/multiple-tags/a' 428 - }); 429 - } 430 - 431 - /** 432 - * @returns void Success 433 - * @throws ApiError 434 - */ 435 - public static dummyB(): CancelablePromise<DummyBResponse> { 436 - return __request(OpenAPI, { 437 - method: 'GET', 438 - url: '/api/v{api-version}/multiple-tags/b' 439 - }); 440 - } 441 - } 442 - 443 - export class MultipleTags2 { 444 - /** 445 - * @returns _400 446 - * @throws ApiError 447 - */ 448 - public static dummyA(): CancelablePromise<DummyAResponse> { 449 - return __request(OpenAPI, { 450 - method: 'GET', 451 - url: '/api/v{api-version}/multiple-tags/a' 452 - }); 453 - } 454 - 455 - /** 456 - * @returns void Success 457 - * @throws ApiError 458 - */ 459 - public static dummyB(): CancelablePromise<DummyBResponse> { 460 - return __request(OpenAPI, { 461 - method: 'GET', 462 - url: '/api/v{api-version}/multiple-tags/b' 463 - }); 464 - } 465 - } 466 - 467 - export class MultipleTags3 { 468 - /** 469 - * @returns void Success 470 - * @throws ApiError 471 - */ 472 - public static dummyB(): CancelablePromise<DummyBResponse> { 473 - return __request(OpenAPI, { 474 - method: 'GET', 475 - url: '/api/v{api-version}/multiple-tags/b' 476 - }); 477 - } 478 - } 479 - 480 - export class NoContent { 481 - /** 482 - * @returns void Success 483 - * @throws ApiError 484 - */ 485 - public static callWithNoContentResponse(): CancelablePromise<CallWithNoContentResponseResponse> { 486 - return __request(OpenAPI, { 487 - method: 'GET', 488 - url: '/api/v{api-version}/no-content' 489 - }); 490 - } 491 - 492 - /** 493 - * @returns number Response is a simple number 494 - * @returns void Success 495 - * @throws ApiError 496 - */ 497 - public static callWithResponseAndNoContentResponse(): CancelablePromise<CallWithResponseAndNoContentResponseResponse> { 498 - return __request(OpenAPI, { 499 - method: 'GET', 500 - url: '/api/v{api-version}/multiple-tags/response-and-no-content' 501 - }); 502 - } 503 - } 504 - 505 - export class NonAsciiÆøåÆøÅöôêÊ { 506 - /** 507 - * @param data The data for the request. 508 - * @param data.nonAsciiParamæøåÆøÅöôêÊ Dummy input param 509 - * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response 510 - * @throws ApiError 511 - */ 512 - public static nonAsciiæøåÆøÅöôêÊ字符串(data: NonAsciiæøåÆøÅöôêÊ字符串Data): CancelablePromise<NonAsciiæøåÆøÅöôêÊ字符串Response> { 513 - return __request(OpenAPI, { 514 - method: 'POST', 515 - url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', 516 - query: { 517 - 'nonAsciiParamæøåÆØÅöôêÊ': data.nonAsciiParamæøåÆøÅöôêÊ 518 - } 519 - }); 520 - } 521 - 522 - /** 523 - * Login User 524 - * @param data The data for the request. 525 - * @param data.formData 526 - * @throws ApiError 527 - */ 528 - public static putWithFormUrlEncoded(data: PutWithFormUrlEncodedData): CancelablePromise<void> { 529 - return __request(OpenAPI, { 530 - method: 'PUT', 531 - url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', 532 - formData: data.formData, 533 - mediaType: 'application/x-www-form-urlencoded' 534 - }); 535 - } 536 - } 537 - 538 - export class Parameters { 539 - /** 540 - * @param data The data for the request. 541 - * @param data.fooParam foo in method 542 - * @param data.barParam bar in method 543 - * @param data.xFooBar Parameter with illegal characters 544 - * @throws ApiError 545 - */ 546 - public static deleteFoo(data: DeleteFooData3): CancelablePromise<void> { 547 - return __request(OpenAPI, { 548 - method: 'DELETE', 549 - url: '/api/v{api-version}/foo/{foo_param}/bar/{BarParam}', 550 - path: { 551 - foo_param: data.fooParam, 552 - BarParam: data.barParam 553 - }, 554 - headers: { 555 - 'x-Foo-Bar': data.xFooBar 556 - } 557 - }); 558 - } 559 - 560 - /** 561 - * @param data The data for the request. 562 - * @param data.parameterHeader This is the parameter that goes into the header 563 - * @param data.fooAllOfEnum 564 - * @param data.cursor This is the parameter that goes into the query params 565 - * @param data.parameterCookie This is the parameter that goes into the cookie 566 - * @param data.parameterPath This is the parameter that goes into the path 567 - * @param data.requestBody This is the parameter that goes into the body 568 - * @param data.fooRefEnum 569 - * @throws ApiError 570 - */ 571 - public static callWithParameters(data: CallWithParametersData): CancelablePromise<void> { 572 - return __request(OpenAPI, { 573 - method: 'POST', 574 - url: '/api/v{api-version}/parameters/{parameterPath}', 575 - path: { 576 - parameterPath: data.parameterPath 577 - }, 578 - cookies: { 579 - parameterCookie: data.parameterCookie 580 - }, 581 - headers: { 582 - parameterHeader: data.parameterHeader 583 - }, 584 - query: { 585 - foo_ref_enum: data.fooRefEnum, 586 - foo_all_of_enum: data.fooAllOfEnum, 587 - cursor: data.cursor 588 - }, 589 - body: data.requestBody, 590 - mediaType: 'application/json' 591 - }); 592 - } 593 - 594 - /** 595 - * @param data The data for the request. 596 - * @param data.parameterHeader This is the parameter that goes into the request header 597 - * @param data.parameterQuery This is the parameter that goes into the request query params 598 - * @param data.parameterCookie This is the parameter that goes into the cookie 599 - * @param data.requestBody This is the parameter that goes into the body 600 - * @param data.parameterPath1 This is the parameter that goes into the path 601 - * @param data.parameterPath2 This is the parameter that goes into the path 602 - * @param data.parameterPath3 This is the parameter that goes into the path 603 - * @param data._default This is the parameter with a reserved keyword 604 - * @throws ApiError 605 - */ 606 - public static callWithWeirdParameterNames(data: CallWithWeirdParameterNamesData): CancelablePromise<void> { 607 - return __request(OpenAPI, { 608 - method: 'POST', 609 - url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', 610 - path: { 611 - 'parameter.path.1': data.parameterPath1, 612 - 'parameter-path-2': data.parameterPath2, 613 - 'PARAMETER-PATH-3': data.parameterPath3 614 - }, 615 - cookies: { 616 - 'PARAMETER-COOKIE': data.parameterCookie 617 - }, 618 - headers: { 619 - 'parameter.header': data.parameterHeader 620 - }, 621 - query: { 622 - default: data._default, 623 - 'parameter-query': data.parameterQuery 624 - }, 625 - body: data.requestBody, 626 - mediaType: 'application/json' 627 - }); 628 - } 629 - 630 - /** 631 - * @param data The data for the request. 632 - * @param data.requestBody This is a required parameter 633 - * @param data.page This is an optional parameter 634 - * @throws ApiError 635 - */ 636 - public static getCallWithOptionalParam(data: GetCallWithOptionalParamData): CancelablePromise<void> { 637 - return __request(OpenAPI, { 638 - method: 'GET', 639 - url: '/api/v{api-version}/parameters/', 640 - query: { 641 - page: data.page 642 - }, 643 - body: data.requestBody, 644 - mediaType: 'application/json' 645 - }); 646 - } 647 - 648 - /** 649 - * @param data The data for the request. 650 - * @param data.parameter This is a required parameter 651 - * @param data.requestBody This is an optional parameter 652 - * @returns number Response is a simple number 653 - * @returns void Success 654 - * @throws ApiError 655 - */ 656 - public static postCallWithOptionalParam(data: PostCallWithOptionalParamData): CancelablePromise<PostCallWithOptionalParamResponse> { 657 - return __request(OpenAPI, { 658 - method: 'POST', 659 - url: '/api/v{api-version}/parameters/', 660 - query: { 661 - parameter: data.parameter 662 - }, 663 - body: data.requestBody, 664 - mediaType: 'application/json' 665 - }); 666 - } 667 - } 668 - 669 - export class RequestBody { 670 - /** 671 - * @param data The data for the request. 672 - * @param data.parameter This is a reusable parameter 673 - * @param data.foo A reusable request body 674 - * @throws ApiError 675 - */ 676 - public static postApiRequestBody(data: PostApiRequestBodyData = {}): CancelablePromise<void> { 677 - return __request(OpenAPI, { 678 - method: 'POST', 679 - url: '/api/v{api-version}/requestBody/', 680 - query: { 681 - parameter: data.parameter 682 - }, 683 - body: data.foo, 684 - mediaType: 'application/json' 685 - }); 686 - } 687 - } 688 - 689 - export class Response { 690 - /** 691 - * @returns number Response is a simple number 692 - * @returns void Success 693 - * @throws ApiError 694 - */ 695 - public static callWithResponseAndNoContentResponse(): CancelablePromise<CallWithResponseAndNoContentResponseResponse> { 696 - return __request(OpenAPI, { 697 - method: 'GET', 698 - url: '/api/v{api-version}/multiple-tags/response-and-no-content' 699 - }); 700 - } 701 - 702 - /** 703 - * @returns import 704 - * @throws ApiError 705 - */ 706 - public static callWithResponse(): CancelablePromise<CallWithResponseResponse> { 707 - return __request(OpenAPI, { 708 - method: 'GET', 709 - url: '/api/v{api-version}/response' 710 - }); 711 - } 712 - 713 - /** 714 - * @returns unknown Message for 200 response 715 - * @returns ModelWithString Message for 201 response 716 - * @returns ModelWithString Message for 202 response 717 - * @throws ApiError 718 - */ 719 - public static callWithDuplicateResponses(): CancelablePromise<CallWithDuplicateResponsesResponse> { 720 - return __request(OpenAPI, { 721 - method: 'POST', 722 - url: '/api/v{api-version}/response', 723 - errors: { 724 - 500: 'Message for 500 error', 725 - 501: 'Message for 501 error', 726 - 502: 'Message for 502 error', 727 - '4XX': 'Message for 4XX errors', 728 - default: 'Default error response' 729 - } 730 - }); 731 - } 732 - 733 - /** 734 - * @returns unknown Message for 200 response 735 - * @returns ModelThatExtends Message for 201 response 736 - * @returns ModelThatExtendsExtends Message for 202 response 737 - * @throws ApiError 738 - */ 739 - public static callWithResponses(): CancelablePromise<CallWithResponsesResponse> { 740 - return __request(OpenAPI, { 741 - method: 'PUT', 742 - url: '/api/v{api-version}/response', 743 - errors: { 744 - 500: 'Message for 500 error', 745 - 501: 'Message for 501 error', 746 - 502: 'Message for 502 error', 747 - default: 'Message for default response' 748 - } 749 - }); 750 - } 751 - } 752 - 753 - export class Simple { 754 - /** 755 - * @returns Model_From_Zendesk Success 756 - * @throws ApiError 757 - */ 758 - public static apiVVersionODataControllerCount(): CancelablePromise<ApiVVersionODataControllerCountResponse> { 759 - return __request(OpenAPI, { 760 - method: 'GET', 761 - url: '/api/v{api-version}/simple/$count' 762 - }); 763 - } 764 - 765 - /** 766 - * @throws ApiError 767 - */ 768 - public static getCallWithoutParametersAndResponse(): CancelablePromise<void> { 769 - return __request(OpenAPI, { 770 - method: 'GET', 771 - url: '/api/v{api-version}/simple' 772 - }); 773 - } 774 - 775 - /** 776 - * @throws ApiError 777 - */ 778 - public static putCallWithoutParametersAndResponse(): CancelablePromise<void> { 779 - return __request(OpenAPI, { 780 - method: 'PUT', 781 - url: '/api/v{api-version}/simple' 782 - }); 783 - } 784 - 785 - /** 786 - * @throws ApiError 787 - */ 788 - public static postCallWithoutParametersAndResponse(): CancelablePromise<void> { 789 - return __request(OpenAPI, { 790 - method: 'POST', 791 - url: '/api/v{api-version}/simple' 792 - }); 793 - } 794 - 795 - /** 796 - * @throws ApiError 797 - */ 798 - public static deleteCallWithoutParametersAndResponse(): CancelablePromise<void> { 799 - return __request(OpenAPI, { 800 - method: 'DELETE', 801 - url: '/api/v{api-version}/simple' 802 - }); 803 - } 804 - 805 - /** 806 - * @throws ApiError 807 - */ 808 - public static optionsCallWithoutParametersAndResponse(): CancelablePromise<void> { 809 - return __request(OpenAPI, { 810 - method: 'OPTIONS', 811 - url: '/api/v{api-version}/simple' 812 - }); 813 - } 814 - 815 - /** 816 - * @throws ApiError 817 - */ 818 - public static headCallWithoutParametersAndResponse(): CancelablePromise<void> { 819 - return __request(OpenAPI, { 820 - method: 'HEAD', 821 - url: '/api/v{api-version}/simple' 822 - }); 823 - } 824 - 825 - /** 826 - * @throws ApiError 827 - */ 828 - public static patchCallWithoutParametersAndResponse(): CancelablePromise<void> { 829 - return __request(OpenAPI, { 830 - method: 'PATCH', 831 - url: '/api/v{api-version}/simple' 832 - }); 833 - } 834 - } 835 - 836 - export class Types { 837 - /** 838 - * @param data The data for the request. 839 - * @param data.parameterArray This is an array parameter 840 - * @param data.parameterDictionary This is a dictionary parameter 841 - * @param data.parameterEnum This is an enum parameter 842 - * @param data.parameterTuple This is tuple parameter 843 - * @param data.parameterNumber This is a number parameter 844 - * @param data.parameterString This is a string parameter 845 - * @param data.parameterBoolean This is a boolean parameter 846 - * @param data.parameterObject This is an object parameter 847 - * @param data.id This is a number parameter 848 - * @returns number Response is a simple number 849 - * @returns string Response is a simple string 850 - * @returns boolean Response is a simple boolean 851 - * @returns unknown Response is a simple object 852 - * @throws ApiError 853 - */ 854 - public static types(data: TypesData): CancelablePromise<TypesResponse> { 855 - return __request(OpenAPI, { 856 - method: 'GET', 857 - url: '/api/v{api-version}/types', 858 - path: { 859 - id: data.id 860 - }, 861 - query: { 862 - parameterNumber: data.parameterNumber, 863 - parameterString: data.parameterString, 864 - parameterBoolean: data.parameterBoolean, 865 - parameterObject: data.parameterObject, 866 - parameterArray: data.parameterArray, 867 - parameterDictionary: data.parameterDictionary, 868 - parameterEnum: data.parameterEnum, 869 - parameterTuple: data.parameterTuple 870 - } 871 - }); 872 - } 873 - } 874 - 875 - export class Upload { 876 - /** 877 - * @param data The data for the request. 878 - * @param data.formData 879 - * @returns boolean 880 - * @throws ApiError 881 - */ 882 - public static uploadFile(data: UploadFileData): CancelablePromise<UploadFileResponse> { 883 - return __request(OpenAPI, { 884 - method: 'POST', 885 - url: '/api/v{api-version}/upload', 886 - formData: data.formData, 887 - mediaType: 'application/x-www-form-urlencoded' 888 - }); 889 - } 890 - }
-1524
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_enums_typescript_namespace/types.gen.ts.snap
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - export enum _3e_num_1Период { 4 - BIRD = 'Bird', 5 - DOG = 'Dog' 6 - } 7 - 8 - /** 9 - * Model with number-only name 10 - */ 11 - export type _400 = string; 12 - 13 - export type _default = { 14 - name?: string; 15 - }; 16 - 17 - /** 18 - * Model with restricted keyword name 19 - */ 20 - export type _import = string; 21 - 22 - export type AdditionalPropertiesIntegerIssue = { 23 - value: number; 24 - [key: string]: (number) | undefined; 25 - }; 26 - 27 - export type AdditionalPropertiesUnknownIssue = { 28 - [key: string]: (string | number); 29 - }; 30 - 31 - export type AdditionalPropertiesUnknownIssue2 = { 32 - [key: string]: (string | number); 33 - }; 34 - 35 - export type AdditionalPropertiesUnknownIssue3 = string & { 36 - entries: { 37 - [key: string]: AdditionalPropertiesUnknownIssue; 38 - }; 39 - }; 40 - 41 - export type AnyOfAnyAndNull = { 42 - data?: (unknown | null); 43 - }; 44 - 45 - /** 46 - * This is a simple array with any of properties 47 - */ 48 - export type AnyOfArrays = { 49 - results?: Array<({ 50 - foo?: string; 51 - } | { 52 - bar?: string; 53 - })>; 54 - }; 55 - 56 - /** 57 - * This is a simple array with any of properties 58 - */ 59 - export type ArrayWithAnyOfProperties = Array<({ 60 - foo?: string; 61 - } | { 62 - bar?: string; 63 - })>; 64 - 65 - /** 66 - * This is a simple array containing an array 67 - */ 68 - export type ArrayWithArray = Array<Array<ModelWithString>>; 69 - 70 - /** 71 - * This is a simple array with booleans 72 - */ 73 - export type ArrayWithBooleans = Array<(boolean)>; 74 - 75 - /** 76 - * This is a simple array with numbers 77 - */ 78 - export type ArrayWithNumbers = Array<(number)>; 79 - 80 - /** 81 - * This is a simple array with properties 82 - */ 83 - export type ArrayWithProperties = Array<{ 84 - '16x16'?: camelCaseCommentWithBreaks; 85 - bar?: string; 86 - }>; 87 - 88 - /** 89 - * This is a simple array with references 90 - */ 91 - export type ArrayWithReferences = Array<ModelWithString>; 92 - 93 - /** 94 - * This is a simple array with strings 95 - */ 96 - export type ArrayWithStrings = Array<(string)>; 97 - 98 - /** 99 - * Testing multiline comments in string: First line 100 - * Second line 101 - * 102 - * Fourth line 103 - */ 104 - export type camelCaseCommentWithBreaks = number; 105 - 106 - /** 107 - * Some % character 108 - */ 109 - export type CharactersInDescription = string; 110 - 111 - /** 112 - * Testing backticks in string: `backticks` and ```multiple backticks``` should work 113 - */ 114 - export type CommentWithBackticks = number; 115 - 116 - /** 117 - * Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work 118 - */ 119 - export type CommentWithBackticksAndQuotes = number; 120 - 121 - /** 122 - * Testing multiline comments in string: First line 123 - * Second line 124 - * 125 - * Fourth line 126 - */ 127 - export type CommentWithBreaks = number; 128 - 129 - /** 130 - * Testing expression placeholders in string: ${expression} should work 131 - */ 132 - export type CommentWithExpressionPlaceholders = number; 133 - 134 - /** 135 - * Testing quotes in string: 'single quote''' and "double quotes""" should work 136 - */ 137 - export type CommentWithQuotes = number; 138 - 139 - /** 140 - * Testing reserved characters in string: * inline * and ** inline ** should work 141 - */ 142 - export type CommentWithReservedCharacters = number; 143 - 144 - /** 145 - * Testing slashes in string: \backwards\\\ and /forwards/// should work 146 - */ 147 - export type CommentWithSlashes = number; 148 - 149 - /** 150 - * This is a base model with two simple optional properties 151 - */ 152 - export type CompositionBaseModel = { 153 - firstName?: string; 154 - lastname?: string; 155 - }; 156 - 157 - /** 158 - * This is a model that extends the base model 159 - */ 160 - export type CompositionExtendedModel = CompositionBaseModel & { 161 - firstName: string; 162 - lastname: string; 163 - age: number; 164 - }; 165 - 166 - /** 167 - * This is a model with one property with a 'all of' relationship 168 - */ 169 - export type CompositionWithAllOfAndNullable = { 170 - propA?: (({ 171 - boolean?: boolean; 172 - } & ModelWithEnum & ModelWithArray & ModelWithDictionary) | null); 173 - }; 174 - 175 - /** 176 - * This is a model with one property with a 'any of' relationship 177 - */ 178 - export type CompositionWithAnyOf = { 179 - propA?: (ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary); 180 - }; 181 - 182 - /** 183 - * This is a model with one property with a 'any of' relationship 184 - */ 185 - export type CompositionWithAnyOfAndNullable = { 186 - propA?: (({ 187 - boolean?: boolean; 188 - } | ModelWithEnum | ModelWithArray | ModelWithDictionary) | null); 189 - }; 190 - 191 - /** 192 - * This is a model with one property with a 'any of' relationship where the options are not $ref 193 - */ 194 - export type CompositionWithAnyOfAnonymous = { 195 - propA?: ({ 196 - propA?: string; 197 - } | string | number); 198 - }; 199 - 200 - /** 201 - * This is a model with nested 'any of' property with a type null 202 - */ 203 - export type CompositionWithNestedAnyAndTypeNull = { 204 - propA?: (Array<(ModelWithDictionary | null)> | Array<(ModelWithArray | null)>); 205 - }; 206 - 207 - /** 208 - * This is a model with one property with a 'any of' relationship where the options are not $ref 209 - */ 210 - export type CompositionWithNestedAnyOfAndNull = { 211 - propA?: (Array<(_3e_num_1Период | ConstValue)> | null); 212 - }; 213 - 214 - /** 215 - * This is a model with one property with a 'one of' relationship 216 - */ 217 - export type CompositionWithOneOf = { 218 - propA?: (ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary); 219 - }; 220 - 221 - /** 222 - * This is a model that contains a dictionary of complex arrays (composited) within composition 223 - */ 224 - export type CompositionWithOneOfAndComplexArrayDictionary = { 225 - propA?: (boolean | { 226 - [key: string]: Array<(number | string)>; 227 - }); 228 - }; 229 - 230 - /** 231 - * This is a model with one property with a 'one of' relationship 232 - */ 233 - export type CompositionWithOneOfAndNullable = { 234 - propA?: (({ 235 - boolean?: boolean; 236 - } | ModelWithEnum | ModelWithArray | ModelWithDictionary) | null); 237 - }; 238 - 239 - export type CompositionWithOneOfAndProperties = ({ 240 - foo: ParameterSimpleParameter; 241 - } | { 242 - bar: NonAsciiStringæøåÆØÅöôêÊ字符串; 243 - }) & { 244 - baz: (number) | null; 245 - qux: number; 246 - }; 247 - 248 - /** 249 - * This is a model that contains a dictionary of simple arrays within composition 250 - */ 251 - export type CompositionWithOneOfAndSimpleArrayDictionary = { 252 - propA?: (boolean | { 253 - [key: string]: Array<(boolean)>; 254 - }); 255 - }; 256 - 257 - /** 258 - * This is a model that contains a simple dictionary within composition 259 - */ 260 - export type CompositionWithOneOfAndSimpleDictionary = { 261 - propA?: (boolean | { 262 - [key: string]: (number); 263 - }); 264 - }; 265 - 266 - /** 267 - * This is a model with one property with a 'one of' relationship where the options are not $ref 268 - */ 269 - export type CompositionWithOneOfAnonymous = { 270 - propA?: ({ 271 - propA?: string; 272 - } | string | number); 273 - }; 274 - 275 - /** 276 - * This is a model with one property with a 'one of' relationship where the options are not $ref 277 - */ 278 - export type CompositionWithOneOfDiscriminator = ModelCircle | ModelSquare; 279 - 280 - export type ConstValue = "ConstValue"; 281 - 282 - /** 283 - * Model used to test deduplication strategy 284 - */ 285 - export type DeleteFooData = string; 286 - 287 - /** 288 - * Model used to test deduplication strategy 289 - */ 290 - export type DeleteFooData2 = string; 291 - 292 - /** 293 - * This is a deprecated model with a deprecated property 294 - * @deprecated 295 - */ 296 - export type DeprecatedModel = { 297 - /** 298 - * This is a deprecated property 299 - * @deprecated 300 - */ 301 - prop?: string; 302 - }; 303 - 304 - /** 305 - * This is a complex dictionary 306 - */ 307 - export type DictionaryWithArray = { 308 - [key: string]: Array<ModelWithString>; 309 - }; 310 - 311 - /** 312 - * This is a string dictionary 313 - */ 314 - export type DictionaryWithDictionary = { 315 - [key: string]: { 316 - [key: string]: (string); 317 - }; 318 - }; 319 - 320 - /** 321 - * This is a complex dictionary 322 - */ 323 - export type DictionaryWithProperties = { 324 - [key: string]: { 325 - foo?: string; 326 - bar?: string; 327 - }; 328 - }; 329 - 330 - export type DictionaryWithPropertiesAndAdditionalProperties = { 331 - foo?: number; 332 - bar?: boolean; 333 - [key: string]: (string | number | boolean) | undefined; 334 - }; 335 - 336 - /** 337 - * This is a string reference 338 - */ 339 - export type DictionaryWithReference = { 340 - [key: string]: ModelWithString; 341 - }; 342 - 343 - /** 344 - * This is a string dictionary 345 - */ 346 - export type DictionaryWithString = { 347 - [key: string]: (string); 348 - }; 349 - 350 - /** 351 - * Success=1,Warning=2,Error=3 352 - */ 353 - export type EnumFromDescription = number; 354 - 355 - /** 356 - * This is a simple enum with numbers 357 - */ 358 - export enum EnumWithExtensions { 359 - /** 360 - * Used when the status of something is successful 361 - */ 362 - CUSTOM_SUCCESS = 200, 363 - /** 364 - * Used when the status of something has a warning 365 - */ 366 - CUSTOM_WARNING = 400, 367 - /** 368 - * Used when the status of something has an error 369 - */ 370 - CUSTOM_ERROR = 500 371 - } 372 - 373 - /** 374 - * This is a simple enum with numbers 375 - */ 376 - export enum EnumWithNumbers { 377 - '_1' = 1, 378 - '_2' = 2, 379 - '_3' = 3, 380 - '_1.1' = 1.1, 381 - '_1.2' = 1.2, 382 - '_1.3' = 1.3, 383 - '_100' = 100, 384 - '_200' = 200, 385 - '_300' = 300, 386 - '_-100' = -100, 387 - '_-200' = -200, 388 - '_-300' = -300, 389 - '_-1.1' = -1.1, 390 - '_-1.2' = -1.2, 391 - '_-1.3' = -1.3 392 - } 393 - 394 - export enum EnumWithReplacedCharacters { 395 - _SINGLE_QUOTE_ = "'Single Quote'", 396 - _DOUBLE_QUOTES_ = '"Double Quotes"', 397 - ØÆÅÔÖ_ØÆÅÔÖ字符串 = 'øæåôöØÆÅÔÖ字符串', 398 - '_3.1' = 3.1, 399 - EMPTY_STRING = '' 400 - } 401 - 402 - /** 403 - * This is a simple enum with strings 404 - */ 405 - export enum EnumWithStrings { 406 - SUCCESS = 'Success', 407 - WARNING = 'Warning', 408 - ERROR = 'Error', 409 - _SINGLE_QUOTE_ = "'Single Quote'", 410 - _DOUBLE_QUOTES_ = '"Double Quotes"', 411 - NON_ASCII__ØÆÅÔÖ_ØÆÅÔÖ字符串 = 'Non-ascii: øæåôöØÆÅÔÖ字符串' 412 - } 413 - 414 - export enum EnumWithXEnumNames { 415 - zero = 0, 416 - one = 1, 417 - two = 2 418 - } 419 - 420 - export type File = { 421 - readonly id?: string; 422 - readonly updated_at?: string; 423 - readonly created_at?: string; 424 - mime: string; 425 - readonly file?: string; 426 - }; 427 - 428 - /** 429 - * This is a free-form object with additionalProperties: {}. 430 - */ 431 - export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = { 432 - [key: string]: unknown; 433 - }; 434 - 435 - /** 436 - * This is a free-form object with additionalProperties: true. 437 - */ 438 - export type FreeFormObjectWithAdditionalPropertiesEqTrue = { 439 - [key: string]: unknown; 440 - }; 441 - 442 - /** 443 - * This is a free-form object without additionalProperties. 444 - */ 445 - export type FreeFormObjectWithoutAdditionalProperties = { 446 - [key: string]: unknown; 447 - }; 448 - 449 - export type Generic_Schema_Duplicate_Issue_1_System_Boolean_ = { 450 - item?: boolean; 451 - error?: (string) | null; 452 - readonly hasError?: boolean; 453 - data?: { 454 - [key: string]: unknown; 455 - }; 456 - }; 457 - 458 - export type Generic_Schema_Duplicate_Issue_1_System_String_ = { 459 - item?: (string) | null; 460 - error?: (string) | null; 461 - readonly hasError?: boolean; 462 - }; 463 - 464 - /** 465 - * This schema was giving PascalCase transformations a hard time 466 - */ 467 - export type io_k8s_apimachinery_pkg_apis_meta_v1_DeleteOptions = { 468 - /** 469 - * Must be fulfilled before a deletion is carried out. If not possible, a 409 Conflict status will be returned. 470 - */ 471 - preconditions?: (io_k8s_apimachinery_pkg_apis_meta_v1_Preconditions); 472 - }; 473 - 474 - /** 475 - * This schema was giving PascalCase transformations a hard time 476 - */ 477 - export type io_k8s_apimachinery_pkg_apis_meta_v1_Preconditions = { 478 - /** 479 - * Specifies the target ResourceVersion 480 - */ 481 - resourceVersion?: string; 482 - /** 483 - * Specifies the target UID. 484 - */ 485 - uid?: string; 486 - }; 487 - 488 - /** 489 - * `Comment` or `VoiceComment`. The JSON object for adding voice comments to tickets is different. See [Adding voice comments to tickets](/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets) 490 - */ 491 - export type Model_From_Zendesk = string; 492 - 493 - /** 494 - * Circle 495 - */ 496 - export type ModelCircle = { 497 - kind: 'circle'; 498 - radius?: number; 499 - }; 500 - 501 - /** 502 - * Square 503 - */ 504 - export type ModelSquare = { 505 - kind: 'square'; 506 - sideLength?: number; 507 - }; 508 - 509 - /** 510 - * This is a model that extends another model 511 - */ 512 - export type ModelThatExtends = ModelWithString & { 513 - propExtendsA?: string; 514 - propExtendsB?: ModelWithString; 515 - }; 516 - 517 - /** 518 - * This is a model that extends another model 519 - */ 520 - export type ModelThatExtendsExtends = ModelWithString & ModelThatExtends & { 521 - propExtendsC?: string; 522 - propExtendsD?: ModelWithString; 523 - }; 524 - 525 - /** 526 - * This is a model with one property and additionalProperties: true 527 - */ 528 - export type ModelWithAdditionalPropertiesEqTrue = { 529 - /** 530 - * This is a simple string property 531 - */ 532 - prop?: string; 533 - [key: string]: unknown | string; 534 - }; 535 - 536 - export type ModelWithAnyOfConstantSizeArray = [ 537 - (number | string), 538 - (number | string), 539 - (number | string) 540 - ]; 541 - 542 - export type ModelWithAnyOfConstantSizeArrayAndIntersect = [ 543 - (number & string), 544 - (number & string) 545 - ]; 546 - 547 - export type ModelWithAnyOfConstantSizeArrayNullable = [ 548 - ((number) | null | string), 549 - ((number) | null | string), 550 - ((number) | null | string) 551 - ]; 552 - 553 - export type ModelWithAnyOfConstantSizeArrayWithNSizeAndOptions = [ 554 - (number | _import), 555 - (number | _import) 556 - ]; 557 - 558 - /** 559 - * This is a model with one property containing an array 560 - */ 561 - export type ModelWithArray = { 562 - prop?: Array<ModelWithString>; 563 - propWithFile?: Array<((Blob | File))>; 564 - propWithNumber?: Array<(number)>; 565 - }; 566 - 567 - /** 568 - * This is a model with one property containing an array 569 - */ 570 - export type ModelWithArrayReadOnlyAndWriteOnly = { 571 - prop?: Array<ModelWithReadOnlyAndWriteOnly>; 572 - propWithFile?: Array<((Blob | File))>; 573 - propWithNumber?: Array<(number)>; 574 - }; 575 - 576 - /** 577 - * Some description with `back ticks` 578 - */ 579 - export type ModelWithBackticksInDescription = { 580 - /** 581 - * The template `that` should be used for parsing and importing the contents of the CSV file. 582 - * 583 - * <br/><p>There is one placeholder currently supported:<ul> <li><b>${x}</b> - refers to the n-th column in the CSV file, e.g. ${1}, ${2}, ...)</li></ul><p>Example of a correct JSON template:</p> 584 - * <pre> 585 - * [ 586 - * { 587 - * "resourceType": "Asset", 588 - * "identifier": { 589 - * "name": "${1}", 590 - * "domain": { 591 - * "name": "${2}", 592 - * "community": { 593 - * "name": "Some Community" 594 - * } 595 - * } 596 - * }, 597 - * "attributes" : { 598 - * "00000000-0000-0000-0000-000000003115" : [ { 599 - * "value" : "${3}" 600 - * } ], 601 - * "00000000-0000-0000-0000-000000000222" : [ { 602 - * "value" : "${4}" 603 - * } ] 604 - * } 605 - * } 606 - * ] 607 - * </pre> 608 - */ 609 - template?: string; 610 - }; 611 - 612 - /** 613 - * This is a model with one boolean property 614 - */ 615 - export type ModelWithBoolean = { 616 - /** 617 - * This is a simple boolean property 618 - */ 619 - prop?: boolean; 620 - }; 621 - 622 - /** 623 - * This is a model with one property containing a circular reference 624 - */ 625 - export type ModelWithCircularReference = { 626 - prop?: ModelWithCircularReference; 627 - }; 628 - 629 - export type ModelWithConst = { 630 - String?: "String"; 631 - number?: 0; 632 - null?: null; 633 - withType?: "Some string"; 634 - }; 635 - 636 - export type ModelWithConstantSizeArray = [ 637 - number, 638 - number 639 - ]; 640 - 641 - /** 642 - * This is a model with one property containing a dictionary 643 - */ 644 - export type ModelWithDictionary = { 645 - prop?: { 646 - [key: string]: (string); 647 - }; 648 - }; 649 - 650 - /** 651 - * This is a model with duplicated imports 652 - */ 653 - export type ModelWithDuplicateImports = { 654 - propA?: ModelWithString; 655 - propB?: ModelWithString; 656 - propC?: ModelWithString; 657 - }; 658 - 659 - /** 660 - * This is a model with duplicated properties 661 - */ 662 - export type ModelWithDuplicateProperties = { 663 - prop?: ModelWithString; 664 - }; 665 - 666 - /** 667 - * This is a model with one enum 668 - */ 669 - export type ModelWithEnum = { 670 - /** 671 - * This is a simple enum with strings 672 - */ 673 - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 674 - /** 675 - * These are the HTTP error code enums 676 - */ 677 - statusCode?: '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; 678 - /** 679 - * Simple boolean enum 680 - */ 681 - bool?: boolean; 682 - }; 683 - 684 - export namespace ModelWithEnum { 685 - /** 686 - * This is a simple enum with strings 687 - */ 688 - export enum foo_bar_enum { 689 - SUCCESS = 'Success', 690 - WARNING = 'Warning', 691 - ERROR = 'Error', 692 - ØÆÅ字符串 = 'ØÆÅ字符串' 693 - } 694 - /** 695 - * These are the HTTP error code enums 696 - */ 697 - export enum statusCode { 698 - _100 = '100', 699 - _200_FOO = '200 FOO', 700 - _300_FOO_BAR = '300 FOO_BAR', 701 - _400_FOO_BAR = '400 foo-bar', 702 - _500_FOO_BAR = '500 foo.bar', 703 - _600_FOO_BAR = '600 foo&bar' 704 - } 705 - } 706 - 707 - /** 708 - * This is a model with one enum 709 - */ 710 - export type ModelWithEnumFromDescription = { 711 - /** 712 - * Success=1,Warning=2,Error=3 713 - */ 714 - test?: number; 715 - }; 716 - 717 - /** 718 - * This is a model with one enum with escaped name 719 - */ 720 - export type ModelWithEnumWithHyphen = { 721 - 'foo-bar-baz-qux'?: '3.0'; 722 - }; 723 - 724 - export namespace ModelWithEnumWithHyphen { 725 - export enum foo_bar_baz_qux { 726 - _3_0 = '3.0' 727 - } 728 - } 729 - 730 - /** 731 - * This is a model with one number property 732 - */ 733 - export type ModelWithInteger = { 734 - /** 735 - * This is a simple number property 736 - */ 737 - prop?: number; 738 - }; 739 - 740 - export type ModelWithNestedArrayEnums = { 741 - array_strings?: Array<(string)>; 742 - data?: (ModelWithNestedArrayEnumsData); 743 - }; 744 - 745 - export type ModelWithNestedArrayEnumsData = { 746 - foo?: Array<ModelWithNestedArrayEnumsDataFoo>; 747 - bar?: Array<ModelWithNestedArrayEnumsDataBar>; 748 - }; 749 - 750 - export enum ModelWithNestedArrayEnumsDataBar { 751 - BAZ = 'baz', 752 - QUX = 'qux' 753 - } 754 - 755 - export enum ModelWithNestedArrayEnumsDataFoo { 756 - FOO = 'foo', 757 - BAR = 'bar' 758 - } 759 - 760 - export type ModelWithNestedCompositionEnums = { 761 - foo?: (ModelWithNestedArrayEnumsDataFoo); 762 - }; 763 - 764 - /** 765 - * This is a model with nested enums 766 - */ 767 - export type ModelWithNestedEnums = { 768 - dictionaryWithEnum?: { 769 - [key: string]: ('Success' | 'Warning' | 'Error'); 770 - }; 771 - dictionaryWithEnumFromDescription?: { 772 - [key: string]: (number); 773 - }; 774 - arrayWithEnum?: Array<('Success' | 'Warning' | 'Error')>; 775 - arrayWithDescription?: Array<(number)>; 776 - /** 777 - * This is a simple enum with strings 778 - */ 779 - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 780 - }; 781 - 782 - export namespace ModelWithNestedEnums { 783 - /** 784 - * This is a simple enum with strings 785 - */ 786 - export enum foo_bar_enum { 787 - SUCCESS = 'Success', 788 - WARNING = 'Warning', 789 - ERROR = 'Error', 790 - ØÆÅ字符串 = 'ØÆÅ字符串' 791 - } 792 - } 793 - 794 - /** 795 - * This is a model with one nested property 796 - */ 797 - export type ModelWithNestedProperties = { 798 - readonly first: { 799 - readonly second: { 800 - readonly third: (string) | null; 801 - } | null; 802 - } | null; 803 - }; 804 - 805 - export type ModelWithNullableObject = { 806 - data?: NullableObject; 807 - }; 808 - 809 - /** 810 - * This is a model with one string property 811 - */ 812 - export type ModelWithNullableString = { 813 - /** 814 - * This is a simple string property 815 - */ 816 - nullableProp1?: (string) | null; 817 - /** 818 - * This is a simple string property 819 - */ 820 - nullableRequiredProp1: (string) | null; 821 - /** 822 - * This is a simple string property 823 - */ 824 - nullableProp2?: (string) | null; 825 - /** 826 - * This is a simple string property 827 - */ 828 - nullableRequiredProp2: (string) | null; 829 - /** 830 - * This is a simple enum with strings 831 - */ 832 - 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 833 - }; 834 - 835 - export namespace ModelWithNullableString { 836 - /** 837 - * This is a simple enum with strings 838 - */ 839 - export enum foo_bar_enum { 840 - SUCCESS = 'Success', 841 - WARNING = 'Warning', 842 - ERROR = 'Error', 843 - ØÆÅ字符串 = 'ØÆÅ字符串' 844 - } 845 - } 846 - 847 - export type ModelWithNumericEnumUnion = { 848 - /** 849 - * Период 850 - */ 851 - value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; 852 - }; 853 - 854 - export namespace ModelWithNumericEnumUnion { 855 - /** 856 - * Период 857 - */ 858 - export enum value { 859 - '_-10' = -10, 860 - '_-1' = -1, 861 - '_0' = 0, 862 - '_1' = 1, 863 - '_3' = 3, 864 - '_6' = 6, 865 - '_12' = 12 866 - } 867 - } 868 - 869 - export type ModelWithOneOfAndProperties = (ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { 870 - baz: (number) | null; 871 - qux: number; 872 - }; 873 - 874 - export type ModelWithOneOfEnum = { 875 - foo: 'Bar'; 876 - } | { 877 - foo: 'Baz'; 878 - } | { 879 - foo: 'Qux'; 880 - } | { 881 - content: string; 882 - foo: 'Quux'; 883 - } | { 884 - content: [ 885 - (string), 886 - (string) 887 - ]; 888 - foo: 'Corge'; 889 - }; 890 - 891 - export namespace ModelWithOneOfEnum { 892 - export enum foo { 893 - BAR = 'Bar' 894 - } 895 - } 896 - 897 - /** 898 - * This is a model with ordered properties 899 - */ 900 - export type ModelWithOrderedProperties = { 901 - zebra?: string; 902 - apple?: string; 903 - hawaii?: string; 904 - }; 905 - 906 - /** 907 - * This is a model that contains a some patterns 908 - */ 909 - export type ModelWithPattern = { 910 - key: string; 911 - name: string; 912 - readonly enabled?: boolean; 913 - readonly modified?: string; 914 - id?: string; 915 - text?: string; 916 - patternWithSingleQuotes?: string; 917 - patternWithNewline?: string; 918 - patternWithBacktick?: string; 919 - }; 920 - 921 - export type ModelWithPrefixItemsConstantSizeArray = [ 922 - ModelWithInteger, 923 - (number | string), 924 - string 925 - ]; 926 - 927 - /** 928 - * This is a model with one nested property 929 - */ 930 - export type ModelWithProperties = { 931 - required: string; 932 - readonly requiredAndReadOnly: string; 933 - requiredAndNullable: (string) | null; 934 - string?: string; 935 - number?: number; 936 - boolean?: boolean; 937 - reference?: ModelWithString; 938 - 'property with space'?: string; 939 - default?: string; 940 - try?: string; 941 - readonly '@namespace.string'?: string; 942 - readonly '@namespace.integer'?: number; 943 - }; 944 - 945 - export type ModelWithReadOnlyAndWriteOnly = { 946 - foo: string; 947 - readonly bar: string; 948 - baz: string; 949 - }; 950 - 951 - /** 952 - * This is a model with one property containing a reference 953 - */ 954 - export type ModelWithReference = { 955 - prop?: ModelWithProperties; 956 - }; 957 - 958 - /** 959 - * This is a model with one string property 960 - */ 961 - export type ModelWithString = { 962 - /** 963 - * This is a simple string property 964 - */ 965 - prop?: string; 966 - }; 967 - 968 - /** 969 - * This is a model with one string property 970 - */ 971 - export type ModelWithStringError = { 972 - /** 973 - * This is a simple string property 974 - */ 975 - prop?: string; 976 - }; 977 - 978 - export type NestedAnyOfArraysNullable = { 979 - nullableArray?: (Array<(string | boolean)> | null); 980 - }; 981 - 982 - /** 983 - * A string with non-ascii (unicode) characters valid in typescript identifiers (æøåÆØÅöÔèÈ字符串) 984 - */ 985 - export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; 986 - 987 - /** 988 - * An object that can be null 989 - */ 990 - export type NullableObject = { 991 - foo?: string; 992 - } | null; 993 - 994 - export type OneOfAllOfIssue = ((ConstValue | Generic_Schema_Duplicate_Issue_1_System_Boolean_) & _3e_num_1Период) | Generic_Schema_Duplicate_Issue_1_System_String_; 995 - 996 - export type Pageable = { 997 - page?: number; 998 - size?: number; 999 - sort?: Array<(string)>; 1000 - }; 1001 - 1002 - /** 1003 - * This is a reusable parameter 1004 - */ 1005 - export type ParameterSimpleParameter = string; 1006 - 1007 - /** 1008 - * Model used to test deduplication strategy (unused) 1009 - */ 1010 - export type ParameterSimpleParameterUnused = string; 1011 - 1012 - /** 1013 - * Parameter with illegal characters 1014 - */ 1015 - export type Parameterx_Foo_Bar = ModelWithString; 1016 - 1017 - /** 1018 - * Model used to test deduplication strategy 1019 - */ 1020 - export type PostServiceWithEmptyTagResponse = string; 1021 - 1022 - /** 1023 - * Model used to test deduplication strategy 1024 - */ 1025 - export type PostServiceWithEmptyTagResponse2 = string; 1026 - 1027 - export type SchemaWithFormRestrictedKeys = { 1028 - description?: string; 1029 - 'x-enum-descriptions'?: string; 1030 - 'x-enum-varnames'?: string; 1031 - 'x-enumNames'?: string; 1032 - title?: string; 1033 - object?: { 1034 - description?: string; 1035 - 'x-enum-descriptions'?: string; 1036 - 'x-enum-varnames'?: string; 1037 - 'x-enumNames'?: string; 1038 - title?: string; 1039 - }; 1040 - array?: Array<({ 1041 - description?: string; 1042 - 'x-enum-descriptions'?: string; 1043 - 'x-enum-varnames'?: string; 1044 - 'x-enumNames'?: string; 1045 - title?: string; 1046 - })>; 1047 - }; 1048 - 1049 - /** 1050 - * This is a simple boolean 1051 - */ 1052 - export type SimpleBoolean = boolean; 1053 - 1054 - /** 1055 - * This is a simple file 1056 - */ 1057 - export type SimpleFile = (Blob | File); 1058 - 1059 - /** 1060 - * This is a simple number 1061 - */ 1062 - export type SimpleInteger = number; 1063 - 1064 - /** 1065 - * This is a simple reference 1066 - */ 1067 - export type SimpleReference = ModelWithString; 1068 - 1069 - /** 1070 - * This is a simple string 1071 - */ 1072 - export type SimpleString = string; 1073 - 1074 - /** 1075 - * This is a simple string 1076 - */ 1077 - export type SimpleStringWithPattern = (string) | null; 1078 - 1079 - export type CollectionFormatData = { 1080 - /** 1081 - * This is an array parameter that is sent as csv format (comma-separated values) 1082 - */ 1083 - parameterArrayCsv: Array<(string)> | null; 1084 - /** 1085 - * This is an array parameter that is sent as multi format (multiple parameter instances) 1086 - */ 1087 - parameterArrayMulti: Array<(string)> | null; 1088 - /** 1089 - * This is an array parameter that is sent as pipes format (pipe-separated values) 1090 - */ 1091 - parameterArrayPipes: Array<(string)> | null; 1092 - /** 1093 - * This is an array parameter that is sent as ssv format (space-separated values) 1094 - */ 1095 - parameterArraySsv: Array<(string)> | null; 1096 - /** 1097 - * This is an array parameter that is sent as tsv format (tab-separated values) 1098 - */ 1099 - parameterArrayTsv: Array<(string)> | null; 1100 - }; 1101 - 1102 - export type ComplexTypesData = { 1103 - /** 1104 - * Parameter containing object 1105 - */ 1106 - parameterObject: { 1107 - first?: { 1108 - second?: { 1109 - third?: string; 1110 - }; 1111 - }; 1112 - }; 1113 - /** 1114 - * Parameter containing reference 1115 - */ 1116 - parameterReference: ModelWithString; 1117 - }; 1118 - 1119 - export type ComplexTypesResponse = (Array<ModelWithString>); 1120 - 1121 - export type ComplexParamsData = { 1122 - id: number; 1123 - requestBody?: { 1124 - readonly key: (string) | null; 1125 - name: (string) | null; 1126 - enabled?: boolean; 1127 - readonly type: 'Monkey' | 'Horse' | 'Bird'; 1128 - listOfModels?: Array<ModelWithString> | null; 1129 - listOfStrings?: Array<(string)> | null; 1130 - parameters: (ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary); 1131 - readonly user?: { 1132 - readonly id?: number; 1133 - readonly name?: (string) | null; 1134 - }; 1135 - }; 1136 - }; 1137 - 1138 - export type ComplexParamsResponse = (ModelWithString); 1139 - 1140 - export type PatchApiNoTagResponse = (unknown); 1141 - 1142 - export type ImportData = { 1143 - requestBody: (ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly); 1144 - }; 1145 - 1146 - export type ImportResponse = (Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly); 1147 - 1148 - export type FooWowResponse = (unknown); 1149 - 1150 - export type GetApiSimpleOperationData = { 1151 - /** 1152 - * foo in method 1153 - */ 1154 - fooParam: string; 1155 - }; 1156 - 1157 - export type GetApiSimpleOperationResponse = (number); 1158 - 1159 - export type CallWithDefaultParametersData = { 1160 - /** 1161 - * This is a simple boolean with default value 1162 - */ 1163 - parameterBoolean?: (boolean) | null; 1164 - /** 1165 - * This is a simple enum with default value 1166 - */ 1167 - parameterEnum?: 'Success' | 'Warning' | 'Error'; 1168 - /** 1169 - * This is a simple model with default value 1170 - */ 1171 - parameterModel?: (ModelWithString) | null; 1172 - /** 1173 - * This is a simple number with default value 1174 - */ 1175 - parameterNumber?: (number) | null; 1176 - /** 1177 - * This is a simple string with default value 1178 - */ 1179 - parameterString?: (string) | null; 1180 - }; 1181 - 1182 - export type CallWithDefaultOptionalParametersData = { 1183 - /** 1184 - * This is a simple boolean that is optional with default value 1185 - */ 1186 - parameterBoolean?: boolean; 1187 - /** 1188 - * This is a simple enum that is optional with default value 1189 - */ 1190 - parameterEnum?: 'Success' | 'Warning' | 'Error'; 1191 - /** 1192 - * This is a simple model that is optional with default value 1193 - */ 1194 - parameterModel?: ModelWithString; 1195 - /** 1196 - * This is a simple number that is optional with default value 1197 - */ 1198 - parameterNumber?: number; 1199 - /** 1200 - * This is a simple string that is optional with default value 1201 - */ 1202 - parameterString?: string; 1203 - }; 1204 - 1205 - export type CallToTestOrderOfParamsData = { 1206 - /** 1207 - * This is a optional string with default 1208 - */ 1209 - parameterOptionalStringWithDefault?: string; 1210 - /** 1211 - * This is a optional string with empty default 1212 - */ 1213 - parameterOptionalStringWithEmptyDefault?: string; 1214 - /** 1215 - * This is a optional string with no default 1216 - */ 1217 - parameterOptionalStringWithNoDefault?: string; 1218 - /** 1219 - * This is a string that can be null with default 1220 - */ 1221 - parameterStringNullableWithDefault?: (string) | null; 1222 - /** 1223 - * This is a string that can be null with no default 1224 - */ 1225 - parameterStringNullableWithNoDefault?: (string) | null; 1226 - /** 1227 - * This is a string with default 1228 - */ 1229 - parameterStringWithDefault: string; 1230 - /** 1231 - * This is a string with empty default 1232 - */ 1233 - parameterStringWithEmptyDefault: string; 1234 - /** 1235 - * This is a string with no default 1236 - */ 1237 - parameterStringWithNoDefault: string; 1238 - }; 1239 - 1240 - export type DeprecatedCallData = { 1241 - /** 1242 - * This parameter is deprecated 1243 - * @deprecated 1244 - */ 1245 - parameter: (DeprecatedModel) | null; 1246 - }; 1247 - 1248 - export type CallWithDescriptionsData = { 1249 - /** 1250 - * Testing backticks in string: `backticks` and ```multiple backticks``` should work 1251 - */ 1252 - parameterWithBackticks?: unknown; 1253 - /** 1254 - * Testing multiline comments in string: First line 1255 - * Second line 1256 - * 1257 - * Fourth line 1258 - */ 1259 - parameterWithBreaks?: unknown; 1260 - /** 1261 - * Testing expression placeholders in string: ${expression} should work 1262 - */ 1263 - parameterWithExpressionPlaceholders?: unknown; 1264 - /** 1265 - * Testing quotes in string: 'single quote''' and "double quotes""" should work 1266 - */ 1267 - parameterWithQuotes?: unknown; 1268 - /** 1269 - * Testing reserved characters in string: * inline * and ** inline ** should work 1270 - */ 1271 - parameterWithReservedCharacters?: unknown; 1272 - /** 1273 - * Testing slashes in string: \backwards\\\ and /forwards/// should work 1274 - */ 1275 - parameterWithSlashes?: unknown; 1276 - }; 1277 - 1278 - export type TestErrorCodeData = { 1279 - /** 1280 - * Status code to return 1281 - */ 1282 - status: number; 1283 - }; 1284 - 1285 - export type TestErrorCodeResponse = (unknown); 1286 - 1287 - export type FileResponseData = { 1288 - id: string; 1289 - }; 1290 - 1291 - export type FileResponseResponse = ((Blob | File)); 1292 - 1293 - export type PostApiFormDataData = { 1294 - /** 1295 - * A reusable request body 1296 - */ 1297 - formData?: ModelWithString; 1298 - /** 1299 - * This is a reusable parameter 1300 - */ 1301 - parameter?: string; 1302 - }; 1303 - 1304 - export type CallWithResultFromHeaderResponse = (string); 1305 - 1306 - export type MultipartRequestData = { 1307 - formData?: { 1308 - content?: (Blob | File); 1309 - data?: ((ModelWithString) | null); 1310 - }; 1311 - }; 1312 - 1313 - export type MultipartResponseResponse = ({ 1314 - file?: (Blob | File); 1315 - metadata?: { 1316 - foo?: string; 1317 - bar?: string; 1318 - }; 1319 - }); 1320 - 1321 - export type DummyAResponse = (_400); 1322 - 1323 - export type DummyBResponse = (void); 1324 - 1325 - export type CallWithNoContentResponseResponse = (void); 1326 - 1327 - export type CallWithResponseAndNoContentResponseResponse = (number | void); 1328 - 1329 - export type NonAsciiæøåÆøÅöôêÊ字符串Data = { 1330 - /** 1331 - * Dummy input param 1332 - */ 1333 - nonAsciiParamæøåÆøÅöôêÊ: number; 1334 - }; 1335 - 1336 - export type NonAsciiæøåÆøÅöôêÊ字符串Response = (Array<NonAsciiStringæøåÆØÅöôêÊ字符串>); 1337 - 1338 - export type PutWithFormUrlEncodedData = { 1339 - formData: ArrayWithStrings; 1340 - }; 1341 - 1342 - export type DeleteFooData3 = { 1343 - /** 1344 - * bar in method 1345 - */ 1346 - barParam: string; 1347 - /** 1348 - * foo in method 1349 - */ 1350 - fooParam: string; 1351 - /** 1352 - * Parameter with illegal characters 1353 - */ 1354 - xFooBar: ModelWithString; 1355 - }; 1356 - 1357 - export type CallWithParametersData = { 1358 - /** 1359 - * This is the parameter that goes into the query params 1360 - */ 1361 - cursor: (string) | null; 1362 - fooAllOfEnum: (ModelWithNestedArrayEnumsDataFoo); 1363 - fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; 1364 - /** 1365 - * This is the parameter that goes into the cookie 1366 - */ 1367 - parameterCookie: (string) | null; 1368 - /** 1369 - * This is the parameter that goes into the header 1370 - */ 1371 - parameterHeader: (string) | null; 1372 - /** 1373 - * This is the parameter that goes into the path 1374 - */ 1375 - parameterPath: (string) | null; 1376 - /** 1377 - * This is the parameter that goes into the body 1378 - */ 1379 - requestBody: { 1380 - [key: string]: unknown; 1381 - } | null; 1382 - }; 1383 - 1384 - export type CallWithWeirdParameterNamesData = { 1385 - /** 1386 - * This is the parameter with a reserved keyword 1387 - */ 1388 - _default?: string; 1389 - /** 1390 - * This is the parameter that goes into the cookie 1391 - */ 1392 - parameterCookie: (string) | null; 1393 - /** 1394 - * This is the parameter that goes into the request header 1395 - */ 1396 - parameterHeader: (string) | null; 1397 - /** 1398 - * This is the parameter that goes into the path 1399 - */ 1400 - parameterPath1?: string; 1401 - /** 1402 - * This is the parameter that goes into the path 1403 - */ 1404 - parameterPath2?: string; 1405 - /** 1406 - * This is the parameter that goes into the path 1407 - */ 1408 - parameterPath3?: string; 1409 - /** 1410 - * This is the parameter that goes into the request query params 1411 - */ 1412 - parameterQuery: (string) | null; 1413 - /** 1414 - * This is the parameter that goes into the body 1415 - */ 1416 - requestBody: (ModelWithString) | null; 1417 - }; 1418 - 1419 - export type GetCallWithOptionalParamData = { 1420 - /** 1421 - * This is an optional parameter 1422 - */ 1423 - page?: number; 1424 - /** 1425 - * This is a required parameter 1426 - */ 1427 - requestBody: ModelWithOneOfEnum; 1428 - }; 1429 - 1430 - export type PostCallWithOptionalParamData = { 1431 - /** 1432 - * This is a required parameter 1433 - */ 1434 - parameter: Pageable; 1435 - /** 1436 - * This is an optional parameter 1437 - */ 1438 - requestBody?: { 1439 - offset?: (number) | null; 1440 - }; 1441 - }; 1442 - 1443 - export type PostCallWithOptionalParamResponse = (number | void); 1444 - 1445 - export type PostApiRequestBodyData = { 1446 - /** 1447 - * A reusable request body 1448 - */ 1449 - foo?: ModelWithString; 1450 - /** 1451 - * This is a reusable parameter 1452 - */ 1453 - parameter?: string; 1454 - }; 1455 - 1456 - export type CallWithResponseResponse = (_import); 1457 - 1458 - export type CallWithDuplicateResponsesResponse = ((ModelWithBoolean & ModelWithInteger) | ModelWithString); 1459 - 1460 - export type CallWithResponsesResponse = ({ 1461 - readonly '@namespace.string'?: string; 1462 - readonly '@namespace.integer'?: number; 1463 - readonly value?: Array<ModelWithString>; 1464 - } | ModelThatExtends | ModelThatExtendsExtends); 1465 - 1466 - export type ApiVVersionODataControllerCountResponse = (Model_From_Zendesk); 1467 - 1468 - export type TypesData = { 1469 - /** 1470 - * This is a number parameter 1471 - */ 1472 - id?: number; 1473 - /** 1474 - * This is an array parameter 1475 - */ 1476 - parameterArray: Array<(string)> | null; 1477 - /** 1478 - * This is a boolean parameter 1479 - */ 1480 - parameterBoolean: (boolean) | null; 1481 - /** 1482 - * This is a dictionary parameter 1483 - */ 1484 - parameterDictionary: { 1485 - [key: string]: unknown; 1486 - } | null; 1487 - /** 1488 - * This is an enum parameter 1489 - */ 1490 - parameterEnum: ('Success' | 'Warning' | 'Error') | null; 1491 - /** 1492 - * This is a number parameter 1493 - */ 1494 - parameterNumber: number; 1495 - /** 1496 - * This is an object parameter 1497 - */ 1498 - parameterObject: { 1499 - [key: string]: unknown; 1500 - } | null; 1501 - /** 1502 - * This is a string parameter 1503 - */ 1504 - parameterString: (string) | null; 1505 - /** 1506 - * This is tuple parameter 1507 - */ 1508 - parameterTuple: [ 1509 - number, 1510 - number, 1511 - number, 1512 - number 1513 - ]; 1514 - }; 1515 - 1516 - export type TypesResponse = (number | string | boolean | { 1517 - [key: string]: unknown; 1518 - }); 1519 - 1520 - export type UploadFileData = { 1521 - formData: (Blob | File); 1522 - }; 1523 - 1524 - export type UploadFileResponse = (boolean);
+70 -58
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_node/types.gen.ts.snap
··· 702 702 bool?: boolean; 703 703 }; 704 704 705 - /** 706 - * This is a simple enum with strings 707 - */ 708 - export type foo_bar_enum = 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 709 - 710 - /** 711 - * This is a simple enum with strings 712 - */ 713 - export const foo_bar_enum = { 714 - SUCCESS: 'Success', 715 - WARNING: 'Warning', 716 - ERROR: 'Error', 717 - 'ØÆÅ字符串': 'ØÆÅ字符串' 718 - } as const; 719 - 720 - /** 721 - * These are the HTTP error code enums 722 - */ 723 - export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; 724 - 725 - /** 726 - * These are the HTTP error code enums 727 - */ 728 - export const statusCode = { 729 - _100: '100', 730 - _200_FOO: '200 FOO', 731 - _300_FOO_BAR: '300 FOO_BAR', 732 - _400_FOO_BAR: '400 foo-bar', 733 - _500_FOO_BAR: '500 foo.bar', 734 - _600_FOO_BAR: '600 foo&bar' 735 - } as const; 705 + export namespace ModelWithEnum { 706 + /** 707 + * This is a simple enum with strings 708 + */ 709 + export enum foo_bar_enum { 710 + SUCCESS = 'Success', 711 + WARNING = 'Warning', 712 + ERROR = 'Error', 713 + ØÆÅ字符串 = 'ØÆÅ字符串' 714 + } 715 + /** 716 + * These are the HTTP error code enums 717 + */ 718 + export enum statusCode { 719 + _100 = '100', 720 + _200_FOO = '200 FOO', 721 + _300_FOO_BAR = '300 FOO_BAR', 722 + _400_FOO_BAR = '400 foo-bar', 723 + _500_FOO_BAR = '500 foo.bar', 724 + _600_FOO_BAR = '600 foo&bar' 725 + } 726 + } 736 727 737 728 /** 738 729 * This is a model with one enum ··· 751 742 'foo-bar-baz-qux'?: '3.0'; 752 743 }; 753 744 754 - export type foo_bar_baz_qux = '3.0'; 755 - 756 - export const foo_bar_baz_qux = { 757 - _3_0: '3.0' 758 - } as const; 745 + export namespace ModelWithEnumWithHyphen { 746 + export enum foo_bar_baz_qux { 747 + _3_0 = '3.0' 748 + } 749 + } 759 750 760 751 /** 761 752 * This is a model with one number property ··· 813 804 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 814 805 }; 815 806 807 + export namespace ModelWithNestedEnums { 808 + /** 809 + * This is a simple enum with strings 810 + */ 811 + export enum foo_bar_enum { 812 + SUCCESS = 'Success', 813 + WARNING = 'Warning', 814 + ERROR = 'Error', 815 + ØÆÅ字符串 = 'ØÆÅ字符串' 816 + } 817 + } 818 + 816 819 /** 817 820 * This is a model with one nested property 818 821 */ ··· 854 857 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 855 858 }; 856 859 860 + export namespace ModelWithNullableString { 861 + /** 862 + * This is a simple enum with strings 863 + */ 864 + export enum foo_bar_enum { 865 + SUCCESS = 'Success', 866 + WARNING = 'Warning', 867 + ERROR = 'Error', 868 + ØÆÅ字符串 = 'ØÆÅ字符串' 869 + } 870 + } 871 + 857 872 export type ModelWithNumericEnumUnion = { 858 873 /** 859 874 * Период ··· 861 876 value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; 862 877 }; 863 878 864 - /** 865 - * Период 866 - */ 867 - export type value = -10 | -1 | 0 | 1 | 3 | 6 | 12; 868 - 869 - /** 870 - * Период 871 - */ 872 - export const value = { 873 - '_-10': -10, 874 - '_-1': -1, 875 - '_0': 0, 876 - '_1': 1, 877 - '_3': 3, 878 - '_6': 6, 879 - '_12': 12 880 - } as const; 879 + export namespace ModelWithNumericEnumUnion { 880 + /** 881 + * Период 882 + */ 883 + export enum value { 884 + '_-10' = -10, 885 + '_-1' = -1, 886 + '_0' = 0, 887 + '_1' = 1, 888 + '_3' = 3, 889 + '_6' = 6, 890 + '_12' = 12 891 + } 892 + } 881 893 882 894 export type ModelWithOneOfAndProperties = (ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { 883 895 baz: (number) | null; ··· 901 913 foo: 'Corge'; 902 914 }; 903 915 904 - export type foo = 'Bar'; 905 - 906 - export const foo = { 907 - BAR: 'Bar' 908 - } as const; 916 + export namespace ModelWithOneOfEnum { 917 + export enum foo { 918 + BAR = 'Bar' 919 + } 920 + } 909 921 910 922 /** 911 923 * This is a model with ordered properties
+70 -58
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_services_filter/types.gen.ts.snap
··· 702 702 bool?: boolean; 703 703 }; 704 704 705 - /** 706 - * This is a simple enum with strings 707 - */ 708 - export type foo_bar_enum = 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 709 - 710 - /** 711 - * This is a simple enum with strings 712 - */ 713 - export const foo_bar_enum = { 714 - SUCCESS: 'Success', 715 - WARNING: 'Warning', 716 - ERROR: 'Error', 717 - 'ØÆÅ字符串': 'ØÆÅ字符串' 718 - } as const; 719 - 720 - /** 721 - * These are the HTTP error code enums 722 - */ 723 - export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; 724 - 725 - /** 726 - * These are the HTTP error code enums 727 - */ 728 - export const statusCode = { 729 - _100: '100', 730 - _200_FOO: '200 FOO', 731 - _300_FOO_BAR: '300 FOO_BAR', 732 - _400_FOO_BAR: '400 foo-bar', 733 - _500_FOO_BAR: '500 foo.bar', 734 - _600_FOO_BAR: '600 foo&bar' 735 - } as const; 705 + export namespace ModelWithEnum { 706 + /** 707 + * This is a simple enum with strings 708 + */ 709 + export enum foo_bar_enum { 710 + SUCCESS = 'Success', 711 + WARNING = 'Warning', 712 + ERROR = 'Error', 713 + ØÆÅ字符串 = 'ØÆÅ字符串' 714 + } 715 + /** 716 + * These are the HTTP error code enums 717 + */ 718 + export enum statusCode { 719 + _100 = '100', 720 + _200_FOO = '200 FOO', 721 + _300_FOO_BAR = '300 FOO_BAR', 722 + _400_FOO_BAR = '400 foo-bar', 723 + _500_FOO_BAR = '500 foo.bar', 724 + _600_FOO_BAR = '600 foo&bar' 725 + } 726 + } 736 727 737 728 /** 738 729 * This is a model with one enum ··· 751 742 'foo-bar-baz-qux'?: '3.0'; 752 743 }; 753 744 754 - export type foo_bar_baz_qux = '3.0'; 755 - 756 - export const foo_bar_baz_qux = { 757 - _3_0: '3.0' 758 - } as const; 745 + export namespace ModelWithEnumWithHyphen { 746 + export enum foo_bar_baz_qux { 747 + _3_0 = '3.0' 748 + } 749 + } 759 750 760 751 /** 761 752 * This is a model with one number property ··· 813 804 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 814 805 }; 815 806 807 + export namespace ModelWithNestedEnums { 808 + /** 809 + * This is a simple enum with strings 810 + */ 811 + export enum foo_bar_enum { 812 + SUCCESS = 'Success', 813 + WARNING = 'Warning', 814 + ERROR = 'Error', 815 + ØÆÅ字符串 = 'ØÆÅ字符串' 816 + } 817 + } 818 + 816 819 /** 817 820 * This is a model with one nested property 818 821 */ ··· 854 857 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 855 858 }; 856 859 860 + export namespace ModelWithNullableString { 861 + /** 862 + * This is a simple enum with strings 863 + */ 864 + export enum foo_bar_enum { 865 + SUCCESS = 'Success', 866 + WARNING = 'Warning', 867 + ERROR = 'Error', 868 + ØÆÅ字符串 = 'ØÆÅ字符串' 869 + } 870 + } 871 + 857 872 export type ModelWithNumericEnumUnion = { 858 873 /** 859 874 * Период ··· 861 876 value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; 862 877 }; 863 878 864 - /** 865 - * Период 866 - */ 867 - export type value = -10 | -1 | 0 | 1 | 3 | 6 | 12; 868 - 869 - /** 870 - * Период 871 - */ 872 - export const value = { 873 - '_-10': -10, 874 - '_-1': -1, 875 - '_0': 0, 876 - '_1': 1, 877 - '_3': 3, 878 - '_6': 6, 879 - '_12': 12 880 - } as const; 879 + export namespace ModelWithNumericEnumUnion { 880 + /** 881 + * Период 882 + */ 883 + export enum value { 884 + '_-10' = -10, 885 + '_-1' = -1, 886 + '_0' = 0, 887 + '_1' = 1, 888 + '_3' = 3, 889 + '_6' = 6, 890 + '_12' = 12 891 + } 892 + } 881 893 882 894 export type ModelWithOneOfAndProperties = (ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { 883 895 baz: (number) | null; ··· 901 913 foo: 'Corge'; 902 914 }; 903 915 904 - export type foo = 'Bar'; 905 - 906 - export const foo = { 907 - BAR: 'Bar' 908 - } as const; 916 + export namespace ModelWithOneOfEnum { 917 + export enum foo { 918 + BAR = 'Bar' 919 + } 920 + } 909 921 910 922 /** 911 923 * This is a model with ordered properties
+70 -58
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_services_name/types.gen.ts.snap
··· 702 702 bool?: boolean; 703 703 }; 704 704 705 - /** 706 - * This is a simple enum with strings 707 - */ 708 - export type foo_bar_enum = 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 709 - 710 - /** 711 - * This is a simple enum with strings 712 - */ 713 - export const foo_bar_enum = { 714 - SUCCESS: 'Success', 715 - WARNING: 'Warning', 716 - ERROR: 'Error', 717 - 'ØÆÅ字符串': 'ØÆÅ字符串' 718 - } as const; 719 - 720 - /** 721 - * These are the HTTP error code enums 722 - */ 723 - export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; 724 - 725 - /** 726 - * These are the HTTP error code enums 727 - */ 728 - export const statusCode = { 729 - _100: '100', 730 - _200_FOO: '200 FOO', 731 - _300_FOO_BAR: '300 FOO_BAR', 732 - _400_FOO_BAR: '400 foo-bar', 733 - _500_FOO_BAR: '500 foo.bar', 734 - _600_FOO_BAR: '600 foo&bar' 735 - } as const; 705 + export namespace ModelWithEnum { 706 + /** 707 + * This is a simple enum with strings 708 + */ 709 + export enum foo_bar_enum { 710 + SUCCESS = 'Success', 711 + WARNING = 'Warning', 712 + ERROR = 'Error', 713 + ØÆÅ字符串 = 'ØÆÅ字符串' 714 + } 715 + /** 716 + * These are the HTTP error code enums 717 + */ 718 + export enum statusCode { 719 + _100 = '100', 720 + _200_FOO = '200 FOO', 721 + _300_FOO_BAR = '300 FOO_BAR', 722 + _400_FOO_BAR = '400 foo-bar', 723 + _500_FOO_BAR = '500 foo.bar', 724 + _600_FOO_BAR = '600 foo&bar' 725 + } 726 + } 736 727 737 728 /** 738 729 * This is a model with one enum ··· 751 742 'foo-bar-baz-qux'?: '3.0'; 752 743 }; 753 744 754 - export type foo_bar_baz_qux = '3.0'; 755 - 756 - export const foo_bar_baz_qux = { 757 - _3_0: '3.0' 758 - } as const; 745 + export namespace ModelWithEnumWithHyphen { 746 + export enum foo_bar_baz_qux { 747 + _3_0 = '3.0' 748 + } 749 + } 759 750 760 751 /** 761 752 * This is a model with one number property ··· 813 804 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 814 805 }; 815 806 807 + export namespace ModelWithNestedEnums { 808 + /** 809 + * This is a simple enum with strings 810 + */ 811 + export enum foo_bar_enum { 812 + SUCCESS = 'Success', 813 + WARNING = 'Warning', 814 + ERROR = 'Error', 815 + ØÆÅ字符串 = 'ØÆÅ字符串' 816 + } 817 + } 818 + 816 819 /** 817 820 * This is a model with one nested property 818 821 */ ··· 854 857 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 855 858 }; 856 859 860 + export namespace ModelWithNullableString { 861 + /** 862 + * This is a simple enum with strings 863 + */ 864 + export enum foo_bar_enum { 865 + SUCCESS = 'Success', 866 + WARNING = 'Warning', 867 + ERROR = 'Error', 868 + ØÆÅ字符串 = 'ØÆÅ字符串' 869 + } 870 + } 871 + 857 872 export type ModelWithNumericEnumUnion = { 858 873 /** 859 874 * Период ··· 861 876 value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; 862 877 }; 863 878 864 - /** 865 - * Период 866 - */ 867 - export type value = -10 | -1 | 0 | 1 | 3 | 6 | 12; 868 - 869 - /** 870 - * Период 871 - */ 872 - export const value = { 873 - '_-10': -10, 874 - '_-1': -1, 875 - '_0': 0, 876 - '_1': 1, 877 - '_3': 3, 878 - '_6': 6, 879 - '_12': 12 880 - } as const; 879 + export namespace ModelWithNumericEnumUnion { 880 + /** 881 + * Период 882 + */ 883 + export enum value { 884 + '_-10' = -10, 885 + '_-1' = -1, 886 + '_0' = 0, 887 + '_1' = 1, 888 + '_3' = 3, 889 + '_6' = 6, 890 + '_12' = 12 891 + } 892 + } 881 893 882 894 export type ModelWithOneOfAndProperties = (ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { 883 895 baz: (number) | null; ··· 901 913 foo: 'Corge'; 902 914 }; 903 915 904 - export type foo = 'Bar'; 905 - 906 - export const foo = { 907 - BAR: 'Bar' 908 - } as const; 916 + export namespace ModelWithOneOfEnum { 917 + export enum foo { 918 + BAR = 'Bar' 919 + } 920 + } 909 921 910 922 /** 911 923 * This is a model with ordered properties
+70 -58
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_tree_shakeable/types.gen.ts.snap
··· 702 702 bool?: boolean; 703 703 }; 704 704 705 - /** 706 - * This is a simple enum with strings 707 - */ 708 - export type foo_bar_enum = 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 709 - 710 - /** 711 - * This is a simple enum with strings 712 - */ 713 - export const foo_bar_enum = { 714 - SUCCESS: 'Success', 715 - WARNING: 'Warning', 716 - ERROR: 'Error', 717 - 'ØÆÅ字符串': 'ØÆÅ字符串' 718 - } as const; 719 - 720 - /** 721 - * These are the HTTP error code enums 722 - */ 723 - export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; 724 - 725 - /** 726 - * These are the HTTP error code enums 727 - */ 728 - export const statusCode = { 729 - _100: '100', 730 - _200_FOO: '200 FOO', 731 - _300_FOO_BAR: '300 FOO_BAR', 732 - _400_FOO_BAR: '400 foo-bar', 733 - _500_FOO_BAR: '500 foo.bar', 734 - _600_FOO_BAR: '600 foo&bar' 735 - } as const; 705 + export namespace ModelWithEnum { 706 + /** 707 + * This is a simple enum with strings 708 + */ 709 + export enum foo_bar_enum { 710 + SUCCESS = 'Success', 711 + WARNING = 'Warning', 712 + ERROR = 'Error', 713 + ØÆÅ字符串 = 'ØÆÅ字符串' 714 + } 715 + /** 716 + * These are the HTTP error code enums 717 + */ 718 + export enum statusCode { 719 + _100 = '100', 720 + _200_FOO = '200 FOO', 721 + _300_FOO_BAR = '300 FOO_BAR', 722 + _400_FOO_BAR = '400 foo-bar', 723 + _500_FOO_BAR = '500 foo.bar', 724 + _600_FOO_BAR = '600 foo&bar' 725 + } 726 + } 736 727 737 728 /** 738 729 * This is a model with one enum ··· 751 742 'foo-bar-baz-qux'?: '3.0'; 752 743 }; 753 744 754 - export type foo_bar_baz_qux = '3.0'; 755 - 756 - export const foo_bar_baz_qux = { 757 - _3_0: '3.0' 758 - } as const; 745 + export namespace ModelWithEnumWithHyphen { 746 + export enum foo_bar_baz_qux { 747 + _3_0 = '3.0' 748 + } 749 + } 759 750 760 751 /** 761 752 * This is a model with one number property ··· 813 804 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 814 805 }; 815 806 807 + export namespace ModelWithNestedEnums { 808 + /** 809 + * This is a simple enum with strings 810 + */ 811 + export enum foo_bar_enum { 812 + SUCCESS = 'Success', 813 + WARNING = 'Warning', 814 + ERROR = 'Error', 815 + ØÆÅ字符串 = 'ØÆÅ字符串' 816 + } 817 + } 818 + 816 819 /** 817 820 * This is a model with one nested property 818 821 */ ··· 854 857 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 855 858 }; 856 859 860 + export namespace ModelWithNullableString { 861 + /** 862 + * This is a simple enum with strings 863 + */ 864 + export enum foo_bar_enum { 865 + SUCCESS = 'Success', 866 + WARNING = 'Warning', 867 + ERROR = 'Error', 868 + ØÆÅ字符串 = 'ØÆÅ字符串' 869 + } 870 + } 871 + 857 872 export type ModelWithNumericEnumUnion = { 858 873 /** 859 874 * Период ··· 861 876 value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; 862 877 }; 863 878 864 - /** 865 - * Период 866 - */ 867 - export type value = -10 | -1 | 0 | 1 | 3 | 6 | 12; 868 - 869 - /** 870 - * Период 871 - */ 872 - export const value = { 873 - '_-10': -10, 874 - '_-1': -1, 875 - '_0': 0, 876 - '_1': 1, 877 - '_3': 3, 878 - '_6': 6, 879 - '_12': 12 880 - } as const; 879 + export namespace ModelWithNumericEnumUnion { 880 + /** 881 + * Период 882 + */ 883 + export enum value { 884 + '_-10' = -10, 885 + '_-1' = -1, 886 + '_0' = 0, 887 + '_1' = 1, 888 + '_3' = 3, 889 + '_6' = 6, 890 + '_12' = 12 891 + } 892 + } 881 893 882 894 export type ModelWithOneOfAndProperties = (ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { 883 895 baz: (number) | null; ··· 901 913 foo: 'Corge'; 902 914 }; 903 915 904 - export type foo = 'Bar'; 905 - 906 - export const foo = { 907 - BAR: 'Bar' 908 - } as const; 916 + export namespace ModelWithOneOfEnum { 917 + export enum foo { 918 + BAR = 'Bar' 919 + } 920 + } 909 921 910 922 /** 911 923 * This is a model with ordered properties
+70 -58
packages/openapi-ts-tests/test/__snapshots__/test/generated/v3_xhr/types.gen.ts.snap
··· 702 702 bool?: boolean; 703 703 }; 704 704 705 - /** 706 - * This is a simple enum with strings 707 - */ 708 - export type foo_bar_enum = 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 709 - 710 - /** 711 - * This is a simple enum with strings 712 - */ 713 - export const foo_bar_enum = { 714 - SUCCESS: 'Success', 715 - WARNING: 'Warning', 716 - ERROR: 'Error', 717 - 'ØÆÅ字符串': 'ØÆÅ字符串' 718 - } as const; 719 - 720 - /** 721 - * These are the HTTP error code enums 722 - */ 723 - export type statusCode = '100' | '200 FOO' | '300 FOO_BAR' | '400 foo-bar' | '500 foo.bar' | '600 foo&bar'; 724 - 725 - /** 726 - * These are the HTTP error code enums 727 - */ 728 - export const statusCode = { 729 - _100: '100', 730 - _200_FOO: '200 FOO', 731 - _300_FOO_BAR: '300 FOO_BAR', 732 - _400_FOO_BAR: '400 foo-bar', 733 - _500_FOO_BAR: '500 foo.bar', 734 - _600_FOO_BAR: '600 foo&bar' 735 - } as const; 705 + export namespace ModelWithEnum { 706 + /** 707 + * This is a simple enum with strings 708 + */ 709 + export enum foo_bar_enum { 710 + SUCCESS = 'Success', 711 + WARNING = 'Warning', 712 + ERROR = 'Error', 713 + ØÆÅ字符串 = 'ØÆÅ字符串' 714 + } 715 + /** 716 + * These are the HTTP error code enums 717 + */ 718 + export enum statusCode { 719 + _100 = '100', 720 + _200_FOO = '200 FOO', 721 + _300_FOO_BAR = '300 FOO_BAR', 722 + _400_FOO_BAR = '400 foo-bar', 723 + _500_FOO_BAR = '500 foo.bar', 724 + _600_FOO_BAR = '600 foo&bar' 725 + } 726 + } 736 727 737 728 /** 738 729 * This is a model with one enum ··· 751 742 'foo-bar-baz-qux'?: '3.0'; 752 743 }; 753 744 754 - export type foo_bar_baz_qux = '3.0'; 755 - 756 - export const foo_bar_baz_qux = { 757 - _3_0: '3.0' 758 - } as const; 745 + export namespace ModelWithEnumWithHyphen { 746 + export enum foo_bar_baz_qux { 747 + _3_0 = '3.0' 748 + } 749 + } 759 750 760 751 /** 761 752 * This is a model with one number property ··· 813 804 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 814 805 }; 815 806 807 + export namespace ModelWithNestedEnums { 808 + /** 809 + * This is a simple enum with strings 810 + */ 811 + export enum foo_bar_enum { 812 + SUCCESS = 'Success', 813 + WARNING = 'Warning', 814 + ERROR = 'Error', 815 + ØÆÅ字符串 = 'ØÆÅ字符串' 816 + } 817 + } 818 + 816 819 /** 817 820 * This is a model with one nested property 818 821 */ ··· 854 857 'foo_bar-enum'?: 'Success' | 'Warning' | 'Error' | 'ØÆÅ字符串'; 855 858 }; 856 859 860 + export namespace ModelWithNullableString { 861 + /** 862 + * This is a simple enum with strings 863 + */ 864 + export enum foo_bar_enum { 865 + SUCCESS = 'Success', 866 + WARNING = 'Warning', 867 + ERROR = 'Error', 868 + ØÆÅ字符串 = 'ØÆÅ字符串' 869 + } 870 + } 871 + 857 872 export type ModelWithNumericEnumUnion = { 858 873 /** 859 874 * Период ··· 861 876 value?: -10 | -1 | 0 | 1 | 3 | 6 | 12; 862 877 }; 863 878 864 - /** 865 - * Период 866 - */ 867 - export type value = -10 | -1 | 0 | 1 | 3 | 6 | 12; 868 - 869 - /** 870 - * Период 871 - */ 872 - export const value = { 873 - '_-10': -10, 874 - '_-1': -1, 875 - '_0': 0, 876 - '_1': 1, 877 - '_3': 3, 878 - '_6': 6, 879 - '_12': 12 880 - } as const; 879 + export namespace ModelWithNumericEnumUnion { 880 + /** 881 + * Период 882 + */ 883 + export enum value { 884 + '_-10' = -10, 885 + '_-1' = -1, 886 + '_0' = 0, 887 + '_1' = 1, 888 + '_3' = 3, 889 + '_6' = 6, 890 + '_12' = 12 891 + } 892 + } 881 893 882 894 export type ModelWithOneOfAndProperties = (ParameterSimpleParameter | NonAsciiStringæøåÆØÅöôêÊ字符串) & { 883 895 baz: (number) | null; ··· 901 913 foo: 'Corge'; 902 914 }; 903 915 904 - export type foo = 'Bar'; 905 - 906 - export const foo = { 907 - BAR: 'Bar' 908 - } as const; 916 + export namespace ModelWithOneOfEnum { 917 + export enum foo { 918 + BAR = 'Bar' 919 + } 920 + } 909 921 910 922 /** 911 923 * This is a model with ordered properties
-17
packages/openapi-ts-tests/test/index.test.ts
··· 297 297 }, 298 298 { 299 299 config: createConfig({ 300 - plugins: [ 301 - 'legacy/fetch', 302 - { 303 - enums: 'typescript+namespace', 304 - name: '@hey-api/typescript', 305 - }, 306 - { 307 - asClass: true, 308 - name: '@hey-api/sdk', 309 - }, 310 - ], 311 - }), 312 - description: 'generate TypeScript enums with namespace', 313 - name: 'v3_enums_typescript_namespace', 314 - }, 315 - { 316 - config: createConfig({ 317 300 exportCore: false, 318 301 parser: { 319 302 transforms: {
+35 -16
packages/openapi-ts-tests/test/openapi-ts.config.ts
··· 37 37 // 'invalid', 38 38 // 'servers-entry.yaml', 39 39 // ), 40 - path: path.resolve(__dirname, 'spec', '3.1.x', 'validators.yaml'), 40 + path: path.resolve( 41 + __dirname, 42 + 'spec', 43 + '3.1.x', 44 + // 'case.yaml', 45 + // 'enum-inline.yaml', 46 + 'full.yaml', 47 + // 'transformers-all-of.yaml', 48 + // 'validators-circular-ref-2.yaml', 49 + ), 41 50 // path: path.resolve(__dirname, 'spec', 'v3-transforms.json'), 42 51 // path: path.resolve(__dirname, 'spec', 'v3.json'), 43 52 // path: 'http://localhost:4000/', ··· 103 112 }, 104 113 transforms: { 105 114 enums: { 106 - enabled: false, 107 - mode: 'inline', 115 + // enabled: false, 116 + mode: 'root', 108 117 // name: '{{name}}', 109 118 }, 110 119 readWrite: { ··· 130 139 }, 131 140 { 132 141 // case: 'snake_case', 142 + // definitions: '你_snake_{{name}}', 133 143 enums: { 134 144 // case: 'PascalCase', 135 145 // constantsIgnoreNull: true, 136 - enabled: false, 137 - type: 'typescript+namespace', 146 + // enabled: false, 147 + // mode: 'typescript', 138 148 }, 149 + // errors: { 150 + // error: '他們_error_{{name}}', 151 + // name: '你們_errors_{{name}}', 152 + // }, 139 153 name: '@hey-api/typescript', 154 + // requests: '我們_data_{{name}}', 155 + // responses: { 156 + // name: '我_responses_{{name}}', 157 + // response: '他_response_{{name}}', 158 + // }, 140 159 // tree: true, 141 160 }, 142 161 { ··· 151 170 // operationId: false, 152 171 // responseStyle: 'data', 153 172 // throwOnError: true, 154 - // transformer: '@hey-api/transformers', 173 + transformer: '@hey-api/transformers', 155 174 // transformer: true, 156 - validator: { 157 - request: 'zod', 158 - response: 'valibot', 159 - }, 175 + // validator: { 176 + // request: 'zod', 177 + // response: 'valibot', 178 + // }, 160 179 }, 161 180 { 162 181 // bigInt: true, 163 182 // dates: true, 164 - // name: '@hey-api/transformers', 183 + name: '@hey-api/transformers', 165 184 }, 166 185 { 167 - // name: 'fastify', 186 + name: 'fastify', 168 187 }, 169 188 { 170 189 // case: 'SCREAMING_SNAKE_CASE', ··· 179 198 // mutationOptions: { 180 199 // name: '{{name}}MO', 181 200 // }, 182 - // name: '@tanstack/react-query', 201 + name: '@tanstack/react-query', 183 202 // queryKeys: { 184 203 // name: '{{name}}QK', 185 204 // }, ··· 193 212 definitions: 'z{{name}}Definition', 194 213 // exportFromIndex: true, 195 214 metadata: true, 196 - name: 'valibot', 215 + // name: 'valibot', 197 216 requests: { 198 217 // case: 'SCREAMING_SNAKE_CASE', 199 218 name: 'z{{name}}TestData', ··· 212 231 definitions: 'z{{name}}Definition', 213 232 // exportFromIndex: true, 214 233 // metadata: true, 215 - name: 'zod', 234 + // name: 'zod', 216 235 requests: { 217 236 // case: 'SCREAMING_SNAKE_CASE', 218 237 // name: 'z{{name}}TestData', ··· 224 243 }, 225 244 { 226 245 exportFromIndex: true, 227 - name: '@hey-api/schemas', 246 + // name: '@hey-api/schemas', 228 247 // type: 'json', 229 248 }, 230 249 ],
-144
packages/openapi-ts-tests/test/spec/3.0.x/case.json
··· 1 - { 2 - "openapi": "3.0.2", 3 - "info": { 4 - "title": "OpenAPI 3.0.2 case example", 5 - "version": "1" 6 - }, 7 - "paths": { 8 - "/foo": { 9 - "get": { 10 - "parameters": [ 11 - { 12 - "description": "original name: fooBar", 13 - "in": "query", 14 - "name": "fooBar", 15 - "required": true, 16 - "schema": { 17 - "type": "string" 18 - } 19 - }, 20 - { 21 - "description": "original name: BarBaz", 22 - "in": "query", 23 - "name": "BarBaz", 24 - "required": true, 25 - "schema": { 26 - "type": "string" 27 - } 28 - }, 29 - { 30 - "description": "original name: qux_quux", 31 - "in": "query", 32 - "name": "qux_quux", 33 - "required": true, 34 - "schema": { 35 - "type": "string" 36 - } 37 - } 38 - ], 39 - "requestBody": { 40 - "required": true, 41 - "content": { 42 - "application/json": { 43 - "schema": { 44 - "$ref": "#/components/schemas/Foo" 45 - } 46 - } 47 - } 48 - }, 49 - "responses": { 50 - "200": { 51 - "description": "OK", 52 - "content": { 53 - "application/json": { 54 - "schema": { 55 - "$ref": "#/components/schemas/Foo" 56 - } 57 - } 58 - } 59 - }, 60 - "201": { 61 - "description": "OK", 62 - "content": { 63 - "application/json": { 64 - "schema": { 65 - "$ref": "#/components/schemas/201" 66 - } 67 - } 68 - } 69 - } 70 - } 71 - } 72 - } 73 - }, 74 - "components": { 75 - "schemas": { 76 - "Foo": { 77 - "description": "original name: Foo", 78 - "properties": { 79 - "fooBar": { 80 - "description": "original name: fooBar", 81 - "allOf": [ 82 - { 83 - "$ref": "#/components/schemas/foo_bar" 84 - } 85 - ] 86 - }, 87 - "BarBaz": { 88 - "description": "original name: BarBaz", 89 - "allOf": [ 90 - { 91 - "$ref": "#/components/schemas/Foo" 92 - } 93 - ] 94 - }, 95 - "qux_quux": { 96 - "description": "original name: qux_quux", 97 - "properties": { 98 - "fooBar": { 99 - "description": "original name: fooBar", 100 - "allOf": [ 101 - { 102 - "$ref": "#/components/schemas/fooBar" 103 - } 104 - ] 105 - }, 106 - "BarBaz": { 107 - "description": "original name: BarBaz", 108 - "allOf": [ 109 - { 110 - "$ref": "#/components/schemas/FooBar" 111 - } 112 - ] 113 - }, 114 - "qux_quux": { 115 - "description": "original name: qux_quux", 116 - "type": "boolean" 117 - } 118 - }, 119 - "required": ["fooBar", "BarBaz", "qux_quux"], 120 - "type": "object" 121 - } 122 - }, 123 - "required": ["fooBar", "BarBaz", "qux_quux"], 124 - "type": "object" 125 - }, 126 - "201": { 127 - "description": "original name: 201", 128 - "type": "number" 129 - }, 130 - "foo_bar": { 131 - "description": "original name: foo_bar", 132 - "type": "boolean" 133 - }, 134 - "fooBar": { 135 - "description": "original name: fooBar", 136 - "type": "number" 137 - }, 138 - "FooBar": { 139 - "description": "original name: FooBar", 140 - "type": "string" 141 - } 142 - } 143 - } 144 - }
+94
packages/openapi-ts-tests/test/spec/3.0.x/case.yaml
··· 1 + openapi: 3.0.2 2 + info: 3 + title: OpenAPI 3.0.2 case example 4 + version: '1' 5 + paths: 6 + /foo: 7 + get: 8 + parameters: 9 + - description: 'original name: fooBar' 10 + in: query 11 + name: fooBar 12 + required: true 13 + schema: 14 + type: string 15 + - description: 'original name: BarBaz' 16 + in: query 17 + name: BarBaz 18 + required: true 19 + schema: 20 + type: string 21 + - description: 'original name: qux_quux' 22 + in: query 23 + name: qux_quux 24 + required: true 25 + schema: 26 + type: string 27 + requestBody: 28 + required: true 29 + content: 30 + application/json: 31 + schema: 32 + $ref: '#/components/schemas/Foo' 33 + responses: 34 + '200': 35 + description: OK 36 + content: 37 + application/json: 38 + schema: 39 + $ref: '#/components/schemas/Foo' 40 + '201': 41 + description: OK 42 + content: 43 + application/json: 44 + schema: 45 + $ref: '#/components/schemas/201' 46 + components: 47 + schemas: 48 + '201': 49 + description: 'original name: 201' 50 + type: number 51 + Foo: 52 + description: 'original name: Foo' 53 + properties: 54 + fooBar: 55 + description: 'original name: fooBar' 56 + allOf: 57 + - $ref: '#/components/schemas/foo_bar' 58 + BarBaz: 59 + description: 'original name: BarBaz' 60 + allOf: 61 + - $ref: '#/components/schemas/Foo' 62 + qux_quux: 63 + description: 'original name: qux_quux' 64 + properties: 65 + fooBar: 66 + description: 'original name: fooBar' 67 + allOf: 68 + - $ref: '#/components/schemas/fooBar' 69 + BarBaz: 70 + description: 'original name: BarBaz' 71 + allOf: 72 + - $ref: '#/components/schemas/FooBar' 73 + qux_quux: 74 + description: 'original name: qux_quux' 75 + type: boolean 76 + required: 77 + - fooBar 78 + - BarBaz 79 + - qux_quux 80 + type: object 81 + required: 82 + - fooBar 83 + - BarBaz 84 + - qux_quux 85 + type: object 86 + foo_bar: 87 + description: 'original name: foo_bar' 88 + type: boolean 89 + fooBar: 90 + description: 'original name: fooBar' 91 + type: number 92 + FooBar: 93 + description: 'original name: FooBar' 94 + type: string
-128
packages/openapi-ts-tests/test/spec/3.1.x/case.json
··· 1 - { 2 - "openapi": "3.1.0", 3 - "info": { 4 - "title": "OpenAPI 3.1.0 case example", 5 - "version": "1" 6 - }, 7 - "paths": { 8 - "/foo": { 9 - "get": { 10 - "parameters": [ 11 - { 12 - "description": "original name: fooBar", 13 - "in": "query", 14 - "name": "fooBar", 15 - "required": true, 16 - "schema": { 17 - "type": "string" 18 - } 19 - }, 20 - { 21 - "description": "original name: BarBaz", 22 - "in": "query", 23 - "name": "BarBaz", 24 - "required": true, 25 - "schema": { 26 - "type": "string" 27 - } 28 - }, 29 - { 30 - "description": "original name: qux_quux", 31 - "in": "query", 32 - "name": "qux_quux", 33 - "required": true, 34 - "schema": { 35 - "type": "string" 36 - } 37 - } 38 - ], 39 - "requestBody": { 40 - "required": true, 41 - "content": { 42 - "application/json": { 43 - "schema": { 44 - "$ref": "#/components/schemas/Foo" 45 - } 46 - } 47 - } 48 - }, 49 - "responses": { 50 - "200": { 51 - "description": "OK", 52 - "content": { 53 - "application/json": { 54 - "schema": { 55 - "$ref": "#/components/schemas/Foo" 56 - } 57 - } 58 - } 59 - }, 60 - "201": { 61 - "description": "OK", 62 - "content": { 63 - "application/json": { 64 - "schema": { 65 - "$ref": "#/components/schemas/201" 66 - } 67 - } 68 - } 69 - } 70 - } 71 - } 72 - } 73 - }, 74 - "components": { 75 - "schemas": { 76 - "Foo": { 77 - "description": "original name: Foo", 78 - "properties": { 79 - "fooBar": { 80 - "description": "original name: fooBar", 81 - "$ref": "#/components/schemas/foo_bar" 82 - }, 83 - "BarBaz": { 84 - "description": "original name: BarBaz", 85 - "$ref": "#/components/schemas/Foo" 86 - }, 87 - "qux_quux": { 88 - "description": "original name: qux_quux", 89 - "properties": { 90 - "fooBar": { 91 - "description": "original name: fooBar", 92 - "$ref": "#/components/schemas/fooBar" 93 - }, 94 - "BarBaz": { 95 - "description": "original name: BarBaz", 96 - "$ref": "#/components/schemas/FooBar" 97 - }, 98 - "qux_quux": { 99 - "description": "original name: qux_quux", 100 - "type": "boolean" 101 - } 102 - }, 103 - "required": ["fooBar", "BarBaz", "qux_quux"], 104 - "type": "object" 105 - } 106 - }, 107 - "required": ["fooBar", "BarBaz", "qux_quux"], 108 - "type": "object" 109 - }, 110 - "201": { 111 - "description": "original name: 201", 112 - "type": "number" 113 - }, 114 - "foo_bar": { 115 - "description": "original name: foo_bar", 116 - "type": "boolean" 117 - }, 118 - "fooBar": { 119 - "description": "original name: fooBar", 120 - "type": "number" 121 - }, 122 - "FooBar": { 123 - "description": "original name: FooBar", 124 - "type": "string" 125 - } 126 - } 127 - } 128 - }
+90
packages/openapi-ts-tests/test/spec/3.1.x/case.yaml
··· 1 + openapi: 3.1.0 2 + info: 3 + title: OpenAPI 3.1.0 case example 4 + version: '1' 5 + paths: 6 + /foo: 7 + get: 8 + parameters: 9 + - description: 'original name: fooBar' 10 + in: query 11 + name: fooBar 12 + required: true 13 + schema: 14 + type: string 15 + - description: 'original name: BarBaz' 16 + in: query 17 + name: BarBaz 18 + required: true 19 + schema: 20 + type: string 21 + - description: 'original name: qux_quux' 22 + in: query 23 + name: qux_quux 24 + required: true 25 + schema: 26 + type: string 27 + requestBody: 28 + required: true 29 + content: 30 + application/json: 31 + schema: 32 + $ref: '#/components/schemas/Foo' 33 + responses: 34 + '200': 35 + description: OK 36 + content: 37 + application/json: 38 + schema: 39 + $ref: '#/components/schemas/Foo' 40 + '201': 41 + description: OK 42 + content: 43 + application/json: 44 + schema: 45 + $ref: '#/components/schemas/201' 46 + components: 47 + schemas: 48 + '201': 49 + description: 'original name: 201' 50 + type: number 51 + Foo: 52 + description: 'original name: Foo' 53 + properties: 54 + fooBar: 55 + description: 'original name: fooBar' 56 + $ref: '#/components/schemas/foo_bar' 57 + BarBaz: 58 + description: 'original name: BarBaz' 59 + $ref: '#/components/schemas/Foo' 60 + qux_quux: 61 + description: 'original name: qux_quux' 62 + properties: 63 + fooBar: 64 + description: 'original name: fooBar' 65 + $ref: '#/components/schemas/fooBar' 66 + BarBaz: 67 + description: 'original name: BarBaz' 68 + $ref: '#/components/schemas/FooBar' 69 + qux_quux: 70 + description: 'original name: qux_quux' 71 + type: boolean 72 + required: 73 + - fooBar 74 + - BarBaz 75 + - qux_quux 76 + type: object 77 + required: 78 + - fooBar 79 + - BarBaz 80 + - qux_quux 81 + type: object 82 + foo_bar: 83 + description: 'original name: foo_bar' 84 + type: boolean 85 + fooBar: 86 + description: 'original name: fooBar' 87 + type: number 88 + FooBar: 89 + description: 'original name: FooBar' 90 + type: string
+6 -2
packages/openapi-ts/src/compiler/module.ts
··· 123 123 destructure?: boolean; 124 124 exportConst?: boolean; 125 125 expression: ts.Expression; 126 - name: string; 126 + name: string | ts.TypeReferenceNode; 127 127 // TODO: support a more intuitive definition of generics for example 128 128 typeName?: string | ts.IndexedAccessTypeNode | ts.TypeNode; 129 129 }): ts.VariableStatement => { ··· 136 136 : assertion, 137 137 }) 138 138 : expression; 139 - const nameIdentifier = createIdentifier({ text: name }); 139 + const nameIdentifier = 140 + typeof name === 'string' 141 + ? createIdentifier({ text: name }) 142 + : // TODO: https://github.com/hey-api/openapi-ts/issues/2289 143 + (name as unknown as ts.Identifier); 140 144 const declaration = ts.factory.createVariableDeclaration( 141 145 destructure 142 146 ? ts.factory.createObjectBindingPattern([
+8 -4
packages/openapi-ts/src/compiler/typedef.ts
··· 69 69 * } 70 70 * ``` 71 71 */ 72 - indexKey?: string; 72 + indexKey?: ts.TypeReferenceNode; 73 73 /** 74 74 * Adds an index signature if defined. 75 75 * ··· 132 132 type: 133 133 indexProperty.type ?? createKeywordTypeNode({ keyword: 'string' }), 134 134 typeParameter: createTypeParameterDeclaration({ 135 - constraint: createTypeReferenceNode({ typeName: indexKey }), 135 + constraint: indexKey, 136 136 name: createIdentifier({ text: String(indexProperty.name) }), 137 137 }), 138 138 }); ··· 179 179 types, 180 180 }: { 181 181 isNullable?: boolean; 182 - types: (any | ts.TypeNode)[]; 182 + types: ReadonlyArray<any | ts.TypeNode>; 183 183 }) => { 184 184 const nodes = types.map((type) => createTypeNode(type)); 185 185 const node = ts.factory.createUnionTypeNode(nodes); ··· 263 263 * @returns ts.TypeReferenceNode | ts.UnionTypeNode 264 264 */ 265 265 export const createTypeArrayNode = ( 266 - types: (any | ts.TypeNode)[] | ts.TypeNode | string, 266 + types: 267 + | ReadonlyArray<any | ts.TypeNode> 268 + | ts.TypeNode 269 + | ts.Identifier 270 + | string, 267 271 isNullable: boolean = false, 268 272 ) => { 269 273 const node = createTypeReferenceNode({
+22 -8
packages/openapi-ts/src/compiler/types.ts
··· 48 48 49 49 return createTypeReferenceNode({ 50 50 typeArguments: args?.map((arg) => createTypeNode(arg)), 51 - typeName: base, 51 + typeName: ts.isIdentifier(base) ? base.text : base, 52 52 }); 53 53 }; 54 54 ··· 762 762 }: { 763 763 comments?: Record<string | number, Comments>; 764 764 leadingComment?: Comments; 765 - name: string; 765 + name: string | ts.TypeReferenceNode; 766 766 obj: T; 767 767 }): ts.EnumDeclaration => { 768 768 const members: Array<ts.EnumMember> = Array.isArray(obj) ··· 801 801 802 802 const node = ts.factory.createEnumDeclaration( 803 803 [createModifier({ keyword: 'export' })], 804 - createIdentifier({ text: name }), 804 + typeof name === 'string' 805 + ? createIdentifier({ text: name }) 806 + : // TODO: https://github.com/hey-api/openapi-ts/issues/2289 807 + (name as unknown as ts.Identifier), 805 808 members, 806 809 ); 807 810 ··· 898 901 return expression; 899 902 }; 900 903 901 - export const createTypeOfExpression = ({ text }: { text: string }) => { 904 + export const createTypeOfExpression = ({ 905 + text, 906 + }: { 907 + text: string | ts.TypeReferenceNode; 908 + }) => { 902 909 const expression = ts.factory.createTypeOfExpression( 903 - createIdentifier({ text }), 910 + // TODO: this crashes when passing reference, fix 911 + // TODO: https://github.com/hey-api/openapi-ts/issues/2289 912 + typeof text === 'string' 913 + ? createIdentifier({ text }) 914 + : (text as unknown as ts.Identifier), 904 915 ); 905 916 return expression; 906 917 }; ··· 921 932 }: { 922 933 comment?: Comments; 923 934 exportType?: boolean; 924 - name: string; 925 - type: string | ts.TypeNode; 935 + name: string | ts.TypeReferenceNode; 936 + type: string | ts.TypeNode | ts.Identifier; 926 937 typeParameters?: FunctionTypeParameter[]; 927 938 }): ts.TypeAliasDeclaration => { 928 939 const node = ts.factory.createTypeAliasDeclaration( 929 940 exportType ? [createModifier({ keyword: 'export' })] : undefined, 930 - createIdentifier({ text: name }), 941 + // TODO: https://github.com/hey-api/openapi-ts/issues/2289 942 + // passing type reference node seems to work and allows for dynamic renaming 943 + // @ts-expect-error 944 + typeof name === 'string' ? createIdentifier({ text: name }) : name, 931 945 toTypeParameters(typeParameters), 932 946 createTypeNode(type), 933 947 );
+8 -5
packages/openapi-ts/src/compiler/utils.ts
··· 5 5 import type { AccessLevel } from './types'; 6 6 import { createStringLiteral, syntaxKindKeyword } from './types'; 7 7 8 - export interface ImportExportItemObject { 9 - alias?: string; 8 + export interface ImportExportItemObject< 9 + Name extends string | undefined = string | undefined, 10 + Alias extends string | undefined = undefined, 11 + > { 12 + alias?: Alias; 10 13 asType?: boolean; 11 - name: string; 14 + name: Name; 12 15 } 13 16 14 17 const printer = ts.createPrinter({ ··· 125 128 boolean: (value: boolean) => 126 129 value ? ts.factory.createTrue() : ts.factory.createFalse(), 127 130 export: ({ alias, asType = false, name }: ImportExportItemObject) => { 128 - const nameNode = createIdentifier({ text: name }); 131 + const nameNode = createIdentifier({ text: name! }); 129 132 if (alias) { 130 133 const aliasNode = createIdentifier({ text: alias }); 131 134 return ts.factory.createExportSpecifier(asType, nameNode, aliasNode); ··· 133 136 return ts.factory.createExportSpecifier(asType, undefined, nameNode); 134 137 }, 135 138 import: ({ alias, asType = false, name }: ImportExportItemObject) => { 136 - const nameNode = createIdentifier({ text: name }); 139 + const nameNode = createIdentifier({ text: name! }); 137 140 if (alias) { 138 141 const aliasNode = createIdentifier({ text: alias }); 139 142 return ts.factory.createImportSpecifier(asType, nameNode, aliasNode);
+2
packages/openapi-ts/src/config/parser.ts
··· 71 71 requests: valueToObject({ 72 72 defaultValue: parser.transforms.readWrite.requests, 73 73 mappers: { 74 + function: (name) => ({ name }), 74 75 string: (name) => ({ name }), 75 76 }, 76 77 value: fields.requests, ··· 78 79 responses: valueToObject({ 79 80 defaultValue: parser.transforms.readWrite.responses, 80 81 mappers: { 82 + function: (name) => ({ name }), 81 83 string: (name) => ({ name }), 82 84 }, 83 85 value: fields.responses,
+22 -2
packages/openapi-ts/src/config/utils.ts
··· 7 7 boolean: T extends boolean 8 8 ? (value: boolean) => Partial<ObjectType<T>> 9 9 : never; 10 + function: T extends (...args: any[]) => any 11 + ? (value: (...args: any[]) => any) => Partial<ObjectType<T>> 12 + : never; 10 13 number: T extends number ? (value: number) => Partial<ObjectType<T>> : never; 11 14 object?: (value: Partial<ObjectType<T>>) => Partial<ObjectType<T>>; 12 15 string: T extends string ? (value: string) => Partial<ObjectType<T>> : never; ··· 15 18 : never; 16 19 17 20 type IsObjectOnly<T> = T extends Record<string, any> | undefined 18 - ? Extract<T, string | boolean | number> extends never 21 + ? Extract< 22 + T, 23 + string | boolean | number | ((...args: any[]) => any) 24 + > extends never 19 25 ? true 20 26 : false 21 27 : false; 22 28 23 29 export type ValueToObject = < 24 - T extends undefined | string | boolean | number | Record<string, any>, 30 + T extends 31 + | undefined 32 + | string 33 + | boolean 34 + | number 35 + | ((...args: any[]) => any) 36 + | Record<string, any>, 25 37 >( 26 38 args: { 27 39 defaultValue: ObjectType<T>; ··· 61 73 value: boolean, 62 74 ) => Record<string, any>; 63 75 result = mergeResult(result, mapper(value)); 76 + } 77 + break; 78 + case 'function': 79 + if (mappers && 'function' in mappers) { 80 + const mapper = mappers.function as ( 81 + value: (...args: any[]) => any, 82 + ) => Record<string, any>; 83 + result = mergeResult(result, mapper(value as (...args: any[]) => any)); 64 84 } 65 85 break; 66 86 case 'number':
+3
packages/openapi-ts/src/generate/__tests__/class.test.ts
··· 82 82 output: '', 83 83 }, 84 84 '@hey-api/typescript': { 85 + api: { 86 + getId: () => '', 87 + }, 85 88 config: { 86 89 enums: 'javascript', 87 90 name: '@hey-api/typescript',
+9
packages/openapi-ts/src/generate/__tests__/core.test.ts
··· 97 97 output: '', 98 98 }, 99 99 '@hey-api/typescript': { 100 + api: { 101 + getId: () => '', 102 + }, 100 103 config: { 101 104 enums: 'javascript', 102 105 name: '@hey-api/typescript', ··· 227 230 output: '', 228 231 }, 229 232 '@hey-api/typescript': { 233 + api: { 234 + getId: () => '', 235 + }, 230 236 config: { 231 237 enums: 'javascript', 232 238 name: '@hey-api/typescript', ··· 340 346 output: '', 341 347 }, 342 348 '@hey-api/typescript': { 349 + api: { 350 + getId: () => '', 351 + }, 343 352 config: { 344 353 enums: 'javascript', 345 354 name: '@hey-api/typescript',
+2 -2
packages/openapi-ts/src/generate/__tests__/files.test.ts packages/openapi-ts/src/generate/file/__tests__/file.test.ts
··· 1 1 import { describe, expect, it } from 'vitest'; 2 2 3 - import type { Identifiers } from '../files'; 4 - import { _test } from '../files'; 3 + import { _test } from '../index'; 4 + import type { Identifiers } from '../types'; 5 5 6 6 const { ensureUniqueIdentifier, parseRef, splitNameAndExtension } = _test; 7 7
+77
packages/openapi-ts/src/generate/file/types.d.ts
··· 1 + import type ts from 'typescript'; 2 + 3 + export interface Identifier { 4 + /** 5 + * Did this function add a new property to the file's `identifiers` map? 6 + */ 7 + created: boolean; 8 + /** 9 + * The resolved identifier name. False means the identifier has been blacklisted. 10 + */ 11 + name: string | false; 12 + } 13 + 14 + type NamespaceEntry = Pick<Identifier, 'name'> & { 15 + /** 16 + * Ref to the type in OpenAPI specification. 17 + */ 18 + $ref: string; 19 + }; 20 + 21 + export type Identifiers = Record< 22 + string, 23 + { 24 + /** 25 + * TypeScript enum only namespace. 26 + * 27 + * @example 28 + * ```ts 29 + * export enum Foo = { 30 + * FOO = 'foo' 31 + * } 32 + * ``` 33 + */ 34 + enum?: Record<string, NamespaceEntry>; 35 + /** 36 + * Type namespace. Types, interfaces, and type aliases exist here. 37 + * 38 + * @example 39 + * ```ts 40 + * export type Foo = string; 41 + * ``` 42 + */ 43 + type?: Record<string, NamespaceEntry>; 44 + /** 45 + * Value namespace. Variables, functions, classes, and constants exist here. 46 + * 47 + * @example 48 + * ```js 49 + * export const foo = ''; 50 + * ``` 51 + */ 52 + value?: Record<string, NamespaceEntry>; 53 + } 54 + >; 55 + 56 + export type Namespace = keyof Identifiers[keyof Identifiers]; 57 + 58 + export type FileImportResult< 59 + Name extends string | undefined = string | undefined, 60 + Alias extends string | undefined = undefined, 61 + > = { 62 + asType?: boolean; 63 + name: Alias extends string ? Alias : Name; 64 + }; 65 + 66 + export type NodeInfo = { 67 + /** 68 + * Is this node exported from the file? 69 + * 70 + * @default false 71 + */ 72 + exported?: boolean; 73 + /** 74 + * Reference to the node object. 75 + */ 76 + node: ts.TypeReferenceNode; 77 + };
+143 -86
packages/openapi-ts/src/generate/files.ts packages/openapi-ts/src/generate/file/index.ts
··· 3 3 4 4 import ts from 'typescript'; 5 5 6 - import { compiler } from '../compiler'; 7 - import { type ImportExportItemObject, tsNodeToString } from '../compiler/utils'; 8 - import type { IR } from '../ir/types'; 9 - import { ensureValidIdentifier } from '../openApi/shared/utils/identifier'; 10 - import type { StringCase } from '../types/case'; 11 - import { stringCase } from '../utils/stringCase'; 12 - import { ensureDirSync } from './utils'; 13 - 14 - export interface Identifier { 15 - /** 16 - * Did this function add a new property to the file's `identifiers` map? 17 - */ 18 - created: boolean; 19 - /** 20 - * The resolved identifier name. False means the identifier has been blacklisted. 21 - */ 22 - name: string | false; 23 - } 6 + import { compiler } from '../../compiler'; 7 + import { 8 + type ImportExportItemObject, 9 + tsNodeToString, 10 + } from '../../compiler/utils'; 11 + import type { IR } from '../../ir/types'; 12 + import { getUniqueComponentName } from '../../openApi/shared/transforms/utils'; 13 + import { ensureValidIdentifier } from '../../openApi/shared/utils/identifier'; 14 + import type { StringCase } from '../../types/case'; 15 + import { stringCase } from '../../utils/stringCase'; 16 + import { ensureDirSync } from '../utils'; 17 + import type { 18 + FileImportResult, 19 + Identifier, 20 + Identifiers, 21 + Namespace, 22 + NodeInfo, 23 + } from './types'; 24 24 25 - type NamespaceEntry = Pick<Identifier, 'name'> & { 26 - /** 27 - * Ref to the type in OpenAPI specification. 28 - */ 29 - $ref: string; 30 - }; 31 - 32 - export type Identifiers = Record< 33 - string, 34 - { 35 - /** 36 - * TypeScript enum only namespace. 37 - * 38 - * @example 39 - * ```ts 40 - * export enum Foo = { 41 - * FOO = 'foo' 42 - * } 43 - * ``` 44 - */ 45 - enum?: Record<string, NamespaceEntry>; 46 - /** 47 - * Type namespace. Types, interfaces, and type aliases exist here. 48 - * 49 - * @example 50 - * ```ts 51 - * export type Foo = string; 52 - * ``` 53 - */ 54 - type?: Record<string, NamespaceEntry>; 55 - /** 56 - * Value namespace. Variables, functions, classes, and constants exist here. 57 - * 58 - * @example 59 - * ```js 60 - * export const foo = ''; 61 - * ``` 62 - */ 63 - value?: Record<string, NamespaceEntry>; 64 - } 65 - >; 66 - 67 - type Namespace = keyof Identifiers[keyof Identifiers]; 68 - 69 - export type FileImportResult = Pick<ImportExportItemObject, 'asType' | 'name'>; 70 - 71 - export class TypeScriptFile { 25 + export class GeneratedFile { 26 + private _case: StringCase | undefined; 72 27 /** 73 28 * Should the exports from this file be re-exported in the index barrel file? 74 29 */ 75 30 private _exportFromIndex: boolean; 76 31 private _headers: Array<string> = []; 77 32 private _id: string; 78 - private _identifierCase: StringCase | undefined; 79 33 private _imports = new Map<string, Map<string, ImportExportItemObject>>(); 80 34 private _items: Array<ts.Node | string> = []; 81 35 private _name: string; 82 36 private _path: string; 83 37 38 + /** @deprecated use `names` and `nodes` */ 84 39 public identifiers: Identifiers = {}; 85 40 86 41 /** 42 + * Map of node IDs. This can be used to obtain actual node names. Keys are 43 + * node IDs which can be any string, values are names. Values are kept in 44 + * sync with `nodes`. 45 + * 46 + * @example 47 + * ```json 48 + * { 49 + * "#/my-id": "final_name", 50 + * "anyId": "name" 51 + * } 52 + * ``` 53 + */ 54 + private names: Record<string, string> = {}; 55 + /** 56 + * Text value from node is kept in sync with `names`. 57 + * 58 + * @example 59 + * ```js 60 + * { 61 + * "#/my-id": { 62 + * "node": TypeReferenceNode 63 + * }, 64 + * "anyId": { 65 + * "node": TypeReferenceNode 66 + * } 67 + * } 68 + * ``` 69 + */ 70 + private nodes: Record<string, NodeInfo> = {}; 71 + 72 + /** 87 73 * Path relative to the client output root. 88 74 */ 89 75 // TODO: parser - add relative path property for quick access, currently ··· 91 77 // public relativePath: string; 92 78 93 79 public constructor({ 80 + case: _case, 94 81 dir, 95 82 exportFromIndex = false, 96 83 header = true, 97 84 id, 98 - identifierCase, 99 85 name, 100 86 }: { 87 + case?: StringCase; 101 88 dir: string; 102 89 /** 103 90 * Should the exports from this file be re-exported in the index barrel file? ··· 110 97 * nested inside another folder. 111 98 */ 112 99 id: string; 113 - identifierCase?: StringCase; 114 100 name: string; 115 101 }) { 102 + this._case = _case; 116 103 this._exportFromIndex = exportFromIndex; 117 104 this._id = id; 118 - this._identifierCase = identifierCase; 119 105 this._name = this._setName(name); 120 106 this._path = path.resolve(dir, this._name); 121 107 ··· 162 148 return this._exportFromIndex; 163 149 } 164 150 151 + /** 152 + * Returns an actual node name. If node doesn't exist throws an error. 153 + * 154 + * @param id Node ID. 155 + * @returns Actual node name. 156 + */ 157 + public getName(id: string): string | undefined { 158 + const name = this.names[id]; 159 + if (!name) { 160 + return; 161 + } 162 + return name; 163 + } 164 + 165 + /** 166 + * Returns a node. If node doesn't exist, creates a blank reference. 167 + * 168 + * @param id Node ID. 169 + * @returns Information about the node. 170 + */ 171 + public getNode(id: string): NodeInfo { 172 + if (!this.nodes[id]) { 173 + this.nodes[id] = { 174 + node: compiler.typeReferenceNode({ typeName: '' }), 175 + }; 176 + } 177 + return this.nodes[id]!; 178 + } 179 + 165 180 public get id(): string { 166 181 return this._id; 167 182 } 168 183 184 + /** @deprecated use `names` and `nodes` */ 169 185 public identifier( 170 186 args: Pick< 171 187 EnsureUniqueIdentifierData, ··· 176 192 }, 177 193 ): Identifier { 178 194 return ensureUniqueIdentifier({ 179 - case: args.case ?? this._identifierCase, 195 + case: args.case ?? this._case, 180 196 identifiers: this.identifiers, 181 197 ...args, 182 198 }); ··· 187 203 * import. Returns the imported name. If we import an aliased export, `name` 188 204 * will be equal to the specified `alias`. 189 205 */ 190 - public import({ 206 + public import< 207 + Name extends string | undefined = string | undefined, 208 + Alias extends string | undefined = undefined, 209 + >({ 191 210 module, 192 211 ...importedItem 193 - }: ImportExportItemObject & { 212 + }: ImportExportItemObject<Name, Alias> & { 194 213 module: string; 195 - }): FileImportResult { 214 + }): FileImportResult<Name, Alias> { 215 + if (!importedItem.name) { 216 + return { 217 + name: undefined as any, 218 + }; 219 + } 220 + 196 221 let moduleMap = this._imports.get(module); 197 222 198 223 if (!moduleMap) { ··· 204 229 if (match) { 205 230 return { 206 231 ...match, 207 - name: match.alias || match.name, 232 + name: (match.alias || match.name) as any, 208 233 }; 209 234 } 210 235 211 - moduleMap.set(importedItem.name, importedItem); 236 + moduleMap.set(importedItem.name, importedItem as any); 212 237 return { 213 238 ...importedItem, 214 - name: importedItem.alias || importedItem.name, 239 + name: (importedItem.alias || importedItem.name) as any, 215 240 }; 216 241 } 217 242 ··· 287 312 288 313 /** 289 314 * Removes last node form the stack. Works as undo. 315 + * 316 + * @deprecated 290 317 */ 291 - public removeNode() { 318 + public removeNode_LEGACY() { 292 319 this._items = this._items.slice(0, this._items.length - 1); 293 320 } 294 321 ··· 346 373 return output.join(separator); 347 374 } 348 375 376 + /** 377 + * Inserts or updates a node. 378 + * 379 + * @param id Node ID. 380 + * @param args Information about the node. 381 + * @returns Updated node. 382 + */ 383 + public updateNode( 384 + id: string, 385 + args: Pick<NodeInfo, 'exported'> & { 386 + name: string; 387 + }, 388 + ): NodeInfo { 389 + // update name 390 + const name = getUniqueComponentName({ 391 + base: ensureValidIdentifier(args.name), 392 + components: Object.values(this.names), 393 + }); 394 + this.names[id] = name; 395 + const node = compiler.typeReferenceNode({ typeName: name }); 396 + // update node 397 + if (!this.nodes[id]) { 398 + this.nodes[id] = { node }; 399 + } else { 400 + Object.assign(this.nodes[id].node, node); 401 + } 402 + if (args.exported !== undefined) { 403 + this.nodes[id].exported = args.exported; 404 + } 405 + return this.nodes[id]; 406 + } 407 + 349 408 public write(separator = '\n', tsConfig: ts.ParsedCommandLine | null = null) { 350 409 if (this.isEmpty()) { 351 410 this.remove({ force: true }); ··· 411 470 const transformName = ( 412 471 name: string, 413 472 transformer: ((name: string) => string) | string, 414 - identifierCase?: StringCase, 473 + _case?: StringCase, 415 474 ): string => { 416 475 if (typeof transformer === 'function') { 417 476 return transformer(name); 418 477 } 419 478 420 - const separator = identifierCase === 'preserve' ? '' : '-'; 479 + const separator = _case === 'preserve' ? '' : '-'; 421 480 return transformer.replace('{{name}}', `${separator}${name}${separator}`); 422 481 }; 423 482 ··· 436 495 437 496 const ensureUniqueIdentifier = ({ 438 497 $ref, 439 - case: identifierCase, 498 + case: _case, 440 499 count = 1, 441 500 create = false, 442 501 identifiers, ··· 453 512 } 454 513 455 514 let nameWithCasingAndTransformer = stringCase({ 456 - case: identifierCase, 457 - value: nameTransformer 458 - ? transformName(name, nameTransformer, identifierCase) 459 - : name, 515 + case: _case, 516 + value: nameTransformer ? transformName(name, nameTransformer, _case) : name, 460 517 }); 461 518 if (count > 1) { 462 519 nameWithCasingAndTransformer = `${nameWithCasingAndTransformer}${count}`; ··· 475 532 ) { 476 533 return ensureUniqueIdentifier({ 477 534 $ref: ref, 478 - case: identifierCase, 535 + case: _case, 479 536 count: count + 1, 480 537 create, 481 538 identifiers, ··· 512 569 513 570 return ensureUniqueIdentifier({ 514 571 $ref: ref, 515 - case: identifierCase, 572 + case: _case, 516 573 count: count + 1, 517 574 create, 518 575 identifiers,
+7 -4
packages/openapi-ts/src/generate/legacy/__tests__/index.test.ts
··· 4 4 import { describe, expect, it, vi } from 'vitest'; 5 5 6 6 import { setConfig } from '../../../utils/config'; 7 - import { TypeScriptFile } from '../../files'; 7 + import { GeneratedFile } from '../../file'; 8 8 import { generateIndexFile } from '../indexFile'; 9 9 10 10 vi.mock('node:fs'); ··· 81 81 output: '', 82 82 }, 83 83 '@hey-api/typescript': { 84 + api: { 85 + getId: () => '', 86 + }, 84 87 config: { 85 88 enums: 'javascript', 86 89 name: '@hey-api/typescript', ··· 103 106 }); 104 107 105 108 const files: Parameters<typeof generateIndexFile>[0]['files'] = { 106 - schemas: new TypeScriptFile({ 109 + schemas: new GeneratedFile({ 107 110 dir: '/', 108 111 id: 'schemas', 109 112 name: 'schemas.ts', 110 113 }), 111 - sdk: new TypeScriptFile({ 114 + sdk: new GeneratedFile({ 112 115 dir: '/', 113 116 id: 'sdk', 114 117 name: 'sdk.ts', 115 118 }), 116 - types: new TypeScriptFile({ 119 + types: new GeneratedFile({ 117 120 dir: '/', 118 121 id: 'types', 119 122 name: 'types.ts',
+3
packages/openapi-ts/src/generate/legacy/__tests__/output.test.ts
··· 95 95 output: '', 96 96 }, 97 97 '@hey-api/typescript': { 98 + api: { 99 + getId: () => '', 100 + }, 98 101 config: { 99 102 enums: 'javascript', 100 103 name: '@hey-api/typescript',
+2 -2
packages/openapi-ts/src/generate/legacy/indexFile.ts
··· 2 2 import { getClientPlugin } from '../../plugins/@hey-api/client-core/utils'; 3 3 import type { Files } from '../../types/utils'; 4 4 import { getConfig, legacyNameFromConfig } from '../../utils/config'; 5 - import { TypeScriptFile } from '../files'; 5 + import { GeneratedFile } from '../file'; 6 6 7 7 export const generateIndexFile = ({ files }: { files: Files }): void => { 8 8 const config = getConfig(); 9 9 10 - files.index = new TypeScriptFile({ 10 + files.index = new GeneratedFile({ 11 11 dir: config.output.path, 12 12 id: 'index', 13 13 name: 'index.ts',
+2 -2
packages/openapi-ts/src/generate/legacy/output.ts
··· 9 9 import { generateLegacyClientClass } from '../class'; 10 10 import { generateClientBundle } from '../client'; 11 11 import { generateLegacyCore } from '../core'; 12 - import { TypeScriptFile } from '../files'; 12 + import { GeneratedFile } from '../file'; 13 13 import { findTsConfigPath, loadTsConfig } from '../tsConfig'; 14 14 import { removeDirSync } from '../utils'; 15 15 import { generateIndexFile } from './indexFile'; ··· 92 92 config.output.path, 93 93 ...outputParts.slice(0, outputParts.length - 1), 94 94 ); 95 - files[plugin.name] = new TypeScriptFile({ 95 + files[plugin.name] = new GeneratedFile({ 96 96 dir: outputDir, 97 97 id: `legacy-unused-${plugin.name}`, 98 98 name: `${outputParts[outputParts.length - 1]}.ts`,
+9 -9
packages/openapi-ts/src/ir/context.ts
··· 1 1 import path from 'node:path'; 2 2 3 - import { TypeScriptFile } from '../generate/files'; 3 + import { GeneratedFile } from '../generate/file'; 4 4 import type { PluginConfigMap } from '../plugins/config'; 5 5 import { PluginInstance } from '../plugins/shared/utils/instance'; 6 6 import type { PluginNames } from '../plugins/types'; ··· 12 12 13 13 export interface ContextFile { 14 14 /** 15 + * Define casing for identifiers in this file. 16 + */ 17 + case?: StringCase; 18 + /** 15 19 * Should the exports from this file be re-exported in the index barrel file? 16 20 */ 17 21 exportFromIndex?: boolean; ··· 20 24 */ 21 25 id: string; 22 26 /** 23 - * Define casing for identifiers in this file. 24 - */ 25 - identifierCase?: StringCase; 26 - /** 27 27 * Relative file path to the output path. 28 28 * 29 29 * @example ··· 68 68 * Create and return a new TypeScript file. Also set the current file context 69 69 * to the newly created file. 70 70 */ 71 - public createFile(file: ContextFile): TypeScriptFile { 71 + public createFile(file: ContextFile): GeneratedFile { 72 72 // TODO: parser - handle attempt to create duplicate 73 73 const outputParts = file.path.split('/'); 74 74 const outputDir = path.resolve( 75 75 this.config.output.path, 76 76 ...outputParts.slice(0, outputParts.length - 1), 77 77 ); 78 - const createdFile = new TypeScriptFile({ 78 + const createdFile = new GeneratedFile({ 79 + case: file.case, 79 80 dir: outputDir, 80 81 exportFromIndex: file.exportFromIndex, 81 82 id: file.id, 82 - identifierCase: file.identifierCase, 83 83 name: `${outputParts[outputParts.length - 1]}.ts`, 84 84 }); 85 85 this.files[file.id] = createdFile; ··· 103 103 /** 104 104 * Returns a specific file by ID from `files`. 105 105 */ 106 - public file({ id }: Pick<ContextFile, 'id'>): TypeScriptFile | undefined { 106 + public file({ id }: Pick<ContextFile, 'id'>): GeneratedFile | undefined { 107 107 return this.files[id]; 108 108 } 109 109
+3
packages/openapi-ts/src/openApi/common/parser/__tests__/type.test.ts
··· 7 7 const config: Partial<Config> = { 8 8 plugins: { 9 9 '@hey-api/typescript': { 10 + api: { 11 + getId: () => '', 12 + }, 10 13 config: { 11 14 name: '@hey-api/typescript', 12 15 },
+1 -3
packages/openapi-ts/src/openApi/shared/transforms/utils.ts
··· 14 14 }; 15 15 16 16 export const getUniqueComponentName = ({ 17 - base: _base, 17 + base, 18 18 components, 19 19 extraComponents, 20 20 }: { ··· 29 29 extraComponents?: Obj; 30 30 }): string => { 31 31 let index = 2; 32 - // Strip trailing number. For example, if base is "foo2", the clean base will be "foo" 33 - const base = _base.replace(/\d+$/, ''); 34 32 let name = base; 35 33 while ( 36 34 hasName(components, name) ||
+3 -3
packages/openapi-ts/src/openApi/shared/utils/name.ts
··· 1 - import type { StringCase } from '../../../types/case'; 1 + import type { StringCase, StringName } from '../../../types/case'; 2 2 import { stringCase } from '../../../utils/stringCase'; 3 3 4 4 export const buildName = ({ ··· 7 7 }: { 8 8 config: { 9 9 case: StringCase; 10 - name: string | ((name: string) => string); 10 + name?: StringName; 11 11 }; 12 12 name: string; 13 13 }): string => { 14 14 if (typeof config.name === 'function') { 15 15 name = config.name(name); 16 - } else { 16 + } else if (config.name) { 17 17 name = config.name.replace('{{name}}', name); 18 18 } 19 19
+2 -2
packages/openapi-ts/src/openApi/shared/utils/operation.ts
··· 47 47 value: sanitizeNamespaceIdentifier(id), 48 48 }); 49 49 } else { 50 - const urlWithoutPlaceholders = path 50 + const pathWithoutPlaceholders = path 51 51 .replace(/{(.*?)}/g, 'by-$1') 52 52 // replace slashes with hyphens for camelcase method at the end 53 53 .replace(/[/:+]/g, '-'); 54 54 55 55 result = stringCase({ 56 56 case: 'camelCase', 57 - value: `${method}-${urlWithoutPlaceholders}`, 57 + value: `${method}-${pathWithoutPlaceholders}`, 58 58 }); 59 59 } 60 60
+3
packages/openapi-ts/src/openApi/v3/parser/__tests__/getModel.test.ts
··· 9 9 const config: Partial<Config> = { 10 10 plugins: { 11 11 '@hey-api/typescript': { 12 + api: { 13 + getId: () => '', 14 + }, 12 15 config: { 13 16 name: '@hey-api/typescript', 14 17 },
+2 -2
packages/openapi-ts/src/plugins/@hey-api/client-axios/types.d.ts
··· 1 1 import type { DefinePlugin, Plugin } from '../../types'; 2 2 import type { Client } from '../client-core/types'; 3 3 4 - export type Config = Plugin.Name<'@hey-api/client-axios'> & 4 + export type UserConfig = Plugin.Name<'@hey-api/client-axios'> & 5 5 Client.Config & { 6 6 /** 7 7 * Throw an error instead of returning it in the response? ··· 11 11 throwOnError?: boolean; 12 12 }; 13 13 14 - export type HeyApiClientAxiosPlugin = DefinePlugin<Config>; 14 + export type HeyApiClientAxiosPlugin = DefinePlugin<UserConfig>;
+8 -2
packages/openapi-ts/src/plugins/@hey-api/client-core/client.ts
··· 42 42 module: clientModule, 43 43 name: 'createConfig', 44 44 }); 45 + const pluginTypeScript = plugin.getPlugin('@hey-api/typescript')!; 46 + const fileTypeScript = plugin.context.file({ id: typesId })!; 45 47 const clientOptions = file.import({ 46 48 asType: true, 47 49 module: file.relativePathToFile({ context: plugin.context, id: typesId }), 48 - name: 'ClientOptions', 50 + name: fileTypeScript.getName( 51 + pluginTypeScript.api.getId({ type: 'ClientOptions' }), 52 + ), 49 53 }); 50 54 51 55 const createClientConfig = plugin.config.runtimeConfigPath ··· 94 98 parameters: defaultValues.length 95 99 ? [compiler.objectExpression({ obj: defaultValues })] 96 100 : undefined, 97 - types: [compiler.typeReferenceNode({ typeName: clientOptions.name })], 101 + types: clientOptions.name 102 + ? [compiler.typeReferenceNode({ typeName: clientOptions.name })] 103 + : undefined, 98 104 }), 99 105 ]; 100 106
+8 -2
packages/openapi-ts/src/plugins/@hey-api/client-core/createClientConfig.ts
··· 13 13 config: plugin.context.config, 14 14 sourceOutput: file.nameWithoutExtension(), 15 15 }); 16 + const pluginTypeScript = plugin.getPlugin('@hey-api/typescript')!; 17 + const fileTypeScript = plugin.context.file({ id: typesId })!; 16 18 const clientOptions = file.import({ 17 19 asType: true, 18 20 module: file.relativePathToFile({ context: plugin.context, id: typesId }), 19 - name: 'ClientOptions', 21 + name: fileTypeScript.getName( 22 + pluginTypeScript.api.getId({ type: 'ClientOptions' }), 23 + ), 20 24 }); 21 25 const configType = file.import({ 22 26 asType: true, ··· 78 82 }), 79 83 typeParameters: [ 80 84 { 81 - default: compiler.typeReferenceNode({ typeName: clientOptions.name }), 85 + default: clientOptions.name 86 + ? compiler.typeReferenceNode({ typeName: clientOptions.name }) 87 + : undefined, 82 88 extends: defaultClientOptionsType, 83 89 name: 'T', 84 90 },
+2 -2
packages/openapi-ts/src/plugins/@hey-api/client-fetch/types.d.ts
··· 1 1 import type { DefinePlugin, Plugin } from '../../types'; 2 2 import type { Client } from '../client-core/types'; 3 3 4 - export type Config = Plugin.Name<'@hey-api/client-fetch'> & 4 + export type UserConfig = Plugin.Name<'@hey-api/client-fetch'> & 5 5 Client.Config & { 6 6 /** 7 7 * Throw an error instead of returning it in the response? ··· 11 11 throwOnError?: boolean; 12 12 }; 13 13 14 - export type HeyApiClientFetchPlugin = DefinePlugin<Config>; 14 + export type HeyApiClientFetchPlugin = DefinePlugin<UserConfig>;
+2 -2
packages/openapi-ts/src/plugins/@hey-api/client-next/types.d.ts
··· 1 1 import type { DefinePlugin, Plugin } from '../../types'; 2 2 import type { Client } from '../client-core/types'; 3 3 4 - export type Config = Plugin.Name<'@hey-api/client-next'> & 4 + export type UserConfig = Plugin.Name<'@hey-api/client-next'> & 5 5 Client.Config & { 6 6 /** 7 7 * Throw an error instead of returning it in the response? ··· 11 11 throwOnError?: boolean; 12 12 }; 13 13 14 - export type HeyApiClientNextPlugin = DefinePlugin<Config>; 14 + export type HeyApiClientNextPlugin = DefinePlugin<UserConfig>;
+2 -2
packages/openapi-ts/src/plugins/@hey-api/client-nuxt/types.d.ts
··· 1 1 import type { DefinePlugin, Plugin } from '../../types'; 2 2 import type { Client } from '../client-core/types'; 3 3 4 - export type Config = Plugin.Name<'@hey-api/client-nuxt'> & Client.Config; 4 + export type UserConfig = Plugin.Name<'@hey-api/client-nuxt'> & Client.Config; 5 5 6 - export type HeyApiClientNuxtPlugin = DefinePlugin<Config>; 6 + export type HeyApiClientNuxtPlugin = DefinePlugin<UserConfig>;
+2 -2
packages/openapi-ts/src/plugins/@hey-api/legacy-angular/types.d.ts
··· 1 1 import type { DefinePlugin, Plugin } from '../../types'; 2 2 import type { Client } from '../client-core/types'; 3 3 4 - export type Config = Plugin.Name<'legacy/angular'> & 4 + export type UserConfig = Plugin.Name<'legacy/angular'> & 5 5 Pick<Client.Config, 'output'>; 6 6 7 - export type HeyApiClientLegacyAngularPlugin = DefinePlugin<Config>; 7 + export type HeyApiClientLegacyAngularPlugin = DefinePlugin<UserConfig>;
+2 -2
packages/openapi-ts/src/plugins/@hey-api/legacy-axios/types.d.ts
··· 1 1 import type { DefinePlugin, Plugin } from '../../types'; 2 2 import type { Client } from '../client-core/types'; 3 3 4 - export type Config = Plugin.Name<'legacy/axios'> & 4 + export type UserConfig = Plugin.Name<'legacy/axios'> & 5 5 Pick<Client.Config, 'output'>; 6 6 7 - export type HeyApiClientLegacyAxiosPlugin = DefinePlugin<Config>; 7 + export type HeyApiClientLegacyAxiosPlugin = DefinePlugin<UserConfig>;
+2 -2
packages/openapi-ts/src/plugins/@hey-api/legacy-fetch/types.d.ts
··· 1 1 import type { DefinePlugin, Plugin } from '../../types'; 2 2 import type { Client } from '../client-core/types'; 3 3 4 - export type Config = Plugin.Name<'legacy/fetch'> & 4 + export type UserConfig = Plugin.Name<'legacy/fetch'> & 5 5 Pick<Client.Config, 'output'>; 6 6 7 - export type HeyApiClientLegacyFetchPlugin = DefinePlugin<Config>; 7 + export type HeyApiClientLegacyFetchPlugin = DefinePlugin<UserConfig>;
+3 -2
packages/openapi-ts/src/plugins/@hey-api/legacy-node/types.d.ts
··· 1 1 import type { DefinePlugin, Plugin } from '../../types'; 2 2 import type { Client } from '../client-core/types'; 3 3 4 - export type Config = Plugin.Name<'legacy/node'> & Pick<Client.Config, 'output'>; 4 + export type UserConfig = Plugin.Name<'legacy/node'> & 5 + Pick<Client.Config, 'output'>; 5 6 6 - export type HeyApiClientLegacyNodePlugin = DefinePlugin<Config>; 7 + export type HeyApiClientLegacyNodePlugin = DefinePlugin<UserConfig>;
+3 -2
packages/openapi-ts/src/plugins/@hey-api/legacy-xhr/types.d.ts
··· 1 1 import type { DefinePlugin, Plugin } from '../../types'; 2 2 import type { Client } from '../client-core/types'; 3 3 4 - export type Config = Plugin.Name<'legacy/xhr'> & Pick<Client.Config, 'output'>; 4 + export type UserConfig = Plugin.Name<'legacy/xhr'> & 5 + Pick<Client.Config, 'output'>; 5 6 6 - export type HeyApiClientLegacyXhrPlugin = DefinePlugin<Config>; 7 + export type HeyApiClientLegacyXhrPlugin = DefinePlugin<UserConfig>;
+6
packages/openapi-ts/src/plugins/@hey-api/schemas/__tests__/schemas.test.ts
··· 84 84 output: '', 85 85 }, 86 86 '@hey-api/typescript': { 87 + api: { 88 + getId: () => '', 89 + }, 87 90 config: { 88 91 enums: 'javascript', 89 92 name: '@hey-api/typescript', ··· 216 219 output: '', 217 220 }, 218 221 '@hey-api/typescript': { 222 + api: { 223 + getId: () => '', 224 + }, 219 225 config: { 220 226 enums: 'javascript', 221 227 name: '@hey-api/typescript',
+2 -2
packages/openapi-ts/src/plugins/@hey-api/schemas/plugin-legacy.ts
··· 1 1 import { compiler } from '../../../compiler'; 2 - import { TypeScriptFile } from '../../../generate/files'; 2 + import { GeneratedFile } from '../../../generate/file'; 3 3 import type { OpenApiV2Schema, OpenApiV3Schema } from '../../../openApi'; 4 4 import { ensureValidTypeScriptJavaScriptIdentifier } from '../../../openApi'; 5 5 import { getConfig } from '../../../utils/config'; ··· 81 81 }) => { 82 82 const config = getConfig(); 83 83 84 - files.schemas = new TypeScriptFile({ 84 + files.schemas = new GeneratedFile({ 85 85 dir: config.output.path, 86 86 exportFromIndex: plugin.config.exportFromIndex, 87 87 id: 'schemas',
+2 -2
packages/openapi-ts/src/plugins/@hey-api/schemas/types.d.ts
··· 4 4 import type { OpenApiV3_1_XTypes } from '../../../openApi/3.1.x'; 5 5 import type { DefinePlugin, Plugin } from '../../types'; 6 6 7 - export type Config = Plugin.Name<'@hey-api/schemas'> & { 7 + export type UserConfig = Plugin.Name<'@hey-api/schemas'> & { 8 8 /** 9 9 * Should the exports from the generated files be re-exported in the index 10 10 * barrel file? ··· 47 47 type?: 'form' | 'json'; 48 48 }; 49 49 50 - export type HeyApiSchemasPlugin = DefinePlugin<Config>; 50 + export type HeyApiSchemasPlugin = DefinePlugin<UserConfig>;
+17 -5
packages/openapi-ts/src/plugins/@hey-api/sdk/__tests__/plugin.test.ts
··· 4 4 import { describe, expect, it, vi } from 'vitest'; 5 5 6 6 import { openApi } from '../../../../generate/__tests__/mocks'; 7 - import { TypeScriptFile } from '../../../../generate/files'; 7 + import { GeneratedFile } from '../../../../generate/file'; 8 8 import type { Operation } from '../../../../types/client'; 9 9 import type { Config } from '../../../../types/config'; 10 10 import type { Files } from '../../../../types/utils'; ··· 87 87 output: '', 88 88 }, 89 89 '@hey-api/typescript': { 90 + api: { 91 + getId: () => '', 92 + }, 90 93 config: { 91 94 name: '@hey-api/typescript', 92 95 }, ··· 147 150 148 151 const files: Files = {}; 149 152 150 - files.types = new TypeScriptFile({ 153 + files.types = new GeneratedFile({ 151 154 dir: '/', 152 155 id: 'types', 153 156 name: 'types.ts', ··· 291 294 output: '', 292 295 }, 293 296 '@hey-api/typescript': { 297 + api: { 298 + getId: () => '', 299 + }, 294 300 config: { 295 301 name: '@hey-api/typescript', 296 302 }, ··· 313 319 314 320 const files: Files = {}; 315 321 316 - files.types = new TypeScriptFile({ 322 + files.types = new GeneratedFile({ 317 323 dir: '/', 318 324 id: 'types', 319 325 name: 'types.ts', ··· 418 424 output: '', 419 425 }, 420 426 '@hey-api/typescript': { 427 + api: { 428 + getId: () => '', 429 + }, 421 430 config: { 422 431 name: '@hey-api/typescript', 423 432 }, ··· 440 449 441 450 const files: Files = {}; 442 451 443 - files.types = new TypeScriptFile({ 452 + files.types = new GeneratedFile({ 444 453 dir: '/', 445 454 id: 'types', 446 455 name: 'types.ts', ··· 547 556 output: '', 548 557 }, 549 558 '@hey-api/typescript': { 559 + api: { 560 + getId: () => '', 561 + }, 550 562 config: { 551 563 name: '@hey-api/typescript', 552 564 }, ··· 569 581 570 582 const files: Files = {}; 571 583 572 - files.types = new TypeScriptFile({ 584 + files.types = new GeneratedFile({ 573 585 dir: '/', 574 586 id: 'types', 575 587 name: 'types.ts',
+57 -45
packages/openapi-ts/src/plugins/@hey-api/sdk/operation.ts
··· 3 3 import { compiler } from '../../../compiler'; 4 4 import type { ObjectValue } from '../../../compiler/types'; 5 5 import { clientApi, clientModulePath } from '../../../generate/client'; 6 - import type { TypeScriptFile } from '../../../generate/files'; 6 + import type { GeneratedFile } from '../../../generate/file'; 7 7 import { statusCodeToGroup } from '../../../ir/operation'; 8 8 import type { IR } from '../../../ir/types'; 9 9 import { sanitizeNamespaceIdentifier } from '../../../openApi'; ··· 15 15 operationTransformerIrRef, 16 16 transformersId, 17 17 } from '../transformers/plugin'; 18 - import { importIdentifier } from '../typescript/ref'; 18 + import { typesId } from '../typescript/ref'; 19 19 import { operationAuth } from './auth'; 20 20 import { nuxtTypeComposable, nuxtTypeDefault, sdkId } from './constants'; 21 21 import type { HeyApiSdkPlugin } from './types'; ··· 140 140 }; 141 141 142 142 export const operationOptionsType = ({ 143 - context, 144 143 file, 145 144 operation, 145 + plugin, 146 146 throwOnError, 147 147 }: { 148 - context: IR.Context; 149 - file: TypeScriptFile; 148 + file: GeneratedFile; 150 149 operation: IR.OperationObject; 150 + plugin: HeyApiSdkPlugin['Instance']; 151 151 throwOnError?: string; 152 152 }) => { 153 - const client = getClientPlugin(context.config); 153 + const client = getClientPlugin(plugin.context.config); 154 154 const isNuxtClient = client.name === '@hey-api/client-nuxt'; 155 155 156 - const identifierData = importIdentifier({ 157 - context, 158 - file, 159 - operation, 160 - type: 'data', 161 - }); 162 - const identifierResponse = importIdentifier({ 163 - context, 164 - file, 165 - operation, 166 - type: isNuxtClient ? 'response' : 'responses', 156 + const pluginTypeScript = plugin.getPlugin('@hey-api/typescript')!; 157 + const fileTypeScript = plugin.context.file({ id: typesId })!; 158 + const dataImport = file.import({ 159 + asType: true, 160 + module: file.relativePathToFile({ context: plugin.context, id: typesId }), 161 + name: fileTypeScript.getName( 162 + pluginTypeScript.api.getId({ operation, type: 'data' }), 163 + ), 167 164 }); 168 - 169 165 const optionsName = clientApi.Options.name; 170 166 171 167 if (isNuxtClient) { 172 - return `${optionsName}<${nuxtTypeComposable}, ${identifierData.name || 'unknown'}, ${identifierResponse.name || 'unknown'}, ${nuxtTypeDefault}>`; 168 + const responseImport = file.import({ 169 + asType: true, 170 + module: file.relativePathToFile({ context: plugin.context, id: typesId }), 171 + name: fileTypeScript.getName( 172 + pluginTypeScript.api.getId({ 173 + operation, 174 + type: isNuxtClient ? 'response' : 'responses', 175 + }), 176 + ), 177 + }); 178 + return `${optionsName}<${nuxtTypeComposable}, ${dataImport.name || 'unknown'}, ${responseImport.name || 'unknown'}, ${nuxtTypeDefault}>`; 173 179 } 174 180 175 181 // TODO: refactor this to be more generic, works for now 176 182 if (throwOnError) { 177 - return `${optionsName}<${identifierData.name || 'unknown'}, ${throwOnError}>`; 183 + return `${optionsName}<${dataImport.name || 'unknown'}, ${throwOnError}>`; 178 184 } 179 - return identifierData.name 180 - ? `${optionsName}<${identifierData.name}>` 181 - : optionsName; 185 + return dataImport.name ? `${optionsName}<${dataImport.name}>` : optionsName; 182 186 }; 183 187 184 188 /** ··· 238 242 }; 239 243 240 244 export const operationStatements = ({ 241 - context, 242 245 isRequiredOptions, 243 246 operation, 244 247 plugin, 245 248 }: { 246 - context: IR.Context; 247 249 isRequiredOptions: boolean; 248 250 operation: IR.OperationObject; 249 251 plugin: HeyApiSdkPlugin['Instance']; 250 252 }): Array<ts.Statement> => { 251 - const file = context.file({ id: sdkId })!; 253 + const file = plugin.context.file({ id: sdkId })!; 252 254 const sdkOutput = file.nameWithoutExtension(); 253 255 254 - const client = getClientPlugin(context.config); 256 + const client = getClientPlugin(plugin.context.config); 255 257 const isNuxtClient = client.name === '@hey-api/client-nuxt'; 256 258 257 - const identifierError = importIdentifier({ 258 - context, 259 - file, 260 - operation, 261 - type: isNuxtClient ? 'error' : 'errors', 259 + const pluginTypeScript = plugin.getPlugin('@hey-api/typescript')!; 260 + const fileTypeScript = plugin.context.file({ id: typesId })!; 261 + const responseImport = file.import({ 262 + asType: true, 263 + module: file.relativePathToFile({ context: plugin.context, id: typesId }), 264 + name: fileTypeScript.getName( 265 + pluginTypeScript.api.getId({ 266 + operation, 267 + type: isNuxtClient ? 'response' : 'responses', 268 + }), 269 + ), 262 270 }); 263 - const identifierResponse = importIdentifier({ 264 - context, 265 - file, 266 - operation, 267 - type: isNuxtClient ? 'response' : 'responses', 271 + const errorImport = file.import({ 272 + asType: true, 273 + module: file.relativePathToFile({ context: plugin.context, id: typesId }), 274 + name: fileTypeScript.getName( 275 + pluginTypeScript.api.getId({ 276 + operation, 277 + type: isNuxtClient ? 'error' : 'errors', 278 + }), 279 + ), 268 280 }); 269 281 270 282 // TODO: transform parameters ··· 291 303 requestOptions.push({ spread: 'formDataBodySerializer' }); 292 304 file.import({ 293 305 module: clientModulePath({ 294 - config: context.config, 306 + config: plugin.context.config, 295 307 sourceOutput: sdkOutput, 296 308 }), 297 309 name: 'formDataBodySerializer', ··· 312 324 requestOptions.push({ spread: 'urlSearchParamsBodySerializer' }); 313 325 file.import({ 314 326 module: clientModulePath({ 315 - config: context.config, 327 + config: plugin.context.config, 316 328 sourceOutput: sdkOutput, 317 329 }), 318 330 name: 'urlSearchParamsBodySerializer', ··· 364 376 } 365 377 366 378 if (plugin.config.transformer === '@hey-api/transformers') { 367 - const identifierTransformer = context 379 + const identifierTransformer = plugin.context 368 380 .file({ id: transformersId })! 369 381 .identifier({ 370 382 $ref: operationTransformerIrRef({ id: operation.id, type: 'response' }), ··· 374 386 if (identifierTransformer.name) { 375 387 file.import({ 376 388 module: file.relativePathToFile({ 377 - context, 389 + context: plugin.context, 378 390 id: transformersId, 379 391 }), 380 392 name: identifierTransformer.name, ··· 422 434 }); 423 435 } 424 436 425 - const auth = operationAuth({ context, operation, plugin }); 437 + const auth = operationAuth({ context: plugin.context, operation, plugin }); 426 438 if (auth.length) { 427 439 requestOptions.push({ 428 440 key: 'security', ··· 467 479 } 468 480 } 469 481 470 - const responseType = identifierResponse.name || 'unknown'; 471 - const errorType = identifierError.name || 'unknown'; 482 + const responseType = responseImport.name || 'unknown'; 483 + const errorType = errorImport.name || 'unknown'; 472 484 473 485 const heyApiClient = plugin.config.client 474 486 ? file.import({ 475 487 alias: '_heyApiClient', 476 488 module: file.relativePathToFile({ 477 - context, 489 + context: plugin.context, 478 490 id: clientId, 479 491 }), 480 492 name: 'client',
+2 -2
packages/openapi-ts/src/plugins/@hey-api/sdk/plugin-legacy.ts
··· 7 7 ObjectValue, 8 8 } from '../../../compiler/types'; 9 9 import { clientApi, clientModulePath } from '../../../generate/client'; 10 - import { TypeScriptFile } from '../../../generate/files'; 10 + import { GeneratedFile } from '../../../generate/file'; 11 11 import type { IR } from '../../../ir/types'; 12 12 import { isOperationParameterRequired } from '../../../openApi'; 13 13 import type { ··· 810 810 811 811 const sdkOutput = 'sdk'; 812 812 813 - files.sdk = new TypeScriptFile({ 813 + files.sdk = new GeneratedFile({ 814 814 dir: config.output.path, 815 815 exportFromIndex: plugin.config.exportFromIndex, 816 816 id: 'sdk',
+32 -28
packages/openapi-ts/src/plugins/@hey-api/sdk/plugin.ts
··· 8 8 isOperationOptionsRequired, 9 9 } from '../../shared/utils/operation'; 10 10 import { getClientPlugin } from '../client-core/utils'; 11 - import { importIdentifier } from '../typescript/ref'; 11 + import { typesId } from '../typescript/ref'; 12 12 import { nuxtTypeComposable, nuxtTypeDefault, sdkId } from './constants'; 13 13 import { 14 14 operationClasses, ··· 131 131 context: plugin.context, 132 132 operation, 133 133 }); 134 - const identifierResponse = importIdentifier({ 135 - context: plugin.context, 136 - file, 137 - operation, 138 - type: 'response', 134 + const pluginTypeScript = plugin.getPlugin('@hey-api/typescript')!; 135 + const fileTypeScript = plugin.context.file({ id: typesId })!; 136 + const responseImport = file.import({ 137 + asType: true, 138 + module: file.relativePathToFile({ context: plugin.context, id: typesId }), 139 + name: isNuxtClient 140 + ? fileTypeScript.getName( 141 + pluginTypeScript.api.getId({ operation, type: 'response' }), 142 + ) 143 + : undefined, 139 144 }); 140 145 141 146 const classes = operationClasses({ ··· 186 191 isRequired: isRequiredOptions, 187 192 name: 'options', 188 193 type: operationOptionsType({ 189 - context: plugin.context, 190 194 file, 191 195 operation, 196 + plugin, 192 197 throwOnError: isNuxtClient ? undefined : 'ThrowOnError', 193 198 }), 194 199 }, 195 200 ], 196 201 returnType: undefined, 197 202 statements: operationStatements({ 198 - context: plugin.context, 199 203 isRequiredOptions, 200 204 operation, 201 205 plugin, ··· 208 212 name: nuxtTypeComposable, 209 213 }, 210 214 { 211 - default: identifierResponse.name 215 + default: responseImport.name 212 216 ? compiler.typeReferenceNode({ 213 - typeName: identifierResponse.name, 217 + typeName: responseImport.name, 214 218 }) 215 219 : compiler.typeNode('undefined'), 216 - extends: identifierResponse.name 220 + extends: responseImport.name 217 221 ? compiler.typeReferenceNode({ 218 - typeName: identifierResponse.name, 222 + typeName: responseImport.name, 219 223 }) 220 224 : undefined, 221 225 name: nuxtTypeDefault, ··· 333 337 context: plugin.context, 334 338 operation, 335 339 }); 336 - const identifierResponse = importIdentifier({ 337 - context: plugin.context, 338 - file, 339 - operation, 340 - type: 'response', 340 + const pluginTypeScript = plugin.getPlugin('@hey-api/typescript')!; 341 + const fileTypeScript = plugin.context.file({ id: typesId })!; 342 + const responseImport = file.import({ 343 + asType: true, 344 + module: file.relativePathToFile({ context: plugin.context, id: typesId }), 345 + name: isNuxtClient 346 + ? fileTypeScript.getName( 347 + pluginTypeScript.api.getId({ operation, type: 'response' }), 348 + ) 349 + : undefined, 341 350 }); 342 351 const node = compiler.constVariable({ 343 352 comment: createOperationComment({ operation }), ··· 348 357 isRequired: isRequiredOptions, 349 358 name: 'options', 350 359 type: operationOptionsType({ 351 - context: plugin.context, 352 360 file, 353 361 operation, 362 + plugin, 354 363 throwOnError: isNuxtClient ? undefined : 'ThrowOnError', 355 364 }), 356 365 }, 357 366 ], 358 367 returnType: undefined, 359 368 statements: operationStatements({ 360 - context: plugin.context, 361 369 isRequiredOptions, 362 370 operation, 363 371 plugin, ··· 370 378 name: nuxtTypeComposable, 371 379 }, 372 380 { 373 - default: identifierResponse.name 381 + default: responseImport.name 374 382 ? compiler.typeReferenceNode({ 375 - typeName: identifierResponse.name, 383 + typeName: responseImport.name, 376 384 }) 377 385 : compiler.typeNode('undefined'), 378 - extends: identifierResponse.name 386 + extends: responseImport.name 379 387 ? compiler.typeReferenceNode({ 380 - typeName: identifierResponse.name, 388 + typeName: responseImport.name, 381 389 }) 382 390 : undefined, 383 391 name: nuxtTypeDefault, ··· 432 440 }); 433 441 } 434 442 435 - createTypeOptions({ 436 - clientOptions, 437 - context: plugin.context, 438 - plugin, 439 - }); 443 + createTypeOptions({ clientOptions, plugin }); 440 444 441 445 if (plugin.config.asClass) { 442 446 generateClassSdk({ plugin });
+5 -8
packages/openapi-ts/src/plugins/@hey-api/sdk/typeOptions.ts
··· 1 1 import { compiler } from '../../../compiler'; 2 2 import { clientModulePath } from '../../../generate/client'; 3 - import type { FileImportResult } from '../../../generate/files'; 4 - import type { IR } from '../../../ir/types'; 3 + import type { FileImportResult } from '../../../generate/file/types'; 5 4 import { getClientPlugin } from '../client-core/utils'; 6 5 import { nuxtTypeDefault, nuxtTypeResponse, sdkId } from './constants'; 7 6 import type { HeyApiSdkPlugin } from './types'; 8 7 9 8 export const createTypeOptions = ({ 10 9 clientOptions, 11 - context, 12 10 plugin, 13 11 }: { 14 - clientOptions: FileImportResult; 15 - context: IR.Context; 12 + clientOptions: FileImportResult<string, string>; 16 13 plugin: HeyApiSdkPlugin['Instance']; 17 14 }) => { 18 - const file = context.file({ id: sdkId })!; 19 - const client = getClientPlugin(context.config); 15 + const file = plugin.context.file({ id: sdkId })!; 16 + const client = getClientPlugin(plugin.context.config); 20 17 const isNuxtClient = client.name === '@hey-api/client-nuxt'; 21 18 22 19 const clientModule = clientModulePath({ 23 - config: context.config, 20 + config: plugin.context.config, 24 21 sourceOutput: file.nameWithoutExtension(), 25 22 }); 26 23 const tDataShape = file.import({
+6 -5
packages/openapi-ts/src/plugins/@hey-api/sdk/types.d.ts
··· 1 1 import type { IR } from '../../../ir/types'; 2 + import type { StringName } from '../../../types/case'; 2 3 import type { Operation } from '../../../types/client'; 3 4 import type { 4 5 DefinePlugin, ··· 7 8 PluginValidatorNames, 8 9 } from '../../types'; 9 10 10 - export type Config = Plugin.Name<'@hey-api/sdk'> & { 11 + export type UserConfig = Plugin.Name<'@hey-api/sdk'> & { 11 12 /** 12 13 * Group operation methods into classes? When enabled, you can select which 13 14 * classes to export with `sdk.include` and/or transform their names with ··· 34 35 * 35 36 * This option has no effect if `sdk.asClass` is `false`. 36 37 */ 37 - classNameBuilder?: string | ((name: string) => string); 38 + classNameBuilder?: StringName; 38 39 /** 39 40 * How should we structure your SDK? By default, we try to infer the ideal 40 41 * structure using `operationId` keywords. If you prefer a flatter structure, ··· 180 181 response?: 'body' | 'response'; 181 182 }; 182 183 183 - export type ResolvedConfig = Plugin.Name<'@hey-api/sdk'> & { 184 + export type Config = Plugin.Name<'@hey-api/sdk'> & { 184 185 /** 185 186 * Group operation methods into classes? When enabled, you can select which 186 187 * classes to export with `sdk.include` and/or transform their names with ··· 207 208 * 208 209 * This option has no effect if `sdk.asClass` is `false`. 209 210 */ 210 - classNameBuilder: string | ((name: string) => string); 211 + classNameBuilder: StringName; 211 212 /** 212 213 * How should we structure your SDK? By default, we try to infer the ideal 213 214 * structure using `operationId` keywords. If you prefer a flatter structure, ··· 332 333 response: 'body' | 'response'; 333 334 }; 334 335 335 - export type HeyApiSdkPlugin = DefinePlugin<Config, ResolvedConfig>; 336 + export type HeyApiSdkPlugin = DefinePlugin<UserConfig, Config>;
+4 -4
packages/openapi-ts/src/plugins/@hey-api/transformers/expressions.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 3 import { compiler } from '../../../compiler'; 4 - import type { TypeScriptFile } from '../../../generate/files'; 4 + import type { GeneratedFile } from '../../../generate/file'; 5 5 import type { IR } from '../../../ir/types'; 6 - import type { Config } from './types'; 6 + import type { UserConfig } from './types'; 7 7 8 8 export type ExpressionTransformer = ({ 9 9 config, ··· 11 11 file, 12 12 schema, 13 13 }: { 14 - config: Omit<Config, 'name'>; 14 + config: Omit<UserConfig, 'name'>; 15 15 dataExpression?: ts.Expression | string; 16 - file: TypeScriptFile; 16 + file: GeneratedFile; 17 17 schema: IR.SchemaObject; 18 18 }) => Array<ts.Expression> | undefined; 19 19
+1 -1
packages/openapi-ts/src/plugins/@hey-api/transformers/plugin-legacy.ts
··· 258 258 files.types?.add(node); 259 259 }; 260 260 const onRemoveNode: TypesProps['onRemoveNode'] = () => { 261 - files.types?.removeNode(); 261 + files.types?.removeNode_LEGACY(); 262 262 }; 263 263 264 264 for (const service of client.services) {
+10 -15
packages/openapi-ts/src/plugins/@hey-api/transformers/plugin.ts
··· 6 6 operationResponsesMap, 7 7 } from '../../../ir/operation'; 8 8 import type { IR } from '../../../ir/types'; 9 - import { irRef } from '../../../utils/ref'; 10 9 import { stringCase } from '../../../utils/stringCase'; 11 - import { operationIrRef } from '../../shared/utils/ref'; 12 10 import { typesId } from '../typescript/ref'; 13 11 import { bigIntExpressions, dateExpressions } from './expressions'; 14 12 import type { HeyApiTransformersPlugin } from './types'; ··· 38 36 affix = 'ResponseTransformer'; 39 37 break; 40 38 } 39 + const irRef = '#/ir/'; 41 40 return `${irRef}${stringCase({ 42 41 // TODO: parser - do not pascalcase for functions, only for types 43 42 case: 'camelCase', ··· 417 416 return; 418 417 } 419 418 420 - const identifierResponse = plugin.context 421 - .file({ id: typesId })! 422 - .identifier({ 423 - $ref: operationIrRef({ 424 - config: plugin.context.config, 425 - id: operation.id, 426 - type: 'response', 427 - }), 428 - namespace: 'type', 429 - }); 430 - if (!identifierResponse.name) { 419 + const pluginTypeScript = plugin.getPlugin('@hey-api/typescript')!; 420 + const fileTypeScript = plugin.context.file({ id: typesId })!; 421 + const responseName = fileTypeScript.getName( 422 + pluginTypeScript.api.getId({ operation, type: 'response' }), 423 + ); 424 + 425 + if (!responseName) { 431 426 return; 432 427 } 433 428 ··· 449 444 context: plugin.context, 450 445 id: typesId, 451 446 }), 452 - name: identifierResponse.name, 447 + name: responseName, 453 448 }); 454 449 const responseTransformerNode = compiler.constVariable({ 455 450 exportConst: true, ··· 466 461 returnType: compiler.typeReferenceNode({ 467 462 typeArguments: [ 468 463 compiler.typeReferenceNode({ 469 - typeName: identifierResponse.name, 464 + typeName: responseName, 470 465 }), 471 466 ], 472 467 typeName: 'Promise',
+2 -2
packages/openapi-ts/src/plugins/@hey-api/transformers/types.d.ts
··· 1 1 import type { DefinePlugin, Plugin } from '../../types'; 2 2 import type { ExpressionTransformer } from './expressions'; 3 3 4 - export type Config = Plugin.Name<'@hey-api/transformers'> & { 4 + export type UserConfig = Plugin.Name<'@hey-api/transformers'> & { 5 5 /** 6 6 * Convert long integers into BigInt values? 7 7 * ··· 33 33 transformers?: ReadonlyArray<ExpressionTransformer>; 34 34 }; 35 35 36 - export type HeyApiTransformersPlugin = DefinePlugin<Config>; 36 + export type HeyApiTransformersPlugin = DefinePlugin<UserConfig>;
+5 -2
packages/openapi-ts/src/plugins/@hey-api/typescript/__tests__/plugin.test.ts
··· 3 3 import { describe, expect, it, vi } from 'vitest'; 4 4 5 5 import { openApi } from '../../../../generate/__tests__/mocks'; 6 - import { TypeScriptFile } from '../../../../generate/files'; 6 + import { GeneratedFile } from '../../../../generate/file'; 7 7 import type { Config } from '../../../../types/config'; 8 8 import { setConfig } from '../../../../utils/config'; 9 9 import { PluginInstance } from '../../../shared/utils/instance'; ··· 84 84 output: '', 85 85 }, 86 86 '@hey-api/typescript': { 87 + api: { 88 + getId: () => '', 89 + }, 87 90 config: { 88 91 enums: 'javascript', 89 92 name: '@hey-api/typescript', ··· 139 142 }; 140 143 141 144 const files = { 142 - types: new TypeScriptFile({ 145 + types: new GeneratedFile({ 143 146 dir: '/', 144 147 id: 'types', 145 148 name: 'types.ts',
+37
packages/openapi-ts/src/plugins/@hey-api/typescript/api.ts
··· 1 + import type { IR } from '../../../ir/types'; 2 + 3 + type GetIdArgs = 4 + | { 5 + type: 'ClientOptions'; 6 + } 7 + | { 8 + operation: IR.OperationObject; 9 + type: 'data' | 'error' | 'errors' | 'response' | 'responses'; 10 + } 11 + | { 12 + type: 'ref'; 13 + value: string; 14 + }; 15 + 16 + const getId = (args: GetIdArgs): string => { 17 + switch (args.type) { 18 + case 'data': 19 + case 'error': 20 + case 'errors': 21 + case 'response': 22 + case 'responses': 23 + return `${args.operation.id}-${args.type}`; 24 + case 'ref': 25 + return args.value; 26 + default: 27 + return args.type; 28 + } 29 + }; 30 + 31 + export type Api = { 32 + getId: (args: GetIdArgs) => string; 33 + }; 34 + 35 + export const api: Api = { 36 + getId, 37 + };
+17 -21
packages/openapi-ts/src/plugins/@hey-api/typescript/clientOptions.ts
··· 1 1 import ts from 'typescript'; 2 2 3 3 import { compiler } from '../../../compiler'; 4 - import type { Identifier } from '../../../generate/files'; 4 + import type { NodeInfo } from '../../../generate/file/types'; 5 5 import type { IR } from '../../../ir/types'; 6 6 import { parseUrl } from '../../../utils/url'; 7 7 import { getClientBaseUrlKey, getClientPlugin } from '../client-core/utils'; ··· 31 31 }; 32 32 33 33 export const createClientOptions = ({ 34 - identifier, 34 + nodeInfo, 35 35 plugin, 36 36 servers, 37 37 }: { 38 - identifier: Identifier; 38 + nodeInfo: NodeInfo; 39 39 plugin: HeyApiTypeScriptPlugin['Instance']; 40 40 servers: ReadonlyArray<IR.ServerObject>; 41 41 }) => { 42 42 const file = plugin.context.file({ id: typesId })!; 43 - 44 - if (!identifier.name) { 45 - return; 46 - } 47 43 48 44 const client = getClientPlugin(plugin.context.config); 49 45 ··· 63 59 ); 64 60 } 65 61 66 - const typeClientOptions = compiler.typeAliasDeclaration({ 67 - exportType: true, 68 - name: identifier.name, 69 - type: compiler.typeInterfaceNode({ 70 - properties: [ 71 - { 72 - name: getClientBaseUrlKey(plugin.context.config), 73 - type: compiler.typeUnionNode({ types }), 74 - }, 75 - ], 76 - useLegacyResolution: false, 77 - }), 62 + const type = compiler.typeInterfaceNode({ 63 + properties: [ 64 + { 65 + name: getClientBaseUrlKey(plugin.context.config), 66 + type: compiler.typeUnionNode({ types }), 67 + }, 68 + ], 69 + useLegacyResolution: false, 70 + }); 71 + const node = compiler.typeAliasDeclaration({ 72 + exportType: nodeInfo.exported, 73 + name: nodeInfo.node, 74 + type, 78 75 }); 79 - 80 - file.add(typeClientOptions); 76 + file.add(node); 81 77 };
+52
packages/openapi-ts/src/plugins/@hey-api/typescript/config.ts
··· 1 1 import { definePluginConfig } from '../../shared/utils/config'; 2 + import { api } from './api'; 2 3 import { handler } from './plugin'; 3 4 import { handlerLegacy } from './plugin-legacy'; 4 5 import type { HeyApiTypeScriptPlugin } from './types'; 5 6 6 7 export const defaultConfig: HeyApiTypeScriptPlugin['Config'] = { 8 + api, 7 9 config: { 8 10 case: 'PascalCase', 9 11 exportFromIndex: true, ··· 15 17 name: '@hey-api/typescript', 16 18 output: 'types', 17 19 resolveConfig: (plugin, context) => { 20 + plugin.config.definitions = context.valueToObject({ 21 + defaultValue: { 22 + case: plugin.config.case ?? 'PascalCase', 23 + name: '{{name}}', 24 + }, 25 + mappers: { 26 + function: (name) => ({ name }), 27 + string: (name) => ({ name }), 28 + }, 29 + value: plugin.config.definitions, 30 + }); 31 + 18 32 plugin.config.enums = context.valueToObject({ 19 33 defaultValue: { 20 34 case: 'SCREAMING_SNAKE_CASE', ··· 27 41 string: (mode) => ({ mode }), 28 42 }, 29 43 value: plugin.config.enums, 44 + }); 45 + 46 + plugin.config.errors = context.valueToObject({ 47 + defaultValue: { 48 + case: plugin.config.case ?? 'PascalCase', 49 + error: '{{name}}Error', 50 + name: '{{name}}Errors', 51 + }, 52 + mappers: { 53 + function: (name) => ({ name }), 54 + string: (name) => ({ name }), 55 + }, 56 + value: plugin.config.errors, 57 + }); 58 + 59 + plugin.config.requests = context.valueToObject({ 60 + defaultValue: { 61 + case: plugin.config.case ?? 'PascalCase', 62 + name: '{{name}}Data', 63 + }, 64 + mappers: { 65 + function: (name) => ({ name }), 66 + string: (name) => ({ name }), 67 + }, 68 + value: plugin.config.requests, 69 + }); 70 + 71 + plugin.config.responses = context.valueToObject({ 72 + defaultValue: { 73 + case: plugin.config.case ?? 'PascalCase', 74 + name: '{{name}}Responses', 75 + response: '{{name}}Response', 76 + }, 77 + mappers: { 78 + function: (name) => ({ name }), 79 + string: (name) => ({ name }), 80 + }, 81 + value: plugin.config.responses, 30 82 }); 31 83 }, 32 84 };
+7 -22
packages/openapi-ts/src/plugins/@hey-api/typescript/plugin-legacy.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 3 import { type Comments, compiler } from '../../../compiler'; 4 - import { TypeScriptFile } from '../../../generate/files'; 4 + import { GeneratedFile } from '../../../generate/file'; 5 5 import { isOperationParameterRequired } from '../../../openApi'; 6 6 import type { 7 7 Client, ··· 128 128 }; 129 129 130 130 const processComposition = (props: TypesProps) => { 131 - const config = getConfig(); 132 - 133 131 const enumDeclarations = [] as ts.EnumDeclaration[]; 134 132 135 133 processType(props); 136 134 137 - props.model.enums.forEach((enumerator) => { 138 - const pluginTypeScript = config.plugins['@hey-api/typescript']; 139 - if ( 140 - pluginTypeScript?.config && 141 - typeof pluginTypeScript.config.enums === 'object' && 142 - pluginTypeScript.config.enums.mode !== 'typescript+namespace' 143 - ) { 144 - return processEnum({ 145 - ...props, 146 - model: enumerator, 147 - }); 148 - } 149 - 150 - return processScopedEnum({ 135 + props.model.enums.forEach((enumerator) => 136 + processScopedEnum({ 151 137 ...props, 152 138 model: enumerator, 153 139 onNode: (node) => { 154 140 enumDeclarations.push(node as ts.EnumDeclaration); 155 141 }, 156 - }); 157 - }); 142 + }), 143 + ); 158 144 159 145 if (enumDeclarations.length) { 160 146 props.onNode( ··· 190 176 pluginTypeScript?.config && 191 177 typeof pluginTypeScript.config.enums === 'object' && 192 178 pluginTypeScript.config.enums.enabled && 193 - (pluginTypeScript.config.enums.mode === 'typescript' || 194 - pluginTypeScript.config.enums.mode === 'typescript+namespace') 179 + pluginTypeScript.config.enums.mode === 'typescript' 195 180 ) { 196 181 generateEnum({ 197 182 client, ··· 625 610 }) => { 626 611 const config = getConfig(); 627 612 628 - files.types = new TypeScriptFile({ 613 + files.types = new GeneratedFile({ 629 614 dir: config.output.path, 630 615 exportFromIndex: plugin.config.exportFromIndex, 631 616 id: 'types',
+270 -566
packages/openapi-ts/src/plugins/@hey-api/typescript/plugin.ts
··· 5 5 import { operationResponsesMap } from '../../../ir/operation'; 6 6 import { deduplicateSchema } from '../../../ir/schema'; 7 7 import type { IR } from '../../../ir/types'; 8 - import { irRef, isRefOpenApiComponent } from '../../../utils/ref'; 8 + import { buildName } from '../../../openApi/shared/utils/name'; 9 + import { refToName } from '../../../utils/ref'; 9 10 import { numberRegExp } from '../../../utils/regexp'; 10 11 import { stringCase } from '../../../utils/stringCase'; 11 12 import { fieldName } from '../../shared/utils/case'; 12 - import { operationIrRef } from '../../shared/utils/ref'; 13 13 import { createSchemaComment } from '../../shared/utils/schema'; 14 14 import { createClientOptions } from './clientOptions'; 15 15 import { typesId } from './ref'; ··· 20 20 type: Extract<Required<IR.SchemaObject>['type'], T>; 21 21 } 22 22 23 - interface State { 24 - /** 25 - * If set, we keep the specified properties (read-only or write-only) and 26 - * strip the other type. 27 - */ 28 - accessScope?: 'read' | 'write'; 29 - /** 30 - * Path to the currently processed field. This can be used to generate 31 - * deduplicated inline types. For example, if two schemas define a different 32 - * enum `foo`, we want to generate two unique types instead of one. 33 - */ 34 - path: ReadonlyArray<string>; 35 - } 36 - 37 - const addJavaScriptEnum = ({ 38 - $ref, 39 - plugin, 40 - schema, 41 - }: { 42 - $ref: string; 43 - plugin: HeyApiTypeScriptPlugin['Instance']; 44 - schema: SchemaWithType<'enum'>; 45 - }) => { 46 - const file = plugin.context.file({ id: typesId })!; 47 - const identifier = file.identifier({ 48 - $ref, 49 - create: true, 50 - namespace: 'value', 51 - }); 52 - 53 - // TODO: parser - this is the old parser behavior where we would NOT 54 - // print nested enum identifiers if they already exist. This is a 55 - // blocker for referencing these identifiers within the file as 56 - // we cannot guarantee just because they have a duplicate identifier, 57 - // they have a duplicate value. 58 - if (!identifier.created) { 59 - return; 60 - } 61 - 62 - const enumObject = schemaToEnumObject({ plugin, schema }); 63 - 64 - // JavaScript enums might want to ignore null values 65 - if ( 66 - plugin.config.enums.constantsIgnoreNull && 67 - enumObject.typeofItems.includes('object') 68 - ) { 69 - enumObject.obj = enumObject.obj.filter((item) => item.value !== null); 70 - } 71 - 72 - const expression = compiler.objectExpression({ 73 - multiLine: true, 74 - obj: enumObject.obj, 75 - }); 76 - const node = compiler.constVariable({ 77 - assertion: 'const', 78 - comment: createSchemaComment({ schema }), 79 - exportConst: true, 80 - expression, 81 - name: identifier.name || '', 82 - }); 83 - return node; 84 - }; 85 - 86 23 const schemaToEnumObject = ({ 87 24 plugin, 88 25 schema, ··· 135 72 if ( 136 73 numberRegExp.test(key) && 137 74 plugin.config.enums.enabled && 138 - (plugin.config.enums.mode === 'typescript' || 139 - plugin.config.enums.mode === 'typescript+namespace') 75 + plugin.config.enums.mode === 'typescript' 140 76 ) { 141 77 key = `_${key}`; 142 78 } ··· 155 91 }; 156 92 }; 157 93 158 - const addTypeEnum = ({ 159 - $ref, 160 - plugin, 161 - schema, 162 - state, 163 - }: { 164 - $ref: string; 165 - plugin: HeyApiTypeScriptPlugin['Instance']; 166 - schema: SchemaWithType<'enum'>; 167 - state: State | undefined; 168 - }): ts.TypeAliasDeclaration | undefined => { 169 - const file = plugin.context.file({ id: typesId })!; 170 - const identifier = file.identifier({ 171 - $ref, 172 - create: true, 173 - namespace: 'type', 174 - }); 175 - 176 - // TODO: parser - this is the old parser behavior where we would NOT 177 - // print nested enum identifiers if they already exist. This is a 178 - // blocker for referencing these identifiers within the file as 179 - // we cannot guarantee just because they have a duplicate identifier, 180 - // they have a duplicate value. 181 - if ( 182 - !identifier.created && 183 - !isRefOpenApiComponent($ref) && 184 - plugin.config.enums.mode !== 'typescript+namespace' 185 - ) { 186 - return; 187 - } 188 - 189 - const type = schemaToType({ 190 - plugin, 191 - schema: { 192 - ...schema, 193 - type: undefined, 194 - }, 195 - state, 196 - }); 197 - 198 - if (type) { 199 - const node = compiler.typeAliasDeclaration({ 200 - comment: createSchemaComment({ schema }), 201 - exportType: true, 202 - name: identifier.name || '', 203 - type, 204 - }); 205 - return node; 206 - } 207 - 208 - return; 209 - }; 210 - 211 - const shouldCreateTypeScriptEnum = ({ 212 - plugin, 213 - schema, 214 - }: { 215 - plugin: HeyApiTypeScriptPlugin['Instance']; 216 - schema: SchemaWithType<'enum'>; 217 - }) => { 218 - const enumObject = schemaToEnumObject({ plugin, schema }); 219 - // TypeScript enums support only string and number values 220 - return !enumObject.typeofItems.filter( 221 - (type) => type !== 'number' && type !== 'string', 222 - ).length; 223 - }; 224 - 225 - const addTypeScriptEnum = ({ 226 - $ref, 227 - plugin, 228 - schema, 229 - state, 230 - }: { 231 - $ref: string; 232 - plugin: HeyApiTypeScriptPlugin['Instance']; 233 - schema: SchemaWithType<'enum'>; 234 - state: State | undefined; 235 - }) => { 236 - const enumObject = schemaToEnumObject({ plugin, schema }); 237 - 238 - // fallback to types 239 - if (!shouldCreateTypeScriptEnum({ plugin, schema })) { 240 - const node = addTypeEnum({ 241 - $ref, 242 - plugin, 243 - schema, 244 - state, 245 - }); 246 - return node; 247 - } 248 - 249 - const file = plugin.context.file({ id: typesId })!; 250 - const identifier = file.identifier({ 251 - $ref, 252 - create: true, 253 - namespace: 'enum', 254 - }); 255 - const node = compiler.enumDeclaration({ 256 - leadingComment: createSchemaComment({ schema }), 257 - name: identifier.name || '', 258 - obj: enumObject.obj, 259 - }); 260 - return node; 261 - }; 262 - 263 94 const arrayTypeToIdentifier = ({ 264 - namespace, 265 95 plugin, 266 96 schema, 267 - state, 268 97 }: { 269 - namespace: Array<ts.Statement>; 270 98 plugin: HeyApiTypeScriptPlugin['Instance']; 271 99 schema: SchemaWithType<'array'>; 272 - state: State | undefined; 273 - }): ts.TypeNode | undefined => { 100 + }): ts.TypeNode => { 274 101 if (!schema.items) { 275 102 return compiler.typeArrayNode( 276 103 compiler.keywordTypeNode({ ··· 285 112 286 113 for (const item of schema.items!) { 287 114 const type = schemaToType({ 288 - namespace, 289 115 plugin, 290 116 schema: item, 291 - state, 292 117 }); 293 - 294 - if (type) { 295 - itemTypes.push(type); 296 - } 297 - } 298 - 299 - if (!itemTypes.length) { 300 - return; 118 + itemTypes.push(type); 301 119 } 302 120 303 121 if (itemTypes.length === 1) { ··· 316 134 const booleanTypeToIdentifier = ({ 317 135 schema, 318 136 }: { 319 - namespace: Array<ts.Statement>; 320 137 schema: SchemaWithType<'boolean'>; 321 138 }): ts.TypeNode => { 322 139 if (schema.const !== undefined) { ··· 331 148 }; 332 149 333 150 const enumTypeToIdentifier = ({ 334 - $ref, 335 - namespace, 336 151 plugin, 337 152 schema, 338 - state, 339 153 }: { 340 - $ref?: string; 341 - namespace: Array<ts.Statement>; 342 154 plugin: HeyApiTypeScriptPlugin['Instance']; 343 155 schema: SchemaWithType<'enum'>; 344 - state: State | undefined; 345 - }): ts.TypeNode | undefined => { 346 - const file = plugin.context.file({ id: typesId })!; 347 - const isRefComponent = $ref ? isRefOpenApiComponent($ref) : false; 348 - 349 - if ($ref && isRefComponent) { 350 - // when enums are disabled (default), emit only reusable components 351 - // as types, otherwise the output would be broken if we skipped all enums 352 - if (!plugin.config.enums.enabled) { 353 - const typeNode = addTypeEnum({ 354 - $ref, 355 - plugin, 356 - schema, 357 - state, 358 - }); 359 - if (typeNode) { 360 - file.add(typeNode); 361 - } 362 - } 363 - 364 - if (plugin.config.enums.enabled) { 365 - if (plugin.config.enums.mode === 'javascript') { 366 - const typeNode = addTypeEnum({ 367 - $ref, 368 - plugin, 369 - schema, 370 - state, 371 - }); 372 - if (typeNode) { 373 - file.add(typeNode); 374 - } 375 - 376 - const objectNode = addJavaScriptEnum({ 377 - $ref, 378 - plugin, 379 - schema, 380 - }); 381 - if (objectNode) { 382 - file.add(objectNode); 383 - } 384 - } 385 - 386 - if (plugin.config.enums.mode === 'typescript') { 387 - const enumNode = addTypeScriptEnum({ 388 - $ref, 389 - plugin, 390 - schema, 391 - state, 392 - }); 393 - if (enumNode) { 394 - file.add(enumNode); 395 - } 396 - } 397 - 398 - if (plugin.config.enums.mode === 'typescript+namespace') { 399 - const enumNode = addTypeScriptEnum({ 400 - $ref, 401 - plugin, 402 - schema, 403 - state, 404 - }); 405 - if (enumNode) { 406 - if (isRefComponent) { 407 - file.add(enumNode); 408 - } else { 409 - // emit enum inside TypeScript namespace 410 - namespace.push(enumNode); 411 - } 412 - } 413 - } 414 - } 415 - } 416 - 156 + }): ts.TypeNode => { 417 157 const type = schemaToType({ 418 158 plugin, 419 159 schema: { 420 160 ...schema, 421 161 type: undefined, 422 162 }, 423 - state, 424 163 }); 425 164 return type; 426 165 }; ··· 429 168 plugin, 430 169 schema, 431 170 }: { 432 - namespace: Array<ts.Statement>; 433 171 plugin: HeyApiTypeScriptPlugin['Instance']; 434 172 schema: SchemaWithType<'integer' | 'number'>; 435 173 }): ts.TypeNode => { ··· 452 190 }; 453 191 454 192 const objectTypeToIdentifier = ({ 455 - namespace, 456 193 plugin, 457 194 schema, 458 - state, 459 195 }: { 460 - namespace: Array<ts.Statement>; 461 196 plugin: HeyApiTypeScriptPlugin['Instance']; 462 197 schema: SchemaWithType<'object'>; 463 - state: State | undefined; 464 - }): ts.TypeNode | undefined => { 198 + }): ts.TypeNode => { 465 199 const file = plugin.context.file({ id: typesId })!; 466 200 467 201 // TODO: parser - handle constants 468 - let indexKey: string | undefined; 202 + let indexKey: ts.TypeReferenceNode | undefined; 469 203 let indexProperty: Property | undefined; 470 204 const schemaProperties: Array<Property> = []; 471 205 let indexPropertyItems: Array<IR.SchemaObject> = []; ··· 474 208 475 209 for (const name in schema.properties) { 476 210 const property = schema.properties[name]!; 477 - 478 211 const propertyType = schemaToType({ 479 - $ref: state ? [...state.path, name].join('/') : `${irRef}${name}`, 480 - namespace, 481 212 plugin, 482 213 schema: property, 483 - state, 484 214 }); 485 - 486 - if (!propertyType) { 487 - continue; 488 - } 489 - 490 215 const isRequired = required.includes(name); 491 216 schemaProperties.push({ 492 217 comment: createSchemaComment({ schema: property }), ··· 522 247 isRequired: !schema.propertyNames, 523 248 name: 'key', 524 249 type: schemaToType({ 525 - namespace, 526 250 plugin, 527 251 schema: 528 252 indexPropertyItems.length === 1 ··· 531 255 items: indexPropertyItems, 532 256 logicalOperator: 'or', 533 257 }, 534 - state, 535 258 }), 536 259 }; 537 260 538 261 if (schema.propertyNames?.$ref) { 539 - const identifier = file.identifier({ 540 - $ref: schema.propertyNames.$ref, 541 - create: true, 542 - namespace: 'type', 543 - }); 544 - if (identifier.name) { 545 - indexKey = identifier.name; 546 - } 262 + indexKey = file.getNode( 263 + plugin.api.getId({ type: 'ref', value: schema.propertyNames.$ref }), 264 + ).node; 547 265 } 548 266 } 549 267 ··· 559 277 plugin, 560 278 schema, 561 279 }: { 562 - namespace: Array<ts.Statement>; 563 280 plugin: HeyApiTypeScriptPlugin['Instance']; 564 281 schema: SchemaWithType<'string'>; 565 282 }): ts.TypeNode => { ··· 597 314 }; 598 315 599 316 const tupleTypeToIdentifier = ({ 600 - namespace, 601 317 plugin, 602 318 schema, 603 - state, 604 319 }: { 605 - namespace: Array<ts.Statement>; 606 320 plugin: HeyApiTypeScriptPlugin['Instance']; 607 321 schema: SchemaWithType<'tuple'>; 608 - state: State | undefined; 609 - }): ts.TypeNode | undefined => { 322 + }): ts.TypeNode => { 610 323 let itemTypes: Array<ts.Expression | ts.TypeNode> = []; 611 324 612 325 if (schema.const && Array.isArray(schema.const)) { ··· 617 330 } else if (schema.items) { 618 331 for (const item of schema.items) { 619 332 const type = schemaToType({ 620 - namespace, 621 333 plugin, 622 334 schema: item, 623 - state, 624 335 }); 625 - 626 - if (type) { 627 - itemTypes.push(type); 628 - } 336 + itemTypes.push(type); 629 337 } 630 338 } 631 339 632 - if (!itemTypes.length) { 633 - return; 634 - } 635 - 636 340 return compiler.typeTupleNode({ 637 341 types: itemTypes, 638 342 }); 639 343 }; 640 344 641 345 const schemaTypeToIdentifier = ({ 642 - $ref, 643 - namespace, 644 346 plugin, 645 347 schema, 646 - state, 647 348 }: { 648 - $ref?: string; 649 - namespace: Array<ts.Statement>; 650 349 plugin: HeyApiTypeScriptPlugin['Instance']; 651 350 schema: IR.SchemaObject; 652 - state: State | undefined; 653 - }): ts.TypeNode | undefined => { 351 + }): ts.TypeNode => { 654 352 switch (schema.type as Required<IR.SchemaObject>['type']) { 655 353 case 'array': 656 354 return arrayTypeToIdentifier({ 657 - namespace, 658 355 plugin, 659 356 schema: schema as SchemaWithType<'array'>, 660 - state, 661 357 }); 662 358 case 'boolean': 663 359 return booleanTypeToIdentifier({ 664 - namespace, 665 360 schema: schema as SchemaWithType<'boolean'>, 666 361 }); 667 362 case 'enum': 668 363 return enumTypeToIdentifier({ 669 - $ref, 670 - namespace, 671 364 plugin, 672 365 schema: schema as SchemaWithType<'enum'>, 673 - state, 674 366 }); 675 367 case 'integer': 676 368 case 'number': 677 369 return numberTypeToIdentifier({ 678 - namespace, 679 370 plugin, 680 371 schema: schema as SchemaWithType<'integer' | 'number'>, 681 372 }); ··· 689 380 }); 690 381 case 'object': 691 382 return objectTypeToIdentifier({ 692 - namespace, 693 383 plugin, 694 384 schema: schema as SchemaWithType<'object'>, 695 - state, 696 385 }); 697 386 case 'string': 698 387 return stringTypeToIdentifier({ 699 - namespace, 700 388 plugin, 701 389 schema: schema as SchemaWithType<'string'>, 702 390 }); 703 391 case 'tuple': 704 392 return tupleTypeToIdentifier({ 705 - namespace, 706 393 plugin, 707 394 schema: schema as SchemaWithType<'tuple'>, 708 - state, 709 395 }); 710 396 case 'undefined': 711 397 return compiler.keywordTypeNode({ ··· 836 522 837 523 data.required = dataRequired; 838 524 839 - const identifier = file.identifier({ 840 - $ref: operationIrRef({ 841 - config: plugin.context.config, 842 - id: operation.id, 843 - type: 'data', 844 - }), 845 - create: true, 846 - namespace: 'type', 525 + const name = buildName({ 526 + config: plugin.config.requests, 527 + name: operation.id, 847 528 }); 529 + const nodeInfo = file.updateNode( 530 + plugin.api.getId({ operation, type: 'data' }), 531 + { 532 + exported: true, 533 + name, 534 + }, 535 + ); 848 536 const type = schemaToType({ 849 537 plugin, 850 538 schema: data, 851 - state: { 852 - path: [operation.method, operation.path, 'data'], 853 - }, 854 539 }); 855 - 856 - if (type) { 857 - const node = compiler.typeAliasDeclaration({ 858 - exportType: true, 859 - name: identifier.name || '', 860 - type, 861 - }); 862 - file.add(node); 863 - } 540 + const node = compiler.typeAliasDeclaration({ 541 + exportType: nodeInfo.exported, 542 + name: nodeInfo.node, 543 + type, 544 + }); 545 + file.add(node); 864 546 }; 865 547 866 548 const operationToType = ({ ··· 878 560 operationResponsesMap(operation); 879 561 880 562 if (errors) { 881 - const identifierErrors = file.identifier({ 882 - $ref: operationIrRef({ 883 - config: plugin.context.config, 884 - id: operation.id, 885 - type: 'errors', 886 - }), 887 - create: true, 888 - namespace: 'type', 563 + const name = buildName({ 564 + config: plugin.config.errors, 565 + name: operation.id, 889 566 }); 890 - if (identifierErrors.name) { 891 - const type = schemaToType({ 892 - plugin, 893 - schema: errors, 894 - state: { 895 - path: [operation.method, operation.path, 'errors'], 567 + const nodeInfo = file.updateNode( 568 + plugin.api.getId({ operation, type: 'errors' }), 569 + { 570 + exported: true, 571 + name, 572 + }, 573 + ); 574 + const type = schemaToType({ 575 + plugin, 576 + schema: errors, 577 + }); 578 + const node = compiler.typeAliasDeclaration({ 579 + exportType: nodeInfo.exported, 580 + name: nodeInfo.node, 581 + type, 582 + }); 583 + file.add(node); 584 + 585 + if (error) { 586 + const name = buildName({ 587 + config: { 588 + case: plugin.config.errors.case, 589 + name: plugin.config.errors.error, 896 590 }, 591 + name: operation.id, 897 592 }); 898 - 899 - if (type) { 900 - const node = compiler.typeAliasDeclaration({ 901 - exportType: true, 902 - name: identifierErrors.name, 903 - type, 904 - }); 905 - file.add(node); 906 - } 907 - 908 - if (error) { 909 - const identifierError = file.identifier({ 910 - $ref: operationIrRef({ 911 - config: plugin.context.config, 912 - id: operation.id, 913 - type: 'error', 914 - }), 915 - create: true, 916 - namespace: 'type', 917 - }); 918 - if (identifierError.name) { 919 - const errorsType = compiler.typeReferenceNode({ 920 - typeName: identifierErrors.name, 921 - }); 922 - const keyofType = ts.factory.createTypeOperatorNode( 923 - ts.SyntaxKind.KeyOfKeyword, 924 - errorsType, 925 - ); 926 - const node = compiler.typeAliasDeclaration({ 927 - exportType: true, 928 - name: identifierError.name, 929 - type: compiler.indexedAccessTypeNode({ 930 - indexType: keyofType, 931 - objectType: errorsType, 932 - }), 933 - }); 934 - file.add(node); 935 - } 936 - } 593 + const errorNodeInfo = file.updateNode( 594 + plugin.api.getId({ operation, type: 'error' }), 595 + { 596 + exported: true, 597 + name, 598 + }, 599 + ); 600 + const type = compiler.indexedAccessTypeNode({ 601 + indexType: ts.factory.createTypeOperatorNode( 602 + ts.SyntaxKind.KeyOfKeyword, 603 + nodeInfo.node, 604 + ), 605 + objectType: nodeInfo.node, 606 + }); 607 + const node = compiler.typeAliasDeclaration({ 608 + exportType: errorNodeInfo.exported, 609 + name: errorNodeInfo.node, 610 + type, 611 + }); 612 + file.add(node); 937 613 } 938 614 } 939 615 940 616 if (responses) { 941 - const identifierResponses = file.identifier({ 942 - $ref: operationIrRef({ 943 - config: plugin.context.config, 944 - id: operation.id, 945 - type: 'responses', 946 - }), 947 - create: true, 948 - namespace: 'type', 617 + const name = buildName({ 618 + config: plugin.config.responses, 619 + name: operation.id, 949 620 }); 950 - if (identifierResponses.name) { 951 - const type = schemaToType({ 952 - plugin, 953 - schema: responses, 954 - state: { 955 - path: [operation.method, operation.path, 'responses'], 621 + const nodeInfo = file.updateNode( 622 + plugin.api.getId({ operation, type: 'responses' }), 623 + { 624 + exported: true, 625 + name, 626 + }, 627 + ); 628 + const type = schemaToType({ 629 + plugin, 630 + schema: responses, 631 + }); 632 + const node = compiler.typeAliasDeclaration({ 633 + exportType: nodeInfo.exported, 634 + name: nodeInfo.node, 635 + type, 636 + }); 637 + file.add(node); 638 + 639 + if (response) { 640 + const name = buildName({ 641 + config: { 642 + case: plugin.config.responses.case, 643 + name: plugin.config.responses.response, 644 + }, 645 + name: operation.id, 646 + }); 647 + const responseNodeInfo = file.updateNode( 648 + plugin.api.getId({ operation, type: 'response' }), 649 + { 650 + exported: true, 651 + name, 956 652 }, 653 + ); 654 + const type = compiler.indexedAccessTypeNode({ 655 + indexType: ts.factory.createTypeOperatorNode( 656 + ts.SyntaxKind.KeyOfKeyword, 657 + nodeInfo.node, 658 + ), 659 + objectType: nodeInfo.node, 957 660 }); 958 - 959 - if (type) { 960 - const node = compiler.typeAliasDeclaration({ 961 - exportType: true, 962 - name: identifierResponses.name, 963 - type, 964 - }); 965 - file.add(node); 966 - } 967 - 968 - if (response) { 969 - const identifierResponse = file.identifier({ 970 - $ref: operationIrRef({ 971 - config: plugin.context.config, 972 - id: operation.id, 973 - type: 'response', 974 - }), 975 - create: true, 976 - namespace: 'type', 977 - }); 978 - if (identifierResponse.name) { 979 - const responsesType = compiler.typeReferenceNode({ 980 - typeName: identifierResponses.name, 981 - }); 982 - const keyofType = ts.factory.createTypeOperatorNode( 983 - ts.SyntaxKind.KeyOfKeyword, 984 - responsesType, 985 - ); 986 - const node = compiler.typeAliasDeclaration({ 987 - exportType: true, 988 - name: identifierResponse.name, 989 - type: compiler.indexedAccessTypeNode({ 990 - indexType: keyofType, 991 - objectType: responsesType, 992 - }), 993 - }); 994 - file.add(node); 995 - } 996 - } 661 + const node = compiler.typeAliasDeclaration({ 662 + exportType: responseNodeInfo.exported, 663 + name: responseNodeInfo.node, 664 + type, 665 + }); 666 + file.add(node); 997 667 } 998 668 } 999 669 }; 1000 670 1001 671 export const schemaToType = ({ 1002 - $ref, 1003 - namespace = [], 1004 672 plugin, 1005 673 schema, 1006 - state, 1007 674 }: { 1008 - $ref?: string; 1009 - namespace?: Array<ts.Statement>; 1010 675 plugin: HeyApiTypeScriptPlugin['Instance']; 1011 676 schema: IR.SchemaObject; 1012 - state: State | undefined; 1013 - }): ts.TypeNode | undefined => { 677 + }): ts.TypeNode => { 1014 678 const file = plugin.context.file({ id: typesId })!; 1015 - 1016 - let type: ts.TypeNode | undefined; 1017 679 1018 680 if (schema.$ref) { 1019 - const refSchema = plugin.context.resolveIrRef<IR.SchemaObject>(schema.$ref); 681 + return file.getNode(plugin.api.getId({ type: 'ref', value: schema.$ref })) 682 + .node; 683 + } 1020 684 1021 - const identifier = file.identifier({ 1022 - $ref: schema.$ref, 1023 - create: true, 1024 - namespace: 1025 - refSchema.type === 'enum' && 1026 - plugin.config.enums.enabled && 1027 - (plugin.config.enums.mode === 'typescript' || 1028 - plugin.config.enums.mode === 'typescript+namespace') && 1029 - shouldCreateTypeScriptEnum({ 1030 - plugin, 1031 - schema: refSchema as SchemaWithType<'enum'>, 1032 - }) 1033 - ? 'enum' 1034 - : 'type', 1035 - }); 1036 - type = compiler.typeReferenceNode({ 1037 - typeName: identifier.name || '', 1038 - }); 1039 - } else if (schema.type) { 1040 - type = schemaTypeToIdentifier({ 1041 - $ref, 1042 - namespace, 1043 - plugin, 1044 - schema, 1045 - state, 1046 - }); 1047 - } else if (schema.items) { 685 + if (schema.type) { 686 + return schemaTypeToIdentifier({ plugin, schema }); 687 + } 688 + 689 + if (schema.items) { 1048 690 schema = deduplicateSchema({ detectFormat: false, schema }); 1049 691 if (schema.items) { 1050 692 const itemTypes: Array<ts.TypeNode> = []; 1051 693 1052 694 for (const item of schema.items) { 1053 - // TODO: correctly populate state.path 1054 695 const type = schemaToType({ 1055 - namespace, 1056 696 plugin, 1057 697 schema: item, 1058 - state, 1059 698 }); 1060 - if (type) { 1061 - itemTypes.push(type); 1062 - } 699 + itemTypes.push(type); 1063 700 } 1064 701 1065 - type = 1066 - schema.logicalOperator === 'and' 1067 - ? compiler.typeIntersectionNode({ types: itemTypes }) 1068 - : compiler.typeUnionNode({ types: itemTypes }); 1069 - } else { 1070 - // TODO: correctly populate state.path 1071 - type = schemaToType({ 1072 - namespace, 1073 - plugin, 1074 - schema, 1075 - state, 1076 - }); 702 + return schema.logicalOperator === 'and' 703 + ? compiler.typeIntersectionNode({ types: itemTypes }) 704 + : compiler.typeUnionNode({ types: itemTypes }); 1077 705 } 1078 - } else { 1079 - // catch-all fallback for failed schemas 1080 - type = schemaTypeToIdentifier({ 1081 - namespace, 706 + 707 + return schemaToType({ 1082 708 plugin, 1083 - schema: { 1084 - type: 'unknown', 1085 - }, 1086 - state, 709 + schema, 1087 710 }); 1088 711 } 1089 712 1090 - // emit nodes only if $ref points to a reusable component 1091 - if ($ref && isRefOpenApiComponent($ref)) { 1092 - // emit namespace if it has any members 1093 - if (namespace.length) { 1094 - const identifier = file.identifier({ 1095 - $ref, 1096 - create: true, 1097 - namespace: 'value', 1098 - }); 1099 - const node = compiler.namespaceDeclaration({ 1100 - name: identifier.name || '', 1101 - statements: namespace, 713 + // catch-all fallback for failed schemas 714 + return schemaTypeToIdentifier({ 715 + plugin, 716 + schema: { 717 + type: 'unknown', 718 + }, 719 + }); 720 + }; 721 + 722 + const exportType = ({ 723 + id, 724 + plugin, 725 + schema, 726 + type, 727 + }: { 728 + id: string; 729 + plugin: HeyApiTypeScriptPlugin['Instance']; 730 + schema: IR.SchemaObject; 731 + type: ts.TypeNode; 732 + }) => { 733 + const file = plugin.context.file({ id: typesId })!; 734 + 735 + const nodeInfo = file.getNode(plugin.api.getId({ type: 'ref', value: id })); 736 + 737 + // root enums have an additional export 738 + if (schema.type === 'enum' && plugin.config.enums.enabled) { 739 + const enumObject = schemaToEnumObject({ plugin, schema }); 740 + 741 + if (plugin.config.enums.mode === 'javascript') { 742 + // JavaScript enums might want to ignore null values 743 + if ( 744 + plugin.config.enums.constantsIgnoreNull && 745 + enumObject.typeofItems.includes('object') 746 + ) { 747 + enumObject.obj = enumObject.obj.filter((item) => item.value !== null); 748 + } 749 + 750 + const objectNode = compiler.constVariable({ 751 + assertion: 'const', 752 + comment: createSchemaComment({ schema }), 753 + exportConst: nodeInfo.exported, 754 + expression: compiler.objectExpression({ 755 + multiLine: true, 756 + obj: enumObject.obj, 757 + }), 758 + name: nodeInfo.node, 1102 759 }); 1103 - file.add(node); 1104 - } 760 + file.add(objectNode); 1105 761 1106 - // enum handler emits its own artifacts 1107 - if (schema.type !== 'enum' && type) { 1108 - const identifier = file.identifier({ 1109 - $ref, 1110 - create: true, 1111 - namespace: 'type', 1112 - }); 762 + // TODO: https://github.com/hey-api/openapi-ts/issues/2289 763 + const typeofType = compiler.typeOfExpression({ 764 + text: nodeInfo.node.typeName as unknown as string, 765 + }) as unknown as ts.TypeNode; 766 + const keyofType = ts.factory.createTypeOperatorNode( 767 + ts.SyntaxKind.KeyOfKeyword, 768 + typeofType, 769 + ); 1113 770 const node = compiler.typeAliasDeclaration({ 1114 771 comment: createSchemaComment({ schema }), 1115 - exportType: true, 1116 - name: identifier.name || '', 1117 - type, 772 + exportType: nodeInfo.exported, 773 + name: nodeInfo.node, 774 + type: compiler.indexedAccessTypeNode({ 775 + indexType: keyofType, 776 + objectType: typeofType, 777 + }), 1118 778 }); 1119 779 file.add(node); 780 + return; 781 + } else if (plugin.config.enums.mode === 'typescript') { 782 + // TypeScript enums support only string and number values 783 + const shouldCreateTypeScriptEnum = !enumObject.typeofItems.some( 784 + (type) => type !== 'number' && type !== 'string', 785 + ); 786 + if (shouldCreateTypeScriptEnum) { 787 + const enumNode = compiler.enumDeclaration({ 788 + leadingComment: createSchemaComment({ schema }), 789 + name: nodeInfo.node, 790 + obj: enumObject.obj, 791 + }); 792 + file.add(enumNode); 793 + return; 794 + } 1120 795 } 1121 796 } 1122 797 1123 - return type; 798 + const node = compiler.typeAliasDeclaration({ 799 + comment: createSchemaComment({ schema }), 800 + exportType: nodeInfo.exported, 801 + name: nodeInfo.node, 802 + type, 803 + }); 804 + file.add(node); 805 + }; 806 + 807 + const handleComponent = ({ 808 + id, 809 + plugin, 810 + schema, 811 + }: { 812 + id: string; 813 + plugin: HeyApiTypeScriptPlugin['Instance']; 814 + schema: IR.SchemaObject; 815 + }) => { 816 + const file = plugin.context.file({ id: typesId })!; 817 + const type = schemaToType({ plugin, schema }); 818 + const name = buildName({ 819 + config: plugin.config.definitions, 820 + name: refToName(id), 821 + }); 822 + file.updateNode(plugin.api.getId({ type: 'ref', value: id }), { 823 + exported: true, 824 + name, 825 + }); 826 + exportType({ 827 + id, 828 + plugin, 829 + schema, 830 + type, 831 + }); 1124 832 }; 1125 833 1126 834 export const handler: HeyApiTypeScriptPlugin['Handler'] = ({ plugin }) => { 1127 835 const file = plugin.createFile({ 836 + case: plugin.config.case, 1128 837 id: typesId, 1129 - identifierCase: plugin.config.case, 1130 838 path: plugin.output, 1131 839 }); 1132 840 1133 841 // reserve identifier for ClientOptions 1134 - const clientOptions = file.identifier({ 1135 - $ref: 'ClientOptions', 1136 - create: true, 1137 - namespace: 'type', 842 + const clientOptionsName = buildName({ 843 + config: { 844 + case: plugin.config.case, 845 + }, 846 + name: 'ClientOptions', 1138 847 }); 848 + const clientOptionsNodeInfo = file.updateNode( 849 + plugin.api.getId({ type: 'ClientOptions' }), 850 + { 851 + exported: true, 852 + name: clientOptionsName, 853 + }, 854 + ); 1139 855 1140 856 const servers: Array<IR.ServerObject> = []; 1141 857 ··· 1149 865 if (event.type === 'operation') { 1150 866 operationToType({ operation: event.operation, plugin }); 1151 867 } else if (event.type === 'parameter') { 1152 - schemaToType({ 1153 - $ref: event.$ref, 868 + handleComponent({ 869 + id: event.$ref, 1154 870 plugin, 1155 871 schema: event.parameter.schema, 1156 - state: { 1157 - // TODO: correctly populate state.path 1158 - path: [], 1159 - }, 1160 872 }); 1161 873 } else if (event.type === 'requestBody') { 1162 - schemaToType({ 1163 - $ref: event.$ref, 874 + handleComponent({ 875 + id: event.$ref, 1164 876 plugin, 1165 877 schema: event.requestBody.schema, 1166 - state: { 1167 - // TODO: correctly populate state.path 1168 - path: [], 1169 - }, 1170 878 }); 1171 879 } else if (event.type === 'schema') { 1172 - schemaToType({ 1173 - $ref: event.$ref, 880 + handleComponent({ 881 + id: event.$ref, 1174 882 plugin, 1175 883 schema: event.schema, 1176 - state: { 1177 - // TODO: correctly populate state.path 1178 - path: [], 1179 - }, 1180 884 }); 1181 885 } else if (event.type === 'server') { 1182 886 servers.push(event.server); ··· 1184 888 }, 1185 889 ); 1186 890 1187 - createClientOptions({ identifier: clientOptions, plugin, servers }); 891 + createClientOptions({ nodeInfo: clientOptionsNodeInfo, plugin, servers }); 1188 892 };
-47
packages/openapi-ts/src/plugins/@hey-api/typescript/ref.ts
··· 1 - import type { Identifier, TypeScriptFile } from '../../../generate/files'; 2 - import type { IR } from '../../../ir/types'; 3 - import { operationIrRef } from '../../shared/utils/ref'; 4 - 5 1 export const typesId = 'types'; 6 - 7 - function refIdentifier<T extends Identifier>( 8 - identifier: T, 9 - onGet?: (identifier: T) => void, 10 - ): T { 11 - return { 12 - ...identifier, 13 - get name() { 14 - onGet?.(identifier); 15 - return identifier.name; 16 - }, 17 - }; 18 - } 19 - 20 - export const importIdentifier = ({ 21 - context, 22 - file, 23 - operation, 24 - type, 25 - }: { 26 - context: IR.Context; 27 - file: TypeScriptFile; 28 - operation: IR.OperationObject; 29 - type: Parameters<typeof operationIrRef>[0]['type']; 30 - }): Identifier => { 31 - const identifier = context.file({ id: typesId })!.identifier({ 32 - $ref: operationIrRef({ 33 - config: context.config, 34 - id: operation.id, 35 - type, 36 - }), 37 - namespace: 'type', 38 - }); 39 - return refIdentifier(identifier, (ref) => { 40 - if (ref.name) { 41 - file.import({ 42 - asType: true, 43 - module: file.relativePathToFile({ context, id: typesId }), 44 - name: ref.name, 45 - }); 46 - } 47 - }); 48 - };
+234 -7
packages/openapi-ts/src/plugins/@hey-api/typescript/types.d.ts
··· 1 - import type { StringCase } from '../../../types/case'; 1 + import type { StringCase, StringName } from '../../../types/case'; 2 2 import type { DefinePlugin, Plugin } from '../../types'; 3 + import type { Api } from './api'; 3 4 4 - export type EnumsType = 'javascript' | 'typescript' | 'typescript+namespace'; 5 + export type EnumsType = 'javascript' | 'typescript'; 5 6 6 - export type Config = Plugin.Name<'@hey-api/typescript'> & { 7 + export type UserConfig = Plugin.Name<'@hey-api/typescript'> & { 7 8 /** 8 9 * The casing convention to use for generated names. 9 10 * ··· 11 12 */ 12 13 case?: Exclude<StringCase, 'SCREAMING_SNAKE_CASE'>; 13 14 /** 15 + * Configuration for reusable schema definitions. 16 + * 17 + * Controls generation of shared types that can be referenced across 18 + * requests and responses. 19 + * 20 + * Can be: 21 + * - `string` or `function`: Shorthand for `{ name: string | function }` 22 + * - `object`: Full configuration object 23 + * 24 + * @default '{{name}}' 25 + */ 26 + definitions?: 27 + | StringName 28 + | { 29 + /** 30 + * The casing convention to use for generated definition names. 31 + * 32 + * @default 'PascalCase' 33 + */ 34 + case?: StringCase; 35 + /** 36 + * Custom naming pattern for generated definition names. The name variable 37 + * is obtained from the schema name. 38 + * 39 + * @default '{{name}}' 40 + */ 41 + name?: StringName; 42 + }; 43 + /** 14 44 * By default, enums are emitted as types to preserve runtime-free output. 15 45 * 16 46 * However, you may want to generate enums as JavaScript objects or ··· 51 81 * Can be: 52 82 * - `javascript`: Generates JavaScript objects 53 83 * - `typescript`: Generates TypeScript enums 54 - * - `typescript+namespace`: Generates TypeScript enums within a namespace 55 84 * 56 85 * @default 'javascript' 57 86 */ 58 87 mode?: EnumsType; 59 88 }; 60 89 /** 90 + * Configuration for error-specific types. 91 + * 92 + * Controls generation of types for error response bodies and status codes. 93 + * 94 + * Can be: 95 + * - `string` or `function`: Shorthand for `{ name: string | function }` 96 + * - `object`: Full configuration object 97 + * 98 + * @default '{{name}}Errors' 99 + */ 100 + errors?: 101 + | StringName 102 + | { 103 + /** 104 + * The casing convention to use for generated error type names. 105 + * 106 + * @default 'PascalCase' 107 + */ 108 + case?: StringCase; 109 + /** 110 + * Custom naming pattern for generated error type names. The name 111 + * variable is obtained from the operation name. 112 + * 113 + * @default '{{name}}Error' 114 + */ 115 + error?: StringName; 116 + /** 117 + * Custom naming pattern for generated error type names. The name 118 + * variable is obtained from the operation name. 119 + * 120 + * @default '{{name}}Errors' 121 + */ 122 + name?: StringName; 123 + }; 124 + /** 61 125 * Should the exports from the generated files be re-exported in the index 62 126 * barrel file? 63 127 * ··· 70 134 * @default 'types' 71 135 */ 72 136 output?: string; 137 + /** 138 + * Configuration for request-specific types. 139 + * 140 + * Controls generation of types for request bodies, query parameters, path 141 + * parameters, and headers. 142 + * 143 + * Can be: 144 + * - `string` or `function`: Shorthand for `{ name: string | function }` 145 + * - `object`: Full configuration object 146 + * 147 + * @default '{{name}}Data' 148 + */ 149 + requests?: 150 + | StringName 151 + | { 152 + /** 153 + * The casing convention to use for generated request type names. 154 + * 155 + * @default 'PascalCase' 156 + */ 157 + case?: StringCase; 158 + /** 159 + * Custom naming pattern for generated request type names. The name 160 + * variable is obtained from the operation name. 161 + * 162 + * @default '{{name}}Data' 163 + */ 164 + name?: StringName; 165 + }; 166 + /** 167 + * Configuration for response-specific types. 168 + * 169 + * Controls generation of types for response bodies and status codes. 170 + * 171 + * Can be: 172 + * - `string` or `function`: Shorthand for `{ name: string | function }` 173 + * - `object`: Full configuration object 174 + * 175 + * @default '{{name}}Responses' 176 + */ 177 + responses?: 178 + | StringName 179 + | { 180 + /** 181 + * The casing convention to use for generated response type names. 182 + * 183 + * @default 'PascalCase' 184 + */ 185 + case?: StringCase; 186 + /** 187 + * Custom naming pattern for generated response type names. The name 188 + * variable is obtained from the operation name. 189 + * 190 + * @default '{{name}}Responses' 191 + */ 192 + name?: StringName; 193 + /** 194 + * Custom naming pattern for generated response type names. The name 195 + * variable is obtained from the operation name. 196 + * 197 + * @default '{{name}}Response' 198 + */ 199 + response?: StringName; 200 + }; 73 201 74 202 // DEPRECATED OPTIONS BELOW 75 203 ··· 103 231 tree?: boolean; 104 232 }; 105 233 106 - export type ResolvedConfig = Plugin.Name<'@hey-api/typescript'> & { 234 + export type Config = Plugin.Name<'@hey-api/typescript'> & { 107 235 /** 108 236 * The casing convention to use for generated names. 109 237 * ··· 111 239 */ 112 240 case: Exclude<StringCase, 'SCREAMING_SNAKE_CASE'>; 113 241 /** 242 + * Configuration for reusable schema definitions. 243 + * 244 + * Controls generation of shared types that can be referenced across 245 + * requests and responses. 246 + */ 247 + definitions: { 248 + /** 249 + * The casing convention to use for generated definition names. 250 + * 251 + * @default 'PascalCase' 252 + */ 253 + case: StringCase; 254 + /** 255 + * Custom naming pattern for generated definition names. The name variable 256 + * is obtained from the schema name. 257 + * 258 + * @default '{{name}}' 259 + */ 260 + name: StringName; 261 + }; 262 + /** 114 263 * By default, enums are emitted as types to preserve runtime-free output. 115 264 * 116 265 * However, you may want to generate enums as JavaScript objects or ··· 146 295 * Can be: 147 296 * - `javascript`: Generates JavaScript objects 148 297 * - `typescript`: Generates TypeScript enums 149 - * - `typescript+namespace`: Generates TypeScript enums within a namespace 150 298 * 151 299 * @default 'javascript' 152 300 */ 153 301 mode: EnumsType; 154 302 }; 155 303 /** 304 + * Configuration for error-specific types. 305 + * 306 + * Controls generation of types for error response bodies and status codes. 307 + * 308 + * Can be: 309 + * - `string` or `function`: Shorthand for `{ name: string | function }` 310 + * - `object`: Full configuration object 311 + */ 312 + errors: { 313 + /** 314 + * The casing convention to use for generated error type names. 315 + * 316 + * @default 'PascalCase' 317 + */ 318 + case: StringCase; 319 + /** 320 + * Custom naming pattern for generated error type names. The name 321 + * variable is obtained from the operation name. 322 + * 323 + * @default '{{name}}Error' 324 + */ 325 + error: StringName; 326 + /** 327 + * Custom naming pattern for generated error type names. The name 328 + * variable is obtained from the operation name. 329 + * 330 + * @default '{{name}}Errors' 331 + */ 332 + name: StringName; 333 + }; 334 + /** 156 335 * Should the exports from the generated files be re-exported in the index 157 336 * barrel file? 158 337 * ··· 165 344 * @default 'types' 166 345 */ 167 346 output: string; 347 + /** 348 + * Configuration for request-specific types. 349 + * 350 + * Controls generation of types for request bodies, query parameters, path 351 + * parameters, and headers. 352 + */ 353 + requests: { 354 + /** 355 + * The casing convention to use for generated request type names. 356 + * 357 + * @default 'PascalCase' 358 + */ 359 + case: StringCase; 360 + /** 361 + * Custom naming pattern for generated request type names. The name 362 + * variable is obtained from the operation name. 363 + * 364 + * @default '{{name}}Data' 365 + */ 366 + name: StringName; 367 + }; 368 + /** 369 + * Configuration for response-specific types. 370 + * 371 + * Controls generation of types for response bodies and status codes. 372 + */ 373 + responses: { 374 + /** 375 + * The casing convention to use for generated response type names. 376 + * 377 + * @default 'PascalCase' 378 + */ 379 + case: StringCase; 380 + /** 381 + * Custom naming pattern for generated response type names. The name 382 + * variable is obtained from the operation name. 383 + * 384 + * @default '{{name}}Responses' 385 + */ 386 + name: StringName; 387 + /** 388 + * Custom naming pattern for generated response type names. The name 389 + * variable is obtained from the operation name. 390 + * 391 + * @default '{{name}}Response' 392 + */ 393 + response: StringName; 394 + }; 168 395 169 396 // DEPRECATED OPTIONS BELOW 170 397 ··· 198 425 tree: boolean; 199 426 }; 200 427 201 - export type HeyApiTypeScriptPlugin = DefinePlugin<Config, ResolvedConfig>; 428 + export type HeyApiTypeScriptPlugin = DefinePlugin<UserConfig, Config, Api>;
+10 -5
packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/config.ts
··· 23 23 }, 24 24 mappers: { 25 25 boolean: (enabled) => ({ enabled }), 26 - string: (name) => ({ enabled: true, name }), 26 + function: (name) => ({ name }), 27 + string: (name) => ({ name }), 27 28 }, 28 29 value: plugin.config.infiniteQueryKeys, 29 30 }); ··· 36 37 }, 37 38 mappers: { 38 39 boolean: (enabled) => ({ enabled }), 39 - string: (name) => ({ enabled: true, name }), 40 + function: (name) => ({ name }), 41 + string: (name) => ({ name }), 40 42 }, 41 43 value: plugin.config.infiniteQueryOptions, 42 44 }); ··· 49 51 }, 50 52 mappers: { 51 53 boolean: (enabled) => ({ enabled }), 52 - string: (name) => ({ enabled: true, name }), 54 + function: (name) => ({ name }), 55 + string: (name) => ({ name }), 53 56 }, 54 57 value: plugin.config.mutationOptions, 55 58 }); ··· 62 65 }, 63 66 mappers: { 64 67 boolean: (enabled) => ({ enabled }), 65 - string: (name) => ({ enabled: true, name }), 68 + function: (name) => ({ name }), 69 + string: (name) => ({ name }), 66 70 }, 67 71 value: plugin.config.queryKeys, 68 72 }); ··· 75 79 }, 76 80 mappers: { 77 81 boolean: (enabled) => ({ enabled }), 78 - string: (name) => ({ enabled: true, name }), 82 + function: (name) => ({ name }), 83 + string: (name) => ({ name }), 79 84 }, 80 85 value: plugin.config.queryOptions, 81 86 });
+258 -54
packages/openapi-ts/src/plugins/@tanstack/angular-query-experimental/types.d.ts
··· 1 - import type { StringCase } from '../../../types/case'; 1 + import type { StringCase, StringName } from '../../../types/case'; 2 2 import type { DefinePlugin, Plugin } from '../../types'; 3 3 4 - export type Config = Plugin.Name<'@tanstack/angular-query-experimental'> & { 4 + export type UserConfig = Plugin.Name<'@tanstack/angular-query-experimental'> & { 5 5 /** 6 6 * The casing convention to use for generated names. 7 7 * ··· 24 24 * Configuration for generated infinite query key helpers. 25 25 * 26 26 * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions} 27 + * 28 + * Can be: 29 + * - `boolean`: Shorthand for `{ enabled: boolean }` 30 + * - `string` or `function`: Shorthand for `{ name: string | function }` 31 + * - `object`: Full configuration object 32 + * 33 + * @default true 27 34 */ 28 35 infiniteQueryKeys?: 29 36 | boolean 30 - | string 37 + | StringName 31 38 | { 39 + /** 40 + * The casing convention to use for generated names. 41 + * 42 + * @default 'camelCase' 43 + */ 32 44 case?: StringCase; 45 + /** 46 + * Whether to generate infinite query key helpers. 47 + * 48 + * @default true 49 + */ 33 50 enabled?: boolean; 34 - name?: string | ((name: string) => string); 51 + /** 52 + * Custom naming pattern for generated infinite query key names. The name variable is 53 + * obtained from the SDK function name. 54 + * 55 + * @default '{{name}}InfiniteQueryKey' 56 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 57 + */ 58 + name?: StringName; 35 59 }; 36 60 /** 37 61 * Configuration for generated infinite query options helpers. 38 62 * 39 63 * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions} 64 + * 65 + * Can be: 66 + * - `boolean`: Shorthand for `{ enabled: boolean }` 67 + * - `string` or `function`: Shorthand for `{ name: string | function }` 68 + * - `object`: Full configuration object 69 + * 70 + * @default true 40 71 */ 41 72 infiniteQueryOptions?: 42 73 | boolean 43 - | string 74 + | StringName 44 75 | { 76 + /** 77 + * The casing convention to use for generated names. 78 + * 79 + * @default 'camelCase' 80 + */ 45 81 case?: StringCase; 82 + /** 83 + * Whether to generate infinite query options helpers. 84 + * 85 + * @default true 86 + */ 46 87 enabled?: boolean; 47 - name?: string | ((name: string) => string); 88 + /** 89 + * Custom naming pattern for generated infinite query options names. The name variable is 90 + * obtained from the SDK function name. 91 + * 92 + * @default '{{name}}InfiniteOptions' 93 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 94 + */ 95 + name?: StringName; 48 96 }; 49 97 /** 50 98 * Configuration for generated mutation options helpers. 51 99 * 52 100 * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/useMutation} 101 + * 102 + * Can be: 103 + * - `boolean`: Shorthand for `{ enabled: boolean }` 104 + * - `string` or `function`: Shorthand for `{ name: string | function }` 105 + * - `object`: Full configuration object 106 + * 107 + * @default true 53 108 */ 54 109 mutationOptions?: 55 110 | boolean 56 - | string 111 + | StringName 57 112 | { 113 + /** 114 + * The casing convention to use for generated names. 115 + * 116 + * @default 'camelCase' 117 + */ 58 118 case?: StringCase; 119 + /** 120 + * Whether to generate mutation options helpers. 121 + * 122 + * @default true 123 + */ 59 124 enabled?: boolean; 60 - name?: string | ((name: string) => string); 125 + /** 126 + * Custom naming pattern for generated mutation options names. The name variable is 127 + * obtained from the SDK function name. 128 + * 129 + * @default '{{name}}Mutation' 130 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/useMutation 131 + */ 132 + name?: StringName; 61 133 }; 62 134 /** 63 135 * Name of the generated file. ··· 69 141 * Configuration for generated query keys. 70 142 * 71 143 * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/queryKey} 144 + * 145 + * Can be: 146 + * - `boolean`: Shorthand for `{ enabled: boolean }` 147 + * - `string` or `function`: Shorthand for `{ name: string | function }` 148 + * - `object`: Full configuration object 149 + * 150 + * @default true 72 151 */ 73 152 queryKeys?: 74 153 | boolean 75 - | string 154 + | StringName 76 155 | { 156 + /** 157 + * The casing convention to use for generated names. 158 + * 159 + * @default 'camelCase' 160 + */ 77 161 case?: StringCase; 162 + /** 163 + * Whether to generate query keys. 164 + * 165 + * @default true 166 + */ 78 167 enabled?: boolean; 79 - name?: string | ((name: string) => string); 168 + /** 169 + * Custom naming pattern for generated query key names. The name variable is 170 + * obtained from the SDK function name. 171 + * 172 + * @default '{{name}}QueryKey' 173 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryKey 174 + */ 175 + name?: StringName; 80 176 }; 81 177 /** 82 178 * Configuration for generated query options helpers. 83 179 * 84 180 * See {@link https://tanstack.com/query/v5/docs/framework/angular/reference/queryOptions} 181 + * 182 + * Can be: 183 + * - `boolean`: Shorthand for `{ enabled: boolean }` 184 + * - `string` or `function`: Shorthand for `{ name: string | function }` 185 + * - `object`: Full configuration object 186 + * 187 + * @default true 85 188 */ 86 189 queryOptions?: 87 190 | boolean 88 - | string 191 + | StringName 89 192 | { 193 + /** 194 + * The casing convention to use for generated names. 195 + * 196 + * @default 'camelCase' 197 + */ 90 198 case?: StringCase; 199 + /** 200 + * Whether to generate query options helpers. 201 + * 202 + * @default true 203 + */ 91 204 enabled?: boolean; 92 - name?: string | ((name: string) => string); 205 + /** 206 + * Custom naming pattern for generated query options names. The name variable is 207 + * obtained from the SDK function name. 208 + * 209 + * @default '{{name}}Options' 210 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryOptions 211 + */ 212 + name?: StringName; 93 213 }; 94 214 }; 95 215 96 - export type ResolvedConfig = 97 - Plugin.Name<'@tanstack/angular-query-experimental'> & { 216 + export type Config = Plugin.Name<'@tanstack/angular-query-experimental'> & { 217 + /** 218 + * The casing convention to use for generated names. 219 + * 220 + * @default 'camelCase' 221 + */ 222 + case: StringCase; 223 + /** 224 + * Add comments from SDK functions to the generated TanStack Query code? 225 + * 226 + * @default true 227 + */ 228 + comments: boolean; 229 + /** 230 + * Should the exports from the generated files be re-exported in the index barrel file? 231 + * 232 + * @default false 233 + */ 234 + exportFromIndex: boolean; 235 + /** 236 + * Resolved configuration for generated infinite query key helpers. 237 + * 238 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 239 + */ 240 + infiniteQueryKeys: { 98 241 /** 99 242 * The casing convention to use for generated names. 100 243 * ··· 102 245 */ 103 246 case: StringCase; 104 247 /** 105 - * Add comments from SDK functions to the generated TanStack Query code? 248 + * Whether to generate infinite query key helpers. 106 249 * 107 250 * @default true 108 251 */ 109 - comments: boolean; 252 + enabled: boolean; 110 253 /** 111 - * Should the exports from the generated files be re-exported in the index barrel file? 254 + * Custom naming pattern for generated infinite query key names. The name variable is 255 + * obtained from the SDK function name. 112 256 * 113 - * @default false 257 + * @default '{{name}}InfiniteQueryKey' 258 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 114 259 */ 115 - exportFromIndex: boolean; 260 + name: StringName; 261 + }; 262 + /** 263 + * Resolved configuration for generated infinite query options helpers. 264 + * 265 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 266 + */ 267 + infiniteQueryOptions: { 116 268 /** 117 - * Resolved configuration for generated infinite query key helpers. 269 + * The casing convention to use for generated names. 118 270 * 119 - * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 271 + * @default 'camelCase' 120 272 */ 121 - infiniteQueryKeys: { 122 - case: StringCase; 123 - enabled: boolean; 124 - name: string | ((name: string) => string); 125 - }; 273 + case: StringCase; 126 274 /** 127 - * Resolved configuration for generated infinite query options helpers. 275 + * Whether to generate infinite query options helpers. 128 276 * 277 + * @default true 278 + */ 279 + enabled: boolean; 280 + /** 281 + * Custom naming pattern for generated infinite query options names. The name variable is 282 + * obtained from the SDK function name. 283 + * 284 + * @default '{{name}}InfiniteOptions' 129 285 * @see https://tanstack.com/query/v5/docs/framework/angular/reference/infiniteQueryOptions 130 286 */ 131 - infiniteQueryOptions: { 132 - case: StringCase; 133 - enabled: boolean; 134 - name: string | ((name: string) => string); 135 - }; 287 + name: StringName; 288 + }; 289 + /** 290 + * Resolved configuration for generated mutation options helpers. 291 + * 292 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/useMutation 293 + */ 294 + mutationOptions: { 295 + /** 296 + * The casing convention to use for generated names. 297 + * 298 + * @default 'camelCase' 299 + */ 300 + case: StringCase; 136 301 /** 137 - * Resolved configuration for generated mutation options helpers. 302 + * Whether to generate mutation options helpers. 138 303 * 304 + * @default true 305 + */ 306 + enabled: boolean; 307 + /** 308 + * Custom naming pattern for generated mutation options names. The name variable is 309 + * obtained from the SDK function name. 310 + * 311 + * @default '{{name}}Mutation' 139 312 * @see https://tanstack.com/query/v5/docs/framework/angular/reference/useMutation 140 313 */ 141 - mutationOptions: { 142 - case: StringCase; 143 - enabled: boolean; 144 - name: string | ((name: string) => string); 145 - }; 314 + name: StringName; 315 + }; 316 + /** 317 + * Name of the generated file. 318 + * 319 + * @default '@tanstack/angular-query-experimental' 320 + */ 321 + output: string; 322 + /** 323 + * Resolved configuration for generated query keys. 324 + * 325 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryKey 326 + */ 327 + queryKeys: { 328 + /** 329 + * The casing convention to use for generated names. 330 + * 331 + * @default 'camelCase' 332 + */ 333 + case: StringCase; 146 334 /** 147 - * Name of the generated file. 335 + * Whether to generate query keys. 148 336 * 149 - * @default '@tanstack/angular-query-experimental' 337 + * @default true 150 338 */ 151 - output: string; 339 + enabled: boolean; 152 340 /** 153 - * Resolved configuration for generated query keys. 341 + * Custom naming pattern for generated query key names. The name variable is 342 + * obtained from the SDK function name. 154 343 * 344 + * @default '{{name}}QueryKey' 155 345 * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryKey 156 346 */ 157 - queryKeys: { 158 - case: StringCase; 159 - enabled: boolean; 160 - name: string | ((name: string) => string); 161 - }; 347 + name: StringName; 348 + }; 349 + /** 350 + * Resolved configuration for generated query options helpers. 351 + * 352 + * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryOptions 353 + */ 354 + queryOptions: { 355 + /** 356 + * The casing convention to use for generated names. 357 + * 358 + * @default 'camelCase' 359 + */ 360 + case: StringCase; 361 + /** 362 + * Whether to generate query options helpers. 363 + * 364 + * @default true 365 + */ 366 + enabled: boolean; 162 367 /** 163 - * Resolved configuration for generated query options helpers. 368 + * Custom naming pattern for generated query options names. The name variable is 369 + * obtained from the SDK function name. 164 370 * 371 + * @default '{{name}}Options' 165 372 * @see https://tanstack.com/query/v5/docs/framework/angular/reference/queryOptions 166 373 */ 167 - queryOptions: { 168 - case: StringCase; 169 - enabled: boolean; 170 - name: string | ((name: string) => string); 171 - }; 374 + name: StringName; 172 375 }; 376 + }; 173 377 174 - export type TanStackAngularQueryPlugin = DefinePlugin<Config, ResolvedConfig>; 378 + export type TanStackAngularQueryPlugin = DefinePlugin<UserConfig, Config>;
+8 -9
packages/openapi-ts/src/plugins/@tanstack/query-core/infiniteQueryOptions.ts
··· 237 237 }) => { 238 238 if ( 239 239 !plugin.config.infiniteQueryOptions || 240 - !(['get', 'post'] as (typeof operation.method)[]).includes(operation.method) 240 + !(['get', 'post'] as ReadonlyArray<typeof operation.method>).includes( 241 + operation.method, 242 + ) 241 243 ) { 242 244 return state; 243 245 } ··· 297 299 const type = schemaToType({ 298 300 plugin: pluginTypeScript as Parameters<typeof schemaToType>[0]['plugin'], 299 301 schema: pagination.schema, 300 - state: undefined, 301 302 }); 302 - const typePageParam = type 303 - ? `${tsNodeToString({ 304 - node: type, 305 - unescape: true, 306 - })} | ${typePageObjectParam}` 307 - : `${typePageObjectParam}`; 303 + const typePageParam = `${tsNodeToString({ 304 + node: type, 305 + unescape: true, 306 + })} | ${typePageObjectParam}`; 308 307 309 308 const node = queryKeyStatement({ 310 309 isInfinite: true, ··· 499 498 // TODO: better types syntax 500 499 types: [ 501 500 typeResponse, 502 - typeError.name, 501 + typeError.name || 'unknown', 503 502 `${typeof state.typeInfiniteData === 'string' ? state.typeInfiniteData : state.typeInfiniteData.name}<${typeResponse}>`, 504 503 typeQueryKey, 505 504 typePageParam,
+3 -1
packages/openapi-ts/src/plugins/@tanstack/query-core/mutationOptions.ts
··· 22 22 if ( 23 23 !plugin.config.mutationOptions.enabled || 24 24 !( 25 - ['delete', 'patch', 'post', 'put'] as (typeof operation.method)[] 25 + ['delete', 'patch', 'post', 'put'] as ReadonlyArray< 26 + typeof operation.method 27 + > 26 28 ).includes(operation.method) 27 29 ) { 28 30 return state;
+1 -1
packages/openapi-ts/src/plugins/@tanstack/query-core/plugin-legacy.ts
··· 1176 1176 // TODO: better types syntax 1177 1177 types: [ 1178 1178 typeResponse, 1179 - typeError.name, 1179 + typeError.name!, 1180 1180 `${typeof typeInfiniteData === 'string' ? typeInfiniteData : typeInfiniteData.name}<${typeResponse}>`, 1181 1181 typeQueryKey, 1182 1182 typePageParam,
+1 -1
packages/openapi-ts/src/plugins/@tanstack/query-core/plugin.ts
··· 11 11 12 12 export const handler = ({ plugin }: Parameters<PluginHandler>[0]) => { 13 13 const file = plugin.createFile({ 14 + case: plugin.config.case, 14 15 id: plugin.name, 15 - identifierCase: plugin.config.case, 16 16 path: plugin.output, 17 17 }); 18 18
+1 -1
packages/openapi-ts/src/plugins/@tanstack/query-core/queryKey.ts
··· 243 243 export const createQueryKeyType = ({ plugin }: { plugin: PluginInstance }) => { 244 244 const file = plugin.context.file({ id: plugin.name })!; 245 245 246 - const properties: Property[] = [ 246 + const properties: Array<Property> = [ 247 247 { 248 248 name: '_id', 249 249 type: compiler.keywordTypeNode({
+3 -1
packages/openapi-ts/src/plugins/@tanstack/query-core/queryOptions.ts
··· 29 29 }) => { 30 30 if ( 31 31 !plugin.config.queryOptions || 32 - !(['get', 'post'] as (typeof operation.method)[]).includes(operation.method) 32 + !(['get', 'post'] as ReadonlyArray<typeof operation.method>).includes( 33 + operation.method, 34 + ) 33 35 ) { 34 36 return state; 35 37 }
+22 -19
packages/openapi-ts/src/plugins/@tanstack/query-core/useType.ts
··· 2 2 import type { IR } from '../../../ir/types'; 3 3 import { getClientPlugin } from '../../@hey-api/client-core/utils'; 4 4 import { operationOptionsType } from '../../@hey-api/sdk/operation'; 5 - import { importIdentifier } from '../../@hey-api/typescript/ref'; 5 + import { typesId } from '../../@hey-api/typescript/ref'; 6 6 import type { PluginInstance } from './types'; 7 7 8 8 export const useTypeData = ({ ··· 13 13 plugin: PluginInstance; 14 14 }) => { 15 15 const file = plugin.context.file({ id: plugin.name })!; 16 - 17 - const typeData = operationOptionsType({ 18 - context: plugin.context, 19 - file, 20 - operation, 21 - }); 16 + const pluginSdk = plugin.getPlugin('@hey-api/sdk')!; 17 + const typeData = operationOptionsType({ file, operation, plugin: pluginSdk }); 22 18 return typeData; 23 19 }; 24 20 ··· 30 26 plugin: PluginInstance; 31 27 }) => { 32 28 const file = plugin.context.file({ id: plugin.name })!; 33 - const identifierError = importIdentifier({ 34 - context: plugin.context, 35 - file, 36 - operation, 37 - type: 'error', 29 + const pluginTypeScript = plugin.getPlugin('@hey-api/typescript')!; 30 + const fileTypeScript = plugin.context.file({ id: typesId })!; 31 + const errorImport = file.import({ 32 + asType: true, 33 + module: file.relativePathToFile({ context: plugin.context, id: typesId }), 34 + name: fileTypeScript.getName( 35 + pluginTypeScript.api.getId({ operation, type: 'error' }), 36 + ), 38 37 }); 39 38 let typeError: ImportExportItemObject = { 40 39 asType: true, 41 - name: identifierError.name || '', 40 + name: errorImport.name || '', 42 41 }; 43 42 if (!typeError.name) { 44 43 typeError = file.import({ ··· 70 69 plugin: PluginInstance; 71 70 }) => { 72 71 const file = plugin.context.file({ id: plugin.name })!; 73 - const identifierResponse = importIdentifier({ 74 - context: plugin.context, 75 - file, 76 - operation, 77 - type: 'response', 72 + const pluginTypeScript = plugin.getPlugin('@hey-api/typescript')!; 73 + const fileTypeScript = plugin.context.file({ id: typesId })!; 74 + const responseImport = file.import({ 75 + asType: true, 76 + module: file.relativePathToFile({ context: plugin.context, id: typesId }), 77 + name: fileTypeScript.getName( 78 + pluginTypeScript.api.getId({ operation, type: 'response' }), 79 + ), 78 80 }); 79 - const typeResponse = identifierResponse.name || 'unknown'; 81 + 82 + const typeResponse = responseImport.name || 'unknown'; 80 83 return typeResponse; 81 84 };
+10 -5
packages/openapi-ts/src/plugins/@tanstack/react-query/config.ts
··· 23 23 }, 24 24 mappers: { 25 25 boolean: (enabled) => ({ enabled }), 26 - string: (name) => ({ enabled: true, name }), 26 + function: (name) => ({ name }), 27 + string: (name) => ({ name }), 27 28 }, 28 29 value: plugin.config.infiniteQueryKeys, 29 30 }); ··· 36 37 }, 37 38 mappers: { 38 39 boolean: (enabled) => ({ enabled }), 39 - string: (name) => ({ enabled: true, name }), 40 + function: (name) => ({ name }), 41 + string: (name) => ({ name }), 40 42 }, 41 43 value: plugin.config.infiniteQueryOptions, 42 44 }); ··· 49 51 }, 50 52 mappers: { 51 53 boolean: (enabled) => ({ enabled }), 52 - string: (name) => ({ enabled: true, name }), 54 + function: (name) => ({ name }), 55 + string: (name) => ({ name }), 53 56 }, 54 57 value: plugin.config.mutationOptions, 55 58 }); ··· 62 65 }, 63 66 mappers: { 64 67 boolean: (enabled) => ({ enabled }), 65 - string: (name) => ({ enabled: true, name }), 68 + function: (name) => ({ name }), 69 + string: (name) => ({ name }), 66 70 }, 67 71 value: plugin.config.queryKeys, 68 72 }); ··· 75 79 }, 76 80 mappers: { 77 81 boolean: (enabled) => ({ enabled }), 78 - string: (name) => ({ enabled: true, name }), 82 + function: (name) => ({ name }), 83 + string: (name) => ({ name }), 79 84 }, 80 85 value: plugin.config.queryOptions, 81 86 });
+34 -24
packages/openapi-ts/src/plugins/@tanstack/react-query/types.d.ts
··· 1 - import type { StringCase } from '../../../types/case'; 1 + import type { StringCase, StringName } from '../../../types/case'; 2 2 import type { DefinePlugin, Plugin } from '../../types'; 3 3 4 - export type Config = Plugin.Name<'@tanstack/react-query'> & { 4 + export type UserConfig = Plugin.Name<'@tanstack/react-query'> & { 5 5 /** 6 6 * The casing convention to use for generated names. 7 7 * ··· 32 32 * 33 33 * Can be: 34 34 * - `boolean`: Shorthand for `{ enabled: boolean }` 35 - * - `string`: Shorthand for `{ enabled: true; name: string }` 35 + * - `string` or `function`: Shorthand for `{ name: string | function }` 36 36 * - `object`: Full configuration object 37 + * 38 + * @default true 37 39 */ 38 40 infiniteQueryKeys?: 39 41 | boolean 40 - | string 42 + | StringName 41 43 | { 42 44 /** 43 45 * The casing convention to use for generated names. ··· 58 60 * @default '{{name}}InfiniteQueryKey' 59 61 * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 60 62 */ 61 - name?: string | ((name: string) => string); 63 + name?: StringName; 62 64 }; 63 65 /** 64 66 * Configuration for generated infinite query options helpers. ··· 67 69 * 68 70 * Can be: 69 71 * - `boolean`: Shorthand for `{ enabled: boolean }` 70 - * - `string`: Shorthand for `{ enabled: true; name: string }` 72 + * - `string` or `function`: Shorthand for `{ name: string | function }` 71 73 * - `object`: Full configuration object 74 + * 75 + * @default true 72 76 */ 73 77 infiniteQueryOptions?: 74 78 | boolean 75 - | string 79 + | StringName 76 80 | { 77 81 /** 78 82 * The casing convention to use for generated names. ··· 93 97 * @default '{{name}}InfiniteOptions' 94 98 * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 95 99 */ 96 - name?: string | ((name: string) => string); 100 + name?: StringName; 97 101 }; 98 102 /** 99 103 * Configuration for generated mutation options helpers. ··· 102 106 * 103 107 * Can be: 104 108 * - `boolean`: Shorthand for `{ enabled: boolean }` 105 - * - `string`: Shorthand for `{ enabled: true; name: string }` 109 + * - `string` or `function`: Shorthand for `{ name: string | function }` 106 110 * - `object`: Full configuration object 111 + * 112 + * @default true 107 113 */ 108 114 mutationOptions?: 109 115 | boolean 110 - | string 116 + | StringName 111 117 | { 112 118 /** 113 119 * The casing convention to use for generated names. ··· 128 134 * @default '{{name}}Mutation' 129 135 * @see https://tanstack.com/query/v5/docs/framework/react/reference/useMutation 130 136 */ 131 - name?: string | ((name: string) => string); 137 + name?: StringName; 132 138 }; 133 139 /** 134 140 * Name of the generated file. ··· 143 149 * 144 150 * Can be: 145 151 * - `boolean`: Shorthand for `{ enabled: boolean }` 146 - * - `string`: Shorthand for `{ enabled: true; name: string }` 152 + * - `string` or `function`: Shorthand for `{ name: string | function }` 147 153 * - `object`: Full configuration object 154 + * 155 + * @default true 148 156 */ 149 157 queryKeys?: 150 158 | boolean 151 - | string 159 + | StringName 152 160 | { 153 161 /** 154 162 * The casing convention to use for generated names. ··· 169 177 * @default '{{name}}QueryKey' 170 178 * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryKey 171 179 */ 172 - name?: string | ((name: string) => string); 180 + name?: StringName; 173 181 }; 174 182 /** 175 183 * Configuration for generated query options helpers. ··· 178 186 * 179 187 * Can be: 180 188 * - `boolean`: Shorthand for `{ enabled: boolean }` 181 - * - `string`: Shorthand for `{ enabled: true; name: string }` 189 + * - `string` or `function`: Shorthand for `{ name: string | function }` 182 190 * - `object`: Full configuration object 191 + * 192 + * @default true 183 193 */ 184 194 queryOptions?: 185 195 | boolean 186 - | string 196 + | StringName 187 197 | { 188 198 /** 189 199 * The casing convention to use for generated names. ··· 204 214 * @default '{{name}}Options' 205 215 * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryOptions 206 216 */ 207 - name?: string | ((name: string) => string); 217 + name?: StringName; 208 218 }; 209 219 }; 210 220 211 - export type ResolvedConfig = Plugin.Name<'@tanstack/react-query'> & { 221 + export type Config = Plugin.Name<'@tanstack/react-query'> & { 212 222 /** 213 223 * The casing convention to use for generated names. 214 224 * ··· 251 261 * @default '{{name}}InfiniteQueryKey' 252 262 * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 253 263 */ 254 - name: string | ((name: string) => string); 264 + name: StringName; 255 265 }; 256 266 /** 257 267 * Resolved configuration for generated infinite query options helpers. ··· 277 287 * @default '{{name}}InfiniteOptions' 278 288 * @see https://tanstack.com/query/v5/docs/framework/react/reference/infiniteQueryOptions 279 289 */ 280 - name: string | ((name: string) => string); 290 + name: StringName; 281 291 }; 282 292 /** 283 293 * Resolved configuration for generated mutation options helpers. ··· 303 313 * @default '{{name}}Mutation' 304 314 * @see https://tanstack.com/query/v5/docs/framework/react/reference/useMutation 305 315 */ 306 - name: string | ((name: string) => string); 316 + name: StringName; 307 317 }; 308 318 /** 309 319 * Name of the generated file. ··· 335 345 * @default '{{name}}QueryKey' 336 346 * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryKey 337 347 */ 338 - name: string | ((name: string) => string); 348 + name: StringName; 339 349 }; 340 350 /** 341 351 * Resolved configuration for generated query options helpers. ··· 361 371 * @default '{{name}}Options' 362 372 * @see https://tanstack.com/query/v5/docs/framework/react/reference/queryOptions 363 373 */ 364 - name: string | ((name: string) => string); 374 + name: StringName; 365 375 }; 366 376 }; 367 377 368 - export type TanStackReactQueryPlugin = DefinePlugin<Config, ResolvedConfig>; 378 + export type TanStackReactQueryPlugin = DefinePlugin<UserConfig, Config>;
+10 -5
packages/openapi-ts/src/plugins/@tanstack/solid-query/config.ts
··· 23 23 }, 24 24 mappers: { 25 25 boolean: (enabled) => ({ enabled }), 26 - string: (name) => ({ enabled: true, name }), 26 + function: (name) => ({ name }), 27 + string: (name) => ({ name }), 27 28 }, 28 29 value: plugin.config.infiniteQueryKeys, 29 30 }); ··· 36 37 }, 37 38 mappers: { 38 39 boolean: (enabled) => ({ enabled }), 39 - string: (name) => ({ enabled: true, name }), 40 + function: (name) => ({ name }), 41 + string: (name) => ({ name }), 40 42 }, 41 43 value: plugin.config.infiniteQueryOptions, 42 44 }); ··· 49 51 }, 50 52 mappers: { 51 53 boolean: (enabled) => ({ enabled }), 52 - string: (name) => ({ enabled: true, name }), 54 + function: (name) => ({ name }), 55 + string: (name) => ({ name }), 53 56 }, 54 57 value: plugin.config.mutationOptions, 55 58 }); ··· 62 65 }, 63 66 mappers: { 64 67 boolean: (enabled) => ({ enabled }), 65 - string: (name) => ({ enabled: true, name }), 68 + function: (name) => ({ name }), 69 + string: (name) => ({ name }), 66 70 }, 67 71 value: plugin.config.queryKeys, 68 72 }); ··· 75 79 }, 76 80 mappers: { 77 81 boolean: (enabled) => ({ enabled }), 78 - string: (name) => ({ enabled: true, name }), 82 + function: (name) => ({ name }), 83 + string: (name) => ({ name }), 79 84 }, 80 85 value: plugin.config.queryOptions, 81 86 });
+224 -19
packages/openapi-ts/src/plugins/@tanstack/solid-query/types.d.ts
··· 1 - import type { StringCase } from '../../../types/case'; 1 + import type { StringCase, StringName } from '../../../types/case'; 2 2 import type { DefinePlugin, Plugin } from '../../types'; 3 3 4 - export type Config = Plugin.Name<'@tanstack/solid-query'> & { 4 + export type UserConfig = Plugin.Name<'@tanstack/solid-query'> & { 5 5 /** 6 6 * The casing convention to use for generated names. 7 7 * ··· 24 24 * Configuration for generated infinite query key helpers. 25 25 * 26 26 * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery} 27 + * 28 + * Can be: 29 + * - `boolean`: Shorthand for `{ enabled: boolean }` 30 + * - `string` or `function`: Shorthand for `{ name: string | function }` 31 + * - `object`: Full configuration object 32 + * 33 + * @default true 27 34 */ 28 35 infiniteQueryKeys?: 29 36 | boolean 30 - | string 37 + | StringName 31 38 | { 39 + /** 40 + * The casing convention to use for generated names. 41 + * 42 + * @default 'camelCase' 43 + */ 32 44 case?: StringCase; 45 + /** 46 + * Whether to generate infinite query key helpers. 47 + * 48 + * @default true 49 + */ 33 50 enabled?: boolean; 34 - name?: string | ((name: string) => string); 51 + /** 52 + * Custom naming pattern for generated infinite query key names. The name variable is 53 + * obtained from the SDK function name. 54 + * 55 + * @default '{{name}}InfiniteQueryKey' 56 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 57 + */ 58 + name?: StringName; 35 59 }; 36 60 /** 37 61 * Configuration for generated infinite query options helpers. 38 62 * 39 63 * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery} 64 + * 65 + * Can be: 66 + * - `boolean`: Shorthand for `{ enabled: boolean }` 67 + * - `string` or `function`: Shorthand for `{ name: string | function }` 68 + * - `object`: Full configuration object 69 + * 70 + * @default true 40 71 */ 41 72 infiniteQueryOptions?: 42 73 | boolean 43 - | string 74 + | StringName 44 75 | { 76 + /** 77 + * The casing convention to use for generated names. 78 + * 79 + * @default 'camelCase' 80 + */ 45 81 case?: StringCase; 82 + /** 83 + * Whether to generate infinite query options helpers. 84 + * 85 + * @default true 86 + */ 46 87 enabled?: boolean; 47 - name?: string | ((name: string) => string); 88 + /** 89 + * Custom naming pattern for generated infinite query options names. The name variable is 90 + * obtained from the SDK function name. 91 + * 92 + * @default '{{name}}InfiniteOptions' 93 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 94 + */ 95 + name?: StringName; 48 96 }; 49 97 /** 50 98 * Configuration for generated mutation options helpers. 51 99 * 52 100 * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/createMutation} 101 + * 102 + * Can be: 103 + * - `boolean`: Shorthand for `{ enabled: boolean }` 104 + * - `string` or `function`: Shorthand for `{ name: string | function }` 105 + * - `object`: Full configuration object 106 + * 107 + * @default true 53 108 */ 54 109 mutationOptions?: 55 110 | boolean 56 - | string 111 + | StringName 57 112 | { 113 + /** 114 + * The casing convention to use for generated names. 115 + * 116 + * @default 'camelCase' 117 + */ 58 118 case?: StringCase; 119 + /** 120 + * Whether to generate mutation options helpers. 121 + * 122 + * @default true 123 + */ 59 124 enabled?: boolean; 60 - name?: string | ((name: string) => string); 125 + /** 126 + * Custom naming pattern for generated mutation options names. The name variable is 127 + * obtained from the SDK function name. 128 + * 129 + * @default '{{name}}Mutation' 130 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createMutation 131 + */ 132 + name?: StringName; 61 133 }; 62 134 /** 63 135 * Name of the generated file. ··· 69 141 * Configuration for generated query keys. 70 142 * 71 143 * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/queryKey} 144 + * 145 + * Can be: 146 + * - `boolean`: Shorthand for `{ enabled: boolean }` 147 + * - `string` or `function`: Shorthand for `{ name: string | function }` 148 + * - `object`: Full configuration object 149 + * 150 + * @default true 72 151 */ 73 152 queryKeys?: 74 153 | boolean 75 - | string 154 + | StringName 76 155 | { 156 + /** 157 + * The casing convention to use for generated names. 158 + * 159 + * @default 'camelCase' 160 + */ 77 161 case?: StringCase; 162 + /** 163 + * Whether to generate query keys. 164 + * 165 + * @default true 166 + */ 78 167 enabled?: boolean; 79 - name?: string | ((name: string) => string); 168 + /** 169 + * Custom naming pattern for generated query key names. The name variable is 170 + * obtained from the SDK function name. 171 + * 172 + * @default '{{name}}QueryKey' 173 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/queryKey 174 + */ 175 + name?: StringName; 80 176 }; 81 177 /** 82 178 * Configuration for generated query options helpers. 83 179 * 84 180 * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/createQuery} 181 + * 182 + * Can be: 183 + * - `boolean`: Shorthand for `{ enabled: boolean }` 184 + * - `string` or `function`: Shorthand for `{ name: string | function }` 185 + * - `object`: Full configuration object 186 + * 187 + * @default true 85 188 */ 86 189 queryOptions?: 87 190 | boolean 88 - | string 191 + | StringName 89 192 | { 193 + /** 194 + * The casing convention to use for generated names. 195 + * 196 + * @default 'camelCase' 197 + */ 90 198 case?: StringCase; 199 + /** 200 + * Whether to generate query options helpers. 201 + * 202 + * @default true 203 + */ 91 204 enabled?: boolean; 92 - name?: string | ((name: string) => string); 205 + /** 206 + * Custom naming pattern for generated query options names. The name variable is 207 + * obtained from the SDK function name. 208 + * 209 + * @default '{{name}}Options' 210 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createQuery 211 + */ 212 + name?: StringName; 93 213 }; 94 214 }; 95 215 96 - export type ResolvedConfig = Plugin.Name<'@tanstack/solid-query'> & { 216 + export type Config = Plugin.Name<'@tanstack/solid-query'> & { 97 217 /** 98 218 * The casing convention to use for generated names. 99 219 * ··· 118 238 * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 119 239 */ 120 240 infiniteQueryKeys: { 241 + /** 242 + * The casing convention to use for generated names. 243 + * 244 + * @default 'camelCase' 245 + */ 121 246 case: StringCase; 247 + /** 248 + * Whether to generate infinite query key helpers. 249 + * 250 + * @default true 251 + */ 122 252 enabled: boolean; 123 - name: string | ((name: string) => string); 253 + /** 254 + * Custom naming pattern for generated infinite query key names. The name variable is 255 + * obtained from the SDK function name. 256 + * 257 + * @default '{{name}}InfiniteQueryKey' 258 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 259 + */ 260 + name: StringName; 124 261 }; 125 262 /** 126 263 * Resolved configuration for generated infinite query options helpers. ··· 128 265 * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 129 266 */ 130 267 infiniteQueryOptions: { 268 + /** 269 + * The casing convention to use for generated names. 270 + * 271 + * @default 'camelCase' 272 + */ 131 273 case: StringCase; 274 + /** 275 + * Whether to generate infinite query options helpers. 276 + * 277 + * @default true 278 + */ 132 279 enabled: boolean; 133 - name: string | ((name: string) => string); 280 + /** 281 + * Custom naming pattern for generated infinite query options names. The name variable is 282 + * obtained from the SDK function name. 283 + * 284 + * @default '{{name}}InfiniteOptions' 285 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createInfiniteQuery 286 + */ 287 + name: StringName; 134 288 }; 135 289 /** 136 290 * Resolved configuration for generated mutation options helpers. ··· 138 292 * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createMutation 139 293 */ 140 294 mutationOptions: { 295 + /** 296 + * The casing convention to use for generated names. 297 + * 298 + * @default 'camelCase' 299 + */ 141 300 case: StringCase; 301 + /** 302 + * Whether to generate mutation options helpers. 303 + * 304 + * @default true 305 + */ 142 306 enabled: boolean; 143 - name: string | ((name: string) => string); 307 + /** 308 + * Custom naming pattern for generated mutation options names. The name variable is 309 + * obtained from the SDK function name. 310 + * 311 + * @default '{{name}}Mutation' 312 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createMutation 313 + */ 314 + name: StringName; 144 315 }; 145 316 /** 146 317 * Name of the generated file. ··· 154 325 * @see https://tanstack.com/query/v5/docs/framework/solid/reference/queryKey 155 326 */ 156 327 queryKeys: { 328 + /** 329 + * The casing convention to use for generated names. 330 + * 331 + * @default 'camelCase' 332 + */ 157 333 case: StringCase; 334 + /** 335 + * Whether to generate query keys. 336 + * 337 + * @default true 338 + */ 158 339 enabled: boolean; 159 - name: string | ((name: string) => string); 340 + /** 341 + * Custom naming pattern for generated query key names. The name variable is 342 + * obtained from the SDK function name. 343 + * 344 + * @default '{{name}}QueryKey' 345 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/queryKey 346 + */ 347 + name: StringName; 160 348 }; 161 349 /** 162 350 * Resolved configuration for generated query options helpers. ··· 164 352 * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createQuery 165 353 */ 166 354 queryOptions: { 355 + /** 356 + * The casing convention to use for generated names. 357 + * 358 + * @default 'camelCase' 359 + */ 167 360 case: StringCase; 361 + /** 362 + * Whether to generate query options helpers. 363 + * 364 + * @default true 365 + */ 168 366 enabled: boolean; 169 - name: string | ((name: string) => string); 367 + /** 368 + * Custom naming pattern for generated query options names. The name variable is 369 + * obtained from the SDK function name. 370 + * 371 + * @default '{{name}}Options' 372 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createQuery 373 + */ 374 + name: StringName; 170 375 }; 171 376 }; 172 377 173 - export type TanStackSolidQueryPlugin = DefinePlugin<Config, ResolvedConfig>; 378 + export type TanStackSolidQueryPlugin = DefinePlugin<UserConfig, Config>;
+10 -5
packages/openapi-ts/src/plugins/@tanstack/svelte-query/config.ts
··· 23 23 }, 24 24 mappers: { 25 25 boolean: (enabled) => ({ enabled }), 26 - string: (name) => ({ enabled: true, name }), 26 + function: (name) => ({ name }), 27 + string: (name) => ({ name }), 27 28 }, 28 29 value: plugin.config.infiniteQueryKeys, 29 30 }); ··· 36 37 }, 37 38 mappers: { 38 39 boolean: (enabled) => ({ enabled }), 39 - string: (name) => ({ enabled: true, name }), 40 + function: (name) => ({ name }), 41 + string: (name) => ({ name }), 40 42 }, 41 43 value: plugin.config.infiniteQueryOptions, 42 44 }); ··· 49 51 }, 50 52 mappers: { 51 53 boolean: (enabled) => ({ enabled }), 52 - string: (name) => ({ enabled: true, name }), 54 + function: (name) => ({ name }), 55 + string: (name) => ({ name }), 53 56 }, 54 57 value: plugin.config.mutationOptions, 55 58 }); ··· 62 65 }, 63 66 mappers: { 64 67 boolean: (enabled) => ({ enabled }), 65 - string: (name) => ({ enabled: true, name }), 68 + function: (name) => ({ name }), 69 + string: (name) => ({ name }), 66 70 }, 67 71 value: plugin.config.queryKeys, 68 72 }); ··· 75 79 }, 76 80 mappers: { 77 81 boolean: (enabled) => ({ enabled }), 78 - string: (name) => ({ enabled: true, name }), 82 + function: (name) => ({ name }), 83 + string: (name) => ({ name }), 79 84 }, 80 85 value: plugin.config.queryOptions, 81 86 });
+225 -20
packages/openapi-ts/src/plugins/@tanstack/svelte-query/types.d.ts
··· 1 - import type { StringCase } from '../../../types/case'; 1 + import type { StringCase, StringName } from '../../../types/case'; 2 2 import type { DefinePlugin, Plugin } from '../../types'; 3 3 4 - export type Config = Plugin.Name<'@tanstack/svelte-query'> & { 4 + export type UserConfig = Plugin.Name<'@tanstack/svelte-query'> & { 5 5 /** 6 6 * The casing convention to use for generated names. 7 7 * ··· 24 24 * Configuration for generated infinite query key helpers. 25 25 * 26 26 * See {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/createInfiniteQuery} 27 + * 28 + * Can be: 29 + * - `boolean`: Shorthand for `{ enabled: boolean }` 30 + * - `string` or `function`: Shorthand for `{ name: string | function }` 31 + * - `object`: Full configuration object 32 + * 33 + * @default true 27 34 */ 28 35 infiniteQueryKeys?: 29 36 | boolean 30 - | string 37 + | StringName 31 38 | { 39 + /** 40 + * The casing convention to use for generated names. 41 + * 42 + * @default 'camelCase' 43 + */ 32 44 case?: StringCase; 45 + /** 46 + * Whether to generate infinite query key helpers. 47 + * 48 + * @default true 49 + */ 33 50 enabled?: boolean; 34 - name?: string | ((name: string) => string); 51 + /** 52 + * Custom naming pattern for generated infinite query key names. The name variable is 53 + * obtained from the SDK function name. 54 + * 55 + * @default '{{name}}InfiniteQueryKey' 56 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/createInfiniteQuery 57 + */ 58 + name?: StringName; 35 59 }; 36 60 /** 37 61 * Configuration for generated infinite query options helpers. 38 62 * 39 63 * See {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/createInfiniteQuery} 64 + * 65 + * Can be: 66 + * - `boolean`: Shorthand for `{ enabled: boolean }` 67 + * - `string` or `function`: Shorthand for `{ name: string | function }` 68 + * - `object`: Full configuration object 69 + * 70 + * @default true 40 71 */ 41 72 infiniteQueryOptions?: 42 73 | boolean 43 - | string 74 + | StringName 44 75 | { 76 + /** 77 + * The casing convention to use for generated names. 78 + * 79 + * @default 'camelCase' 80 + */ 45 81 case?: StringCase; 82 + /** 83 + * Whether to generate infinite query options helpers. 84 + * 85 + * @default true 86 + */ 46 87 enabled?: boolean; 47 - name?: string | ((name: string) => string); 88 + /** 89 + * Custom naming pattern for generated infinite query options names. The name variable is 90 + * obtained from the SDK function name. 91 + * 92 + * @default '{{name}}InfiniteOptions' 93 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/createInfiniteQuery 94 + */ 95 + name?: StringName; 48 96 }; 49 97 /** 50 98 * Configuration for generated mutation options helpers. 51 99 * 52 - * See {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/createMutation} 100 + * See {@link https://tanstack.com/query/v5/docs/framework/solid/reference/createMutation} 101 + * 102 + * Can be: 103 + * - `boolean`: Shorthand for `{ enabled: boolean }` 104 + * - `string` or `function`: Shorthand for `{ name: string | function }` 105 + * - `object`: Full configuration object 106 + * 107 + * @default true 53 108 */ 54 109 mutationOptions?: 55 110 | boolean 56 - | string 111 + | StringName 57 112 | { 113 + /** 114 + * The casing convention to use for generated names. 115 + * 116 + * @default 'camelCase' 117 + */ 58 118 case?: StringCase; 119 + /** 120 + * Whether to generate mutation options helpers. 121 + * 122 + * @default true 123 + */ 59 124 enabled?: boolean; 60 - name?: string | ((name: string) => string); 125 + /** 126 + * Custom naming pattern for generated mutation options names. The name variable is 127 + * obtained from the SDK function name. 128 + * 129 + * @default '{{name}}Mutation' 130 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createMutation 131 + */ 132 + name?: StringName; 61 133 }; 62 134 /** 63 135 * Name of the generated file. ··· 69 141 * Configuration for generated query keys. 70 142 * 71 143 * See {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/queryKey} 144 + * 145 + * Can be: 146 + * - `boolean`: Shorthand for `{ enabled: boolean }` 147 + * - `string` or `function`: Shorthand for `{ name: string | function }` 148 + * - `object`: Full configuration object 149 + * 150 + * @default true 72 151 */ 73 152 queryKeys?: 74 153 | boolean 75 - | string 154 + | StringName 76 155 | { 156 + /** 157 + * The casing convention to use for generated names. 158 + * 159 + * @default 'camelCase' 160 + */ 77 161 case?: StringCase; 162 + /** 163 + * Whether to generate query keys. 164 + * 165 + * @default true 166 + */ 78 167 enabled?: boolean; 79 - name?: string | ((name: string) => string); 168 + /** 169 + * Custom naming pattern for generated query key names. The name variable is 170 + * obtained from the SDK function name. 171 + * 172 + * @default '{{name}}QueryKey' 173 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/queryKey 174 + */ 175 + name?: StringName; 80 176 }; 81 177 /** 82 178 * Configuration for generated query options helpers. 83 179 * 84 180 * See {@link https://tanstack.com/query/v5/docs/framework/svelte/reference/createQuery} 181 + * 182 + * Can be: 183 + * - `boolean`: Shorthand for `{ enabled: boolean }` 184 + * - `string` or `function`: Shorthand for `{ name: string | function }` 185 + * - `object`: Full configuration object 186 + * 187 + * @default true 85 188 */ 86 189 queryOptions?: 87 190 | boolean 88 - | string 191 + | StringName 89 192 | { 193 + /** 194 + * The casing convention to use for generated names. 195 + * 196 + * @default 'camelCase' 197 + */ 90 198 case?: StringCase; 199 + /** 200 + * Whether to generate query options helpers. 201 + * 202 + * @default true 203 + */ 91 204 enabled?: boolean; 92 - name?: string | ((name: string) => string); 205 + /** 206 + * Custom naming pattern for generated query options names. The name variable is 207 + * obtained from the SDK function name. 208 + * 209 + * @default '{{name}}Options' 210 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/createQuery 211 + */ 212 + name?: StringName; 93 213 }; 94 214 }; 95 215 96 - export type ResolvedConfig = Plugin.Name<'@tanstack/svelte-query'> & { 216 + export type Config = Plugin.Name<'@tanstack/svelte-query'> & { 97 217 /** 98 218 * The casing convention to use for generated names. 99 219 * ··· 118 238 * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/createInfiniteQuery 119 239 */ 120 240 infiniteQueryKeys: { 241 + /** 242 + * The casing convention to use for generated names. 243 + * 244 + * @default 'camelCase' 245 + */ 121 246 case: StringCase; 247 + /** 248 + * Whether to generate infinite query key helpers. 249 + * 250 + * @default true 251 + */ 122 252 enabled: boolean; 123 - name: string | ((name: string) => string); 253 + /** 254 + * Custom naming pattern for generated infinite query key names. The name variable is 255 + * obtained from the SDK function name. 256 + * 257 + * @default '{{name}}InfiniteQueryKey' 258 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/createInfiniteQuery 259 + */ 260 + name: StringName; 124 261 }; 125 262 /** 126 263 * Resolved configuration for generated infinite query options helpers. ··· 128 265 * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/createInfiniteQuery 129 266 */ 130 267 infiniteQueryOptions: { 268 + /** 269 + * The casing convention to use for generated names. 270 + * 271 + * @default 'camelCase' 272 + */ 131 273 case: StringCase; 274 + /** 275 + * Whether to generate infinite query options helpers. 276 + * 277 + * @default true 278 + */ 132 279 enabled: boolean; 133 - name: string | ((name: string) => string); 280 + /** 281 + * Custom naming pattern for generated infinite query options names. The name variable is 282 + * obtained from the SDK function name. 283 + * 284 + * @default '{{name}}InfiniteOptions' 285 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/createInfiniteQuery 286 + */ 287 + name: StringName; 134 288 }; 135 289 /** 136 290 * Resolved configuration for generated mutation options helpers. ··· 138 292 * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/createMutation 139 293 */ 140 294 mutationOptions: { 295 + /** 296 + * The casing convention to use for generated names. 297 + * 298 + * @default 'camelCase' 299 + */ 141 300 case: StringCase; 301 + /** 302 + * Whether to generate mutation options helpers. 303 + * 304 + * @default true 305 + */ 142 306 enabled: boolean; 143 - name: string | ((name: string) => string); 307 + /** 308 + * Custom naming pattern for generated mutation options names. The name variable is 309 + * obtained from the SDK function name. 310 + * 311 + * @default '{{name}}Mutation' 312 + * @see https://tanstack.com/query/v5/docs/framework/solid/reference/createMutation 313 + */ 314 + name: StringName; 144 315 }; 145 316 /** 146 317 * Name of the generated file. ··· 154 325 * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/queryKey 155 326 */ 156 327 queryKeys: { 328 + /** 329 + * The casing convention to use for generated names. 330 + * 331 + * @default 'camelCase' 332 + */ 157 333 case: StringCase; 334 + /** 335 + * Whether to generate query keys. 336 + * 337 + * @default true 338 + */ 158 339 enabled: boolean; 159 - name: string | ((name: string) => string); 340 + /** 341 + * Custom naming pattern for generated query key names. The name variable is 342 + * obtained from the SDK function name. 343 + * 344 + * @default '{{name}}QueryKey' 345 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/queryKey 346 + */ 347 + name: StringName; 160 348 }; 161 349 /** 162 350 * Resolved configuration for generated query options helpers. ··· 164 352 * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/createQuery 165 353 */ 166 354 queryOptions: { 355 + /** 356 + * The casing convention to use for generated names. 357 + * 358 + * @default 'camelCase' 359 + */ 167 360 case: StringCase; 361 + /** 362 + * Whether to generate query options helpers. 363 + * 364 + * @default true 365 + */ 168 366 enabled: boolean; 169 - name: string | ((name: string) => string); 367 + /** 368 + * Custom naming pattern for generated query options names. The name variable is 369 + * obtained from the SDK function name. 370 + * 371 + * @default '{{name}}Options' 372 + * @see https://tanstack.com/query/v5/docs/framework/svelte/reference/createQuery 373 + */ 374 + name: StringName; 170 375 }; 171 376 }; 172 377 173 - export type TanStackSvelteQueryPlugin = DefinePlugin<Config, ResolvedConfig>; 378 + export type TanStackSvelteQueryPlugin = DefinePlugin<UserConfig, Config>;
+10 -5
packages/openapi-ts/src/plugins/@tanstack/vue-query/config.ts
··· 23 23 }, 24 24 mappers: { 25 25 boolean: (enabled) => ({ enabled }), 26 - string: (name) => ({ enabled: true, name }), 26 + function: (name) => ({ name }), 27 + string: (name) => ({ name }), 27 28 }, 28 29 value: plugin.config.infiniteQueryKeys, 29 30 }); ··· 36 37 }, 37 38 mappers: { 38 39 boolean: (enabled) => ({ enabled }), 39 - string: (name) => ({ enabled: true, name }), 40 + function: (name) => ({ name }), 41 + string: (name) => ({ name }), 40 42 }, 41 43 value: plugin.config.infiniteQueryOptions, 42 44 }); ··· 49 51 }, 50 52 mappers: { 51 53 boolean: (enabled) => ({ enabled }), 52 - string: (name) => ({ enabled: true, name }), 54 + function: (name) => ({ name }), 55 + string: (name) => ({ name }), 53 56 }, 54 57 value: plugin.config.mutationOptions, 55 58 }); ··· 62 65 }, 63 66 mappers: { 64 67 boolean: (enabled) => ({ enabled }), 65 - string: (name) => ({ enabled: true, name }), 68 + function: (name) => ({ name }), 69 + string: (name) => ({ name }), 66 70 }, 67 71 value: plugin.config.queryKeys, 68 72 }); ··· 75 79 }, 76 80 mappers: { 77 81 boolean: (enabled) => ({ enabled }), 78 - string: (name) => ({ enabled: true, name }), 82 + function: (name) => ({ name }), 83 + string: (name) => ({ name }), 79 84 }, 80 85 value: plugin.config.queryOptions, 81 86 });
+224 -19
packages/openapi-ts/src/plugins/@tanstack/vue-query/types.d.ts
··· 1 - import type { StringCase } from '../../../types/case'; 1 + import type { StringCase, StringName } from '../../../types/case'; 2 2 import type { DefinePlugin, Plugin } from '../../types'; 3 3 4 - export type Config = Plugin.Name<'@tanstack/vue-query'> & { 4 + export type UserConfig = Plugin.Name<'@tanstack/vue-query'> & { 5 5 /** 6 6 * The casing convention to use for generated names. 7 7 * ··· 24 24 * Configuration for generated infinite query key helpers. 25 25 * 26 26 * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions} 27 + * 28 + * Can be: 29 + * - `boolean`: Shorthand for `{ enabled: boolean }` 30 + * - `string` or `function`: Shorthand for `{ name: string | function }` 31 + * - `object`: Full configuration object 32 + * 33 + * @default true 27 34 */ 28 35 infiniteQueryKeys?: 29 36 | boolean 30 - | string 37 + | StringName 31 38 | { 39 + /** 40 + * The casing convention to use for generated names. 41 + * 42 + * @default 'camelCase' 43 + */ 32 44 case?: StringCase; 45 + /** 46 + * Whether to generate infinite query key helpers. 47 + * 48 + * @default true 49 + */ 33 50 enabled?: boolean; 34 - name?: string | ((name: string) => string); 51 + /** 52 + * Custom naming pattern for generated infinite query key names. The name variable is 53 + * obtained from the SDK function name. 54 + * 55 + * @default '{{name}}InfiniteQueryKey' 56 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 57 + */ 58 + name?: StringName; 35 59 }; 36 60 /** 37 61 * Configuration for generated infinite query options helpers. 38 62 * 39 63 * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions} 64 + * 65 + * Can be: 66 + * - `boolean`: Shorthand for `{ enabled: boolean }` 67 + * - `string` or `function`: Shorthand for `{ name: string | function }` 68 + * - `object`: Full configuration object 69 + * 70 + * @default true 40 71 */ 41 72 infiniteQueryOptions?: 42 73 | boolean 43 - | string 74 + | StringName 44 75 | { 76 + /** 77 + * The casing convention to use for generated names. 78 + * 79 + * @default 'camelCase' 80 + */ 45 81 case?: StringCase; 82 + /** 83 + * Whether to generate infinite query options helpers. 84 + * 85 + * @default true 86 + */ 46 87 enabled?: boolean; 47 - name?: string | ((name: string) => string); 88 + /** 89 + * Custom naming pattern for generated infinite query options names. The name variable is 90 + * obtained from the SDK function name. 91 + * 92 + * @default '{{name}}InfiniteOptions' 93 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 94 + */ 95 + name?: StringName; 48 96 }; 49 97 /** 50 98 * Configuration for generated mutation options helpers. 51 99 * 52 100 * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/useMutation} 101 + * 102 + * Can be: 103 + * - `boolean`: Shorthand for `{ enabled: boolean }` 104 + * - `string` or `function`: Shorthand for `{ name: string | function }` 105 + * - `object`: Full configuration object 106 + * 107 + * @default true 53 108 */ 54 109 mutationOptions?: 55 110 | boolean 56 - | string 111 + | StringName 57 112 | { 113 + /** 114 + * The casing convention to use for generated names. 115 + * 116 + * @default 'camelCase' 117 + */ 58 118 case?: StringCase; 119 + /** 120 + * Whether to generate mutation options helpers. 121 + * 122 + * @default true 123 + */ 59 124 enabled?: boolean; 60 - name?: string | ((name: string) => string); 125 + /** 126 + * Custom naming pattern for generated mutation options names. The name variable is 127 + * obtained from the SDK function name. 128 + * 129 + * @default '{{name}}Mutation' 130 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/useMutation 131 + */ 132 + name?: StringName; 61 133 }; 62 134 /** 63 135 * Name of the generated file. ··· 69 141 * Configuration for generated query keys. 70 142 * 71 143 * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/queryKey} 144 + * 145 + * Can be: 146 + * - `boolean`: Shorthand for `{ enabled: boolean }` 147 + * - `string` or `function`: Shorthand for `{ name: string | function }` 148 + * - `object`: Full configuration object 149 + * 150 + * @default true 72 151 */ 73 152 queryKeys?: 74 153 | boolean 75 - | string 154 + | StringName 76 155 | { 156 + /** 157 + * The casing convention to use for generated names. 158 + * 159 + * @default 'camelCase' 160 + */ 77 161 case?: StringCase; 162 + /** 163 + * Whether to generate query keys. 164 + * 165 + * @default true 166 + */ 78 167 enabled?: boolean; 79 - name?: string | ((name: string) => string); 168 + /** 169 + * Custom naming pattern for generated query key names. The name variable is 170 + * obtained from the SDK function name. 171 + * 172 + * @default '{{name}}QueryKey' 173 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryKey 174 + */ 175 + name?: StringName; 80 176 }; 81 177 /** 82 178 * Configuration for generated query options helpers. 83 179 * 84 180 * See {@link https://tanstack.com/query/v5/docs/framework/vue/reference/queryOptions} 181 + * 182 + * Can be: 183 + * - `boolean`: Shorthand for `{ enabled: boolean }` 184 + * - `string` or `function`: Shorthand for `{ name: string | function }` 185 + * - `object`: Full configuration object 186 + * 187 + * @default true 85 188 */ 86 189 queryOptions?: 87 190 | boolean 88 - | string 191 + | StringName 89 192 | { 193 + /** 194 + * The casing convention to use for generated names. 195 + * 196 + * @default 'camelCase' 197 + */ 90 198 case?: StringCase; 199 + /** 200 + * Whether to generate query options helpers. 201 + * 202 + * @default true 203 + */ 91 204 enabled?: boolean; 92 - name?: string | ((name: string) => string); 205 + /** 206 + * Custom naming pattern for generated query options names. The name variable is 207 + * obtained from the SDK function name. 208 + * 209 + * @default '{{name}}Options' 210 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryOptions 211 + */ 212 + name?: StringName; 93 213 }; 94 214 }; 95 215 96 - export type ResolvedConfig = Plugin.Name<'@tanstack/vue-query'> & { 216 + export type Config = Plugin.Name<'@tanstack/vue-query'> & { 97 217 /** 98 218 * The casing convention to use for generated names. 99 219 * ··· 118 238 * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 119 239 */ 120 240 infiniteQueryKeys: { 241 + /** 242 + * The casing convention to use for generated names. 243 + * 244 + * @default 'camelCase' 245 + */ 121 246 case: StringCase; 247 + /** 248 + * Whether to generate infinite query key helpers. 249 + * 250 + * @default true 251 + */ 122 252 enabled: boolean; 123 - name: string | ((name: string) => string); 253 + /** 254 + * Custom naming pattern for generated infinite query key names. The name variable is 255 + * obtained from the SDK function name. 256 + * 257 + * @default '{{name}}InfiniteQueryKey' 258 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 259 + */ 260 + name: StringName; 124 261 }; 125 262 /** 126 263 * Resolved configuration for generated infinite query options helpers. ··· 128 265 * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 129 266 */ 130 267 infiniteQueryOptions: { 268 + /** 269 + * The casing convention to use for generated names. 270 + * 271 + * @default 'camelCase' 272 + */ 131 273 case: StringCase; 274 + /** 275 + * Whether to generate infinite query options helpers. 276 + * 277 + * @default true 278 + */ 132 279 enabled: boolean; 133 - name: string | ((name: string) => string); 280 + /** 281 + * Custom naming pattern for generated infinite query options names. The name variable is 282 + * obtained from the SDK function name. 283 + * 284 + * @default '{{name}}InfiniteOptions' 285 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/infiniteQueryOptions 286 + */ 287 + name: StringName; 134 288 }; 135 289 /** 136 290 * Resolved configuration for generated mutation options helpers. ··· 138 292 * @see https://tanstack.com/query/v5/docs/framework/vue/reference/useMutation 139 293 */ 140 294 mutationOptions: { 295 + /** 296 + * The casing convention to use for generated names. 297 + * 298 + * @default 'camelCase' 299 + */ 141 300 case: StringCase; 301 + /** 302 + * Whether to generate mutation options helpers. 303 + * 304 + * @default true 305 + */ 142 306 enabled: boolean; 143 - name: string | ((name: string) => string); 307 + /** 308 + * Custom naming pattern for generated mutation options names. The name variable is 309 + * obtained from the SDK function name. 310 + * 311 + * @default '{{name}}Mutation' 312 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/useMutation 313 + */ 314 + name: StringName; 144 315 }; 145 316 /** 146 317 * Name of the generated file. ··· 154 325 * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryKey 155 326 */ 156 327 queryKeys: { 328 + /** 329 + * The casing convention to use for generated names. 330 + * 331 + * @default 'camelCase' 332 + */ 157 333 case: StringCase; 334 + /** 335 + * Whether to generate query keys. 336 + * 337 + * @default true 338 + */ 158 339 enabled: boolean; 159 - name: string | ((name: string) => string); 340 + /** 341 + * Custom naming pattern for generated query key names. The name variable is 342 + * obtained from the SDK function name. 343 + * 344 + * @default '{{name}}QueryKey' 345 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryKey 346 + */ 347 + name: StringName; 160 348 }; 161 349 /** 162 350 * Resolved configuration for generated query options helpers. ··· 164 352 * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryOptions 165 353 */ 166 354 queryOptions: { 355 + /** 356 + * The casing convention to use for generated names. 357 + * 358 + * @default 'camelCase' 359 + */ 167 360 case: StringCase; 361 + /** 362 + * Whether to generate query options helpers. 363 + * 364 + * @default true 365 + */ 168 366 enabled: boolean; 169 - name: string | ((name: string) => string); 367 + /** 368 + * Custom naming pattern for generated query options names. The name variable is 369 + * obtained from the SDK function name. 370 + * 371 + * @default '{{name}}Options' 372 + * @see https://tanstack.com/query/v5/docs/framework/vue/reference/queryOptions 373 + */ 374 + name: StringName; 170 375 }; 171 376 }; 172 377 173 - export type TanStackVueQueryPlugin = DefinePlugin<Config, ResolvedConfig>; 378 + export type TanStackVueQueryPlugin = DefinePlugin<UserConfig, Config>;
+66 -60
packages/openapi-ts/src/plugins/fastify/plugin.ts
··· 5 5 import { hasParameterGroupObjectRequired } from '../../ir/parameter'; 6 6 import type { IR } from '../../ir/types'; 7 7 import { typesId } from '../@hey-api/typescript/ref'; 8 - import { operationIrRef } from '../shared/utils/ref'; 9 8 import type { FastifyPlugin } from './types'; 10 9 11 10 const fastifyId = 'fastify'; 12 11 13 12 const operationToRouteHandler = ({ 14 - context, 15 13 operation, 14 + plugin, 16 15 }: { 17 - context: IR.Context; 18 16 operation: IR.OperationObject; 17 + plugin: FastifyPlugin['Instance']; 19 18 }): Property | undefined => { 20 - const file = context.file({ id: fastifyId })!; 21 - const fileTypes = context.file({ id: typesId })!; 19 + const file = plugin.context.file({ id: fastifyId })!; 22 20 23 21 const properties: Array<Property> = []; 24 22 25 - const identifierData = fileTypes.identifier({ 26 - $ref: operationIrRef({ 27 - config: context.config, 28 - id: operation.id, 29 - type: 'data', 30 - }), 31 - namespace: 'type', 32 - }); 33 - if (identifierData.name) { 23 + const pluginTypeScript = plugin.getPlugin('@hey-api/typescript')!; 24 + const fileTypeScript = plugin.context.file({ id: typesId })!; 25 + const dataName = fileTypeScript.getName( 26 + pluginTypeScript.api.getId({ operation, type: 'data' }), 27 + ); 28 + if (dataName) { 34 29 if (operation.body) { 35 30 file.import({ 36 31 asType: true, 37 - module: file.relativePathToFile({ context, id: typesId }), 38 - name: identifierData.name, 32 + module: file.relativePathToFile({ 33 + context: plugin.context, 34 + id: typesId, 35 + }), 36 + name: dataName, 39 37 }); 40 38 properties.push({ 41 39 isRequired: operation.body.required, 42 40 name: 'Body', 43 - type: `${identifierData.name}['body']`, 41 + type: `${dataName}['body']`, 44 42 }); 45 43 } 46 44 ··· 48 46 if (operation.parameters.header) { 49 47 file.import({ 50 48 asType: true, 51 - module: file.relativePathToFile({ context, id: typesId }), 52 - name: identifierData.name, 49 + module: file.relativePathToFile({ 50 + context: plugin.context, 51 + id: typesId, 52 + }), 53 + name: dataName, 53 54 }); 54 55 properties.push({ 55 56 isRequired: hasParameterGroupObjectRequired( 56 57 operation.parameters.header, 57 58 ), 58 59 name: 'Headers', 59 - type: `${identifierData.name}['headers']`, 60 + type: `${dataName}['headers']`, 60 61 }); 61 62 } 62 63 63 64 if (operation.parameters.path) { 64 65 file.import({ 65 66 asType: true, 66 - module: file.relativePathToFile({ context, id: typesId }), 67 - name: identifierData.name, 67 + module: file.relativePathToFile({ 68 + context: plugin.context, 69 + id: typesId, 70 + }), 71 + name: dataName, 68 72 }); 69 73 properties.push({ 70 74 isRequired: hasParameterGroupObjectRequired( 71 75 operation.parameters.path, 72 76 ), 73 77 name: 'Params', 74 - type: `${identifierData.name}['path']`, 78 + type: `${dataName}['path']`, 75 79 }); 76 80 } 77 81 78 82 if (operation.parameters.query) { 79 83 file.import({ 80 84 asType: true, 81 - module: file.relativePathToFile({ context, id: typesId }), 82 - name: identifierData.name, 85 + module: file.relativePathToFile({ 86 + context: plugin.context, 87 + id: typesId, 88 + }), 89 + name: dataName, 83 90 }); 84 91 properties.push({ 85 92 isRequired: hasParameterGroupObjectRequired( 86 93 operation.parameters.query, 87 94 ), 88 95 name: 'Querystring', 89 - type: `${identifierData.name}['query']`, 96 + type: `${dataName}['query']`, 90 97 }); 91 98 } 92 99 } ··· 95 102 const { errors, responses } = operationResponsesMap(operation); 96 103 97 104 let errorsTypeReference: ts.TypeReferenceNode | undefined = undefined; 98 - const identifierErrors = fileTypes.identifier({ 99 - $ref: operationIrRef({ 100 - config: context.config, 101 - id: operation.id, 102 - type: 'errors', 103 - }), 104 - namespace: 'type', 105 - }); 106 - if (identifierErrors.name && errors && errors.properties) { 105 + const errorName = fileTypeScript.getName( 106 + pluginTypeScript.api.getId({ operation, type: 'errors' }), 107 + ); 108 + if (errorName && errors && errors.properties) { 107 109 const keys = Object.keys(errors.properties); 108 110 if (keys.length) { 109 111 const hasDefaultResponse = keys.includes('default'); 110 112 if (!hasDefaultResponse) { 111 113 file.import({ 112 114 asType: true, 113 - module: file.relativePathToFile({ context, id: typesId }), 114 - name: identifierErrors.name, 115 + module: file.relativePathToFile({ 116 + context: plugin.context, 117 + id: typesId, 118 + }), 119 + name: errorName, 115 120 }); 116 121 errorsTypeReference = compiler.typeReferenceNode({ 117 - typeName: identifierErrors.name, 122 + typeName: errorName, 118 123 }); 119 124 } else if (keys.length > 1) { 120 125 file.import({ 121 126 asType: true, 122 - module: file.relativePathToFile({ context, id: typesId }), 123 - name: identifierErrors.name, 127 + module: file.relativePathToFile({ 128 + context: plugin.context, 129 + id: typesId, 130 + }), 131 + name: errorName, 124 132 }); 125 133 const errorsType = compiler.typeReferenceNode({ 126 - typeName: identifierErrors.name, 134 + typeName: errorName, 127 135 }); 128 136 const defaultType = compiler.literalTypeNode({ 129 137 literal: compiler.stringLiteral({ text: 'default' }), ··· 137 145 } 138 146 139 147 let responsesTypeReference: ts.TypeReferenceNode | undefined = undefined; 140 - const identifierResponses = fileTypes.identifier({ 141 - $ref: operationIrRef({ 142 - config: context.config, 143 - id: operation.id, 144 - type: 'responses', 145 - }), 146 - namespace: 'type', 147 - }); 148 - if (identifierResponses.name && responses && responses.properties) { 148 + const responseName = fileTypeScript.getName( 149 + pluginTypeScript.api.getId({ operation, type: 'responses' }), 150 + ); 151 + if (responseName && responses && responses.properties) { 149 152 const keys = Object.keys(responses.properties); 150 153 if (keys.length) { 151 154 const hasDefaultResponse = keys.includes('default'); 152 155 if (!hasDefaultResponse) { 153 156 file.import({ 154 157 asType: true, 155 - module: file.relativePathToFile({ context, id: typesId }), 156 - name: identifierResponses.name, 158 + module: file.relativePathToFile({ 159 + context: plugin.context, 160 + id: typesId, 161 + }), 162 + name: responseName, 157 163 }); 158 164 responsesTypeReference = compiler.typeReferenceNode({ 159 - typeName: identifierResponses.name, 165 + typeName: responseName, 160 166 }); 161 167 } else if (keys.length > 1) { 162 168 file.import({ 163 169 asType: true, 164 - module: file.relativePathToFile({ context, id: typesId }), 165 - name: identifierResponses.name, 170 + module: file.relativePathToFile({ 171 + context: plugin.context, 172 + id: typesId, 173 + }), 174 + name: responseName, 166 175 }); 167 176 const responsesType = compiler.typeReferenceNode({ 168 - typeName: identifierResponses.name, 177 + typeName: responseName, 169 178 }); 170 179 const defaultType = compiler.literalTypeNode({ 171 180 literal: compiler.stringLiteral({ text: 'default' }), ··· 215 224 const routeHandlers: Array<Property> = []; 216 225 217 226 plugin.forEach('operation', ({ operation }) => { 218 - const routeHandler = operationToRouteHandler({ 219 - context: plugin.context, 220 - operation, 221 - }); 227 + const routeHandler = operationToRouteHandler({ operation, plugin }); 222 228 if (routeHandler) { 223 229 routeHandlers.push(routeHandler); 224 230 }
+2 -2
packages/openapi-ts/src/plugins/fastify/types.d.ts
··· 1 1 import type { DefinePlugin, Plugin } from '../types'; 2 2 3 - export type Config = Plugin.Name<'fastify'> & { 3 + export type UserConfig = Plugin.Name<'fastify'> & { 4 4 /** 5 5 * Should the exports from the generated files be re-exported in the index 6 6 * barrel file? ··· 16 16 output?: string; 17 17 }; 18 18 19 - export type FastifyPlugin = DefinePlugin<Config>; 19 + export type FastifyPlugin = DefinePlugin<UserConfig>;
-61
packages/openapi-ts/src/plugins/shared/utils/ref.ts
··· 1 - import type { StringCase } from '../../../types/case'; 2 - import type { Config } from '../../../types/config'; 3 - import { irRef } from '../../../utils/ref'; 4 - import { stringCase } from '../../../utils/stringCase'; 5 - 6 - interface OperationIRRef { 7 - /** 8 - * Operation ID 9 - */ 10 - id: string; 11 - } 12 - 13 - // TODO: this needs refactor 14 - export const operationIrRef = ({ 15 - case: _case = 'PascalCase', 16 - config, 17 - id, 18 - parameterId, 19 - type, 20 - }: OperationIRRef & { 21 - readonly case?: StringCase; 22 - config: Pick<Config, 'plugins'>; 23 - parameterId?: string; 24 - type: 'data' | 'error' | 'errors' | 'parameter' | 'response' | 'responses'; 25 - }): string => { 26 - let affix = ''; 27 - switch (type) { 28 - case 'data': 29 - case 'error': // error union 30 - case 'errors': // errors map 31 - case 'parameter': 32 - case 'response': // response union 33 - case 'responses': // responses map 34 - affix = `${(type[0] ?? '').toLocaleUpperCase()}${type.slice(1)}`; 35 - break; 36 - } 37 - let separate = true; 38 - if (config.plugins['@hey-api/typescript']?.config.case === 'preserve') { 39 - separate = false; 40 - } 41 - const separator = separate ? '-' : ''; 42 - const parts: Array<string> = [ 43 - irRef, 44 - stringCase({ 45 - case: _case, 46 - value: id, 47 - }), 48 - separator, 49 - affix, 50 - ]; 51 - if (parameterId) { 52 - parts.push( 53 - separator, 54 - stringCase({ 55 - case: _case, 56 - value: parameterId, 57 - }), 58 - ); 59 - } 60 - return parts.join(''); 61 - };
+1 -1
packages/openapi-ts/src/plugins/types.d.ts
··· 95 95 config: Omit<T['config'], 'output'>; 96 96 }; 97 97 98 - /** @deprecated - use `definePluginConfig()` instead */ 98 + /** @deprecated use `definePluginConfig()` instead */ 99 99 export type DefineConfig< 100 100 Config extends BaseConfig, 101 101 ResolvedConfig extends BaseConfig = Config,
+5 -5
packages/openapi-ts/src/plugins/valibot/api.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 3 import { compiler } from '../../compiler'; 4 - import type { TypeScriptFile } from '../../generate/files'; 4 + import type { GeneratedFile } from '../../generate/file'; 5 5 import type { IR } from '../../ir/types'; 6 6 import { identifiers, valibotId } from './constants'; 7 7 import type { ValibotPlugin } from './types'; ··· 11 11 operation, 12 12 plugin, 13 13 }: { 14 - file: TypeScriptFile; 14 + file: GeneratedFile; 15 15 operation: IR.OperationObject; 16 16 plugin: ValibotPlugin['Instance']; 17 17 }): ts.ArrowFunction | undefined => { ··· 75 75 operation, 76 76 plugin, 77 77 }: { 78 - file: TypeScriptFile; 78 + file: GeneratedFile; 79 79 operation: IR.OperationObject; 80 80 plugin: ValibotPlugin['Instance']; 81 81 }): ts.ArrowFunction | undefined => { ··· 136 136 137 137 export type Api = { 138 138 createRequestValidator: (args: { 139 - file: TypeScriptFile; 139 + file: GeneratedFile; 140 140 operation: IR.OperationObject; 141 141 plugin: ValibotPlugin['Instance']; 142 142 }) => ts.ArrowFunction | undefined; 143 143 createResponseValidator: (args: { 144 - file: TypeScriptFile; 144 + file: GeneratedFile; 145 145 operation: IR.OperationObject; 146 146 plugin: ValibotPlugin['Instance']; 147 147 }) => ts.ArrowFunction | undefined;
+6 -3
packages/openapi-ts/src/plugins/valibot/config.ts
··· 23 23 }, 24 24 mappers: { 25 25 boolean: (enabled) => ({ enabled }), 26 - string: (name) => ({ enabled: true, name }), 26 + function: (name) => ({ name }), 27 + string: (name) => ({ name }), 27 28 }, 28 29 value: plugin.config.definitions, 29 30 }); ··· 36 37 }, 37 38 mappers: { 38 39 boolean: (enabled) => ({ enabled }), 39 - string: (name) => ({ enabled: true, name }), 40 + function: (name) => ({ name }), 41 + string: (name) => ({ name }), 40 42 }, 41 43 value: plugin.config.requests, 42 44 }); ··· 49 51 }, 50 52 mappers: { 51 53 boolean: (enabled) => ({ enabled }), 52 - string: (name) => ({ enabled: true, name }), 54 + function: (name) => ({ name }), 55 + string: (name) => ({ name }), 53 56 }, 54 57 value: plugin.config.responses, 55 58 });
+4 -4
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 + import type { Identifier } from '../../generate/file/types'; 5 5 import { deduplicateSchema } from '../../ir/schema'; 6 6 import type { IR } from '../../ir/types'; 7 - import type { StringCase } from '../../types/case'; 7 + import type { StringCase, StringName } from '../../types/case'; 8 8 import { numberRegExp } from '../../utils/regexp'; 9 9 import { createSchemaComment } from '../shared/utils/schema'; 10 10 import { identifiers, valibotId } from './constants'; ··· 20 20 circularReferenceTracker: Set<string>; 21 21 hasCircularReference: boolean; 22 22 nameCase: StringCase; 23 - nameTransformer: string | ((name: string) => string); 23 + nameTransformer: StringName; 24 24 } 25 25 26 26 const pipesToExpression = (pipes: Array<ts.Expression>) => { ··· 1055 1055 1056 1056 export const handler: ValibotPlugin['Handler'] = ({ plugin }) => { 1057 1057 const file = plugin.createFile({ 1058 + case: plugin.config.case, 1058 1059 id: valibotId, 1059 - identifierCase: plugin.config.case, 1060 1060 path: plugin.output, 1061 1061 }); 1062 1062
+16 -16
packages/openapi-ts/src/plugins/valibot/types.d.ts
··· 1 - import type { StringCase } from '../../types/case'; 1 + import type { StringCase, StringName } from '../../types/case'; 2 2 import type { DefinePlugin, Plugin } from '../types'; 3 3 import type { Api } from './api'; 4 4 5 - export type Config = Plugin.Name<'valibot'> & { 5 + export type UserConfig = Plugin.Name<'valibot'> & { 6 6 /** 7 7 * The casing convention to use for generated names. 8 8 * ··· 23 23 * 24 24 * Can be: 25 25 * - `boolean`: Shorthand for `{ enabled: boolean }` 26 - * - `string`: Shorthand for `{ enabled: true; name: string }` 26 + * - `string` or `function`: Shorthand for `{ name: string | function }` 27 27 * - `object`: Full configuration object 28 28 */ 29 29 definitions?: 30 30 | boolean 31 - | string 31 + | StringName 32 32 | { 33 33 /** 34 34 * The casing convention to use for generated names. ··· 48 48 * 49 49 * @default 'v{{name}}' 50 50 */ 51 - name?: string | ((name: string) => string); 51 + name?: StringName; 52 52 }; 53 53 /** 54 54 * Should the exports from the generated files be re-exported in the index ··· 79 79 * 80 80 * Can be: 81 81 * - `boolean`: Shorthand for `{ enabled: boolean }` 82 - * - `string`: Shorthand for `{ enabled: true; name: string }` 82 + * - `string` or `function`: Shorthand for `{ name: string | function }` 83 83 * - `object`: Full configuration object 84 84 */ 85 85 requests?: 86 86 | boolean 87 - | string 87 + | StringName 88 88 | { 89 89 /** 90 90 * The casing convention to use for generated names. ··· 104 104 * 105 105 * @default 'v{{name}}Data' 106 106 */ 107 - name?: string | ((name: string) => string); 107 + name?: StringName; 108 108 }; 109 109 /** 110 110 * Configuration for response-specific Valibot schemas. ··· 114 114 * 115 115 * Can be: 116 116 * - `boolean`: Shorthand for `{ enabled: boolean }` 117 - * - `string`: Shorthand for `{ enabled: true; name: string }` 117 + * - `string` or `function`: Shorthand for `{ name: string | function }` 118 118 * - `object`: Full configuration object 119 119 */ 120 120 responses?: 121 121 | boolean 122 - | string 122 + | StringName 123 123 | { 124 124 /** 125 125 * The casing convention to use for generated names. ··· 139 139 * 140 140 * @default 'v{{name}}Response' 141 141 */ 142 - name?: string | ((name: string) => string); 142 + name?: StringName; 143 143 }; 144 144 }; 145 145 146 - export type ResolvedConfig = Plugin.Name<'valibot'> & { 146 + export type Config = Plugin.Name<'valibot'> & { 147 147 /** 148 148 * The casing convention to use for generated names. 149 149 * ··· 181 181 * 182 182 * @default 'v{{name}}' 183 183 */ 184 - name: string | ((name: string) => string); 184 + name: StringName; 185 185 }; 186 186 /** 187 187 * Should the exports from the generated files be re-exported in the index ··· 229 229 * 230 230 * @default 'v{{name}}Data' 231 231 */ 232 - name: string | ((name: string) => string); 232 + name: StringName; 233 233 }; 234 234 /** 235 235 * Configuration for response-specific Valibot schemas. ··· 256 256 * 257 257 * @default 'v{{name}}Response' 258 258 */ 259 - name: string | ((name: string) => string); 259 + name: StringName; 260 260 }; 261 261 }; 262 262 263 - export type ValibotPlugin = DefinePlugin<Config, ResolvedConfig, Api>; 263 + export type ValibotPlugin = DefinePlugin<UserConfig, Config, Api>;
+5 -5
packages/openapi-ts/src/plugins/zod/api.ts
··· 1 1 import type ts from 'typescript'; 2 2 3 3 import { compiler } from '../../compiler'; 4 - import type { TypeScriptFile } from '../../generate/files'; 4 + import type { GeneratedFile } from '../../generate/file'; 5 5 import type { IR } from '../../ir/types'; 6 6 import { identifiers, zodId } from './constants'; 7 7 import type { ZodPlugin } from './types'; ··· 11 11 operation, 12 12 plugin, 13 13 }: { 14 - file: TypeScriptFile; 14 + file: GeneratedFile; 15 15 operation: IR.OperationObject; 16 16 plugin: ZodPlugin['Instance']; 17 17 }): ts.ArrowFunction | undefined => { ··· 66 66 operation, 67 67 plugin, 68 68 }: { 69 - file: TypeScriptFile; 69 + file: GeneratedFile; 70 70 operation: IR.OperationObject; 71 71 plugin: ZodPlugin['Instance']; 72 72 }): ts.ArrowFunction | undefined => { ··· 118 118 119 119 export type Api = { 120 120 createRequestValidator: (args: { 121 - file: TypeScriptFile; 121 + file: GeneratedFile; 122 122 operation: IR.OperationObject; 123 123 plugin: ZodPlugin['Instance']; 124 124 }) => ts.ArrowFunction | undefined; 125 125 createResponseValidator: (args: { 126 - file: TypeScriptFile; 126 + file: GeneratedFile; 127 127 operation: IR.OperationObject; 128 128 plugin: ZodPlugin['Instance']; 129 129 }) => ts.ArrowFunction | undefined;
+6 -3
packages/openapi-ts/src/plugins/zod/config.ts
··· 30 30 }, 31 31 mappers: { 32 32 boolean: (enabled) => ({ enabled }), 33 - string: (name) => ({ enabled: true, name }), 33 + function: (name) => ({ name }), 34 + string: (name) => ({ name }), 34 35 }, 35 36 value: plugin.config.definitions, 36 37 }); ··· 43 44 }, 44 45 mappers: { 45 46 boolean: (enabled) => ({ enabled }), 46 - string: (name) => ({ enabled: true, name }), 47 + function: (name) => ({ name }), 48 + string: (name) => ({ name }), 47 49 }, 48 50 value: plugin.config.requests, 49 51 }); ··· 56 58 }, 57 59 mappers: { 58 60 boolean: (enabled) => ({ enabled }), 59 - string: (name) => ({ enabled: true, name }), 61 + function: (name) => ({ name }), 62 + string: (name) => ({ name }), 60 63 }, 61 64 value: plugin.config.responses, 62 65 });
+4 -4
packages/openapi-ts/src/plugins/zod/plugin.ts
··· 1 1 import ts from 'typescript'; 2 2 3 3 import { compiler } from '../../compiler'; 4 - import type { Identifier } from '../../generate/files'; 4 + import type { Identifier } from '../../generate/file/types'; 5 5 import { deduplicateSchema } from '../../ir/schema'; 6 6 import type { IR } from '../../ir/types'; 7 - import type { StringCase } from '../../types/case'; 7 + import type { StringCase, StringName } from '../../types/case'; 8 8 import { numberRegExp } from '../../utils/regexp'; 9 9 import { createSchemaComment } from '../shared/utils/schema'; 10 10 import { zodId } from './constants'; ··· 20 20 circularReferenceTracker: Set<string>; 21 21 hasCircularReference: boolean; 22 22 nameCase: StringCase; 23 - nameTransformer: string | ((name: string) => string); 23 + nameTransformer: StringName; 24 24 } 25 25 26 26 // frequently used identifiers ··· 1014 1014 1015 1015 export const handler: ZodPlugin['Handler'] = ({ plugin }) => { 1016 1016 const file = plugin.createFile({ 1017 + case: plugin.config.case, 1017 1018 id: zodId, 1018 - identifierCase: plugin.config.case, 1019 1019 path: plugin.output, 1020 1020 }); 1021 1021
+22 -22
packages/openapi-ts/src/plugins/zod/types.d.ts
··· 1 - import type { StringCase } from '../../types/case'; 1 + import type { StringCase, StringName } from '../../types/case'; 2 2 import type { DefinePlugin, Plugin } from '../types'; 3 3 import type { Api } from './api'; 4 4 5 - export type Config = Plugin.Name<'zod'> & { 5 + export type UserConfig = Plugin.Name<'zod'> & { 6 6 /** 7 7 * The casing convention to use for generated names. 8 8 * ··· 40 40 * 41 41 * Can be: 42 42 * - `boolean`: Shorthand for `{ enabled: boolean }` 43 - * - `string`: Shorthand for `{ enabled: true; name: string }` 43 + * - `string` or `function`: Shorthand for `{ name: string | function }` 44 44 * - `object`: Full configuration object 45 45 */ 46 46 definitions?: 47 47 | boolean 48 - | string 48 + | StringName 49 49 | { 50 50 /** 51 51 * The casing convention to use for generated names. ··· 60 60 */ 61 61 enabled?: boolean; 62 62 /** 63 - * Custom naming pattern for generated schema names. The name variable is 64 - * obtained from the schema name. 63 + * Custom naming pattern for generated schema names. The name variable 64 + * is obtained from the schema name. 65 65 * 66 66 * @default 'z{{name}}' 67 67 */ 68 - name?: string | ((name: string) => string); 68 + name?: StringName; 69 69 }; 70 70 /** 71 71 * Should the exports from the generated files be re-exported in the index ··· 96 96 * 97 97 * Can be: 98 98 * - `boolean`: Shorthand for `{ enabled: boolean }` 99 - * - `string`: Shorthand for `{ enabled: true; name: string }` 99 + * - `string` or `function`: Shorthand for `{ name: string | function }` 100 100 * - `object`: Full configuration object 101 101 */ 102 102 requests?: 103 103 | boolean 104 - | string 104 + | StringName 105 105 | { 106 106 /** 107 107 * The casing convention to use for generated names. ··· 116 116 */ 117 117 enabled?: boolean; 118 118 /** 119 - * Custom naming pattern for generated schema names. The name variable is 120 - * obtained from the operation name. 119 + * Custom naming pattern for generated schema names. The name variable 120 + * is obtained from the operation name. 121 121 * 122 122 * @default 'z{{name}}Data' 123 123 */ 124 - name?: string | ((name: string) => string); 124 + name?: StringName; 125 125 }; 126 126 /** 127 127 * Configuration for response-specific Zod schemas. ··· 131 131 * 132 132 * Can be: 133 133 * - `boolean`: Shorthand for `{ enabled: boolean }` 134 - * - `string`: Shorthand for `{ enabled: true; name: string }` 134 + * - `string` or `function`: Shorthand for `{ name: string | function }` 135 135 * - `object`: Full configuration object 136 136 */ 137 137 responses?: 138 138 | boolean 139 - | string 139 + | StringName 140 140 | { 141 141 /** 142 142 * The casing convention to use for generated names. ··· 151 151 */ 152 152 enabled?: boolean; 153 153 /** 154 - * Custom naming pattern for generated schema names. The name variable is 155 - * obtained from the operation name. 154 + * Custom naming pattern for generated schema names. The name variable 155 + * is obtained from the operation name. 156 156 * 157 157 * @default 'z{{name}}Response' 158 158 */ 159 - name?: string | ((name: string) => string); 159 + name?: StringName; 160 160 }; 161 161 }; 162 162 163 - export type ResolvedConfig = Plugin.Name<'zod'> & { 163 + export type Config = Plugin.Name<'zod'> & { 164 164 /** 165 165 * The casing convention to use for generated names. 166 166 * ··· 215 215 * 216 216 * @default 'z{{name}}' 217 217 */ 218 - name: string | ((name: string) => string); 218 + name: StringName; 219 219 }; 220 220 /** 221 221 * Should the exports from the generated files be re-exported in the index ··· 263 263 * 264 264 * @default 'z{{name}}Data' 265 265 */ 266 - name: string | ((name: string) => string); 266 + name: StringName; 267 267 }; 268 268 /** 269 269 * Configuration for response-specific Zod schemas. ··· 290 290 * 291 291 * @default 'z{{name}}Response' 292 292 */ 293 - name: string | ((name: string) => string); 293 + name: StringName; 294 294 }; 295 295 }; 296 296 297 - export type ZodPlugin = DefinePlugin<Config, ResolvedConfig, Api>; 297 + export type ZodPlugin = DefinePlugin<UserConfig, Config, Api>;
+2
packages/openapi-ts/src/types/case.d.ts
··· 4 4 | 'preserve' 5 5 | 'snake_case' 6 6 | 'SCREAMING_SNAKE_CASE'; 7 + 8 + export type StringName = string | ((name: string) => string);
+17 -9
packages/openapi-ts/src/types/parser.d.ts
··· 6 6 OpenApiResponseObject, 7 7 OpenApiSchemaObject, 8 8 } from '../openApi/types'; 9 - import type { StringCase } from './case'; 9 + import type { StringCase, StringName } from './case'; 10 10 11 11 type EnumsMode = 'inline' | 'root'; 12 12 ··· 83 83 * 84 84 * @default '{{name}}Enum' 85 85 */ 86 - name?: string | ((name: string) => string); 86 + name?: StringName; 87 87 }; 88 88 /** 89 89 * Your schemas might contain read-only or write-only fields. Using such ··· 107 107 enabled?: boolean; 108 108 /** 109 109 * Configuration for generated request-specific schemas. 110 + * 111 + * Can be: 112 + * - `string` or `function`: Shorthand for `{ name: string | function }` 113 + * - `object`: Full configuration object 110 114 * 111 115 * @default '{{name}}Writable' 112 116 */ 113 117 requests?: 114 - | string 118 + | StringName 115 119 | { 116 120 /** 117 121 * The casing convention to use for generated names. ··· 125 129 * 126 130 * @default '{{name}}Writable' 127 131 */ 128 - name?: string | ((name: string) => string); 132 + name?: StringName; 129 133 }; 130 134 /** 131 135 * Configuration for generated response-specific schemas. 132 136 * 137 + * Can be: 138 + * - `string` or `function`: Shorthand for `{ name: string | function }` 139 + * - `object`: Full configuration object 140 + * 133 141 * @default '{{name}}' 134 142 */ 135 143 responses?: 136 - | string 144 + | StringName 137 145 | { 138 146 /** 139 147 * The casing convention to use for generated names. ··· 148 156 * 149 157 * @default '{{name}}' 150 158 */ 151 - name?: string | ((name: string) => string); 159 + name?: StringName; 152 160 }; 153 161 }; 154 162 }; ··· 232 240 * 233 241 * @default '{{name}}Enum' 234 242 */ 235 - name: string | ((name: string) => string); 243 + name: StringName; 236 244 }; 237 245 /** 238 246 * Your schemas might contain read-only or write-only fields. Using such ··· 266 274 * 267 275 * @default '{{name}}Writable' 268 276 */ 269 - name: string | ((name: string) => string); 277 + name: StringName; 270 278 }; 271 279 /** 272 280 * Configuration for generated response-specific schemas. ··· 285 293 * 286 294 * @default '{{name}}' 287 295 */ 288 - name: string | ((name: string) => string); 296 + name: StringName; 289 297 }; 290 298 }; 291 299 };
+2 -2
packages/openapi-ts/src/types/utils.d.ts
··· 1 - import type { TypeScriptFile } from '../generate/files'; 1 + import type { GeneratedFile } from '../generate/file'; 2 2 3 - export type Files = Record<string, TypeScriptFile>; 3 + export type Files = Record<string, GeneratedFile>;
+6
packages/openapi-ts/src/utils/__tests__/handlebars.test.ts
··· 80 80 output: '', 81 81 }, 82 82 '@hey-api/typescript': { 83 + api: { 84 + getId: () => '', 85 + }, 83 86 config: { 84 87 enums: 'javascript', 85 88 name: '@hey-api/typescript', ··· 184 187 output: '', 185 188 }, 186 189 '@hey-api/typescript': { 190 + api: { 191 + getId: () => '', 192 + }, 187 193 config: { 188 194 enums: 'javascript', 189 195 name: '@hey-api/typescript',
-8
packages/openapi-ts/src/utils/ref.ts
··· 1 1 const jsonPointerSlash = /~1/g; 2 2 const jsonPointerTilde = /~0/g; 3 3 4 - export const irRef = '#/ir/'; 5 - 6 - export const isRefOpenApiComponent = ($ref: string): boolean => { 7 - const path = jsonPointerToPath($ref); 8 - // reusable components are nested within components/<namespace>/<name> 9 - return path.length === 3 && path[0] === 'components'; 10 - }; 11 - 12 4 /** 13 5 * Returns the reusable component name from `$ref`. 14 6 */