@kubb/plugin-ts 4.14.0 → 4.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/{components-HKIi69kI.js → components-BE9rQGox.js} +60 -28
  2. package/dist/components-BE9rQGox.js.map +1 -0
  3. package/dist/{components-pzX1Kb4u.cjs → components-CGcs8968.cjs} +90 -28
  4. package/dist/components-CGcs8968.cjs.map +1 -0
  5. package/dist/components.cjs +1 -1
  6. package/dist/components.d.cts +3 -1
  7. package/dist/components.d.ts +3 -1
  8. package/dist/components.js +1 -1
  9. package/dist/generators.cjs +1 -1
  10. package/dist/generators.d.cts +1 -1
  11. package/dist/generators.d.ts +1 -1
  12. package/dist/generators.js +1 -1
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.d.cts +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.js +1 -1
  17. package/dist/{plugin-DljW3znk.cjs → plugin-B96TNDf4.cjs} +174 -21
  18. package/dist/plugin-B96TNDf4.cjs.map +1 -0
  19. package/dist/{plugin-BEfry-Dm.js → plugin-DXyNbr_u.js} +173 -21
  20. package/dist/plugin-DXyNbr_u.js.map +1 -0
  21. package/dist/{types-C51mhXW0.d.cts → types-CKtzgWEC.d.cts} +14 -1
  22. package/dist/{types-DcA3qMIF.d.ts → types-CnQREd_1.d.ts} +14 -1
  23. package/package.json +4 -4
  24. package/src/components/Type.tsx +8 -2
  25. package/src/factory.ts +77 -3
  26. package/src/generators/__snapshots__/createPet.ts +1 -1
  27. package/src/generators/__snapshots__/createPetWithEmptySchemaTypeUnknown.ts +1 -1
  28. package/src/generators/__snapshots__/createPetWithEmptySchemaTypeVoid.ts +1 -1
  29. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +1 -1
  30. package/src/generators/__snapshots__/createPetWithUnknownTypeVoid.ts +1 -1
  31. package/src/generators/__snapshots__/deletePet.ts +1 -1
  32. package/src/generators/__snapshots__/getPets.ts +1 -1
  33. package/src/generators/__snapshots__/showPetById.ts +1 -1
  34. package/src/generators/__snapshots__/systemsWithExplodeForm.ts +1 -1
  35. package/src/generators/typeGenerator.tsx +232 -8
  36. package/src/parser.ts +9 -20
  37. package/src/plugin.ts +4 -0
  38. package/src/types.ts +12 -0
  39. package/dist/components-HKIi69kI.js.map +0 -1
  40. package/dist/components-pzX1Kb4u.cjs.map +0 -1
  41. package/dist/plugin-BEfry-Dm.js.map +0 -1
  42. package/dist/plugin-DljW3znk.cjs.map +0 -1
@@ -1,4 +1,4 @@
1
- import { a as createTypeLiteralNode, c as modifiers, i as createTypeAliasDeclaration, n as createIdentifier, o as createTypeReferenceNode, r as createPropertySignature, s as createUnionDeclaration, t as Type } from "./components-HKIi69kI.js";
1
+ import { a as createTypeAliasDeclaration, c as createTypeReferenceNode, d as getUnknownType, f as keywordTypeNodes, i as createPropertySignature, l as createUnionDeclaration, n as createIdentifier, o as createTypeLiteralNode, p as modifiers, r as createIndexedAccessTypeNode, s as createTypeOperatorNode, t as Type, u as createUrlTemplateType } from "./components-BE9rQGox.js";
2
2
  import path from "node:path";
3
3
  import { definePlugin, getBarrelFiles, getMode } from "@kubb/core";
4
4
  import transformers, { camelCase, pascalCase } from "@kubb/core/transformers";
@@ -9,6 +9,7 @@ import { createReactGenerator } from "@kubb/plugin-oas/generators";
9
9
  import { useOas, useOperationManager, useSchemaManager } from "@kubb/plugin-oas/hooks";
10
10
  import { getBanner, getFooter } from "@kubb/plugin-oas/utils";
11
11
  import { File } from "@kubb/react-fabric";
12
+ import ts from "typescript";
12
13
  import { Fragment, jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
13
14
 
14
15
  //#region src/generators/typeGenerator.tsx
@@ -75,22 +76,145 @@ function printCombinedSchema({ name, schemas, pluginManager }) {
75
76
  modifiers: [modifiers.export]
76
77
  }));
77
78
  }
79
+ function printRequestSchema({ baseName, operation, schemas, pluginManager }) {
80
+ const name = pluginManager.resolveName({
81
+ name: `${baseName} Request`,
82
+ pluginKey: [pluginTsName],
83
+ type: "type"
84
+ });
85
+ const results = [];
86
+ const dataRequestProperties = [];
87
+ if (schemas.request) {
88
+ const identifier = pluginManager.resolveName({
89
+ name: schemas.request.name,
90
+ pluginKey: [pluginTsName],
91
+ type: "type"
92
+ });
93
+ dataRequestProperties.push(createPropertySignature({
94
+ name: "data",
95
+ questionToken: true,
96
+ type: createTypeReferenceNode(createIdentifier(identifier), void 0)
97
+ }));
98
+ } else dataRequestProperties.push(createPropertySignature({
99
+ name: "data",
100
+ questionToken: true,
101
+ type: keywordTypeNodes.never
102
+ }));
103
+ if (schemas.pathParams) {
104
+ const identifier = pluginManager.resolveName({
105
+ name: schemas.pathParams.name,
106
+ pluginKey: [pluginTsName],
107
+ type: "type"
108
+ });
109
+ dataRequestProperties.push(createPropertySignature({
110
+ name: "pathParams",
111
+ type: createTypeReferenceNode(createIdentifier(identifier), void 0)
112
+ }));
113
+ } else dataRequestProperties.push(createPropertySignature({
114
+ name: "pathParams",
115
+ questionToken: true,
116
+ type: keywordTypeNodes.never
117
+ }));
118
+ if (schemas.queryParams) {
119
+ const identifier = pluginManager.resolveName({
120
+ name: schemas.queryParams.name,
121
+ pluginKey: [pluginTsName],
122
+ type: "type"
123
+ });
124
+ dataRequestProperties.push(createPropertySignature({
125
+ name: "queryParams",
126
+ questionToken: true,
127
+ type: createTypeReferenceNode(createIdentifier(identifier), void 0)
128
+ }));
129
+ } else dataRequestProperties.push(createPropertySignature({
130
+ name: "queryParams",
131
+ questionToken: true,
132
+ type: keywordTypeNodes.never
133
+ }));
134
+ if (schemas.headerParams) {
135
+ const identifier = pluginManager.resolveName({
136
+ name: schemas.headerParams.name,
137
+ pluginKey: [pluginTsName],
138
+ type: "type"
139
+ });
140
+ dataRequestProperties.push(createPropertySignature({
141
+ name: "headerParams",
142
+ questionToken: true,
143
+ type: createTypeReferenceNode(createIdentifier(identifier), void 0)
144
+ }));
145
+ } else dataRequestProperties.push(createPropertySignature({
146
+ name: "headerParams",
147
+ questionToken: true,
148
+ type: keywordTypeNodes.never
149
+ }));
150
+ dataRequestProperties.push(createPropertySignature({
151
+ name: "url",
152
+ type: createUrlTemplateType(operation.path)
153
+ }));
154
+ const dataRequestNode = createTypeAliasDeclaration({
155
+ name,
156
+ type: createTypeLiteralNode(dataRequestProperties),
157
+ modifiers: [modifiers.export]
158
+ });
159
+ results.push(safePrint(dataRequestNode));
160
+ return results.join("\n\n");
161
+ }
162
+ function printResponseSchema({ baseName, schemas, pluginManager, unknownType }) {
163
+ const results = [];
164
+ const name = pluginManager.resolveName({
165
+ name: `${baseName} ResponseData`,
166
+ pluginKey: [pluginTsName],
167
+ type: "type"
168
+ });
169
+ if (schemas.responses && schemas.responses.length > 0) {
170
+ const responsesProperties = schemas.responses.map((res) => {
171
+ const identifier = pluginManager.resolveName({
172
+ name: res.name,
173
+ pluginKey: [pluginTsName],
174
+ type: "type"
175
+ });
176
+ return createPropertySignature({
177
+ name: res.statusCode?.toString() ?? "default",
178
+ type: createTypeReferenceNode(createIdentifier(identifier), void 0)
179
+ });
180
+ });
181
+ const responsesNode = createTypeAliasDeclaration({
182
+ name: `${baseName}Responses`,
183
+ type: createTypeLiteralNode(responsesProperties),
184
+ modifiers: [modifiers.export]
185
+ });
186
+ results.push(safePrint(responsesNode));
187
+ const responseNode = createTypeAliasDeclaration({
188
+ name,
189
+ type: createIndexedAccessTypeNode(createTypeReferenceNode(createIdentifier(`${baseName}Responses`), void 0), createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, createTypeReferenceNode(createIdentifier(`${baseName}Responses`), void 0))),
190
+ modifiers: [modifiers.export]
191
+ });
192
+ results.push(safePrint(responseNode));
193
+ } else {
194
+ const responseNode = createTypeAliasDeclaration({
195
+ name,
196
+ modifiers: [modifiers.export],
197
+ type: getUnknownType(unknownType)
198
+ });
199
+ results.push(safePrint(responseNode));
200
+ }
201
+ return results.join("\n\n");
202
+ }
78
203
  const typeGenerator = createReactGenerator({
79
204
  name: "typescript",
80
205
  Operation({ operation, generator, plugin }) {
81
- const { options, options: { mapper, enumType, syntaxType, optionalType } } = plugin;
206
+ const { options, options: { mapper, enumType, syntaxType, optionalType, arrayType, unknownType } } = plugin;
82
207
  const mode = useMode();
83
208
  const pluginManager = usePluginManager();
84
209
  const oas = useOas();
85
210
  const { getSchemas, getFile, getName, getGroup } = useOperationManager(generator);
86
211
  const schemaManager = useSchemaManager();
87
- const file = getFile(operation);
88
- const schemas = getSchemas(operation);
89
- const type = getName(operation, {
90
- type: "function",
212
+ const name = getName(operation, {
213
+ type: "type",
91
214
  pluginKey: [pluginTsName]
92
215
  });
93
- const combinedSchemaName = operation.method === "get" ? `${type}Query` : `${type}Mutation`;
216
+ const file = getFile(operation);
217
+ const schemas = getSchemas(operation);
94
218
  const schemaGenerator = new SchemaGenerator(options, {
95
219
  fabric: generator.context.fabric,
96
220
  oas,
@@ -108,18 +232,18 @@ const typeGenerator = createReactGenerator({
108
232
  schemas.request,
109
233
  schemas.response
110
234
  ].flat().filter(Boolean);
111
- const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options$1 }) => {
235
+ const mapOperationSchema = ({ name: name$1, schema, description, keysToOmit, ...options$1 }) => {
112
236
  const tree = schemaGenerator.parse({
113
237
  schema,
114
- name,
238
+ name: name$1,
115
239
  parentName: null
116
240
  });
117
241
  const imports = schemaManager.getImports(tree);
118
242
  const group = options$1.operation ? getGroup(options$1.operation) : void 0;
119
- const type$1 = {
120
- name: schemaManager.getName(name, { type: "type" }),
121
- typedName: schemaManager.getName(name, { type: "type" }),
122
- file: schemaManager.getFile(options$1.operationName || name, { group })
243
+ const type = {
244
+ name: schemaManager.getName(name$1, { type: "type" }),
245
+ typedName: schemaManager.getName(name$1, { type: "type" }),
246
+ file: schemaManager.getFile(options$1.operationName || name$1, { group })
123
247
  };
124
248
  return /* @__PURE__ */ jsxs(Fragment, { children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
125
249
  root: file.path,
@@ -127,23 +251,26 @@ const typeGenerator = createReactGenerator({
127
251
  name: imp.name,
128
252
  isTypeOnly: true
129
253
  }, [
130
- name,
254
+ name$1,
131
255
  imp.name,
132
256
  imp.path,
133
257
  imp.isTypeOnly
134
258
  ].join("-"))), /* @__PURE__ */ jsx(Type, {
135
- name: type$1.name,
136
- typedName: type$1.typedName,
259
+ name: type.name,
260
+ typedName: type.typedName,
137
261
  description,
138
262
  tree,
139
263
  schema,
140
264
  mapper,
141
265
  enumType,
142
266
  optionalType,
267
+ arrayType,
143
268
  keysToOmit,
144
269
  syntaxType
145
270
  })] });
146
271
  };
272
+ const responseName = schemaManager.getName(schemas.response.name, { type: "type" });
273
+ const combinedSchemaName = operation.method === "get" ? `${name}Query` : `${name}Mutation`;
147
274
  return /* @__PURE__ */ jsxs(File, {
148
275
  baseName: file.baseName,
149
276
  path: file.path,
@@ -157,7 +284,29 @@ const typeGenerator = createReactGenerator({
157
284
  oas,
158
285
  output: plugin.options.output
159
286
  }),
160
- children: [operationSchemas.map(mapOperationSchema), /* @__PURE__ */ jsx(File.Source, {
287
+ children: [operationSchemas.map(mapOperationSchema), generator.context.UNSTABLE_NAMING ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
288
+ name: `${name}Request`,
289
+ isExportable: true,
290
+ isIndexable: true,
291
+ isTypeOnly: true,
292
+ children: printRequestSchema({
293
+ baseName: name,
294
+ operation,
295
+ schemas,
296
+ pluginManager
297
+ })
298
+ }), /* @__PURE__ */ jsx(File.Source, {
299
+ name: responseName,
300
+ isExportable: true,
301
+ isIndexable: true,
302
+ isTypeOnly: true,
303
+ children: printResponseSchema({
304
+ baseName: name,
305
+ schemas,
306
+ pluginManager,
307
+ unknownType
308
+ })
309
+ })] }) : /* @__PURE__ */ jsx(File.Source, {
161
310
  name: combinedSchemaName,
162
311
  isExportable: true,
163
312
  isIndexable: true,
@@ -171,7 +320,7 @@ const typeGenerator = createReactGenerator({
171
320
  });
172
321
  },
173
322
  Schema({ schema, plugin }) {
174
- const { options: { mapper, enumType, syntaxType, optionalType, output } } = plugin;
323
+ const { options: { mapper, enumType, syntaxType, optionalType, arrayType, output } } = plugin;
175
324
  const mode = useMode();
176
325
  const oas = useOas();
177
326
  const pluginManager = usePluginManager();
@@ -216,6 +365,7 @@ const typeGenerator = createReactGenerator({
216
365
  mapper,
217
366
  enumType,
218
367
  optionalType,
368
+ arrayType,
219
369
  syntaxType
220
370
  })]
221
371
  });
@@ -229,7 +379,7 @@ const pluginTs = definePlugin((options) => {
229
379
  const { output = {
230
380
  path: "types",
231
381
  barrelType: "named"
232
- }, group, exclude = [], include, override = [], enumType = "asConst", enumSuffix = "enum", dateType = "string", unknownType = "any", optionalType = "questionToken", emptySchemaType = unknownType, syntaxType = "type", transformers: transformers$1 = {}, mapper = {}, generators = [typeGenerator].filter(Boolean), contentType } = options;
382
+ }, group, exclude = [], include, override = [], enumType = "asConst", enumSuffix = "enum", dateType = "string", unknownType = "any", optionalType = "questionToken", arrayType = "array", emptySchemaType = unknownType, syntaxType = "type", transformers: transformers$1 = {}, mapper = {}, generators = [typeGenerator].filter(Boolean), contentType, UNSTABLE_NAMING } = options;
233
383
  return {
234
384
  name: pluginTsName,
235
385
  options: {
@@ -237,6 +387,7 @@ const pluginTs = definePlugin((options) => {
237
387
  transformers: transformers$1,
238
388
  dateType,
239
389
  optionalType,
390
+ arrayType,
240
391
  enumType,
241
392
  enumSuffix,
242
393
  unknownType,
@@ -297,7 +448,8 @@ const pluginTs = definePlugin((options) => {
297
448
  exclude,
298
449
  include,
299
450
  override,
300
- mode
451
+ mode,
452
+ UNSTABLE_NAMING
301
453
  }).build(...generators);
302
454
  await this.upsertFile(...operationFiles);
303
455
  const barrelFiles = await getBarrelFiles(this.fabric.files, {
@@ -313,4 +465,4 @@ const pluginTs = definePlugin((options) => {
313
465
 
314
466
  //#endregion
315
467
  export { pluginTsName as n, typeGenerator as r, pluginTs as t };
316
- //# sourceMappingURL=plugin-BEfry-Dm.js.map
468
+ //# sourceMappingURL=plugin-DXyNbr_u.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-DXyNbr_u.js","names":["properties: Record<string, ts.TypeNode>","factory.createUnionDeclaration","factory.createTypeReferenceNode","factory.createIdentifier","factory.createTypeAliasDeclaration","factory.createTypeLiteralNode","factory.createPropertySignature","results: string[]","dataRequestProperties: ts.PropertySignature[]","responsesProperties: ts.PropertySignature[]","factory.createIndexedAccessTypeNode","factory.createTypeOperatorNode","options","name","options","groupName: Group['name']","transformers"],"sources":["../src/generators/typeGenerator.tsx","../src/plugin.ts"],"sourcesContent":["import type { PluginManager } from '@kubb/core'\nimport { useMode, usePluginManager } from '@kubb/core/hooks'\nimport transformers from '@kubb/core/transformers'\nimport { safePrint } from '@kubb/fabric-core/parsers/typescript'\nimport type { Operation } from '@kubb/oas'\nimport { isKeyword, type OperationSchemas, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport ts from 'typescript'\nimport { Type } from '../components'\nimport * as factory from '../factory.ts'\nimport { createUrlTemplateType, getUnknownType, keywordTypeNodes } from '../factory.ts'\nimport { pluginTsName } from '../plugin.ts'\nimport type { PluginTs } from '../types'\n\nfunction printCombinedSchema({ name, schemas, pluginManager }: { name: string; schemas: OperationSchemas; pluginManager: PluginManager }): string {\n const properties: Record<string, ts.TypeNode> = {}\n\n if (schemas.response) {\n properties['response'] = factory.createUnionDeclaration({\n nodes: schemas.responses.map((res) => {\n const identifier = pluginManager.resolveName({\n name: res.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n\n return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }),\n })!\n }\n\n if (schemas.request) {\n const identifier = pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['request'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.pathParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['pathParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.queryParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['queryParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.headerParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['headerParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.errors) {\n properties['errors'] = factory.createUnionDeclaration({\n nodes: schemas.errors.map((error) => {\n const identifier = pluginManager.resolveName({\n name: error.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n\n return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }),\n })!\n }\n\n const namespaceNode = factory.createTypeAliasDeclaration({\n name,\n type: factory.createTypeLiteralNode(\n Object.keys(properties)\n .map((key) => {\n const type = properties[key]\n if (!type) {\n return undefined\n }\n\n return factory.createPropertySignature({\n name: transformers.pascalCase(key),\n type,\n })\n })\n .filter(Boolean),\n ),\n modifiers: [factory.modifiers.export],\n })\n\n return safePrint(namespaceNode)\n}\n\nfunction printRequestSchema({\n baseName,\n operation,\n schemas,\n pluginManager,\n}: {\n baseName: string\n operation: Operation\n schemas: OperationSchemas\n pluginManager: PluginManager\n}): string {\n const name = pluginManager.resolveName({\n name: `${baseName} Request`,\n pluginKey: [pluginTsName],\n type: 'type',\n })\n\n const results: string[] = []\n\n // Generate DataRequest type\n const dataRequestProperties: ts.PropertySignature[] = []\n\n if (schemas.request) {\n const identifier = pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey: [pluginTsName],\n type: 'type',\n })\n dataRequestProperties.push(\n factory.createPropertySignature({\n name: 'data',\n questionToken: true,\n type: factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined),\n }),\n )\n } else {\n dataRequestProperties.push(\n factory.createPropertySignature({\n name: 'data',\n questionToken: true,\n type: keywordTypeNodes.never,\n }),\n )\n }\n\n // Add pathParams property\n if (schemas.pathParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey: [pluginTsName],\n type: 'type',\n })\n dataRequestProperties.push(\n factory.createPropertySignature({\n name: 'pathParams',\n type: factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined),\n }),\n )\n } else {\n dataRequestProperties.push(\n factory.createPropertySignature({\n name: 'pathParams',\n questionToken: true,\n type: keywordTypeNodes.never,\n }),\n )\n }\n\n // Add queryParams property\n if (schemas.queryParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey: [pluginTsName],\n type: 'type',\n })\n dataRequestProperties.push(\n factory.createPropertySignature({\n name: 'queryParams',\n questionToken: true,\n type: factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined),\n }),\n )\n } else {\n dataRequestProperties.push(\n factory.createPropertySignature({\n name: 'queryParams',\n questionToken: true,\n type: keywordTypeNodes.never,\n }),\n )\n }\n\n // Add headerParams property\n if (schemas.headerParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey: [pluginTsName],\n type: 'type',\n })\n dataRequestProperties.push(\n factory.createPropertySignature({\n name: 'headerParams',\n questionToken: true,\n type: factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined),\n }),\n )\n } else {\n dataRequestProperties.push(\n factory.createPropertySignature({\n name: 'headerParams',\n questionToken: true,\n type: keywordTypeNodes.never,\n }),\n )\n }\n\n // Add url property with template literal type\n dataRequestProperties.push(\n factory.createPropertySignature({\n name: 'url',\n type: createUrlTemplateType(operation.path),\n }),\n )\n\n const dataRequestNode = factory.createTypeAliasDeclaration({\n name,\n type: factory.createTypeLiteralNode(dataRequestProperties),\n modifiers: [factory.modifiers.export],\n })\n\n results.push(safePrint(dataRequestNode))\n\n return results.join('\\n\\n')\n}\n\nfunction printResponseSchema({\n baseName,\n schemas,\n pluginManager,\n unknownType,\n}: {\n baseName: string\n schemas: OperationSchemas\n pluginManager: PluginManager\n unknownType: PluginTs['resolvedOptions']['unknownType']\n}): string {\n const results: string[] = []\n\n const name = pluginManager.resolveName({\n name: `${baseName} ResponseData`,\n pluginKey: [pluginTsName],\n type: 'type',\n })\n\n // Generate Responses type (mapping status codes to response types)\n if (schemas.responses && schemas.responses.length > 0) {\n const responsesProperties: ts.PropertySignature[] = schemas.responses.map((res) => {\n const identifier = pluginManager.resolveName({\n name: res.name,\n pluginKey: [pluginTsName],\n type: 'type',\n })\n\n return factory.createPropertySignature({\n name: res.statusCode?.toString() ?? 'default',\n type: factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined),\n })\n })\n\n const responsesNode = factory.createTypeAliasDeclaration({\n name: `${baseName}Responses`,\n type: factory.createTypeLiteralNode(responsesProperties),\n modifiers: [factory.modifiers.export],\n })\n\n results.push(safePrint(responsesNode))\n\n // Generate Response type (union via indexed access)\n const responseNode = factory.createTypeAliasDeclaration({\n name,\n type: factory.createIndexedAccessTypeNode(\n factory.createTypeReferenceNode(factory.createIdentifier(`${baseName}Responses`), undefined),\n factory.createTypeOperatorNode(\n ts.SyntaxKind.KeyOfKeyword,\n factory.createTypeReferenceNode(factory.createIdentifier(`${baseName}Responses`), undefined),\n ),\n ),\n modifiers: [factory.modifiers.export],\n })\n\n results.push(safePrint(responseNode))\n } else {\n const responseNode = factory.createTypeAliasDeclaration({\n name,\n modifiers: [factory.modifiers.export],\n type: getUnknownType(unknownType),\n })\n\n results.push(safePrint(responseNode))\n }\n\n return results.join('\\n\\n')\n}\n\nexport const typeGenerator = createReactGenerator<PluginTs>({\n name: 'typescript',\n Operation({ operation, generator, plugin }) {\n const {\n options,\n options: { mapper, enumType, syntaxType, optionalType, arrayType, unknownType },\n } = plugin\n\n const mode = useMode()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getFile, getName, getGroup } = useOperationManager(generator)\n const schemaManager = useSchemaManager()\n\n const name = getName(operation, { type: 'type', pluginKey: [pluginTsName] })\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n fabric: generator.context.fabric,\n oas,\n events: generator.context.events,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options }: OperationSchemaType) => {\n const tree = schemaGenerator.parse({ schema, name, parentName: null })\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const type = {\n name: schemaManager.getName(name, { type: 'type' }),\n typedName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(options.operationName || name, { group }),\n }\n\n return (\n <>\n {mode === 'split' &&\n imports.map((imp) => (\n <File.Import key={[name, imp.name, imp.path, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} isTypeOnly />\n ))}\n <Type\n name={type.name}\n typedName={type.typedName}\n description={description}\n tree={tree}\n schema={schema}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n arrayType={arrayType}\n keysToOmit={keysToOmit}\n syntaxType={syntaxType}\n />\n </>\n )\n }\n\n const responseName = schemaManager.getName(schemas.response.name, {\n type: 'type',\n })\n const combinedSchemaName = operation.method === 'get' ? `${name}Query` : `${name}Mutation`\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n {operationSchemas.map(mapOperationSchema)}\n\n {generator.context.UNSTABLE_NAMING ? (\n <>\n <File.Source name={`${name}Request`} isExportable isIndexable isTypeOnly>\n {printRequestSchema({ baseName: name, operation, schemas, pluginManager })}\n </File.Source>\n <File.Source name={responseName} isExportable isIndexable isTypeOnly>\n {printResponseSchema({ baseName: name, schemas, pluginManager, unknownType })}\n </File.Source>\n </>\n ) : (\n <File.Source name={combinedSchemaName} isExportable isIndexable isTypeOnly>\n {printCombinedSchema({ name: combinedSchemaName, schemas, pluginManager })}\n </File.Source>\n )}\n </File>\n )\n },\n Schema({ schema, plugin }) {\n const {\n options: { mapper, enumType, syntaxType, optionalType, arrayType, output },\n } = plugin\n const mode = useMode()\n\n const oas = useOas()\n const pluginManager = usePluginManager()\n\n const { getName, getImports, getFile } = useSchemaManager()\n const imports = getImports(schema.tree)\n const schemaFromTree = schema.tree.find((item) => item.keyword === schemaKeywords.schema)\n\n let typedName = getName(schema.name, { type: 'type' })\n\n if (enumType === 'asConst' && schemaFromTree && isKeyword(schemaFromTree, schemaKeywords.enum)) {\n typedName = typedName += 'Key' //Suffix for avoiding collisions (https://github.com/kubb-labs/kubb/issues/1873)\n }\n\n const type = {\n name: getName(schema.name, { type: 'function' }),\n typedName,\n file: getFile(schema.name),\n }\n\n return (\n <File\n baseName={type.file.baseName}\n path={type.file.path}\n meta={type.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {mode === 'split' &&\n imports.map((imp) => (\n <File.Import key={[schema.name, imp.path, imp.isTypeOnly].join('-')} root={type.file.path} path={imp.path} name={imp.name} isTypeOnly />\n ))}\n <Type\n name={type.name}\n typedName={type.typedName}\n description={schema.value.description}\n tree={schema.tree}\n schema={schema.value}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n arrayType={arrayType}\n syntaxType={syntaxType}\n />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { typeGenerator } from './generators'\nimport type { PluginTs } from './types.ts'\n\nexport const pluginTsName = 'plugin-ts' satisfies PluginTs['name']\n\nexport const pluginTs = definePlugin<PluginTs>((options) => {\n const {\n output = { path: 'types', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n enumType = 'asConst',\n enumSuffix = 'enum',\n dateType = 'string',\n unknownType = 'any',\n optionalType = 'questionToken',\n arrayType = 'array',\n emptySchemaType = unknownType,\n syntaxType = 'type',\n transformers = {},\n mapper = {},\n generators = [typeGenerator].filter(Boolean),\n contentType,\n UNSTABLE_NAMING,\n } = options\n\n const usedEnumNames = {}\n\n return {\n name: pluginTsName,\n options: {\n output,\n transformers,\n dateType,\n optionalType,\n arrayType,\n enumType,\n enumSuffix,\n unknownType,\n emptySchemaType,\n syntaxType,\n group,\n override,\n mapper,\n usedEnumNames,\n },\n pre: [pluginOasName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = pascalCase(name, { isFile: type === 'file' })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n UNSTABLE_NAMING,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.upsertFile(...operationFiles)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,SAAS,oBAAoB,EAAE,MAAM,SAAS,iBAAoG;CAChJ,MAAMA,aAA0C,EAAE;AAElD,KAAI,QAAQ,SACV,YAAW,cAAcC,uBAA+B,EACtD,OAAO,QAAQ,UAAU,KAAK,QAAQ;EACpC,MAAM,aAAa,cAAc,YAAY;GAC3C,MAAM,IAAI;GACV,WAAW,CAAC,aAAa;GACzB,MAAM;GACP,CAAC;AAEF,SAAOC,wBAAgCC,iBAAyB,WAAW,EAAE,OAAU;GACvF,EACH,CAAC;AAGJ,KAAI,QAAQ,SAAS;EACnB,MAAM,aAAa,cAAc,YAAY;GAC3C,MAAM,QAAQ,QAAQ;GACtB,WAAW,CAAC,aAAa;GACzB,MAAM;GACP,CAAC;AACF,aAAW,aAAaD,wBAAgCC,iBAAyB,WAAW,EAAE,OAAU;;AAG1G,KAAI,QAAQ,YAAY;EACtB,MAAM,aAAa,cAAc,YAAY;GAC3C,MAAM,QAAQ,WAAW;GACzB,WAAW,CAAC,a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QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,OAAO,QAAQ,KAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GACrD,MAAM,MAAM,MAAM,KAAK,QAAQ;GAe/B,MAAM,cAAc,MAbI,IAAI,gBAAgB,KAAK,OAAO,SAAS;IAC/D,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS;IACT;IACA;IACA,QAAQ,OAAO;IAChB,CAAC,CAEwC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,WAAW,GAAG,YAAY;GAgBrC,MAAM,iBAAiB,MAdI,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACA;IACD,CAAC,CAE8C,MAAM,GAAG,WAAW;AACpE,SAAM,KAAK,WAAW,GAAG,eAAe;GAExC,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
@@ -828,6 +828,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
828
828
  */
829
829
  plugin: Plugin<TPluginOptions>;
830
830
  mode: KubbFile.Mode;
831
+ UNSTABLE_NAMING?: true;
831
832
  };
832
833
  declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>> {
833
834
  #private;
@@ -1236,6 +1237,13 @@ type Options = {
1236
1237
  * @default 'questionToken'
1237
1238
  */
1238
1239
  optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
1240
+ /**
1241
+ * Choose between `Array<string>` or `string[]` for array types.
1242
+ * - `generic`: Array<Type>
1243
+ * - `array`: Type[]
1244
+ * @default 'array'
1245
+ */
1246
+ arrayType?: 'generic' | 'array';
1239
1247
  transformers?: {
1240
1248
  /**
1241
1249
  * Customize the names based on the type that is provided by the plugin.
@@ -1257,6 +1265,10 @@ type Options = {
1257
1265
  * Define some generators next to the ts generators
1258
1266
  */
1259
1267
  generators?: Array<Generator<PluginTs>>;
1268
+ /**
1269
+ * Unstable naming for v5
1270
+ */
1271
+ UNSTABLE_NAMING?: true;
1260
1272
  };
1261
1273
  type ResolvedOptions = {
1262
1274
  output: Output<Oas>;
@@ -1268,6 +1280,7 @@ type ResolvedOptions = {
1268
1280
  unknownType: NonNullable<Options['unknownType']>;
1269
1281
  emptySchemaType: NonNullable<Options['emptySchemaType']>;
1270
1282
  optionalType: NonNullable<Options['optionalType']>;
1283
+ arrayType: NonNullable<Options['arrayType']>;
1271
1284
  transformers: NonNullable<Options['transformers']>;
1272
1285
  syntaxType: NonNullable<Options['syntaxType']>;
1273
1286
  mapper: Record<string, any>;
@@ -1275,4 +1288,4 @@ type ResolvedOptions = {
1275
1288
  type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>;
1276
1289
  //#endregion
1277
1290
  export { UserPluginWithLifeCycle as a, Schema as i, PluginTs as n, SchemaObject$1 as o, ReactGenerator as r, Options as t };
1278
- //# sourceMappingURL=types-C51mhXW0.d.cts.map
1291
+ //# sourceMappingURL=types-CKtzgWEC.d.cts.map
@@ -828,6 +828,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
828
828
  */
829
829
  plugin: Plugin<TPluginOptions>;
830
830
  mode: KubbFile.Mode;
831
+ UNSTABLE_NAMING?: true;
831
832
  };
832
833
  declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>> {
833
834
  #private;
@@ -1236,6 +1237,13 @@ type Options = {
1236
1237
  * @default 'questionToken'
1237
1238
  */
1238
1239
  optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
1240
+ /**
1241
+ * Choose between `Array<string>` or `string[]` for array types.
1242
+ * - `generic`: Array<Type>
1243
+ * - `array`: Type[]
1244
+ * @default 'array'
1245
+ */
1246
+ arrayType?: 'generic' | 'array';
1239
1247
  transformers?: {
1240
1248
  /**
1241
1249
  * Customize the names based on the type that is provided by the plugin.
@@ -1257,6 +1265,10 @@ type Options = {
1257
1265
  * Define some generators next to the ts generators
1258
1266
  */
1259
1267
  generators?: Array<Generator<PluginTs>>;
1268
+ /**
1269
+ * Unstable naming for v5
1270
+ */
1271
+ UNSTABLE_NAMING?: true;
1260
1272
  };
1261
1273
  type ResolvedOptions = {
1262
1274
  output: Output<Oas>;
@@ -1268,6 +1280,7 @@ type ResolvedOptions = {
1268
1280
  unknownType: NonNullable<Options['unknownType']>;
1269
1281
  emptySchemaType: NonNullable<Options['emptySchemaType']>;
1270
1282
  optionalType: NonNullable<Options['optionalType']>;
1283
+ arrayType: NonNullable<Options['arrayType']>;
1271
1284
  transformers: NonNullable<Options['transformers']>;
1272
1285
  syntaxType: NonNullable<Options['syntaxType']>;
1273
1286
  mapper: Record<string, any>;
@@ -1275,4 +1288,4 @@ type ResolvedOptions = {
1275
1288
  type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>;
1276
1289
  //#endregion
1277
1290
  export { UserPluginWithLifeCycle as a, Schema as i, PluginTs as n, SchemaObject$1 as o, ReactGenerator as r, Options as t };
1278
- //# sourceMappingURL=types-DcA3qMIF.d.ts.map
1291
+ //# sourceMappingURL=types-CnQREd_1.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-ts",
3
- "version": "4.14.0",
3
+ "version": "4.14.1",
4
4
  "description": "TypeScript code generation plugin for Kubb, transforming OpenAPI schemas into TypeScript interfaces, types, and utility functions.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -69,9 +69,9 @@
69
69
  "natural-orderby": "^5.0.0",
70
70
  "remeda": "^2.33.1",
71
71
  "typescript": "5.9.3",
72
- "@kubb/core": "4.14.0",
73
- "@kubb/oas": "4.14.0",
74
- "@kubb/plugin-oas": "4.14.0"
72
+ "@kubb/core": "4.14.1",
73
+ "@kubb/oas": "4.14.1",
74
+ "@kubb/plugin-oas": "4.14.1"
75
75
  },
76
76
  "peerDependencies": {
77
77
  "@kubb/react-fabric": "0.9.2",
@@ -15,6 +15,7 @@ type Props = {
15
15
  schema: SchemaObject
16
16
  tree: Array<Schema>
17
17
  optionalType: PluginTs['resolvedOptions']['optionalType']
18
+ arrayType: PluginTs['resolvedOptions']['arrayType']
18
19
  enumType: PluginTs['resolvedOptions']['enumType']
19
20
  mapper: PluginTs['resolvedOptions']['mapper']
20
21
  syntaxType: PluginTs['resolvedOptions']['syntaxType']
@@ -22,7 +23,7 @@ type Props = {
22
23
  keysToOmit?: string[]
23
24
  }
24
25
 
25
- export function Type({ name, typedName, tree, keysToOmit, schema, optionalType, syntaxType, enumType, mapper, description }: Props): KubbNode {
26
+ export function Type({ name, typedName, tree, keysToOmit, schema, optionalType, arrayType, syntaxType, enumType, mapper, description }: Props): KubbNode {
26
27
  const typeNodes: ts.Node[] = []
27
28
 
28
29
  if (!tree.length) {
@@ -39,6 +40,7 @@ export function Type({ name, typedName, tree, keysToOmit, schema, optionalType,
39
40
  { name, schema, parent: undefined, current, siblings },
40
41
  {
41
42
  optionalType,
43
+ arrayType,
42
44
  enumType,
43
45
  mapper,
44
46
  },
@@ -59,7 +61,11 @@ export function Type({ name, typedName, tree, keysToOmit, schema, optionalType,
59
61
  type = factory.createTypeReferenceNode(typeNameWithKey)
60
62
 
61
63
  if (schema.type === 'array') {
62
- type = factory.createArrayTypeNode(type)
64
+ if (arrayType === 'generic') {
65
+ type = factory.createTypeReferenceNode(factory.createIdentifier('Array'), [type])
66
+ } else {
67
+ type = factory.createArrayTypeNode(type)
68
+ }
63
69
  }
64
70
  }
65
71
  }
package/src/factory.ts CHANGED
@@ -17,6 +17,16 @@ export const syntaxKind = {
17
17
  union: SyntaxKind.UnionType as 192,
18
18
  } as const
19
19
 
20
+ export function getUnknownType(unknownType: 'any' | 'unknown' | 'void' | undefined) {
21
+ if (unknownType === 'any') {
22
+ return keywordTypeNodes.any
23
+ }
24
+ if (unknownType === 'void') {
25
+ return keywordTypeNodes.void
26
+ }
27
+
28
+ return keywordTypeNodes.unknown
29
+ }
20
30
  function isValidIdentifier(str: string): boolean {
21
31
  if (!str.length || str.trim() !== str) {
22
32
  return false
@@ -86,16 +96,29 @@ export function createTupleDeclaration({ nodes, withParentheses }: { nodes: Arra
86
96
  return node
87
97
  }
88
98
 
89
- export function createArrayDeclaration({ nodes }: { nodes: Array<ts.TypeNode> }): ts.TypeNode | null {
99
+ export function createArrayDeclaration({ nodes, arrayType = 'array' }: { nodes: Array<ts.TypeNode>; arrayType?: 'array' | 'generic' }): ts.TypeNode | null {
90
100
  if (!nodes.length) {
91
101
  return factory.createTupleTypeNode([])
92
102
  }
93
103
 
94
104
  if (nodes.length === 1) {
95
- return factory.createArrayTypeNode(nodes.at(0)!)
105
+ const node = nodes[0]
106
+ if (!node) {
107
+ return null
108
+ }
109
+ if (arrayType === 'generic') {
110
+ return factory.createTypeReferenceNode(factory.createIdentifier('Array'), [node])
111
+ }
112
+ return factory.createArrayTypeNode(node)
96
113
  }
97
114
 
98
- return factory.createExpressionWithTypeArguments(factory.createIdentifier('Array'), [factory.createUnionTypeNode(nodes)])
115
+ // For union types (multiple nodes), respect arrayType preference
116
+ const unionType = factory.createUnionTypeNode(nodes)
117
+ if (arrayType === 'generic') {
118
+ return factory.createTypeReferenceNode(factory.createIdentifier('Array'), [unionType])
119
+ }
120
+ // For array syntax with unions, we need parentheses: (string | number)[]
121
+ return factory.createArrayTypeNode(factory.createParenthesizedType(unionType))
99
122
  }
100
123
 
101
124
  /**
@@ -572,8 +595,56 @@ export const keywordTypeNodes = {
572
595
  boolean: factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),
573
596
  undefined: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),
574
597
  null: factory.createLiteralTypeNode(factory.createToken(ts.SyntaxKind.NullKeyword)),
598
+ never: factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword),
575
599
  } as const
576
600
 
601
+ /**
602
+ * Converts a path like '/pet/{petId}/uploadImage' to a template literal type
603
+ * like `/pet/${string}/uploadImage`
604
+ */
605
+ export function createUrlTemplateType(path: string): ts.TypeNode {
606
+ // If no parameters, return literal string type
607
+ if (!path.includes('{')) {
608
+ return factory.createLiteralTypeNode(factory.createStringLiteral(path))
609
+ }
610
+
611
+ // Split path by parameter placeholders, e.g. '/pet/{petId}/upload' -> ['/pet/', 'petId', '/upload']
612
+ const segments = path.split(/(\{[^}]+\})/)
613
+
614
+ // Separate static parts from parameter placeholders
615
+ const parts: string[] = []
616
+ const parameterIndices: number[] = []
617
+
618
+ segments.forEach((segment) => {
619
+ if (segment.startsWith('{') && segment.endsWith('}')) {
620
+ // This is a parameter placeholder
621
+ parameterIndices.push(parts.length)
622
+ parts.push(segment) // Will be replaced with ${string}
623
+ } else if (segment) {
624
+ // This is a static part
625
+ parts.push(segment)
626
+ }
627
+ })
628
+
629
+ // Build template literal type
630
+ // Template literal structure: head + templateSpans[]
631
+ // For '/pet/{petId}/upload': head = '/pet/', spans = [{ type: string, literal: '/upload' }]
632
+
633
+ const head = ts.factory.createTemplateHead(parts[0] || '')
634
+ const templateSpans: ts.TemplateLiteralTypeSpan[] = []
635
+
636
+ parameterIndices.forEach((paramIndex, i) => {
637
+ const isLast = i === parameterIndices.length - 1
638
+ const nextPart = parts[paramIndex + 1] || ''
639
+
640
+ const literal = isLast ? ts.factory.createTemplateTail(nextPart) : ts.factory.createTemplateMiddle(nextPart)
641
+
642
+ templateSpans.push(ts.factory.createTemplateLiteralTypeSpan(keywordTypeNodes.string, literal))
643
+ })
644
+
645
+ return ts.factory.createTemplateLiteralType(head, templateSpans)
646
+ }
647
+
577
648
  export const createTypeLiteralNode = factory.createTypeLiteralNode
578
649
 
579
650
  export const createTypeReferenceNode = factory.createTypeReferenceNode
@@ -581,6 +652,7 @@ export const createNumericLiteral = factory.createNumericLiteral
581
652
  export const createStringLiteral = factory.createStringLiteral
582
653
 
583
654
  export const createArrayTypeNode = factory.createArrayTypeNode
655
+ export const createParenthesizedType = factory.createParenthesizedType
584
656
 
585
657
  export const createLiteralTypeNode = factory.createLiteralTypeNode
586
658
  export const createNull = factory.createNull
@@ -591,3 +663,5 @@ export const createTupleTypeNode = factory.createTupleTypeNode
591
663
  export const createRestTypeNode = factory.createRestTypeNode
592
664
  export const createTrue = factory.createTrue
593
665
  export const createFalse = factory.createFalse
666
+ export const createIndexedAccessTypeNode = factory.createIndexedAccessTypeNode
667
+ export const createTypeOperatorNode = factory.createTypeOperatorNode
@@ -40,7 +40,7 @@ export type CreatePetsMutationRequest = {
40
40
 
41
41
  export type CreatePetsMutationResponse = createPets201 | createPets202
42
42
 
43
- export type createPetsMutation = {
43
+ export type CreatePetsMutation = {
44
44
  Response: createPets201 | createPets202
45
45
  Request: createPetsMutationRequest
46
46
  Errors: any
@@ -40,7 +40,7 @@ export type CreatePetsMutationRequest = {
40
40
 
41
41
  export type CreatePetsMutationResponse = createPets201 | createPets202
42
42
 
43
- export type createPetsMutation = {
43
+ export type CreatePetsMutation = {
44
44
  Response: createPets201 | createPets202
45
45
  Request: createPetsMutationRequest
46
46
  Errors: any
@@ -40,7 +40,7 @@ export type CreatePetsMutationRequest = {
40
40
 
41
41
  export type CreatePetsMutationResponse = createPets201 | createPets202
42
42
 
43
- export type createPetsMutation = {
43
+ export type CreatePetsMutation = {
44
44
  Response: createPets201 | createPets202
45
45
  Request: createPetsMutationRequest
46
46
  Errors: any