@kubb/swagger-ts 2.0.0-alpha.11 → 2.0.0-alpha.12

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.
package/dist/index.cjs CHANGED
@@ -51,16 +51,9 @@ var __privateMethod = (obj, member, method) => {
51
51
  __accessCheck(obj, member, "access private method");
52
52
  return method;
53
53
  };
54
- var _usedAliasNames, _caseOptions, _getTypeFromSchema, getTypeFromSchema_fn, _getTypeFromProperties, getTypeFromProperties_fn, _getRefAlias, getRefAlias_fn, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn;
54
+ var _usedAliasNames, _caseOptions, _getTypeFromSchema, getTypeFromSchema_fn, _getTypeFromProperties, getTypeFromProperties_fn, _getRefAlias, getRefAlias_fn, _getParsedSchema, getParsedSchema_fn, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn;
55
55
  var TypeGenerator = class extends core.SchemaGenerator {
56
- constructor(options = {
57
- usedEnumNames: {},
58
- withJSDocs: true,
59
- resolveName: ({ name }) => name,
60
- enumType: "asConst",
61
- dateType: "string",
62
- optionalType: "questionToken"
63
- }) {
56
+ constructor(options) {
64
57
  super(options);
65
58
  /**
66
59
  * Creates a type node from a given schema.
@@ -76,6 +69,7 @@ var TypeGenerator = class extends core.SchemaGenerator {
76
69
  * Create a type alias for the schema referenced by the given ReferenceObject
77
70
  */
78
71
  __privateAdd(this, _getRefAlias);
72
+ __privateAdd(this, _getParsedSchema);
79
73
  /**
80
74
  * This is the very core of the OpenAPI to TS conversion - it takes a
81
75
  * schema and returns the appropriate type.
@@ -147,7 +141,7 @@ getTypeFromProperties_fn = function(baseSchema, baseName) {
147
141
  const additionalProperties = baseSchema?.additionalProperties;
148
142
  const members = Object.keys(properties).map((name) => {
149
143
  const schema = properties[name];
150
- const isRequired = required && required.includes(name);
144
+ const isRequired = Array.isArray(required) ? required.includes(name) : !!required;
151
145
  let type = __privateMethod(this, _getTypeFromSchema, getTypeFromSchema_fn).call(this, schema, this.options.resolveName({ name: `${baseName || ""} ${name}` }));
152
146
  if (!type) {
153
147
  return null;
@@ -166,7 +160,7 @@ getTypeFromProperties_fn = function(baseSchema, baseName) {
166
160
  node: propertySignature,
167
161
  comments: [
168
162
  schema.description ? `@description ${schema.description}` : void 0,
169
- schema.type ? `@type ${schema.type}${isRequired ? "" : " | undefined"} ${schema.format || ""}` : void 0,
163
+ schema.type ? `@type ${schema.type?.toString()}${isRequired ? "" : " | undefined"} ${schema.format || ""}` : void 0,
170
164
  schema.example ? `@example ${schema.example}` : void 0,
171
165
  schema.deprecated ? `@deprecated` : void 0,
172
166
  schema.default !== void 0 && typeof schema.default === "string" ? `@default '${schema.default}'` : void 0,
@@ -199,8 +193,14 @@ getRefAlias_fn = function(obj, _baseName) {
199
193
  };
200
194
  return factory__namespace.createTypeReferenceNode(ref.propertyName, void 0);
201
195
  };
196
+ _getParsedSchema = new WeakSet();
197
+ getParsedSchema_fn = function(schema) {
198
+ const parsedSchema = utils$1.getSchemaFactory(this.options.oas)(schema);
199
+ return parsedSchema;
200
+ };
202
201
  _getBaseTypeFromSchema = new WeakSet();
203
- getBaseTypeFromSchema_fn = function(schema, baseName) {
202
+ getBaseTypeFromSchema_fn = function(_schema, baseName) {
203
+ const { schema, version } = __privateMethod(this, _getParsedSchema, getParsedSchema_fn).call(this, _schema);
204
204
  if (!schema) {
205
205
  return factory__namespace.keywordTypeNodes.any;
206
206
  }
@@ -212,7 +212,7 @@ getBaseTypeFromSchema_fn = function(schema, baseName) {
212
212
  const union = factory__namespace.createUnionDeclaration({
213
213
  withParentheses: true,
214
214
  nodes: schema.oneOf.map((item) => {
215
- return __privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, item);
215
+ return item && __privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, item);
216
216
  }).filter((item) => {
217
217
  return item && item !== factory__namespace.keywordTypeNodes.any;
218
218
  })
@@ -229,7 +229,7 @@ getBaseTypeFromSchema_fn = function(schema, baseName) {
229
229
  const union = factory__namespace.createUnionDeclaration({
230
230
  withParentheses: true,
231
231
  nodes: schema.anyOf.map((item) => {
232
- return __privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, item);
232
+ return item && __privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, item);
233
233
  }).filter((item) => {
234
234
  return item && item !== factory__namespace.keywordTypeNodes.any;
235
235
  })
@@ -246,7 +246,7 @@ getBaseTypeFromSchema_fn = function(schema, baseName) {
246
246
  const and = factory__namespace.createIntersectionDeclaration({
247
247
  withParentheses: true,
248
248
  nodes: schema.allOf.map((item) => {
249
- return __privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, item);
249
+ return item && __privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, item);
250
250
  }).filter((item) => {
251
251
  return item && item !== factory__namespace.keywordTypeNodes.any;
252
252
  })
@@ -323,7 +323,7 @@ getBaseTypeFromSchema_fn = function(schema, baseName) {
323
323
  if (schema.format === "binary") {
324
324
  return factory__namespace.createTypeReferenceNode("Blob", []);
325
325
  }
326
- if ("const" in schema && schema["const"] !== void 0 && typeof schema["const"] === "string") {
326
+ if (version === "3.1" && typeof schema["const"] === "string") {
327
327
  return factory__namespace.createLiteralTypeNode(factory__namespace.createStringLiteral(schema["const"]));
328
328
  }
329
329
  return factory__namespace.keywordTypeNodes.any;
@@ -349,7 +349,8 @@ var TypeBuilder = class extends swagger.OasBuilder {
349
349
  resolveName: this.options.resolveName,
350
350
  enumType: this.options.enumType,
351
351
  dateType: this.options.dateType,
352
- optionalType: this.options.optionalType
352
+ optionalType: this.options.optionalType,
353
+ oas: this.options.oas
353
354
  });
354
355
  const sources = generator.build({
355
356
  schema: operationSchema.schema,
@@ -405,7 +406,7 @@ var OperationGenerator = class extends swagger.OperationGenerator {
405
406
  }
406
407
  async get(operation, schemas, options) {
407
408
  const { mode, enumType, dateType, optionalType, usedEnumNames } = options;
408
- const { pluginManager, plugin } = this.context;
409
+ const { pluginManager, plugin, oas } = this.context;
409
410
  const type = this.resolve(operation);
410
411
  const fileResolver = (name) => {
411
412
  const root = pluginManager.resolvePath({ baseName: type.baseName, pluginKey: plugin?.key, options: { tag: operation.getTags()[0]?.name } });
@@ -422,7 +423,8 @@ var OperationGenerator = class extends swagger.OperationGenerator {
422
423
  resolveName: (params) => pluginManager.resolveName({ ...params, pluginKey: plugin?.key }),
423
424
  enumType,
424
425
  optionalType,
425
- dateType
426
+ dateType,
427
+ oas
426
428
  }).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.response).add(schemas.errors).configure().print();
427
429
  const combinedSchemaSource = __privateMethod(this, _printCombinedSchema, printCombinedSchema_fn).call(this, type.name, operation, schemas);
428
430
  return {
@@ -437,7 +439,7 @@ var OperationGenerator = class extends swagger.OperationGenerator {
437
439
  }
438
440
  async post(operation, schemas, options) {
439
441
  const { mode, enumType, dateType, optionalType, usedEnumNames } = options;
440
- const { pluginManager, plugin } = this.context;
442
+ const { pluginManager, plugin, oas } = this.context;
441
443
  const type = this.resolve(operation);
442
444
  const fileResolver = (name) => {
443
445
  const root = pluginManager.resolvePath({ baseName: type.baseName, pluginKey: plugin?.key, options: { tag: operation.getTags()[0]?.name } });
@@ -454,7 +456,8 @@ var OperationGenerator = class extends swagger.OperationGenerator {
454
456
  resolveName: (params) => pluginManager.resolveName({ ...params, pluginKey: plugin?.key }),
455
457
  enumType,
456
458
  optionalType,
457
- dateType
459
+ dateType,
460
+ oas
458
461
  }).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.request).add(schemas.response).add(schemas.errors).configure().print();
459
462
  const combinedSchemaSource = __privateMethod(this, _printCombinedSchema, printCombinedSchema_fn).call(this, type.name, operation, schemas);
460
463
  return {
@@ -609,7 +612,8 @@ var definePlugin = core.createPlugin((options) => {
609
612
  withJSDocs: true,
610
613
  enumType,
611
614
  dateType,
612
- optionalType
615
+ optionalType,
616
+ oas
613
617
  }).configure();
614
618
  Object.entries(schemas).forEach(([name, schema]) => {
615
619
  return builder.add({
@@ -641,7 +645,8 @@ var definePlugin = core.createPlugin((options) => {
641
645
  withJSDocs: true,
642
646
  enumType,
643
647
  dateType,
644
- optionalType
648
+ optionalType,
649
+ oas
645
650
  }).configure();
646
651
  Object.entries(schemas).forEach(([name, schema]) => {
647
652
  return builder.add({
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin.ts","../src/builders/TypeBuilder.ts","../src/generators/TypeGenerator.ts","../src/generators/OperationGenerator.ts","../src/index.ts"],"names":["getRelativePath","camelCase","pascalCase","factory","node","print","transformers","options","root"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,OAAO,UAAU;AAEjB,SAAS,cAAc,aAAa,qBAAqB;AACzD,SAAS,mBAAAA,kBAAiB,sBAAsB;AAChD,SAAS,cAAc,yBAAyB;AAEhD,SAAS,aAAAC,YAAW,yBAAyB,cAAAC,aAAY,gCAAgC;;;ACLzF,SAAS,oBAAoB;AAC7B,SAAS,aAAa;AACtB,YAAYC,cAAa;AACzB,SAAS,kBAAkB,kBAAkB;AAC7C,SAAS,kBAAkB;;;ACL3B,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAC9B,YAAY,aAAa;AACzB,SAAS,mBAAmB;AAE5B,SAAS,iBAAiB;AAL1B;AAuBO,IAAM,gBAAN,cAA4B,gBAA4D;AAAA,EAe7F,YACE,UAAmB;AAAA,IACjB,eAAe,CAAC;AAAA,IAChB,YAAY;AAAA,IACZ,aAAa,CAAC,EAAE,KAAK,MAAM;AAAA,IAC3B,UAAU;AAAA,IACV,UAAU;AAAA,IACV,cAAc;AAAA,EAChB,GACA;AACA,UAAM,OAAO;AAwDf;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA;AAAA;AAAA;AAAA;AAsDA;AAAA;AAAA;AAAA;AAuBA;AAAA;AAAA;AAAA;AAAA;AA9KA,gBAAa,CAAC;AAEd,sBAA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,UAAI,KAAK,OAAO,OAAO,UAAU,OAAO;AACtC;AAAA,MACF;AAEA,YAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,IAAI;AAEnE,YAAM,KAAK,YAAY,WAAW;AAAA,QAChC;AAAA,QACA,SAAS;AAAA,QACT,MAAM,EAAE,WAAW,KAAK,OAAO,IAAI;AAAA,QACnC,SAAS;AAAA,UACP,KAAK,CAAC,SAAS;AACb,mBAAO;AAAA,cACL,GAAG;AAAA,cACH,SAAS,KAAK,SAAS,IAAI,CAAC,SAAS;AACnC,oBAAI,UAAU;AACZ,yBAAO;AAAA,oBACL,GAAG;AAAA,oBACH,MAAM;AAAA,oBACN,SAAS,CAAC,CAAC;AAAA,kBACb;AAAA,gBACF;AACA,uBAAO;AAAA,cACT,CAAC;AAAA,YACH;AAAA,UACF;AAAA,UACA;AAAA,UACA,YAAY;AAAA,QACd;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;AI/ND,IAAO,cAAQ","sourcesContent":["import path from 'node:path'\n\nimport { createPlugin, FileManager, PluginManager } from '@kubb/core'\nimport { getRelativePath, renderTemplate } from '@kubb/core/utils'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\n\nimport { camelCase, camelCaseTransformMerge, pascalCase, pascalCaseTransformMerge } from 'change-case'\n\nimport { TypeBuilder } from './builders/index.ts'\nimport { OperationGenerator } from './generators/index.ts'\n\nimport type { KubbFile, KubbPlugin } from '@kubb/core'\nimport type { OpenAPIV3, PluginOptions as SwaggerPluginOptions } from '@kubb/swagger'\nimport type { PluginOptions } from './types.ts'\n\nexport const pluginName = 'swagger-ts' satisfies PluginOptions['name']\nexport const pluginKey: PluginOptions['key'] = ['schema', pluginName] satisfies PluginOptions['key']\n\nexport const definePlugin = createPlugin<PluginOptions>((options) => {\n const {\n output = 'types',\n group,\n exclude = [],\n include,\n override = [],\n enumType = 'asConst',\n dateType = 'string',\n optionalType = 'questionToken',\n transformers = {},\n exportAs,\n } = options\n const template = group?.output ? group.output : `${output}/{{tag}}Controller`\n let pluginsOptions: [KubbPlugin<SwaggerPluginOptions>]\n\n return {\n name: pluginName,\n options,\n kind: 'schema',\n validate(plugins) {\n pluginsOptions = PluginManager.getDependedPlugins<SwaggerPluginOptions>(plugins, [swaggerPluginName])\n\n return true\n },\n resolvePath(baseName, directory, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output))\n\n if (mode === 'file') {\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)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag, { delimiter: '', transform: camelCaseTransformMerge })\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output, baseName)\n },\n resolveName(name, type) {\n const resolvedName = pascalCase(name, { delimiter: '', stripRegexp: /[^A-Z0-9$]/gi, transform: pascalCaseTransformMerge })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async writeFile(source, writePath) {\n if (!writePath.endsWith('.ts') || !source) {\n return\n }\n\n return this.fileManager.write(source, writePath)\n },\n async buildStart() {\n const [swaggerPlugin] = pluginsOptions\n\n const oas = await swaggerPlugin.api.getOas()\n\n const schemas = await swaggerPlugin.api.getSchemas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output))\n // keep the used enumnames between TypeBuilder and OperationGenerator per plugin(pluginKey)\n const usedEnumNames = {}\n\n if (mode === 'directory') {\n const builder = await new TypeBuilder({\n usedEnumNames,\n resolveName: (params) => this.resolveName({ pluginKey: this.plugin.key, ...params }),\n fileResolver: (name) => {\n const resolvedTypeId = this.resolvePath({\n baseName: `${name}.ts`,\n pluginKey: this.plugin.key,\n })\n\n const root = this.resolvePath({ baseName: ``, pluginKey: this.plugin.key })\n\n return getRelativePath(root, resolvedTypeId)\n },\n withJSDocs: true,\n enumType,\n dateType,\n optionalType,\n }).configure()\n Object.entries(schemas).forEach(([name, schema]: [string, OpenAPIV3.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const mapFolderSchema = async ([name]: [string, OpenAPIV3.SchemaObject]) => {\n const resolvedPath = this.resolvePath({ baseName: `${this.resolveName({ name, pluginKey: this.plugin.key })}.ts`, pluginKey: this.plugin.key })\n\n if (!resolvedPath) {\n return null\n }\n\n return this.addFile({\n path: resolvedPath,\n baseName: `${this.resolveName({ name, pluginKey: this.plugin.key })}.ts`,\n source: builder.print(name),\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n }\n\n const promises = Object.entries(schemas).map(mapFolderSchema)\n\n await Promise.all(promises)\n }\n\n if (mode === 'file') {\n // outside the loop because we need to add files to just one instance to have the correct sorting, see refsSorter\n const builder = new TypeBuilder({\n usedEnumNames,\n resolveName: (params) => this.resolveName({ pluginKey: this.plugin.key, ...params }),\n withJSDocs: true,\n enumType,\n dateType,\n optionalType,\n }).configure()\n Object.entries(schemas).forEach(([name, schema]: [string, OpenAPIV3.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const resolvedPath = this.resolvePath({ baseName: '', pluginKey: this.plugin.key })\n if (!resolvedPath) {\n return\n }\n\n await this.addFile({\n path: resolvedPath,\n baseName: output as KubbFile.BaseName,\n source: builder.print(),\n meta: {\n pluginKey: this.plugin.key,\n },\n validate: false,\n })\n }\n\n const operationGenerator = new OperationGenerator(\n {\n mode,\n enumType,\n dateType,\n optionalType,\n usedEnumNames,\n },\n {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.api.contentType,\n exclude,\n include,\n override,\n },\n )\n\n const files = await operationGenerator.build()\n await this.addFile(...files)\n },\n async buildEnd() {\n if (this.config.output.write === false) {\n return\n }\n\n const root = path.resolve(this.config.root, this.config.output.path)\n\n await this.fileManager.addIndexes({\n root,\n extName: '.ts',\n meta: { pluginKey: this.plugin.key },\n options: {\n map: (file) => {\n return {\n ...file,\n exports: file.exports?.map((item) => {\n if (exportAs) {\n return {\n ...item,\n name: exportAs,\n asAlias: !!exportAs,\n }\n }\n return item\n }),\n }\n },\n output,\n isTypeOnly: true,\n },\n })\n },\n }\n})\n","/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { transformers } from '@kubb/core/utils'\nimport { print } from '@kubb/parser'\nimport * as factory from '@kubb/parser/factory'\nimport { ImportsGenerator, OasBuilder } from '@kubb/swagger'\nimport { refsSorter } from '@kubb/swagger/utils'\n\nimport { TypeGenerator } from '../generators/TypeGenerator.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { FileResolver } from '@kubb/swagger'\n\ntype Options = {\n usedEnumNames: Record<string, number>\n\n resolveName: PluginContext['resolveName']\n fileResolver?: FileResolver\n withJSDocs?: boolean\n withImports?: boolean\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n dateType: 'string' | 'date'\n optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'\n}\n\nexport class TypeBuilder extends OasBuilder<Options, never> {\n configure(options?: Options) {\n if (options) {\n this.options = options\n }\n\n if (this.options.fileResolver) {\n this.options.withImports = true\n }\n\n return this\n }\n\n print(name?: string): string {\n const codes: string[] = []\n\n const generated = this.items\n .filter((operationSchema) => (name ? operationSchema.name === name : true))\n .sort(transformers.nameSorter)\n .map((operationSchema) => {\n const generator = new TypeGenerator({\n usedEnumNames: this.options.usedEnumNames,\n withJSDocs: this.options.withJSDocs,\n resolveName: this.options.resolveName,\n enumType: this.options.enumType,\n dateType: this.options.dateType,\n optionalType: this.options.optionalType,\n })\n const sources = generator.build({\n schema: operationSchema.schema,\n baseName: operationSchema.name,\n description: operationSchema.description,\n keysToOmit: operationSchema.keysToOmit,\n })\n\n return {\n import: {\n refs: generator.refs,\n name: operationSchema.name,\n },\n sources,\n }\n })\n .sort(refsSorter)\n\n generated.forEach((item) => {\n codes.push(print(item.sources))\n })\n\n if (this.options.withImports) {\n const importsGenerator = new ImportsGenerator({ fileResolver: this.options.fileResolver })\n const importMeta = importsGenerator.build(generated.map((item) => item.import))\n\n if (importMeta) {\n const nodes = importMeta.map((item) => {\n return factory.createImportDeclaration({\n name: [{ propertyName: item.ref.propertyName }],\n path: item.path,\n isTypeOnly: true,\n })\n })\n\n codes.unshift(print(nodes))\n }\n }\n\n return transformers.combineCodes(codes)\n }\n}\n","import { SchemaGenerator } from '@kubb/core'\nimport { getUniqueName } from '@kubb/core/utils'\nimport * as factory from '@kubb/parser/factory'\nimport { isReference } from '@kubb/swagger/utils'\n\nimport { camelCase } from 'change-case'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { ts } from '@kubb/parser'\nimport type { OpenAPIV3, Refs } from '@kubb/swagger'\nimport type { Options as CaseOptions } from 'change-case'\n\n// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n\ntype Options = {\n usedEnumNames: Record<string, number>\n\n withJSDocs?: boolean\n resolveName: PluginContext['resolveName']\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n dateType: 'string' | 'date'\n optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'\n}\nexport class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObject, ts.Node[]> {\n refs: Refs = {}\n\n extraNodes: ts.Node[] = []\n\n aliases: ts.TypeAliasDeclaration[] = []\n\n // Keep track of already used type aliases\n #usedAliasNames: Record<string, number> = {}\n\n #caseOptions: CaseOptions = {\n delimiter: '',\n stripRegexp: /[^A-Z0-9$]/gi,\n }\n\n constructor(\n options: Options = {\n usedEnumNames: {},\n withJSDocs: true,\n resolveName: ({ name }) => name,\n enumType: 'asConst',\n dateType: 'string',\n optionalType: 'questionToken',\n },\n ) {\n super(options)\n\n return this\n }\n\n build({\n schema,\n baseName,\n description,\n keysToOmit,\n }: {\n schema: OpenAPIV3.SchemaObject\n baseName: string\n description?: string\n keysToOmit?: string[]\n }): ts.Node[] {\n const nodes: ts.Node[] = []\n const type = this.#getTypeFromSchema(schema, baseName)\n\n if (!type) {\n return this.extraNodes\n }\n\n const node = factory.createTypeAliasDeclaration({\n modifiers: [factory.modifiers.export],\n name: this.options.resolveName({ name: baseName }) || baseName,\n type: keysToOmit?.length ? factory.createOmitDeclaration({ keys: keysToOmit, type, nonNullable: true }) : type,\n })\n\n if (description) {\n nodes.push(\n factory.appendJSDocToNode({\n node,\n comments: [`@description ${description}`],\n }),\n )\n } else {\n nodes.push(node)\n }\n\n // filter out if the export name is the same as one that we already defined in extraNodes(see enum)\n const filterdNodes = nodes.filter(\n (node: ts.Node) =>\n !this.extraNodes.some(\n (extraNode: ts.Node) => (extraNode as ts.TypeAliasDeclaration)?.name?.escapedText === (node as ts.TypeAliasDeclaration)?.name?.escapedText,\n ),\n )\n\n return [...this.extraNodes, ...filterdNodes]\n }\n\n /**\n * Creates a type node from a given schema.\n * Delegates to getBaseTypeFromSchema internally and\n * optionally adds a union with null.\n */\n #getTypeFromSchema(schema?: OpenAPIV3.SchemaObject, name?: string): ts.TypeNode | null {\n const type = this.#getBaseTypeFromSchema(schema, name)\n\n if (!type) {\n return null\n }\n\n if (schema && !schema.nullable) {\n return type\n }\n\n return factory.createUnionDeclaration({ nodes: [type, factory.keywordTypeNodes.null] })\n }\n\n /**\n * Recursively creates a type literal with the given props.\n */\n #getTypeFromProperties(baseSchema?: OpenAPIV3.SchemaObject, baseName?: string) {\n const { optionalType } = this.options\n const properties = baseSchema?.properties || {}\n const required = baseSchema?.required\n const additionalProperties = baseSchema?.additionalProperties\n\n const members: Array<ts.TypeElement | null> = Object.keys(properties).map((name) => {\n const schema = properties[name] as OpenAPIV3.SchemaObject\n\n const isRequired = required && required.includes(name)\n let type = this.#getTypeFromSchema(schema, this.options.resolveName({ name: `${baseName || ''} ${name}` }))\n\n if (!type) {\n return null\n }\n\n if (!isRequired && ['undefined', 'questionTokenAndUndefined'].includes(optionalType)) {\n type = factory.createUnionDeclaration({ nodes: [type, factory.keywordTypeNodes.undefined] })\n }\n const propertySignature = factory.createPropertySignature({\n questionToken: ['questionToken', 'questionTokenAndUndefined'].includes(optionalType) && !isRequired,\n name,\n type: type as ts.TypeNode,\n readOnly: schema.readOnly,\n })\n if (this.options.withJSDocs) {\n return factory.appendJSDocToNode({\n node: propertySignature,\n comments: [\n schema.description ? `@description ${schema.description}` : undefined,\n schema.type ? `@type ${schema.type}${isRequired ? '' : ' | undefined'} ${schema.format || ''}` : undefined,\n schema.example ? `@example ${schema.example as string}` : undefined,\n schema.deprecated ? `@deprecated` : undefined,\n schema.default !== undefined && typeof schema.default === 'string' ? `@default '${schema.default}'` : undefined,\n schema.default !== undefined && typeof schema.default !== 'string' ? `@default ${schema.default as string}` : undefined,\n ].filter(Boolean),\n })\n }\n\n return propertySignature\n })\n if (additionalProperties) {\n const type = additionalProperties === true ? factory.keywordTypeNodes.any : this.#getTypeFromSchema(additionalProperties as OpenAPIV3.SchemaObject)\n\n if (type) {\n members.push(factory.createIndexSignature(type))\n }\n }\n return factory.createTypeLiteralNode(members.filter(Boolean))\n }\n\n /**\n * Create a type alias for the schema referenced by the given ReferenceObject\n */\n #getRefAlias(obj: OpenAPIV3.ReferenceObject, _baseName?: string) {\n const { $ref } = obj\n let ref = this.refs[$ref]\n\n if (ref) {\n return factory.createTypeReferenceNode(ref.propertyName, undefined)\n }\n\n const originalName = getUniqueName($ref.replace(/.+\\//, ''), this.#usedAliasNames)\n const propertyName = this.options.resolveName({ name: originalName }) || originalName\n\n ref = this.refs[$ref] = {\n propertyName,\n originalName,\n }\n\n return factory.createTypeReferenceNode(ref.propertyName, undefined)\n }\n\n /**\n * This is the very core of the OpenAPI to TS conversion - it takes a\n * schema and returns the appropriate type.\n */\n #getBaseTypeFromSchema(schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined, baseName?: string): ts.TypeNode | null {\n if (!schema) {\n return factory.keywordTypeNodes.any\n }\n\n if (isReference(schema)) {\n return this.#getRefAlias(schema, baseName)\n }\n\n if (schema.oneOf) {\n // union\n const schemaWithoutOneOf = { ...schema, oneOf: undefined }\n\n const union = factory.createUnionDeclaration({\n withParentheses: true,\n nodes: schema.oneOf\n .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {\n return this.#getBaseTypeFromSchema(item)\n })\n .filter((item) => {\n return item && item !== factory.keywordTypeNodes.any\n }) as Array<ts.TypeNode>,\n })\n\n if (schemaWithoutOneOf.properties) {\n return factory.createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean),\n })\n }\n\n return union\n }\n\n if (schema.anyOf) {\n const schemaWithoutAnyOf = { ...schema, anyOf: undefined }\n\n const union = factory.createUnionDeclaration({\n withParentheses: true,\n nodes: schema.anyOf\n .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {\n return this.#getBaseTypeFromSchema(item)\n })\n .filter((item) => {\n return item && item !== factory.keywordTypeNodes.any\n }) as Array<ts.TypeNode>,\n })\n\n if (schemaWithoutAnyOf.properties) {\n return factory.createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutAnyOf, baseName), union].filter(Boolean),\n })\n }\n\n return union\n }\n if (schema.allOf) {\n // intersection/add\n const schemaWithoutAllOf = { ...schema, allOf: undefined }\n\n const and = factory.createIntersectionDeclaration({\n withParentheses: true,\n nodes: schema.allOf\n .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {\n return this.#getBaseTypeFromSchema(item)\n })\n .filter((item) => {\n return item && item !== factory.keywordTypeNodes.any\n }) as Array<ts.TypeNode>,\n })\n\n if (schemaWithoutAllOf.properties) {\n return factory.createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean),\n })\n }\n\n return and\n }\n\n /**\n * Enum will be defined outside the baseType(hints the baseName check)\n */\n if (schema.enum && baseName) {\n const enumName = getUniqueName(baseName, this.options.usedEnumNames)\n\n let enums: [key: string, value: string | number][] = [...new Set(schema.enum)].map((key) => [key, key])\n\n if ('x-enumNames' in schema) {\n enums = [...new Set(schema['x-enumNames'] as string[])].map((key: string, index) => {\n return [key, schema.enum?.[index]]\n })\n }\n\n this.extraNodes.push(\n ...factory.createEnumDeclaration({\n name: camelCase(enumName, this.#caseOptions),\n typeName: this.options.resolveName({ name: enumName }),\n enums,\n type: this.options.enumType,\n }),\n )\n return factory.createTypeReferenceNode(this.options.resolveName({ name: enumName }), undefined)\n }\n\n if (schema.enum) {\n return factory.createUnionDeclaration({\n nodes: schema.enum.map((name: string) => {\n return factory.createLiteralTypeNode(typeof name === 'number' ? factory.createNumericLiteral(name) : factory.createStringLiteral(`${name}`))\n }) as unknown as Array<ts.TypeNode>,\n })\n }\n\n if ('items' in schema) {\n // items -> array\n const node = this.#getTypeFromSchema(schema.items as OpenAPIV3.SchemaObject, baseName)\n if (node) {\n return factory.createArrayTypeNode(node)\n }\n }\n /**\n * OpenAPI 3.1\n * @link https://json-schema.org/understanding-json-schema/reference/array.html#tuple-validation\n */\n if ('prefixItems' in schema) {\n const prefixItems = schema.prefixItems as OpenAPIV3.SchemaObject[]\n\n return factory.createTupleDeclaration({\n nodes: prefixItems.map((item) => {\n // no baseType so we can fall back on an union when using enum\n return this.#getBaseTypeFromSchema(item, undefined)\n }) as Array<ts.TypeNode>,\n })\n }\n\n if (schema.properties || schema.additionalProperties) {\n // properties -> literal type\n return this.#getTypeFromProperties(schema, baseName)\n }\n\n if (schema.type) {\n if (Array.isArray(schema.type)) {\n // OPENAPI v3.1.0: https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0\n const [type, nullable] = schema.type as Array<OpenAPIV3.NonArraySchemaObjectType>\n\n return factory.createUnionDeclaration({\n nodes: [\n this.#getBaseTypeFromSchema(\n {\n ...schema,\n type,\n },\n baseName,\n ),\n nullable ? factory.createLiteralTypeNode(factory.createNull()) : undefined,\n ].filter(Boolean),\n })\n }\n\n if (this.options.dateType === 'date' && ['date', 'date-time'].some((item) => item === schema.format)) {\n return factory.createTypeReferenceNode(factory.createIdentifier('Date'))\n }\n\n // string, boolean, null, number\n if (schema.type in factory.keywordTypeNodes) {\n return factory.keywordTypeNodes[schema.type as keyof typeof factory.keywordTypeNodes]\n }\n }\n\n if (schema.format === 'binary') {\n return factory.createTypeReferenceNode('Blob', [])\n }\n\n // detect assertion \"const\" and define the type property as a Literal\n if ('const' in schema && schema['const'] !== undefined && typeof schema['const'] === 'string') {\n return factory.createLiteralTypeNode(factory.createStringLiteral(schema['const']))\n }\n\n return factory.keywordTypeNodes.any\n }\n}\n","import { getRelativePath } from '@kubb/core/utils'\nimport { print } from '@kubb/parser'\nimport * as factory from '@kubb/parser/factory'\nimport { OperationGenerator as Generator, resolve } from '@kubb/swagger'\n\nimport { pascalCase } from 'change-case'\n\nimport { TypeBuilder } from '../builders/index.ts'\n\nimport type { KubbFile } from '@kubb/core'\nimport type { FileResolver, Operation, OperationSchemas, Resolver } from '@kubb/swagger'\nimport type ts from 'typescript'\nimport type { FileMeta, PluginOptions } from '../types.ts'\n\ntype Options = {\n usedEnumNames: Record<string, number>\n\n mode: KubbFile.Mode\n enumType: NonNullable<PluginOptions['options']['enumType']>\n dateType: NonNullable<PluginOptions['options']['dateType']>\n optionalType: NonNullable<PluginOptions['options']['optionalType']>\n}\n\nexport class OperationGenerator extends Generator<Options, PluginOptions> {\n resolve(operation: Operation): Resolver {\n const { pluginManager, plugin } = this.context\n\n return resolve({\n operation,\n resolveName: pluginManager.resolveName,\n resolvePath: pluginManager.resolvePath,\n pluginKey: plugin?.key,\n })\n }\n\n async all(): Promise<KubbFile.File | null> {\n return null\n }\n\n #printCombinedSchema(name: string, operation: Operation, schemas: OperationSchemas): string {\n const properties: Record<string, ts.TypeNode> = {\n 'response': factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.response.name),\n undefined,\n ),\n }\n\n if (schemas.request) {\n properties['request'] = factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.request.name),\n undefined,\n )\n }\n\n if (schemas.pathParams) {\n properties['pathParams'] = factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.pathParams.name),\n undefined,\n )\n }\n\n if (schemas.queryParams) {\n properties['queryParams'] = factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.queryParams.name),\n undefined,\n )\n }\n\n if (schemas.headerParams) {\n properties['headerParams'] = factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.headerParams.name),\n undefined,\n )\n }\n\n if (schemas.errors) {\n properties['errors'] = factory.createUnionDeclaration({\n nodes: schemas.errors.map(error => {\n return factory.createTypeReferenceNode(\n factory.createIdentifier(error.name),\n undefined,\n )\n }),\n })!\n }\n\n const namespaceNode = factory.createNamespaceDeclaration({\n name: operation.method === 'get' ? `${name}Query` : `${name}Mutation`,\n statements: Object.keys(properties).map(key => {\n const type = properties[key]\n if (!type) {\n return undefined\n }\n return factory.createTypeAliasDeclaration({\n modifiers: [factory.modifiers.export],\n name: pascalCase(key),\n type,\n })\n }).filter(Boolean),\n })\n\n return print(namespaceNode)\n }\n\n async get(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n const { mode, enumType, dateType, optionalType, usedEnumNames } = options\n const { pluginManager, plugin } = this.context\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const root = pluginManager.resolvePath({ baseName: type.baseName, pluginKey: plugin?.key, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = pluginManager.resolvePath({\n baseName: `${name}.ts`,\n pluginKey: plugin?.key,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder({\n usedEnumNames,\n fileResolver: mode === 'file' ? undefined : fileResolver,\n withJSDocs: true,\n resolveName: (params) => pluginManager.resolveName({ ...params, pluginKey: plugin?.key }),\n enumType,\n optionalType,\n dateType,\n })\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.headerParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure()\n .print()\n\n const combinedSchemaSource = this.#printCombinedSchema(type.name, operation, schemas)\n\n return {\n path: type.path,\n baseName: type.baseName,\n source: [source, combinedSchemaSource].join('\\n'),\n meta: {\n pluginKey: plugin.key,\n tag: operation.getTags()[0]?.name,\n },\n }\n }\n\n async post(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n const { mode, enumType, dateType, optionalType, usedEnumNames } = options\n const { pluginManager, plugin } = this.context\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const root = pluginManager.resolvePath({ baseName: type.baseName, pluginKey: plugin?.key, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = pluginManager.resolvePath({\n baseName: `${name}.ts`,\n pluginKey: plugin?.key,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder({\n usedEnumNames,\n fileResolver: mode === 'file' ? undefined : fileResolver,\n withJSDocs: true,\n resolveName: (params) => pluginManager.resolveName({ ...params, pluginKey: plugin?.key }),\n enumType,\n optionalType,\n dateType,\n })\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.headerParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure()\n .print()\n\n const combinedSchemaSource = this.#printCombinedSchema(type.name, operation, schemas)\n\n return {\n path: type.path,\n baseName: type.baseName,\n source: [source, combinedSchemaSource].join('\\n'),\n meta: {\n pluginKey: plugin.key,\n tag: operation.getTags()[0]?.name,\n },\n }\n }\n\n async put(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n async patch(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n async delete(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n}\n","import { definePlugin } from './plugin.ts'\n\nexport { definePlugin, pluginKey, pluginName } from './plugin.ts'\nexport * from './types.ts'\n\nexport default definePlugin\n"]}
1
+ {"version":3,"sources":["../src/plugin.ts","../src/builders/TypeBuilder.ts","../src/generators/TypeGenerator.ts","../src/generators/OperationGenerator.ts","../src/index.ts"],"names":["getRelativePath","camelCase","pascalCase","factory","node","print","transformers","options","root"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,OAAO,UAAU;AAEjB,SAAS,cAAc,aAAa,qBAAqB;AACzD,SAAS,mBAAAA,kBAAiB,sBAAsB;AAChD,SAAS,cAAc,yBAAyB;AAEhD,SAAS,aAAAC,YAAW,yBAAyB,cAAAC,aAAY,gCAAgC;;;ACLzF,SAAS,oBAAoB;AAC7B,SAAS,aAAa;AACtB,YAAYC,cAAa;AACzB,SAAS,kBAAkB,kBAAkB;AAC7C,SAAS,kBAAkB;;;ACL3B,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAC9B,YAAY,aAAa;AACzB,SAAS,kBAAkB,mBAAmB;AAE9C,SAAS,iBAAiB;AAL1B;AAyBO,IAAM,gBAAN,cAA4B,gBAA2D;AAAA,EAe5F,YACE,SACA;AACA,UAAM,OAAO;AAwDf;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA;AAAA;AAAA;AAAA;AAsDA;AAAA;AAAA;AAAA;AAmBA;AASA;AAAA;AAAA;AAAA;AAAA;AA5KA,gBAAa,CAAC;AAEd,sBAAwB,CAAC;AAEzB,mBAAqC,CAAC;AAGtC;AAAA,wCAA0C,CAAC;AAE3C,qCAA4B;AAAA,MAC1B,WAAW;AAAA,MACX,aAAa;AAA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,cAAc,IAAI;AAAA,UAC/B;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAEA,YAAM,QAAQ,MAAM,mBAAmB,MAAM;AAC7C,YAAM,KAAK,QAAQ,GAAG,KAAK;AAAA,IAC7B;AAAA,IACA,MAAM,WAAW;AACf,UAAI,KAAK,OAAO,OAAO,UAAU,OAAO;AACtC;AAAA,MACF;AAEA,YAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,IAAI;AAEnE,YAAM,KAAK,YAAY,WAAW;AAAA,QAChC;AAAA,QACA,SAAS;AAAA,QACT,MAAM,EAAE,WAAW,KAAK,OAAO,IAAI;AAAA,QACnC,SAAS;AAAA,UACP,KAAK,CAAC,SAAS;AACb,mBAAO;AAAA,cACL,GAAG;AAAA,cACH,SAAS,KAAK,SAAS,IAAI,CAAC,SAAS;AACnC,oBAAI,UAAU;AACZ,yBAAO;AAAA,oBACL,GAAG;AAAA,oBACH,MAAM;AAAA,oBACN,SAAS,CAAC,CAAC;AAAA,kBACb;AAAA,gBACF;AACA,uBAAO;AAAA,cACT,CAAC;AAAA,YACH;AAAA,UACF;AAAA,UACA;AAAA,UACA,YAAY;AAAA,QACd;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;AIjOD,IAAO,cAAQ","sourcesContent":["import path from 'node:path'\n\nimport { createPlugin, FileManager, PluginManager } from '@kubb/core'\nimport { getRelativePath, renderTemplate } from '@kubb/core/utils'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\n\nimport { camelCase, camelCaseTransformMerge, pascalCase, pascalCaseTransformMerge } from 'change-case'\n\nimport { TypeBuilder } from './builders/index.ts'\nimport { OperationGenerator } from './generators/index.ts'\n\nimport type { KubbFile, KubbPlugin } from '@kubb/core'\nimport type { OasTypes, PluginOptions as SwaggerPluginOptions } from '@kubb/swagger'\nimport type { PluginOptions } from './types.ts'\n\nexport const pluginName = 'swagger-ts' satisfies PluginOptions['name']\nexport const pluginKey: PluginOptions['key'] = ['schema', pluginName] satisfies PluginOptions['key']\n\nexport const definePlugin = createPlugin<PluginOptions>((options) => {\n const {\n output = 'types',\n group,\n exclude = [],\n include,\n override = [],\n enumType = 'asConst',\n dateType = 'string',\n optionalType = 'questionToken',\n transformers = {},\n exportAs,\n } = options\n const template = group?.output ? group.output : `${output}/{{tag}}Controller`\n let pluginsOptions: [KubbPlugin<SwaggerPluginOptions>]\n\n return {\n name: pluginName,\n options,\n kind: 'schema',\n validate(plugins) {\n pluginsOptions = PluginManager.getDependedPlugins<SwaggerPluginOptions>(plugins, [swaggerPluginName])\n\n return true\n },\n resolvePath(baseName, directory, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output))\n\n if (mode === 'file') {\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)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag, { delimiter: '', transform: camelCaseTransformMerge })\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output, baseName)\n },\n resolveName(name, type) {\n const resolvedName = pascalCase(name, { delimiter: '', stripRegexp: /[^A-Z0-9$]/gi, transform: pascalCaseTransformMerge })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async writeFile(source, writePath) {\n if (!writePath.endsWith('.ts') || !source) {\n return\n }\n\n return this.fileManager.write(source, writePath)\n },\n async buildStart() {\n const [swaggerPlugin] = pluginsOptions\n\n const oas = await swaggerPlugin.api.getOas()\n\n const schemas = await swaggerPlugin.api.getSchemas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output))\n // keep the used enumnames between TypeBuilder and OperationGenerator per plugin(pluginKey)\n const usedEnumNames = {}\n\n if (mode === 'directory') {\n const builder = await new TypeBuilder({\n usedEnumNames,\n resolveName: (params) => this.resolveName({ pluginKey: this.plugin.key, ...params }),\n fileResolver: (name) => {\n const resolvedTypeId = this.resolvePath({\n baseName: `${name}.ts`,\n pluginKey: this.plugin.key,\n })\n\n const root = this.resolvePath({ baseName: ``, pluginKey: this.plugin.key })\n\n return getRelativePath(root, resolvedTypeId)\n },\n withJSDocs: true,\n enumType,\n dateType,\n optionalType,\n oas,\n }).configure()\n Object.entries(schemas).forEach(([name, schema]: [string, OasTypes.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const mapFolderSchema = async ([name]: [string, OasTypes.SchemaObject]) => {\n const resolvedPath = this.resolvePath({ baseName: `${this.resolveName({ name, pluginKey: this.plugin.key })}.ts`, pluginKey: this.plugin.key })\n\n if (!resolvedPath) {\n return null\n }\n\n return this.addFile({\n path: resolvedPath,\n baseName: `${this.resolveName({ name, pluginKey: this.plugin.key })}.ts`,\n source: builder.print(name),\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n }\n\n const promises = Object.entries(schemas).map(mapFolderSchema)\n\n await Promise.all(promises)\n }\n\n if (mode === 'file') {\n // outside the loop because we need to add files to just one instance to have the correct sorting, see refsSorter\n const builder = new TypeBuilder({\n usedEnumNames,\n resolveName: (params) => this.resolveName({ pluginKey: this.plugin.key, ...params }),\n withJSDocs: true,\n enumType,\n dateType,\n optionalType,\n oas,\n }).configure()\n Object.entries(schemas).forEach(([name, schema]: [string, OasTypes.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const resolvedPath = this.resolvePath({ baseName: '', pluginKey: this.plugin.key })\n if (!resolvedPath) {\n return\n }\n\n await this.addFile({\n path: resolvedPath,\n baseName: output as KubbFile.BaseName,\n source: builder.print(),\n meta: {\n pluginKey: this.plugin.key,\n },\n validate: false,\n })\n }\n\n const operationGenerator = new OperationGenerator(\n {\n mode,\n enumType,\n dateType,\n optionalType,\n usedEnumNames,\n },\n {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.api.contentType,\n exclude,\n include,\n override,\n },\n )\n\n const files = await operationGenerator.build()\n await this.addFile(...files)\n },\n async buildEnd() {\n if (this.config.output.write === false) {\n return\n }\n\n const root = path.resolve(this.config.root, this.config.output.path)\n\n await this.fileManager.addIndexes({\n root,\n extName: '.ts',\n meta: { pluginKey: this.plugin.key },\n options: {\n map: (file) => {\n return {\n ...file,\n exports: file.exports?.map((item) => {\n if (exportAs) {\n return {\n ...item,\n name: exportAs,\n asAlias: !!exportAs,\n }\n }\n return item\n }),\n }\n },\n output,\n isTypeOnly: true,\n },\n })\n },\n }\n})\n","/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { transformers } from '@kubb/core/utils'\nimport { print } from '@kubb/parser'\nimport * as factory from '@kubb/parser/factory'\nimport { ImportsGenerator, OasBuilder } from '@kubb/swagger'\nimport { refsSorter } from '@kubb/swagger/utils'\n\nimport { TypeGenerator } from '../generators/TypeGenerator.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { FileResolver, Oas } from '@kubb/swagger'\n\ntype Options = {\n oas: Oas\n usedEnumNames: Record<string, number>\n resolveName: PluginContext['resolveName']\n fileResolver?: FileResolver\n withJSDocs?: boolean\n withImports?: boolean\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n dateType: 'string' | 'date'\n optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'\n}\n\nexport class TypeBuilder extends OasBuilder<Options, never> {\n configure(options?: Options) {\n if (options) {\n this.options = options\n }\n\n if (this.options.fileResolver) {\n this.options.withImports = true\n }\n\n return this\n }\n\n print(name?: string): string {\n const codes: string[] = []\n\n const generated = this.items\n .filter((operationSchema) => (name ? operationSchema.name === name : true))\n .sort(transformers.nameSorter)\n .map((operationSchema) => {\n const generator = new TypeGenerator({\n usedEnumNames: this.options.usedEnumNames,\n withJSDocs: this.options.withJSDocs,\n resolveName: this.options.resolveName,\n enumType: this.options.enumType,\n dateType: this.options.dateType,\n optionalType: this.options.optionalType,\n oas: this.options.oas,\n })\n const sources = generator.build({\n schema: operationSchema.schema,\n baseName: operationSchema.name,\n description: operationSchema.description,\n keysToOmit: operationSchema.keysToOmit,\n })\n\n return {\n import: {\n refs: generator.refs,\n name: operationSchema.name,\n },\n sources,\n }\n })\n .sort(refsSorter)\n\n generated.forEach((item) => {\n codes.push(print(item.sources))\n })\n\n if (this.options.withImports) {\n const importsGenerator = new ImportsGenerator({ fileResolver: this.options.fileResolver })\n const importMeta = importsGenerator.build(generated.map((item) => item.import))\n\n if (importMeta) {\n const nodes = importMeta.map((item) => {\n return factory.createImportDeclaration({\n name: [{ propertyName: item.ref.propertyName }],\n path: item.path,\n isTypeOnly: true,\n })\n })\n\n codes.unshift(print(nodes))\n }\n }\n\n return transformers.combineCodes(codes)\n }\n}\n","import { SchemaGenerator } from '@kubb/core'\nimport { getUniqueName } from '@kubb/core/utils'\nimport * as factory from '@kubb/parser/factory'\nimport { getSchemaFactory, isReference } from '@kubb/swagger/utils'\n\nimport { camelCase } from 'change-case'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { ts } from '@kubb/parser'\nimport type { Oas, OasTypes, OpenAPIV3, OpenAPIV3_1, Refs } from '@kubb/swagger'\nimport type { Options as CaseOptions } from 'change-case'\n\n// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n\ntype Options = {\n oas: Oas\n usedEnumNames: Record<string, number>\n\n withJSDocs?: boolean\n resolveName: PluginContext['resolveName']\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n dateType: 'string' | 'date'\n optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'\n}\n\nexport class TypeGenerator extends SchemaGenerator<Options, OasTypes.SchemaObject, ts.Node[]> {\n refs: Refs = {}\n\n extraNodes: ts.Node[] = []\n\n aliases: ts.TypeAliasDeclaration[] = []\n\n // Keep track of already used type aliases\n #usedAliasNames: Record<string, number> = {}\n\n #caseOptions: CaseOptions = {\n delimiter: '',\n stripRegexp: /[^A-Z0-9$]/gi,\n }\n\n constructor(\n options: Options,\n ) {\n super(options)\n\n return this\n }\n\n build({\n schema,\n baseName,\n description,\n keysToOmit,\n }: {\n schema: OasTypes.SchemaObject\n baseName: string\n description?: string\n keysToOmit?: string[]\n }): ts.Node[] {\n const nodes: ts.Node[] = []\n const type = this.#getTypeFromSchema(schema, baseName)\n\n if (!type) {\n return this.extraNodes\n }\n\n const node = factory.createTypeAliasDeclaration({\n modifiers: [factory.modifiers.export],\n name: this.options.resolveName({ name: baseName }) || baseName,\n type: keysToOmit?.length ? factory.createOmitDeclaration({ keys: keysToOmit, type, nonNullable: true }) : type,\n })\n\n if (description) {\n nodes.push(\n factory.appendJSDocToNode({\n node,\n comments: [`@description ${description}`],\n }),\n )\n } else {\n nodes.push(node)\n }\n\n // filter out if the export name is the same as one that we already defined in extraNodes(see enum)\n const filterdNodes = nodes.filter(\n (node: ts.Node) =>\n !this.extraNodes.some(\n (extraNode: ts.Node) => (extraNode as ts.TypeAliasDeclaration)?.name?.escapedText === (node as ts.TypeAliasDeclaration)?.name?.escapedText,\n ),\n )\n\n return [...this.extraNodes, ...filterdNodes]\n }\n\n /**\n * Creates a type node from a given schema.\n * Delegates to getBaseTypeFromSchema internally and\n * optionally adds a union with null.\n */\n #getTypeFromSchema(schema?: OasTypes.SchemaObject, name?: string): ts.TypeNode | null {\n const type = this.#getBaseTypeFromSchema(schema, name)\n\n if (!type) {\n return null\n }\n\n if (schema && !schema.nullable) {\n return type\n }\n\n return factory.createUnionDeclaration({ nodes: [type, factory.keywordTypeNodes.null] })\n }\n\n /**\n * Recursively creates a type literal with the given props.\n */\n #getTypeFromProperties(baseSchema?: OasTypes.SchemaObject, baseName?: string) {\n const { optionalType } = this.options\n const properties = baseSchema?.properties || {}\n const required = baseSchema?.required\n const additionalProperties = baseSchema?.additionalProperties\n\n const members: Array<ts.TypeElement | null> = Object.keys(properties).map((name) => {\n const schema = properties[name] as OasTypes.SchemaObject\n\n const isRequired = Array.isArray(required) ? required.includes(name) : !!required\n let type = this.#getTypeFromSchema(schema, this.options.resolveName({ name: `${baseName || ''} ${name}` }))\n\n if (!type) {\n return null\n }\n\n if (!isRequired && ['undefined', 'questionTokenAndUndefined'].includes(optionalType)) {\n type = factory.createUnionDeclaration({ nodes: [type, factory.keywordTypeNodes.undefined] })\n }\n const propertySignature = factory.createPropertySignature({\n questionToken: ['questionToken', 'questionTokenAndUndefined'].includes(optionalType) && !isRequired,\n name,\n type: type as ts.TypeNode,\n readOnly: schema.readOnly,\n })\n if (this.options.withJSDocs) {\n return factory.appendJSDocToNode({\n node: propertySignature,\n comments: [\n schema.description ? `@description ${schema.description}` : undefined,\n schema.type ? `@type ${schema.type?.toString()}${isRequired ? '' : ' | undefined'} ${schema.format || ''}` : undefined,\n schema.example ? `@example ${schema.example as string}` : undefined,\n schema.deprecated ? `@deprecated` : undefined,\n schema.default !== undefined && typeof schema.default === 'string' ? `@default '${schema.default}'` : undefined,\n schema.default !== undefined && typeof schema.default !== 'string' ? `@default ${schema.default as string}` : undefined,\n ].filter(Boolean),\n })\n }\n\n return propertySignature\n })\n if (additionalProperties) {\n const type = additionalProperties === true ? factory.keywordTypeNodes.any : this.#getTypeFromSchema(additionalProperties as OasTypes.SchemaObject)\n\n if (type) {\n members.push(factory.createIndexSignature(type))\n }\n }\n return factory.createTypeLiteralNode(members.filter(Boolean))\n }\n\n /**\n * Create a type alias for the schema referenced by the given ReferenceObject\n */\n #getRefAlias(obj: OpenAPIV3.ReferenceObject, _baseName?: string) {\n const { $ref } = obj\n let ref = this.refs[$ref]\n\n if (ref) {\n return factory.createTypeReferenceNode(ref.propertyName, undefined)\n }\n\n const originalName = getUniqueName($ref.replace(/.+\\//, ''), this.#usedAliasNames)\n const propertyName = this.options.resolveName({ name: originalName }) || originalName\n\n ref = this.refs[$ref] = {\n propertyName,\n originalName,\n }\n\n return factory.createTypeReferenceNode(ref.propertyName, undefined)\n }\n\n #getParsedSchema(schema?: OasTypes.SchemaObject) {\n const parsedSchema = getSchemaFactory(this.options.oas)(schema)\n return parsedSchema\n }\n\n /**\n * This is the very core of the OpenAPI to TS conversion - it takes a\n * schema and returns the appropriate type.\n */\n #getBaseTypeFromSchema(\n _schema: OasTypes.SchemaObject | undefined,\n baseName?: string,\n ): ts.TypeNode | null {\n const { schema, version } = this.#getParsedSchema(_schema)\n\n if (!schema) {\n return factory.keywordTypeNodes.any\n }\n\n if (isReference(schema)) {\n return this.#getRefAlias(schema, baseName)\n }\n\n if (schema.oneOf) {\n // union\n const schemaWithoutOneOf = { ...schema, oneOf: undefined } as OasTypes.SchemaObject\n\n const union = factory.createUnionDeclaration({\n withParentheses: true,\n nodes: schema.oneOf\n .map((item) => {\n return item && this.#getBaseTypeFromSchema(item as OasTypes.SchemaObject)\n })\n .filter((item) => {\n return item && item !== factory.keywordTypeNodes.any\n }) as Array<ts.TypeNode>,\n })\n\n if (schemaWithoutOneOf.properties) {\n return factory.createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean),\n })\n }\n\n return union\n }\n\n if (schema.anyOf) {\n const schemaWithoutAnyOf = { ...schema, anyOf: undefined } as OasTypes.SchemaObject\n\n const union = factory.createUnionDeclaration({\n withParentheses: true,\n nodes: schema.anyOf\n .map((item) => {\n return item && this.#getBaseTypeFromSchema(item as OasTypes.SchemaObject)\n })\n .filter((item) => {\n return item && item !== factory.keywordTypeNodes.any\n }) as Array<ts.TypeNode>,\n })\n\n if (schemaWithoutAnyOf.properties) {\n return factory.createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutAnyOf, baseName), union].filter(Boolean),\n })\n }\n\n return union\n }\n if (schema.allOf) {\n // intersection/add\n const schemaWithoutAllOf = { ...schema, allOf: undefined } as OasTypes.SchemaObject\n\n const and = factory.createIntersectionDeclaration({\n withParentheses: true,\n nodes: schema.allOf\n .map((item) => {\n return item && this.#getBaseTypeFromSchema(item as OasTypes.SchemaObject)\n })\n .filter((item) => {\n return item && item !== factory.keywordTypeNodes.any\n }) as Array<ts.TypeNode>,\n })\n\n if (schemaWithoutAllOf.properties) {\n return factory.createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean),\n })\n }\n\n return and\n }\n\n /**\n * Enum will be defined outside the baseType(hints the baseName check)\n */\n if (schema.enum && baseName) {\n const enumName = getUniqueName(baseName, this.options.usedEnumNames)\n\n let enums: [key: string, value: string | number][] = [...new Set(schema.enum)].map((key) => [key, key])\n\n if ('x-enumNames' in schema) {\n enums = [...new Set(schema['x-enumNames'] as string[])].map((key: string, index) => {\n return [key, schema.enum?.[index] as string]\n })\n }\n\n this.extraNodes.push(\n ...factory.createEnumDeclaration({\n name: camelCase(enumName, this.#caseOptions),\n typeName: this.options.resolveName({ name: enumName }),\n enums,\n type: this.options.enumType,\n }),\n )\n return factory.createTypeReferenceNode(this.options.resolveName({ name: enumName }), undefined)\n }\n\n if (schema.enum) {\n return factory.createUnionDeclaration({\n nodes: schema.enum.map((name) => {\n return factory.createLiteralTypeNode(typeof name === 'number' ? factory.createNumericLiteral(name) : factory.createStringLiteral(`${name}`))\n }) as unknown as Array<ts.TypeNode>,\n })\n }\n\n if ('items' in schema) {\n // items -> array\n const node = this.#getTypeFromSchema(schema.items as OasTypes.SchemaObject, baseName)\n if (node) {\n return factory.createArrayTypeNode(node)\n }\n }\n\n /**\n * OpenAPI 3.1\n * @link https://json-schema.org/understanding-json-schema/reference/array.html#tuple-validation\n */\n\n if ('prefixItems' in schema) {\n const prefixItems = schema.prefixItems as OasTypes.SchemaObject[]\n\n return factory.createTupleDeclaration({\n nodes: prefixItems.map((item) => {\n // no baseType so we can fall back on an union when using enum\n return this.#getBaseTypeFromSchema(item, undefined)\n }) as Array<ts.TypeNode>,\n })\n }\n\n if (schema.properties || schema.additionalProperties) {\n // properties -> literal type\n return this.#getTypeFromProperties(schema, baseName)\n }\n\n if (schema.type) {\n if (Array.isArray(schema.type)) {\n // OPENAPI v3.1.0: https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0\n const [type, nullable] = schema.type as Array<OpenAPIV3_1.NonArraySchemaObjectType>\n\n return factory.createUnionDeclaration({\n nodes: [\n this.#getBaseTypeFromSchema(\n {\n ...schema,\n type,\n },\n baseName,\n ),\n nullable ? factory.createLiteralTypeNode(factory.createNull()) : undefined,\n ].filter(Boolean),\n })\n }\n\n if (this.options.dateType === 'date' && ['date', 'date-time'].some((item) => item === schema.format)) {\n return factory.createTypeReferenceNode(factory.createIdentifier('Date'))\n }\n\n // string, boolean, null, number\n if (schema.type in factory.keywordTypeNodes) {\n return factory.keywordTypeNodes[schema.type as keyof typeof factory.keywordTypeNodes]\n }\n }\n\n if (schema.format === 'binary') {\n return factory.createTypeReferenceNode('Blob', [])\n }\n\n // detect assertion \"const\" and define the type property as a Literal\n if (version === '3.1' && typeof schema['const'] === 'string') {\n return factory.createLiteralTypeNode(factory.createStringLiteral(schema['const']))\n }\n\n return factory.keywordTypeNodes.any\n }\n}\n","import { getRelativePath } from '@kubb/core/utils'\nimport { print } from '@kubb/parser'\nimport * as factory from '@kubb/parser/factory'\nimport { OperationGenerator as Generator, resolve } from '@kubb/swagger'\n\nimport { pascalCase } from 'change-case'\n\nimport { TypeBuilder } from '../builders/index.ts'\n\nimport type { KubbFile } from '@kubb/core'\nimport type { FileResolver, Operation, OperationSchemas, Resolver } from '@kubb/swagger'\nimport type ts from 'typescript'\nimport type { FileMeta, PluginOptions } from '../types.ts'\n\ntype Options = {\n usedEnumNames: Record<string, number>\n\n mode: KubbFile.Mode\n enumType: NonNullable<PluginOptions['options']['enumType']>\n dateType: NonNullable<PluginOptions['options']['dateType']>\n optionalType: NonNullable<PluginOptions['options']['optionalType']>\n}\n\nexport class OperationGenerator extends Generator<Options, PluginOptions> {\n resolve(operation: Operation): Resolver {\n const { pluginManager, plugin } = this.context\n\n return resolve({\n operation,\n resolveName: pluginManager.resolveName,\n resolvePath: pluginManager.resolvePath,\n pluginKey: plugin?.key,\n })\n }\n\n async all(): Promise<KubbFile.File | null> {\n return null\n }\n\n #printCombinedSchema(name: string, operation: Operation, schemas: OperationSchemas): string {\n const properties: Record<string, ts.TypeNode> = {\n 'response': factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.response.name),\n undefined,\n ),\n }\n\n if (schemas.request) {\n properties['request'] = factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.request.name),\n undefined,\n )\n }\n\n if (schemas.pathParams) {\n properties['pathParams'] = factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.pathParams.name),\n undefined,\n )\n }\n\n if (schemas.queryParams) {\n properties['queryParams'] = factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.queryParams.name),\n undefined,\n )\n }\n\n if (schemas.headerParams) {\n properties['headerParams'] = factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.headerParams.name),\n undefined,\n )\n }\n\n if (schemas.errors) {\n properties['errors'] = factory.createUnionDeclaration({\n nodes: schemas.errors.map(error => {\n return factory.createTypeReferenceNode(\n factory.createIdentifier(error.name),\n undefined,\n )\n }),\n })!\n }\n\n const namespaceNode = factory.createNamespaceDeclaration({\n name: operation.method === 'get' ? `${name}Query` : `${name}Mutation`,\n statements: Object.keys(properties).map(key => {\n const type = properties[key]\n if (!type) {\n return undefined\n }\n return factory.createTypeAliasDeclaration({\n modifiers: [factory.modifiers.export],\n name: pascalCase(key),\n type,\n })\n }).filter(Boolean),\n })\n\n return print(namespaceNode)\n }\n\n async get(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n const { mode, enumType, dateType, optionalType, usedEnumNames } = options\n const { pluginManager, plugin, oas } = this.context\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const root = pluginManager.resolvePath({ baseName: type.baseName, pluginKey: plugin?.key, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = pluginManager.resolvePath({\n baseName: `${name}.ts`,\n pluginKey: plugin?.key,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder({\n usedEnumNames,\n fileResolver: mode === 'file' ? undefined : fileResolver,\n withJSDocs: true,\n resolveName: (params) => pluginManager.resolveName({ ...params, pluginKey: plugin?.key }),\n enumType,\n optionalType,\n dateType,\n oas,\n })\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.headerParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure()\n .print()\n\n const combinedSchemaSource = this.#printCombinedSchema(type.name, operation, schemas)\n\n return {\n path: type.path,\n baseName: type.baseName,\n source: [source, combinedSchemaSource].join('\\n'),\n meta: {\n pluginKey: plugin.key,\n tag: operation.getTags()[0]?.name,\n },\n }\n }\n\n async post(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n const { mode, enumType, dateType, optionalType, usedEnumNames } = options\n const { pluginManager, plugin, oas } = this.context\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const root = pluginManager.resolvePath({ baseName: type.baseName, pluginKey: plugin?.key, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = pluginManager.resolvePath({\n baseName: `${name}.ts`,\n pluginKey: plugin?.key,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder({\n usedEnumNames,\n fileResolver: mode === 'file' ? undefined : fileResolver,\n withJSDocs: true,\n resolveName: (params) => pluginManager.resolveName({ ...params, pluginKey: plugin?.key }),\n enumType,\n optionalType,\n dateType,\n oas,\n })\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.headerParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure()\n .print()\n\n const combinedSchemaSource = this.#printCombinedSchema(type.name, operation, schemas)\n\n return {\n path: type.path,\n baseName: type.baseName,\n source: [source, combinedSchemaSource].join('\\n'),\n meta: {\n pluginKey: plugin.key,\n tag: operation.getTags()[0]?.name,\n },\n }\n }\n\n async put(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n async patch(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n async delete(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n}\n","import { definePlugin } from './plugin.ts'\n\nexport { definePlugin, pluginKey, pluginName } from './plugin.ts'\nexport * from './types.ts'\n\nexport default definePlugin\n"]}
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { pluginName as pluginName$1, OasBuilder, ImportsGenerator, OperationGene
6
6
  import { camelCase, camelCaseTransformMerge, pascalCase, pascalCaseTransformMerge } from 'change-case';
7
7
  import { print } from '@kubb/parser';
8
8
  import * as factory from '@kubb/parser/factory';
9
- import { refsSorter, isReference } from '@kubb/swagger/utils';
9
+ import { refsSorter, isReference, getSchemaFactory } from '@kubb/swagger/utils';
10
10
 
11
11
  createRequire(import.meta.url);
12
12
 
@@ -27,16 +27,9 @@ var __privateMethod = (obj, member, method) => {
27
27
  __accessCheck(obj, member, "access private method");
28
28
  return method;
29
29
  };
30
- var _usedAliasNames, _caseOptions, _getTypeFromSchema, getTypeFromSchema_fn, _getTypeFromProperties, getTypeFromProperties_fn, _getRefAlias, getRefAlias_fn, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn;
30
+ var _usedAliasNames, _caseOptions, _getTypeFromSchema, getTypeFromSchema_fn, _getTypeFromProperties, getTypeFromProperties_fn, _getRefAlias, getRefAlias_fn, _getParsedSchema, getParsedSchema_fn, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn;
31
31
  var TypeGenerator = class extends SchemaGenerator {
32
- constructor(options = {
33
- usedEnumNames: {},
34
- withJSDocs: true,
35
- resolveName: ({ name }) => name,
36
- enumType: "asConst",
37
- dateType: "string",
38
- optionalType: "questionToken"
39
- }) {
32
+ constructor(options) {
40
33
  super(options);
41
34
  /**
42
35
  * Creates a type node from a given schema.
@@ -52,6 +45,7 @@ var TypeGenerator = class extends SchemaGenerator {
52
45
  * Create a type alias for the schema referenced by the given ReferenceObject
53
46
  */
54
47
  __privateAdd(this, _getRefAlias);
48
+ __privateAdd(this, _getParsedSchema);
55
49
  /**
56
50
  * This is the very core of the OpenAPI to TS conversion - it takes a
57
51
  * schema and returns the appropriate type.
@@ -123,7 +117,7 @@ getTypeFromProperties_fn = function(baseSchema, baseName) {
123
117
  const additionalProperties = baseSchema?.additionalProperties;
124
118
  const members = Object.keys(properties).map((name) => {
125
119
  const schema = properties[name];
126
- const isRequired = required && required.includes(name);
120
+ const isRequired = Array.isArray(required) ? required.includes(name) : !!required;
127
121
  let type = __privateMethod(this, _getTypeFromSchema, getTypeFromSchema_fn).call(this, schema, this.options.resolveName({ name: `${baseName || ""} ${name}` }));
128
122
  if (!type) {
129
123
  return null;
@@ -142,7 +136,7 @@ getTypeFromProperties_fn = function(baseSchema, baseName) {
142
136
  node: propertySignature,
143
137
  comments: [
144
138
  schema.description ? `@description ${schema.description}` : void 0,
145
- schema.type ? `@type ${schema.type}${isRequired ? "" : " | undefined"} ${schema.format || ""}` : void 0,
139
+ schema.type ? `@type ${schema.type?.toString()}${isRequired ? "" : " | undefined"} ${schema.format || ""}` : void 0,
146
140
  schema.example ? `@example ${schema.example}` : void 0,
147
141
  schema.deprecated ? `@deprecated` : void 0,
148
142
  schema.default !== void 0 && typeof schema.default === "string" ? `@default '${schema.default}'` : void 0,
@@ -175,8 +169,14 @@ getRefAlias_fn = function(obj, _baseName) {
175
169
  };
176
170
  return factory.createTypeReferenceNode(ref.propertyName, void 0);
177
171
  };
172
+ _getParsedSchema = new WeakSet();
173
+ getParsedSchema_fn = function(schema) {
174
+ const parsedSchema = getSchemaFactory(this.options.oas)(schema);
175
+ return parsedSchema;
176
+ };
178
177
  _getBaseTypeFromSchema = new WeakSet();
179
- getBaseTypeFromSchema_fn = function(schema, baseName) {
178
+ getBaseTypeFromSchema_fn = function(_schema, baseName) {
179
+ const { schema, version } = __privateMethod(this, _getParsedSchema, getParsedSchema_fn).call(this, _schema);
180
180
  if (!schema) {
181
181
  return factory.keywordTypeNodes.any;
182
182
  }
@@ -188,7 +188,7 @@ getBaseTypeFromSchema_fn = function(schema, baseName) {
188
188
  const union = factory.createUnionDeclaration({
189
189
  withParentheses: true,
190
190
  nodes: schema.oneOf.map((item) => {
191
- return __privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, item);
191
+ return item && __privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, item);
192
192
  }).filter((item) => {
193
193
  return item && item !== factory.keywordTypeNodes.any;
194
194
  })
@@ -205,7 +205,7 @@ getBaseTypeFromSchema_fn = function(schema, baseName) {
205
205
  const union = factory.createUnionDeclaration({
206
206
  withParentheses: true,
207
207
  nodes: schema.anyOf.map((item) => {
208
- return __privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, item);
208
+ return item && __privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, item);
209
209
  }).filter((item) => {
210
210
  return item && item !== factory.keywordTypeNodes.any;
211
211
  })
@@ -222,7 +222,7 @@ getBaseTypeFromSchema_fn = function(schema, baseName) {
222
222
  const and = factory.createIntersectionDeclaration({
223
223
  withParentheses: true,
224
224
  nodes: schema.allOf.map((item) => {
225
- return __privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, item);
225
+ return item && __privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, item);
226
226
  }).filter((item) => {
227
227
  return item && item !== factory.keywordTypeNodes.any;
228
228
  })
@@ -299,7 +299,7 @@ getBaseTypeFromSchema_fn = function(schema, baseName) {
299
299
  if (schema.format === "binary") {
300
300
  return factory.createTypeReferenceNode("Blob", []);
301
301
  }
302
- if ("const" in schema && schema["const"] !== void 0 && typeof schema["const"] === "string") {
302
+ if (version === "3.1" && typeof schema["const"] === "string") {
303
303
  return factory.createLiteralTypeNode(factory.createStringLiteral(schema["const"]));
304
304
  }
305
305
  return factory.keywordTypeNodes.any;
@@ -325,7 +325,8 @@ var TypeBuilder = class extends OasBuilder {
325
325
  resolveName: this.options.resolveName,
326
326
  enumType: this.options.enumType,
327
327
  dateType: this.options.dateType,
328
- optionalType: this.options.optionalType
328
+ optionalType: this.options.optionalType,
329
+ oas: this.options.oas
329
330
  });
330
331
  const sources = generator.build({
331
332
  schema: operationSchema.schema,
@@ -381,7 +382,7 @@ var OperationGenerator = class extends OperationGenerator$1 {
381
382
  }
382
383
  async get(operation, schemas, options) {
383
384
  const { mode, enumType, dateType, optionalType, usedEnumNames } = options;
384
- const { pluginManager, plugin } = this.context;
385
+ const { pluginManager, plugin, oas } = this.context;
385
386
  const type = this.resolve(operation);
386
387
  const fileResolver = (name) => {
387
388
  const root = pluginManager.resolvePath({ baseName: type.baseName, pluginKey: plugin?.key, options: { tag: operation.getTags()[0]?.name } });
@@ -398,7 +399,8 @@ var OperationGenerator = class extends OperationGenerator$1 {
398
399
  resolveName: (params) => pluginManager.resolveName({ ...params, pluginKey: plugin?.key }),
399
400
  enumType,
400
401
  optionalType,
401
- dateType
402
+ dateType,
403
+ oas
402
404
  }).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.response).add(schemas.errors).configure().print();
403
405
  const combinedSchemaSource = __privateMethod(this, _printCombinedSchema, printCombinedSchema_fn).call(this, type.name, operation, schemas);
404
406
  return {
@@ -413,7 +415,7 @@ var OperationGenerator = class extends OperationGenerator$1 {
413
415
  }
414
416
  async post(operation, schemas, options) {
415
417
  const { mode, enumType, dateType, optionalType, usedEnumNames } = options;
416
- const { pluginManager, plugin } = this.context;
418
+ const { pluginManager, plugin, oas } = this.context;
417
419
  const type = this.resolve(operation);
418
420
  const fileResolver = (name) => {
419
421
  const root = pluginManager.resolvePath({ baseName: type.baseName, pluginKey: plugin?.key, options: { tag: operation.getTags()[0]?.name } });
@@ -430,7 +432,8 @@ var OperationGenerator = class extends OperationGenerator$1 {
430
432
  resolveName: (params) => pluginManager.resolveName({ ...params, pluginKey: plugin?.key }),
431
433
  enumType,
432
434
  optionalType,
433
- dateType
435
+ dateType,
436
+ oas
434
437
  }).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.request).add(schemas.response).add(schemas.errors).configure().print();
435
438
  const combinedSchemaSource = __privateMethod(this, _printCombinedSchema, printCombinedSchema_fn).call(this, type.name, operation, schemas);
436
439
  return {
@@ -585,7 +588,8 @@ var definePlugin = createPlugin((options) => {
585
588
  withJSDocs: true,
586
589
  enumType,
587
590
  dateType,
588
- optionalType
591
+ optionalType,
592
+ oas
589
593
  }).configure();
590
594
  Object.entries(schemas).forEach(([name, schema]) => {
591
595
  return builder.add({
@@ -617,7 +621,8 @@ var definePlugin = createPlugin((options) => {
617
621
  withJSDocs: true,
618
622
  enumType,
619
623
  dateType,
620
- optionalType
624
+ optionalType,
625
+ oas
621
626
  }).configure();
622
627
  Object.entries(schemas).forEach(([name, schema]) => {
623
628
  return builder.add({
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin.ts","../src/builders/TypeBuilder.ts","../src/generators/TypeGenerator.ts","../src/generators/OperationGenerator.ts","../src/index.ts"],"names":["getRelativePath","camelCase","pascalCase","factory","node","print","transformers","options","root"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,UAAU;AAEjB,SAAS,cAAc,aAAa,qBAAqB;AACzD,SAAS,mBAAAA,kBAAiB,sBAAsB;AAChD,SAAS,cAAc,yBA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A,QACd;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;AI/ND,IAAO,cAAQ","sourcesContent":["import path from 'node:path'\n\nimport { createPlugin, FileManager, PluginManager } from '@kubb/core'\nimport { getRelativePath, renderTemplate } from '@kubb/core/utils'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\n\nimport { camelCase, camelCaseTransformMerge, pascalCase, pascalCaseTransformMerge } from 'change-case'\n\nimport { TypeBuilder } from './builders/index.ts'\nimport { OperationGenerator } from './generators/index.ts'\n\nimport type { KubbFile, KubbPlugin } from '@kubb/core'\nimport type { OpenAPIV3, PluginOptions as SwaggerPluginOptions } from '@kubb/swagger'\nimport type { PluginOptions } from './types.ts'\n\nexport const pluginName = 'swagger-ts' satisfies PluginOptions['name']\nexport const pluginKey: PluginOptions['key'] = ['schema', pluginName] satisfies PluginOptions['key']\n\nexport const definePlugin = createPlugin<PluginOptions>((options) => {\n const {\n output = 'types',\n group,\n exclude = [],\n include,\n override = [],\n enumType = 'asConst',\n dateType = 'string',\n optionalType = 'questionToken',\n transformers = {},\n exportAs,\n } = options\n const template = group?.output ? group.output : `${output}/{{tag}}Controller`\n let pluginsOptions: [KubbPlugin<SwaggerPluginOptions>]\n\n return {\n name: pluginName,\n options,\n kind: 'schema',\n validate(plugins) {\n pluginsOptions = PluginManager.getDependedPlugins<SwaggerPluginOptions>(plugins, [swaggerPluginName])\n\n return true\n },\n resolvePath(baseName, directory, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output))\n\n if (mode === 'file') {\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)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag, { delimiter: '', transform: camelCaseTransformMerge })\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output, baseName)\n },\n resolveName(name, type) {\n const resolvedName = pascalCase(name, { delimiter: '', stripRegexp: /[^A-Z0-9$]/gi, transform: pascalCaseTransformMerge })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async writeFile(source, writePath) {\n if (!writePath.endsWith('.ts') || !source) {\n return\n }\n\n return this.fileManager.write(source, writePath)\n },\n async buildStart() {\n const [swaggerPlugin] = pluginsOptions\n\n const oas = await swaggerPlugin.api.getOas()\n\n const schemas = await swaggerPlugin.api.getSchemas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output))\n // keep the used enumnames between TypeBuilder and OperationGenerator per plugin(pluginKey)\n const usedEnumNames = {}\n\n if (mode === 'directory') {\n const builder = await new TypeBuilder({\n usedEnumNames,\n resolveName: (params) => this.resolveName({ pluginKey: this.plugin.key, ...params }),\n fileResolver: (name) => {\n const resolvedTypeId = this.resolvePath({\n baseName: `${name}.ts`,\n pluginKey: this.plugin.key,\n })\n\n const root = this.resolvePath({ baseName: ``, pluginKey: this.plugin.key })\n\n return getRelativePath(root, resolvedTypeId)\n },\n withJSDocs: true,\n enumType,\n dateType,\n optionalType,\n }).configure()\n Object.entries(schemas).forEach(([name, schema]: [string, OpenAPIV3.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const mapFolderSchema = async ([name]: [string, OpenAPIV3.SchemaObject]) => {\n const resolvedPath = this.resolvePath({ baseName: `${this.resolveName({ name, pluginKey: this.plugin.key })}.ts`, pluginKey: this.plugin.key })\n\n if (!resolvedPath) {\n return null\n }\n\n return this.addFile({\n path: resolvedPath,\n baseName: `${this.resolveName({ name, pluginKey: this.plugin.key })}.ts`,\n source: builder.print(name),\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n }\n\n const promises = Object.entries(schemas).map(mapFolderSchema)\n\n await Promise.all(promises)\n }\n\n if (mode === 'file') {\n // outside the loop because we need to add files to just one instance to have the correct sorting, see refsSorter\n const builder = new TypeBuilder({\n usedEnumNames,\n resolveName: (params) => this.resolveName({ pluginKey: this.plugin.key, ...params }),\n withJSDocs: true,\n enumType,\n dateType,\n optionalType,\n }).configure()\n Object.entries(schemas).forEach(([name, schema]: [string, OpenAPIV3.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const resolvedPath = this.resolvePath({ baseName: '', pluginKey: this.plugin.key })\n if (!resolvedPath) {\n return\n }\n\n await this.addFile({\n path: resolvedPath,\n baseName: output as KubbFile.BaseName,\n source: builder.print(),\n meta: {\n pluginKey: this.plugin.key,\n },\n validate: false,\n })\n }\n\n const operationGenerator = new OperationGenerator(\n {\n mode,\n enumType,\n dateType,\n optionalType,\n usedEnumNames,\n },\n {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.api.contentType,\n exclude,\n include,\n override,\n },\n )\n\n const files = await operationGenerator.build()\n await this.addFile(...files)\n },\n async buildEnd() {\n if (this.config.output.write === false) {\n return\n }\n\n const root = path.resolve(this.config.root, this.config.output.path)\n\n await this.fileManager.addIndexes({\n root,\n extName: '.ts',\n meta: { pluginKey: this.plugin.key },\n options: {\n map: (file) => {\n return {\n ...file,\n exports: file.exports?.map((item) => {\n if (exportAs) {\n return {\n ...item,\n name: exportAs,\n asAlias: !!exportAs,\n }\n }\n return item\n }),\n }\n },\n output,\n isTypeOnly: true,\n },\n })\n },\n }\n})\n","/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { transformers } from '@kubb/core/utils'\nimport { print } from '@kubb/parser'\nimport * as factory from '@kubb/parser/factory'\nimport { ImportsGenerator, OasBuilder } from '@kubb/swagger'\nimport { refsSorter } from '@kubb/swagger/utils'\n\nimport { TypeGenerator } from '../generators/TypeGenerator.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { FileResolver } from '@kubb/swagger'\n\ntype Options = {\n usedEnumNames: Record<string, number>\n\n resolveName: PluginContext['resolveName']\n fileResolver?: FileResolver\n withJSDocs?: boolean\n withImports?: boolean\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n dateType: 'string' | 'date'\n optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'\n}\n\nexport class TypeBuilder extends OasBuilder<Options, never> {\n configure(options?: Options) {\n if (options) {\n this.options = options\n }\n\n if (this.options.fileResolver) {\n this.options.withImports = true\n }\n\n return this\n }\n\n print(name?: string): string {\n const codes: string[] = []\n\n const generated = this.items\n .filter((operationSchema) => (name ? operationSchema.name === name : true))\n .sort(transformers.nameSorter)\n .map((operationSchema) => {\n const generator = new TypeGenerator({\n usedEnumNames: this.options.usedEnumNames,\n withJSDocs: this.options.withJSDocs,\n resolveName: this.options.resolveName,\n enumType: this.options.enumType,\n dateType: this.options.dateType,\n optionalType: this.options.optionalType,\n })\n const sources = generator.build({\n schema: operationSchema.schema,\n baseName: operationSchema.name,\n description: operationSchema.description,\n keysToOmit: operationSchema.keysToOmit,\n })\n\n return {\n import: {\n refs: generator.refs,\n name: operationSchema.name,\n },\n sources,\n }\n })\n .sort(refsSorter)\n\n generated.forEach((item) => {\n codes.push(print(item.sources))\n })\n\n if (this.options.withImports) {\n const importsGenerator = new ImportsGenerator({ fileResolver: this.options.fileResolver })\n const importMeta = importsGenerator.build(generated.map((item) => item.import))\n\n if (importMeta) {\n const nodes = importMeta.map((item) => {\n return factory.createImportDeclaration({\n name: [{ propertyName: item.ref.propertyName }],\n path: item.path,\n isTypeOnly: true,\n })\n })\n\n codes.unshift(print(nodes))\n }\n }\n\n return transformers.combineCodes(codes)\n }\n}\n","import { SchemaGenerator } from '@kubb/core'\nimport { getUniqueName } from '@kubb/core/utils'\nimport * as factory from '@kubb/parser/factory'\nimport { isReference } from '@kubb/swagger/utils'\n\nimport { camelCase } from 'change-case'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { ts } from '@kubb/parser'\nimport type { OpenAPIV3, Refs } from '@kubb/swagger'\nimport type { Options as CaseOptions } from 'change-case'\n\n// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n\ntype Options = {\n usedEnumNames: Record<string, number>\n\n withJSDocs?: boolean\n resolveName: PluginContext['resolveName']\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n dateType: 'string' | 'date'\n optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'\n}\nexport class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObject, ts.Node[]> {\n refs: Refs = {}\n\n extraNodes: ts.Node[] = []\n\n aliases: ts.TypeAliasDeclaration[] = []\n\n // Keep track of already used type aliases\n #usedAliasNames: Record<string, number> = {}\n\n #caseOptions: CaseOptions = {\n delimiter: '',\n stripRegexp: /[^A-Z0-9$]/gi,\n }\n\n constructor(\n options: Options = {\n usedEnumNames: {},\n withJSDocs: true,\n resolveName: ({ name }) => name,\n enumType: 'asConst',\n dateType: 'string',\n optionalType: 'questionToken',\n },\n ) {\n super(options)\n\n return this\n }\n\n build({\n schema,\n baseName,\n description,\n keysToOmit,\n }: {\n schema: OpenAPIV3.SchemaObject\n baseName: string\n description?: string\n keysToOmit?: string[]\n }): ts.Node[] {\n const nodes: ts.Node[] = []\n const type = this.#getTypeFromSchema(schema, baseName)\n\n if (!type) {\n return this.extraNodes\n }\n\n const node = factory.createTypeAliasDeclaration({\n modifiers: [factory.modifiers.export],\n name: this.options.resolveName({ name: baseName }) || baseName,\n type: keysToOmit?.length ? factory.createOmitDeclaration({ keys: keysToOmit, type, nonNullable: true }) : type,\n })\n\n if (description) {\n nodes.push(\n factory.appendJSDocToNode({\n node,\n comments: [`@description ${description}`],\n }),\n )\n } else {\n nodes.push(node)\n }\n\n // filter out if the export name is the same as one that we already defined in extraNodes(see enum)\n const filterdNodes = nodes.filter(\n (node: ts.Node) =>\n !this.extraNodes.some(\n (extraNode: ts.Node) => (extraNode as ts.TypeAliasDeclaration)?.name?.escapedText === (node as ts.TypeAliasDeclaration)?.name?.escapedText,\n ),\n )\n\n return [...this.extraNodes, ...filterdNodes]\n }\n\n /**\n * Creates a type node from a given schema.\n * Delegates to getBaseTypeFromSchema internally and\n * optionally adds a union with null.\n */\n #getTypeFromSchema(schema?: OpenAPIV3.SchemaObject, name?: string): ts.TypeNode | null {\n const type = this.#getBaseTypeFromSchema(schema, name)\n\n if (!type) {\n return null\n }\n\n if (schema && !schema.nullable) {\n return type\n }\n\n return factory.createUnionDeclaration({ nodes: [type, factory.keywordTypeNodes.null] })\n }\n\n /**\n * Recursively creates a type literal with the given props.\n */\n #getTypeFromProperties(baseSchema?: OpenAPIV3.SchemaObject, baseName?: string) {\n const { optionalType } = this.options\n const properties = baseSchema?.properties || {}\n const required = baseSchema?.required\n const additionalProperties = baseSchema?.additionalProperties\n\n const members: Array<ts.TypeElement | null> = Object.keys(properties).map((name) => {\n const schema = properties[name] as OpenAPIV3.SchemaObject\n\n const isRequired = required && required.includes(name)\n let type = this.#getTypeFromSchema(schema, this.options.resolveName({ name: `${baseName || ''} ${name}` }))\n\n if (!type) {\n return null\n }\n\n if (!isRequired && ['undefined', 'questionTokenAndUndefined'].includes(optionalType)) {\n type = factory.createUnionDeclaration({ nodes: [type, factory.keywordTypeNodes.undefined] })\n }\n const propertySignature = factory.createPropertySignature({\n questionToken: ['questionToken', 'questionTokenAndUndefined'].includes(optionalType) && !isRequired,\n name,\n type: type as ts.TypeNode,\n readOnly: schema.readOnly,\n })\n if (this.options.withJSDocs) {\n return factory.appendJSDocToNode({\n node: propertySignature,\n comments: [\n schema.description ? `@description ${schema.description}` : undefined,\n schema.type ? `@type ${schema.type}${isRequired ? '' : ' | undefined'} ${schema.format || ''}` : undefined,\n schema.example ? `@example ${schema.example as string}` : undefined,\n schema.deprecated ? `@deprecated` : undefined,\n schema.default !== undefined && typeof schema.default === 'string' ? `@default '${schema.default}'` : undefined,\n schema.default !== undefined && typeof schema.default !== 'string' ? `@default ${schema.default as string}` : undefined,\n ].filter(Boolean),\n })\n }\n\n return propertySignature\n })\n if (additionalProperties) {\n const type = additionalProperties === true ? factory.keywordTypeNodes.any : this.#getTypeFromSchema(additionalProperties as OpenAPIV3.SchemaObject)\n\n if (type) {\n members.push(factory.createIndexSignature(type))\n }\n }\n return factory.createTypeLiteralNode(members.filter(Boolean))\n }\n\n /**\n * Create a type alias for the schema referenced by the given ReferenceObject\n */\n #getRefAlias(obj: OpenAPIV3.ReferenceObject, _baseName?: string) {\n const { $ref } = obj\n let ref = this.refs[$ref]\n\n if (ref) {\n return factory.createTypeReferenceNode(ref.propertyName, undefined)\n }\n\n const originalName = getUniqueName($ref.replace(/.+\\//, ''), this.#usedAliasNames)\n const propertyName = this.options.resolveName({ name: originalName }) || originalName\n\n ref = this.refs[$ref] = {\n propertyName,\n originalName,\n }\n\n return factory.createTypeReferenceNode(ref.propertyName, undefined)\n }\n\n /**\n * This is the very core of the OpenAPI to TS conversion - it takes a\n * schema and returns the appropriate type.\n */\n #getBaseTypeFromSchema(schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined, baseName?: string): ts.TypeNode | null {\n if (!schema) {\n return factory.keywordTypeNodes.any\n }\n\n if (isReference(schema)) {\n return this.#getRefAlias(schema, baseName)\n }\n\n if (schema.oneOf) {\n // union\n const schemaWithoutOneOf = { ...schema, oneOf: undefined }\n\n const union = factory.createUnionDeclaration({\n withParentheses: true,\n nodes: schema.oneOf\n .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {\n return this.#getBaseTypeFromSchema(item)\n })\n .filter((item) => {\n return item && item !== factory.keywordTypeNodes.any\n }) as Array<ts.TypeNode>,\n })\n\n if (schemaWithoutOneOf.properties) {\n return factory.createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean),\n })\n }\n\n return union\n }\n\n if (schema.anyOf) {\n const schemaWithoutAnyOf = { ...schema, anyOf: undefined }\n\n const union = factory.createUnionDeclaration({\n withParentheses: true,\n nodes: schema.anyOf\n .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {\n return this.#getBaseTypeFromSchema(item)\n })\n .filter((item) => {\n return item && item !== factory.keywordTypeNodes.any\n }) as Array<ts.TypeNode>,\n })\n\n if (schemaWithoutAnyOf.properties) {\n return factory.createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutAnyOf, baseName), union].filter(Boolean),\n })\n }\n\n return union\n }\n if (schema.allOf) {\n // intersection/add\n const schemaWithoutAllOf = { ...schema, allOf: undefined }\n\n const and = factory.createIntersectionDeclaration({\n withParentheses: true,\n nodes: schema.allOf\n .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {\n return this.#getBaseTypeFromSchema(item)\n })\n .filter((item) => {\n return item && item !== factory.keywordTypeNodes.any\n }) as Array<ts.TypeNode>,\n })\n\n if (schemaWithoutAllOf.properties) {\n return factory.createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean),\n })\n }\n\n return and\n }\n\n /**\n * Enum will be defined outside the baseType(hints the baseName check)\n */\n if (schema.enum && baseName) {\n const enumName = getUniqueName(baseName, this.options.usedEnumNames)\n\n let enums: [key: string, value: string | number][] = [...new Set(schema.enum)].map((key) => [key, key])\n\n if ('x-enumNames' in schema) {\n enums = [...new Set(schema['x-enumNames'] as string[])].map((key: string, index) => {\n return [key, schema.enum?.[index]]\n })\n }\n\n this.extraNodes.push(\n ...factory.createEnumDeclaration({\n name: camelCase(enumName, this.#caseOptions),\n typeName: this.options.resolveName({ name: enumName }),\n enums,\n type: this.options.enumType,\n }),\n )\n return factory.createTypeReferenceNode(this.options.resolveName({ name: enumName }), undefined)\n }\n\n if (schema.enum) {\n return factory.createUnionDeclaration({\n nodes: schema.enum.map((name: string) => {\n return factory.createLiteralTypeNode(typeof name === 'number' ? factory.createNumericLiteral(name) : factory.createStringLiteral(`${name}`))\n }) as unknown as Array<ts.TypeNode>,\n })\n }\n\n if ('items' in schema) {\n // items -> array\n const node = this.#getTypeFromSchema(schema.items as OpenAPIV3.SchemaObject, baseName)\n if (node) {\n return factory.createArrayTypeNode(node)\n }\n }\n /**\n * OpenAPI 3.1\n * @link https://json-schema.org/understanding-json-schema/reference/array.html#tuple-validation\n */\n if ('prefixItems' in schema) {\n const prefixItems = schema.prefixItems as OpenAPIV3.SchemaObject[]\n\n return factory.createTupleDeclaration({\n nodes: prefixItems.map((item) => {\n // no baseType so we can fall back on an union when using enum\n return this.#getBaseTypeFromSchema(item, undefined)\n }) as Array<ts.TypeNode>,\n })\n }\n\n if (schema.properties || schema.additionalProperties) {\n // properties -> literal type\n return this.#getTypeFromProperties(schema, baseName)\n }\n\n if (schema.type) {\n if (Array.isArray(schema.type)) {\n // OPENAPI v3.1.0: https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0\n const [type, nullable] = schema.type as Array<OpenAPIV3.NonArraySchemaObjectType>\n\n return factory.createUnionDeclaration({\n nodes: [\n this.#getBaseTypeFromSchema(\n {\n ...schema,\n type,\n },\n baseName,\n ),\n nullable ? factory.createLiteralTypeNode(factory.createNull()) : undefined,\n ].filter(Boolean),\n })\n }\n\n if (this.options.dateType === 'date' && ['date', 'date-time'].some((item) => item === schema.format)) {\n return factory.createTypeReferenceNode(factory.createIdentifier('Date'))\n }\n\n // string, boolean, null, number\n if (schema.type in factory.keywordTypeNodes) {\n return factory.keywordTypeNodes[schema.type as keyof typeof factory.keywordTypeNodes]\n }\n }\n\n if (schema.format === 'binary') {\n return factory.createTypeReferenceNode('Blob', [])\n }\n\n // detect assertion \"const\" and define the type property as a Literal\n if ('const' in schema && schema['const'] !== undefined && typeof schema['const'] === 'string') {\n return factory.createLiteralTypeNode(factory.createStringLiteral(schema['const']))\n }\n\n return factory.keywordTypeNodes.any\n }\n}\n","import { getRelativePath } from '@kubb/core/utils'\nimport { print } from '@kubb/parser'\nimport * as factory from '@kubb/parser/factory'\nimport { OperationGenerator as Generator, resolve } from '@kubb/swagger'\n\nimport { pascalCase } from 'change-case'\n\nimport { TypeBuilder } from '../builders/index.ts'\n\nimport type { KubbFile } from '@kubb/core'\nimport type { FileResolver, Operation, OperationSchemas, Resolver } from '@kubb/swagger'\nimport type ts from 'typescript'\nimport type { FileMeta, PluginOptions } from '../types.ts'\n\ntype Options = {\n usedEnumNames: Record<string, number>\n\n mode: KubbFile.Mode\n enumType: NonNullable<PluginOptions['options']['enumType']>\n dateType: NonNullable<PluginOptions['options']['dateType']>\n optionalType: NonNullable<PluginOptions['options']['optionalType']>\n}\n\nexport class OperationGenerator extends Generator<Options, PluginOptions> {\n resolve(operation: Operation): Resolver {\n const { pluginManager, plugin } = this.context\n\n return resolve({\n operation,\n resolveName: pluginManager.resolveName,\n resolvePath: pluginManager.resolvePath,\n pluginKey: plugin?.key,\n })\n }\n\n async all(): Promise<KubbFile.File | null> {\n return null\n }\n\n #printCombinedSchema(name: string, operation: Operation, schemas: OperationSchemas): string {\n const properties: Record<string, ts.TypeNode> = {\n 'response': factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.response.name),\n undefined,\n ),\n }\n\n if (schemas.request) {\n properties['request'] = factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.request.name),\n undefined,\n )\n }\n\n if (schemas.pathParams) {\n properties['pathParams'] = factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.pathParams.name),\n undefined,\n )\n }\n\n if (schemas.queryParams) {\n properties['queryParams'] = factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.queryParams.name),\n undefined,\n )\n }\n\n if (schemas.headerParams) {\n properties['headerParams'] = factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.headerParams.name),\n undefined,\n )\n }\n\n if (schemas.errors) {\n properties['errors'] = factory.createUnionDeclaration({\n nodes: schemas.errors.map(error => {\n return factory.createTypeReferenceNode(\n factory.createIdentifier(error.name),\n undefined,\n )\n }),\n })!\n }\n\n const namespaceNode = factory.createNamespaceDeclaration({\n name: operation.method === 'get' ? `${name}Query` : `${name}Mutation`,\n statements: Object.keys(properties).map(key => {\n const type = properties[key]\n if (!type) {\n return undefined\n }\n return factory.createTypeAliasDeclaration({\n modifiers: [factory.modifiers.export],\n name: pascalCase(key),\n type,\n })\n }).filter(Boolean),\n })\n\n return print(namespaceNode)\n }\n\n async get(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n const { mode, enumType, dateType, optionalType, usedEnumNames } = options\n const { pluginManager, plugin } = this.context\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const root = pluginManager.resolvePath({ baseName: type.baseName, pluginKey: plugin?.key, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = pluginManager.resolvePath({\n baseName: `${name}.ts`,\n pluginKey: plugin?.key,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder({\n usedEnumNames,\n fileResolver: mode === 'file' ? undefined : fileResolver,\n withJSDocs: true,\n resolveName: (params) => pluginManager.resolveName({ ...params, pluginKey: plugin?.key }),\n enumType,\n optionalType,\n dateType,\n })\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.headerParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure()\n .print()\n\n const combinedSchemaSource = this.#printCombinedSchema(type.name, operation, schemas)\n\n return {\n path: type.path,\n baseName: type.baseName,\n source: [source, combinedSchemaSource].join('\\n'),\n meta: {\n pluginKey: plugin.key,\n tag: operation.getTags()[0]?.name,\n },\n }\n }\n\n async post(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n const { mode, enumType, dateType, optionalType, usedEnumNames } = options\n const { pluginManager, plugin } = this.context\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const root = pluginManager.resolvePath({ baseName: type.baseName, pluginKey: plugin?.key, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = pluginManager.resolvePath({\n baseName: `${name}.ts`,\n pluginKey: plugin?.key,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder({\n usedEnumNames,\n fileResolver: mode === 'file' ? undefined : fileResolver,\n withJSDocs: true,\n resolveName: (params) => pluginManager.resolveName({ ...params, pluginKey: plugin?.key }),\n enumType,\n optionalType,\n dateType,\n })\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.headerParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure()\n .print()\n\n const combinedSchemaSource = this.#printCombinedSchema(type.name, operation, schemas)\n\n return {\n path: type.path,\n baseName: type.baseName,\n source: [source, combinedSchemaSource].join('\\n'),\n meta: {\n pluginKey: plugin.key,\n tag: operation.getTags()[0]?.name,\n },\n }\n }\n\n async put(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n async patch(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n async delete(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n}\n","import { definePlugin } from './plugin.ts'\n\nexport { definePlugin, pluginKey, pluginName } from './plugin.ts'\nexport * from './types.ts'\n\nexport default definePlugin\n"]}
1
+ {"version":3,"sources":["../src/plugin.ts","../src/builders/TypeBuilder.ts","../src/generators/TypeGenerator.ts","../src/generators/OperationGenerator.ts","../src/index.ts"],"names":["getRelativePath","camelCase","pascalCase","factory","node","print","transformers","options","root"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,UAAU;AAEjB,SAAS,cAAc,aAAa,qBAAqB;AACzD,SAAS,mBAAAA,kBAA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,UAAU;AACZ,yBAAO;AAAA,oBACL,GAAG;AAAA,oBACH,MAAM;AAAA,oBACN,SAAS,CAAC,CAAC;AAAA,kBACb;AAAA,gBACF;AACA,uBAAO;AAAA,cACT,CAAC;AAAA,YACH;AAAA,UACF;AAAA,UACA;AAAA,UACA,YAAY;AAAA,QACd;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;AIjOD,IAAO,cAAQ","sourcesContent":["import path from 'node:path'\n\nimport { createPlugin, FileManager, PluginManager } from '@kubb/core'\nimport { getRelativePath, renderTemplate } from '@kubb/core/utils'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\n\nimport { camelCase, camelCaseTransformMerge, pascalCase, pascalCaseTransformMerge } from 'change-case'\n\nimport { TypeBuilder } from './builders/index.ts'\nimport { OperationGenerator } from './generators/index.ts'\n\nimport type { KubbFile, KubbPlugin } from '@kubb/core'\nimport type { OasTypes, PluginOptions as SwaggerPluginOptions } from '@kubb/swagger'\nimport type { PluginOptions } from './types.ts'\n\nexport const pluginName = 'swagger-ts' satisfies PluginOptions['name']\nexport const pluginKey: PluginOptions['key'] = ['schema', pluginName] satisfies PluginOptions['key']\n\nexport const definePlugin = createPlugin<PluginOptions>((options) => {\n const {\n output = 'types',\n group,\n exclude = [],\n include,\n override = [],\n enumType = 'asConst',\n dateType = 'string',\n optionalType = 'questionToken',\n transformers = {},\n exportAs,\n } = options\n const template = group?.output ? group.output : `${output}/{{tag}}Controller`\n let pluginsOptions: [KubbPlugin<SwaggerPluginOptions>]\n\n return {\n name: pluginName,\n options,\n kind: 'schema',\n validate(plugins) {\n pluginsOptions = PluginManager.getDependedPlugins<SwaggerPluginOptions>(plugins, [swaggerPluginName])\n\n return true\n },\n resolvePath(baseName, directory, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output))\n\n if (mode === 'file') {\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)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag, { delimiter: '', transform: camelCaseTransformMerge })\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output, baseName)\n },\n resolveName(name, type) {\n const resolvedName = pascalCase(name, { delimiter: '', stripRegexp: /[^A-Z0-9$]/gi, transform: pascalCaseTransformMerge })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async writeFile(source, writePath) {\n if (!writePath.endsWith('.ts') || !source) {\n return\n }\n\n return this.fileManager.write(source, writePath)\n },\n async buildStart() {\n const [swaggerPlugin] = pluginsOptions\n\n const oas = await swaggerPlugin.api.getOas()\n\n const schemas = await swaggerPlugin.api.getSchemas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output))\n // keep the used enumnames between TypeBuilder and OperationGenerator per plugin(pluginKey)\n const usedEnumNames = {}\n\n if (mode === 'directory') {\n const builder = await new TypeBuilder({\n usedEnumNames,\n resolveName: (params) => this.resolveName({ pluginKey: this.plugin.key, ...params }),\n fileResolver: (name) => {\n const resolvedTypeId = this.resolvePath({\n baseName: `${name}.ts`,\n pluginKey: this.plugin.key,\n })\n\n const root = this.resolvePath({ baseName: ``, pluginKey: this.plugin.key })\n\n return getRelativePath(root, resolvedTypeId)\n },\n withJSDocs: true,\n enumType,\n dateType,\n optionalType,\n oas,\n }).configure()\n Object.entries(schemas).forEach(([name, schema]: [string, OasTypes.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const mapFolderSchema = async ([name]: [string, OasTypes.SchemaObject]) => {\n const resolvedPath = this.resolvePath({ baseName: `${this.resolveName({ name, pluginKey: this.plugin.key })}.ts`, pluginKey: this.plugin.key })\n\n if (!resolvedPath) {\n return null\n }\n\n return this.addFile({\n path: resolvedPath,\n baseName: `${this.resolveName({ name, pluginKey: this.plugin.key })}.ts`,\n source: builder.print(name),\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n }\n\n const promises = Object.entries(schemas).map(mapFolderSchema)\n\n await Promise.all(promises)\n }\n\n if (mode === 'file') {\n // outside the loop because we need to add files to just one instance to have the correct sorting, see refsSorter\n const builder = new TypeBuilder({\n usedEnumNames,\n resolveName: (params) => this.resolveName({ pluginKey: this.plugin.key, ...params }),\n withJSDocs: true,\n enumType,\n dateType,\n optionalType,\n oas,\n }).configure()\n Object.entries(schemas).forEach(([name, schema]: [string, OasTypes.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const resolvedPath = this.resolvePath({ baseName: '', pluginKey: this.plugin.key })\n if (!resolvedPath) {\n return\n }\n\n await this.addFile({\n path: resolvedPath,\n baseName: output as KubbFile.BaseName,\n source: builder.print(),\n meta: {\n pluginKey: this.plugin.key,\n },\n validate: false,\n })\n }\n\n const operationGenerator = new OperationGenerator(\n {\n mode,\n enumType,\n dateType,\n optionalType,\n usedEnumNames,\n },\n {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.api.contentType,\n exclude,\n include,\n override,\n },\n )\n\n const files = await operationGenerator.build()\n await this.addFile(...files)\n },\n async buildEnd() {\n if (this.config.output.write === false) {\n return\n }\n\n const root = path.resolve(this.config.root, this.config.output.path)\n\n await this.fileManager.addIndexes({\n root,\n extName: '.ts',\n meta: { pluginKey: this.plugin.key },\n options: {\n map: (file) => {\n return {\n ...file,\n exports: file.exports?.map((item) => {\n if (exportAs) {\n return {\n ...item,\n name: exportAs,\n asAlias: !!exportAs,\n }\n }\n return item\n }),\n }\n },\n output,\n isTypeOnly: true,\n },\n })\n },\n }\n})\n","/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { transformers } from '@kubb/core/utils'\nimport { print } from '@kubb/parser'\nimport * as factory from '@kubb/parser/factory'\nimport { ImportsGenerator, OasBuilder } from '@kubb/swagger'\nimport { refsSorter } from '@kubb/swagger/utils'\n\nimport { TypeGenerator } from '../generators/TypeGenerator.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { FileResolver, Oas } from '@kubb/swagger'\n\ntype Options = {\n oas: Oas\n usedEnumNames: Record<string, number>\n resolveName: PluginContext['resolveName']\n fileResolver?: FileResolver\n withJSDocs?: boolean\n withImports?: boolean\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n dateType: 'string' | 'date'\n optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'\n}\n\nexport class TypeBuilder extends OasBuilder<Options, never> {\n configure(options?: Options) {\n if (options) {\n this.options = options\n }\n\n if (this.options.fileResolver) {\n this.options.withImports = true\n }\n\n return this\n }\n\n print(name?: string): string {\n const codes: string[] = []\n\n const generated = this.items\n .filter((operationSchema) => (name ? operationSchema.name === name : true))\n .sort(transformers.nameSorter)\n .map((operationSchema) => {\n const generator = new TypeGenerator({\n usedEnumNames: this.options.usedEnumNames,\n withJSDocs: this.options.withJSDocs,\n resolveName: this.options.resolveName,\n enumType: this.options.enumType,\n dateType: this.options.dateType,\n optionalType: this.options.optionalType,\n oas: this.options.oas,\n })\n const sources = generator.build({\n schema: operationSchema.schema,\n baseName: operationSchema.name,\n description: operationSchema.description,\n keysToOmit: operationSchema.keysToOmit,\n })\n\n return {\n import: {\n refs: generator.refs,\n name: operationSchema.name,\n },\n sources,\n }\n })\n .sort(refsSorter)\n\n generated.forEach((item) => {\n codes.push(print(item.sources))\n })\n\n if (this.options.withImports) {\n const importsGenerator = new ImportsGenerator({ fileResolver: this.options.fileResolver })\n const importMeta = importsGenerator.build(generated.map((item) => item.import))\n\n if (importMeta) {\n const nodes = importMeta.map((item) => {\n return factory.createImportDeclaration({\n name: [{ propertyName: item.ref.propertyName }],\n path: item.path,\n isTypeOnly: true,\n })\n })\n\n codes.unshift(print(nodes))\n }\n }\n\n return transformers.combineCodes(codes)\n }\n}\n","import { SchemaGenerator } from '@kubb/core'\nimport { getUniqueName } from '@kubb/core/utils'\nimport * as factory from '@kubb/parser/factory'\nimport { getSchemaFactory, isReference } from '@kubb/swagger/utils'\n\nimport { camelCase } from 'change-case'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { ts } from '@kubb/parser'\nimport type { Oas, OasTypes, OpenAPIV3, OpenAPIV3_1, Refs } from '@kubb/swagger'\nimport type { Options as CaseOptions } from 'change-case'\n\n// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n\ntype Options = {\n oas: Oas\n usedEnumNames: Record<string, number>\n\n withJSDocs?: boolean\n resolveName: PluginContext['resolveName']\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n dateType: 'string' | 'date'\n optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'\n}\n\nexport class TypeGenerator extends SchemaGenerator<Options, OasTypes.SchemaObject, ts.Node[]> {\n refs: Refs = {}\n\n extraNodes: ts.Node[] = []\n\n aliases: ts.TypeAliasDeclaration[] = []\n\n // Keep track of already used type aliases\n #usedAliasNames: Record<string, number> = {}\n\n #caseOptions: CaseOptions = {\n delimiter: '',\n stripRegexp: /[^A-Z0-9$]/gi,\n }\n\n constructor(\n options: Options,\n ) {\n super(options)\n\n return this\n }\n\n build({\n schema,\n baseName,\n description,\n keysToOmit,\n }: {\n schema: OasTypes.SchemaObject\n baseName: string\n description?: string\n keysToOmit?: string[]\n }): ts.Node[] {\n const nodes: ts.Node[] = []\n const type = this.#getTypeFromSchema(schema, baseName)\n\n if (!type) {\n return this.extraNodes\n }\n\n const node = factory.createTypeAliasDeclaration({\n modifiers: [factory.modifiers.export],\n name: this.options.resolveName({ name: baseName }) || baseName,\n type: keysToOmit?.length ? factory.createOmitDeclaration({ keys: keysToOmit, type, nonNullable: true }) : type,\n })\n\n if (description) {\n nodes.push(\n factory.appendJSDocToNode({\n node,\n comments: [`@description ${description}`],\n }),\n )\n } else {\n nodes.push(node)\n }\n\n // filter out if the export name is the same as one that we already defined in extraNodes(see enum)\n const filterdNodes = nodes.filter(\n (node: ts.Node) =>\n !this.extraNodes.some(\n (extraNode: ts.Node) => (extraNode as ts.TypeAliasDeclaration)?.name?.escapedText === (node as ts.TypeAliasDeclaration)?.name?.escapedText,\n ),\n )\n\n return [...this.extraNodes, ...filterdNodes]\n }\n\n /**\n * Creates a type node from a given schema.\n * Delegates to getBaseTypeFromSchema internally and\n * optionally adds a union with null.\n */\n #getTypeFromSchema(schema?: OasTypes.SchemaObject, name?: string): ts.TypeNode | null {\n const type = this.#getBaseTypeFromSchema(schema, name)\n\n if (!type) {\n return null\n }\n\n if (schema && !schema.nullable) {\n return type\n }\n\n return factory.createUnionDeclaration({ nodes: [type, factory.keywordTypeNodes.null] })\n }\n\n /**\n * Recursively creates a type literal with the given props.\n */\n #getTypeFromProperties(baseSchema?: OasTypes.SchemaObject, baseName?: string) {\n const { optionalType } = this.options\n const properties = baseSchema?.properties || {}\n const required = baseSchema?.required\n const additionalProperties = baseSchema?.additionalProperties\n\n const members: Array<ts.TypeElement | null> = Object.keys(properties).map((name) => {\n const schema = properties[name] as OasTypes.SchemaObject\n\n const isRequired = Array.isArray(required) ? required.includes(name) : !!required\n let type = this.#getTypeFromSchema(schema, this.options.resolveName({ name: `${baseName || ''} ${name}` }))\n\n if (!type) {\n return null\n }\n\n if (!isRequired && ['undefined', 'questionTokenAndUndefined'].includes(optionalType)) {\n type = factory.createUnionDeclaration({ nodes: [type, factory.keywordTypeNodes.undefined] })\n }\n const propertySignature = factory.createPropertySignature({\n questionToken: ['questionToken', 'questionTokenAndUndefined'].includes(optionalType) && !isRequired,\n name,\n type: type as ts.TypeNode,\n readOnly: schema.readOnly,\n })\n if (this.options.withJSDocs) {\n return factory.appendJSDocToNode({\n node: propertySignature,\n comments: [\n schema.description ? `@description ${schema.description}` : undefined,\n schema.type ? `@type ${schema.type?.toString()}${isRequired ? '' : ' | undefined'} ${schema.format || ''}` : undefined,\n schema.example ? `@example ${schema.example as string}` : undefined,\n schema.deprecated ? `@deprecated` : undefined,\n schema.default !== undefined && typeof schema.default === 'string' ? `@default '${schema.default}'` : undefined,\n schema.default !== undefined && typeof schema.default !== 'string' ? `@default ${schema.default as string}` : undefined,\n ].filter(Boolean),\n })\n }\n\n return propertySignature\n })\n if (additionalProperties) {\n const type = additionalProperties === true ? factory.keywordTypeNodes.any : this.#getTypeFromSchema(additionalProperties as OasTypes.SchemaObject)\n\n if (type) {\n members.push(factory.createIndexSignature(type))\n }\n }\n return factory.createTypeLiteralNode(members.filter(Boolean))\n }\n\n /**\n * Create a type alias for the schema referenced by the given ReferenceObject\n */\n #getRefAlias(obj: OpenAPIV3.ReferenceObject, _baseName?: string) {\n const { $ref } = obj\n let ref = this.refs[$ref]\n\n if (ref) {\n return factory.createTypeReferenceNode(ref.propertyName, undefined)\n }\n\n const originalName = getUniqueName($ref.replace(/.+\\//, ''), this.#usedAliasNames)\n const propertyName = this.options.resolveName({ name: originalName }) || originalName\n\n ref = this.refs[$ref] = {\n propertyName,\n originalName,\n }\n\n return factory.createTypeReferenceNode(ref.propertyName, undefined)\n }\n\n #getParsedSchema(schema?: OasTypes.SchemaObject) {\n const parsedSchema = getSchemaFactory(this.options.oas)(schema)\n return parsedSchema\n }\n\n /**\n * This is the very core of the OpenAPI to TS conversion - it takes a\n * schema and returns the appropriate type.\n */\n #getBaseTypeFromSchema(\n _schema: OasTypes.SchemaObject | undefined,\n baseName?: string,\n ): ts.TypeNode | null {\n const { schema, version } = this.#getParsedSchema(_schema)\n\n if (!schema) {\n return factory.keywordTypeNodes.any\n }\n\n if (isReference(schema)) {\n return this.#getRefAlias(schema, baseName)\n }\n\n if (schema.oneOf) {\n // union\n const schemaWithoutOneOf = { ...schema, oneOf: undefined } as OasTypes.SchemaObject\n\n const union = factory.createUnionDeclaration({\n withParentheses: true,\n nodes: schema.oneOf\n .map((item) => {\n return item && this.#getBaseTypeFromSchema(item as OasTypes.SchemaObject)\n })\n .filter((item) => {\n return item && item !== factory.keywordTypeNodes.any\n }) as Array<ts.TypeNode>,\n })\n\n if (schemaWithoutOneOf.properties) {\n return factory.createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean),\n })\n }\n\n return union\n }\n\n if (schema.anyOf) {\n const schemaWithoutAnyOf = { ...schema, anyOf: undefined } as OasTypes.SchemaObject\n\n const union = factory.createUnionDeclaration({\n withParentheses: true,\n nodes: schema.anyOf\n .map((item) => {\n return item && this.#getBaseTypeFromSchema(item as OasTypes.SchemaObject)\n })\n .filter((item) => {\n return item && item !== factory.keywordTypeNodes.any\n }) as Array<ts.TypeNode>,\n })\n\n if (schemaWithoutAnyOf.properties) {\n return factory.createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutAnyOf, baseName), union].filter(Boolean),\n })\n }\n\n return union\n }\n if (schema.allOf) {\n // intersection/add\n const schemaWithoutAllOf = { ...schema, allOf: undefined } as OasTypes.SchemaObject\n\n const and = factory.createIntersectionDeclaration({\n withParentheses: true,\n nodes: schema.allOf\n .map((item) => {\n return item && this.#getBaseTypeFromSchema(item as OasTypes.SchemaObject)\n })\n .filter((item) => {\n return item && item !== factory.keywordTypeNodes.any\n }) as Array<ts.TypeNode>,\n })\n\n if (schemaWithoutAllOf.properties) {\n return factory.createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean),\n })\n }\n\n return and\n }\n\n /**\n * Enum will be defined outside the baseType(hints the baseName check)\n */\n if (schema.enum && baseName) {\n const enumName = getUniqueName(baseName, this.options.usedEnumNames)\n\n let enums: [key: string, value: string | number][] = [...new Set(schema.enum)].map((key) => [key, key])\n\n if ('x-enumNames' in schema) {\n enums = [...new Set(schema['x-enumNames'] as string[])].map((key: string, index) => {\n return [key, schema.enum?.[index] as string]\n })\n }\n\n this.extraNodes.push(\n ...factory.createEnumDeclaration({\n name: camelCase(enumName, this.#caseOptions),\n typeName: this.options.resolveName({ name: enumName }),\n enums,\n type: this.options.enumType,\n }),\n )\n return factory.createTypeReferenceNode(this.options.resolveName({ name: enumName }), undefined)\n }\n\n if (schema.enum) {\n return factory.createUnionDeclaration({\n nodes: schema.enum.map((name) => {\n return factory.createLiteralTypeNode(typeof name === 'number' ? factory.createNumericLiteral(name) : factory.createStringLiteral(`${name}`))\n }) as unknown as Array<ts.TypeNode>,\n })\n }\n\n if ('items' in schema) {\n // items -> array\n const node = this.#getTypeFromSchema(schema.items as OasTypes.SchemaObject, baseName)\n if (node) {\n return factory.createArrayTypeNode(node)\n }\n }\n\n /**\n * OpenAPI 3.1\n * @link https://json-schema.org/understanding-json-schema/reference/array.html#tuple-validation\n */\n\n if ('prefixItems' in schema) {\n const prefixItems = schema.prefixItems as OasTypes.SchemaObject[]\n\n return factory.createTupleDeclaration({\n nodes: prefixItems.map((item) => {\n // no baseType so we can fall back on an union when using enum\n return this.#getBaseTypeFromSchema(item, undefined)\n }) as Array<ts.TypeNode>,\n })\n }\n\n if (schema.properties || schema.additionalProperties) {\n // properties -> literal type\n return this.#getTypeFromProperties(schema, baseName)\n }\n\n if (schema.type) {\n if (Array.isArray(schema.type)) {\n // OPENAPI v3.1.0: https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0\n const [type, nullable] = schema.type as Array<OpenAPIV3_1.NonArraySchemaObjectType>\n\n return factory.createUnionDeclaration({\n nodes: [\n this.#getBaseTypeFromSchema(\n {\n ...schema,\n type,\n },\n baseName,\n ),\n nullable ? factory.createLiteralTypeNode(factory.createNull()) : undefined,\n ].filter(Boolean),\n })\n }\n\n if (this.options.dateType === 'date' && ['date', 'date-time'].some((item) => item === schema.format)) {\n return factory.createTypeReferenceNode(factory.createIdentifier('Date'))\n }\n\n // string, boolean, null, number\n if (schema.type in factory.keywordTypeNodes) {\n return factory.keywordTypeNodes[schema.type as keyof typeof factory.keywordTypeNodes]\n }\n }\n\n if (schema.format === 'binary') {\n return factory.createTypeReferenceNode('Blob', [])\n }\n\n // detect assertion \"const\" and define the type property as a Literal\n if (version === '3.1' && typeof schema['const'] === 'string') {\n return factory.createLiteralTypeNode(factory.createStringLiteral(schema['const']))\n }\n\n return factory.keywordTypeNodes.any\n }\n}\n","import { getRelativePath } from '@kubb/core/utils'\nimport { print } from '@kubb/parser'\nimport * as factory from '@kubb/parser/factory'\nimport { OperationGenerator as Generator, resolve } from '@kubb/swagger'\n\nimport { pascalCase } from 'change-case'\n\nimport { TypeBuilder } from '../builders/index.ts'\n\nimport type { KubbFile } from '@kubb/core'\nimport type { FileResolver, Operation, OperationSchemas, Resolver } from '@kubb/swagger'\nimport type ts from 'typescript'\nimport type { FileMeta, PluginOptions } from '../types.ts'\n\ntype Options = {\n usedEnumNames: Record<string, number>\n\n mode: KubbFile.Mode\n enumType: NonNullable<PluginOptions['options']['enumType']>\n dateType: NonNullable<PluginOptions['options']['dateType']>\n optionalType: NonNullable<PluginOptions['options']['optionalType']>\n}\n\nexport class OperationGenerator extends Generator<Options, PluginOptions> {\n resolve(operation: Operation): Resolver {\n const { pluginManager, plugin } = this.context\n\n return resolve({\n operation,\n resolveName: pluginManager.resolveName,\n resolvePath: pluginManager.resolvePath,\n pluginKey: plugin?.key,\n })\n }\n\n async all(): Promise<KubbFile.File | null> {\n return null\n }\n\n #printCombinedSchema(name: string, operation: Operation, schemas: OperationSchemas): string {\n const properties: Record<string, ts.TypeNode> = {\n 'response': factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.response.name),\n undefined,\n ),\n }\n\n if (schemas.request) {\n properties['request'] = factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.request.name),\n undefined,\n )\n }\n\n if (schemas.pathParams) {\n properties['pathParams'] = factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.pathParams.name),\n undefined,\n )\n }\n\n if (schemas.queryParams) {\n properties['queryParams'] = factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.queryParams.name),\n undefined,\n )\n }\n\n if (schemas.headerParams) {\n properties['headerParams'] = factory.createTypeReferenceNode(\n factory.createIdentifier(schemas.headerParams.name),\n undefined,\n )\n }\n\n if (schemas.errors) {\n properties['errors'] = factory.createUnionDeclaration({\n nodes: schemas.errors.map(error => {\n return factory.createTypeReferenceNode(\n factory.createIdentifier(error.name),\n undefined,\n )\n }),\n })!\n }\n\n const namespaceNode = factory.createNamespaceDeclaration({\n name: operation.method === 'get' ? `${name}Query` : `${name}Mutation`,\n statements: Object.keys(properties).map(key => {\n const type = properties[key]\n if (!type) {\n return undefined\n }\n return factory.createTypeAliasDeclaration({\n modifiers: [factory.modifiers.export],\n name: pascalCase(key),\n type,\n })\n }).filter(Boolean),\n })\n\n return print(namespaceNode)\n }\n\n async get(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n const { mode, enumType, dateType, optionalType, usedEnumNames } = options\n const { pluginManager, plugin, oas } = this.context\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const root = pluginManager.resolvePath({ baseName: type.baseName, pluginKey: plugin?.key, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = pluginManager.resolvePath({\n baseName: `${name}.ts`,\n pluginKey: plugin?.key,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder({\n usedEnumNames,\n fileResolver: mode === 'file' ? undefined : fileResolver,\n withJSDocs: true,\n resolveName: (params) => pluginManager.resolveName({ ...params, pluginKey: plugin?.key }),\n enumType,\n optionalType,\n dateType,\n oas,\n })\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.headerParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure()\n .print()\n\n const combinedSchemaSource = this.#printCombinedSchema(type.name, operation, schemas)\n\n return {\n path: type.path,\n baseName: type.baseName,\n source: [source, combinedSchemaSource].join('\\n'),\n meta: {\n pluginKey: plugin.key,\n tag: operation.getTags()[0]?.name,\n },\n }\n }\n\n async post(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n const { mode, enumType, dateType, optionalType, usedEnumNames } = options\n const { pluginManager, plugin, oas } = this.context\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const root = pluginManager.resolvePath({ baseName: type.baseName, pluginKey: plugin?.key, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = pluginManager.resolvePath({\n baseName: `${name}.ts`,\n pluginKey: plugin?.key,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder({\n usedEnumNames,\n fileResolver: mode === 'file' ? undefined : fileResolver,\n withJSDocs: true,\n resolveName: (params) => pluginManager.resolveName({ ...params, pluginKey: plugin?.key }),\n enumType,\n optionalType,\n dateType,\n oas,\n })\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.headerParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure()\n .print()\n\n const combinedSchemaSource = this.#printCombinedSchema(type.name, operation, schemas)\n\n return {\n path: type.path,\n baseName: type.baseName,\n source: [source, combinedSchemaSource].join('\\n'),\n meta: {\n pluginKey: plugin.key,\n tag: operation.getTags()[0]?.name,\n },\n }\n }\n\n async put(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n async patch(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n async delete(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n}\n","import { definePlugin } from './plugin.ts'\n\nexport { definePlugin, pluginKey, pluginName } from './plugin.ts'\nexport * from './types.ts'\n\nexport default definePlugin\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/swagger-ts",
3
- "version": "2.0.0-alpha.11",
3
+ "version": "2.0.0-alpha.12",
4
4
  "description": "Generator swagger-ts",
5
5
  "keywords": [
6
6
  "typescript",
@@ -40,16 +40,16 @@
40
40
  "dependencies": {
41
41
  "change-case": "^4.1.2",
42
42
  "typescript": "^5.3.2",
43
- "@kubb/core": "2.0.0-alpha.11",
44
- "@kubb/parser": "2.0.0-alpha.11",
45
- "@kubb/swagger": "2.0.0-alpha.11"
43
+ "@kubb/core": "2.0.0-alpha.12",
44
+ "@kubb/parser": "2.0.0-alpha.12",
45
+ "@kubb/swagger": "2.0.0-alpha.12"
46
46
  },
47
47
  "devDependencies": {
48
48
  "eslint": "^8.54.0",
49
49
  "tsup": "^8.0.1",
50
+ "@kubb/eslint-config": "1.1.8",
50
51
  "@kubb/ts-config": "0.1.0",
51
- "@kubb/tsup-config": "1.1.8",
52
- "@kubb/eslint-config": "1.1.8"
52
+ "@kubb/tsup-config": "1.1.8"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "typescript": "^5.3.0"
@@ -8,11 +8,11 @@ import { refsSorter } from '@kubb/swagger/utils'
8
8
  import { TypeGenerator } from '../generators/TypeGenerator.ts'
9
9
 
10
10
  import type { PluginContext } from '@kubb/core'
11
- import type { FileResolver } from '@kubb/swagger'
11
+ import type { FileResolver, Oas } from '@kubb/swagger'
12
12
 
13
13
  type Options = {
14
+ oas: Oas
14
15
  usedEnumNames: Record<string, number>
15
-
16
16
  resolveName: PluginContext['resolveName']
17
17
  fileResolver?: FileResolver
18
18
  withJSDocs?: boolean
@@ -49,6 +49,7 @@ export class TypeBuilder extends OasBuilder<Options, never> {
49
49
  enumType: this.options.enumType,
50
50
  dateType: this.options.dateType,
51
51
  optionalType: this.options.optionalType,
52
+ oas: this.options.oas,
52
53
  })
53
54
  const sources = generator.build({
54
55
  schema: operationSchema.schema,
@@ -104,7 +104,7 @@ export class OperationGenerator extends Generator<Options, PluginOptions> {
104
104
 
105
105
  async get(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {
106
106
  const { mode, enumType, dateType, optionalType, usedEnumNames } = options
107
- const { pluginManager, plugin } = this.context
107
+ const { pluginManager, plugin, oas } = this.context
108
108
 
109
109
  const type = this.resolve(operation)
110
110
 
@@ -128,6 +128,7 @@ export class OperationGenerator extends Generator<Options, PluginOptions> {
128
128
  enumType,
129
129
  optionalType,
130
130
  dateType,
131
+ oas,
131
132
  })
132
133
  .add(schemas.pathParams)
133
134
  .add(schemas.queryParams)
@@ -152,7 +153,7 @@ export class OperationGenerator extends Generator<Options, PluginOptions> {
152
153
 
153
154
  async post(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {
154
155
  const { mode, enumType, dateType, optionalType, usedEnumNames } = options
155
- const { pluginManager, plugin } = this.context
156
+ const { pluginManager, plugin, oas } = this.context
156
157
 
157
158
  const type = this.resolve(operation)
158
159
 
@@ -176,6 +177,7 @@ export class OperationGenerator extends Generator<Options, PluginOptions> {
176
177
  enumType,
177
178
  optionalType,
178
179
  dateType,
180
+ oas,
179
181
  })
180
182
  .add(schemas.pathParams)
181
183
  .add(schemas.queryParams)
@@ -1,18 +1,19 @@
1
1
  import { SchemaGenerator } from '@kubb/core'
2
2
  import { getUniqueName } from '@kubb/core/utils'
3
3
  import * as factory from '@kubb/parser/factory'
4
- import { isReference } from '@kubb/swagger/utils'
4
+ import { getSchemaFactory, isReference } from '@kubb/swagger/utils'
5
5
 
6
6
  import { camelCase } from 'change-case'
7
7
 
8
8
  import type { PluginContext } from '@kubb/core'
9
9
  import type { ts } from '@kubb/parser'
10
- import type { OpenAPIV3, Refs } from '@kubb/swagger'
10
+ import type { Oas, OasTypes, OpenAPIV3, OpenAPIV3_1, Refs } from '@kubb/swagger'
11
11
  import type { Options as CaseOptions } from 'change-case'
12
12
 
13
13
  // based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398
14
14
 
15
15
  type Options = {
16
+ oas: Oas
16
17
  usedEnumNames: Record<string, number>
17
18
 
18
19
  withJSDocs?: boolean
@@ -21,7 +22,8 @@ type Options = {
21
22
  dateType: 'string' | 'date'
22
23
  optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'
23
24
  }
24
- export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObject, ts.Node[]> {
25
+
26
+ export class TypeGenerator extends SchemaGenerator<Options, OasTypes.SchemaObject, ts.Node[]> {
25
27
  refs: Refs = {}
26
28
 
27
29
  extraNodes: ts.Node[] = []
@@ -37,14 +39,7 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
37
39
  }
38
40
 
39
41
  constructor(
40
- options: Options = {
41
- usedEnumNames: {},
42
- withJSDocs: true,
43
- resolveName: ({ name }) => name,
44
- enumType: 'asConst',
45
- dateType: 'string',
46
- optionalType: 'questionToken',
47
- },
42
+ options: Options,
48
43
  ) {
49
44
  super(options)
50
45
 
@@ -57,7 +52,7 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
57
52
  description,
58
53
  keysToOmit,
59
54
  }: {
60
- schema: OpenAPIV3.SchemaObject
55
+ schema: OasTypes.SchemaObject
61
56
  baseName: string
62
57
  description?: string
63
58
  keysToOmit?: string[]
@@ -102,7 +97,7 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
102
97
  * Delegates to getBaseTypeFromSchema internally and
103
98
  * optionally adds a union with null.
104
99
  */
105
- #getTypeFromSchema(schema?: OpenAPIV3.SchemaObject, name?: string): ts.TypeNode | null {
100
+ #getTypeFromSchema(schema?: OasTypes.SchemaObject, name?: string): ts.TypeNode | null {
106
101
  const type = this.#getBaseTypeFromSchema(schema, name)
107
102
 
108
103
  if (!type) {
@@ -119,16 +114,16 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
119
114
  /**
120
115
  * Recursively creates a type literal with the given props.
121
116
  */
122
- #getTypeFromProperties(baseSchema?: OpenAPIV3.SchemaObject, baseName?: string) {
117
+ #getTypeFromProperties(baseSchema?: OasTypes.SchemaObject, baseName?: string) {
123
118
  const { optionalType } = this.options
124
119
  const properties = baseSchema?.properties || {}
125
120
  const required = baseSchema?.required
126
121
  const additionalProperties = baseSchema?.additionalProperties
127
122
 
128
123
  const members: Array<ts.TypeElement | null> = Object.keys(properties).map((name) => {
129
- const schema = properties[name] as OpenAPIV3.SchemaObject
124
+ const schema = properties[name] as OasTypes.SchemaObject
130
125
 
131
- const isRequired = required && required.includes(name)
126
+ const isRequired = Array.isArray(required) ? required.includes(name) : !!required
132
127
  let type = this.#getTypeFromSchema(schema, this.options.resolveName({ name: `${baseName || ''} ${name}` }))
133
128
 
134
129
  if (!type) {
@@ -149,7 +144,7 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
149
144
  node: propertySignature,
150
145
  comments: [
151
146
  schema.description ? `@description ${schema.description}` : undefined,
152
- schema.type ? `@type ${schema.type}${isRequired ? '' : ' | undefined'} ${schema.format || ''}` : undefined,
147
+ schema.type ? `@type ${schema.type?.toString()}${isRequired ? '' : ' | undefined'} ${schema.format || ''}` : undefined,
153
148
  schema.example ? `@example ${schema.example as string}` : undefined,
154
149
  schema.deprecated ? `@deprecated` : undefined,
155
150
  schema.default !== undefined && typeof schema.default === 'string' ? `@default '${schema.default}'` : undefined,
@@ -161,7 +156,7 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
161
156
  return propertySignature
162
157
  })
163
158
  if (additionalProperties) {
164
- const type = additionalProperties === true ? factory.keywordTypeNodes.any : this.#getTypeFromSchema(additionalProperties as OpenAPIV3.SchemaObject)
159
+ const type = additionalProperties === true ? factory.keywordTypeNodes.any : this.#getTypeFromSchema(additionalProperties as OasTypes.SchemaObject)
165
160
 
166
161
  if (type) {
167
162
  members.push(factory.createIndexSignature(type))
@@ -192,11 +187,21 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
192
187
  return factory.createTypeReferenceNode(ref.propertyName, undefined)
193
188
  }
194
189
 
190
+ #getParsedSchema(schema?: OasTypes.SchemaObject) {
191
+ const parsedSchema = getSchemaFactory(this.options.oas)(schema)
192
+ return parsedSchema
193
+ }
194
+
195
195
  /**
196
196
  * This is the very core of the OpenAPI to TS conversion - it takes a
197
197
  * schema and returns the appropriate type.
198
198
  */
199
- #getBaseTypeFromSchema(schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined, baseName?: string): ts.TypeNode | null {
199
+ #getBaseTypeFromSchema(
200
+ _schema: OasTypes.SchemaObject | undefined,
201
+ baseName?: string,
202
+ ): ts.TypeNode | null {
203
+ const { schema, version } = this.#getParsedSchema(_schema)
204
+
200
205
  if (!schema) {
201
206
  return factory.keywordTypeNodes.any
202
207
  }
@@ -207,13 +212,13 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
207
212
 
208
213
  if (schema.oneOf) {
209
214
  // union
210
- const schemaWithoutOneOf = { ...schema, oneOf: undefined }
215
+ const schemaWithoutOneOf = { ...schema, oneOf: undefined } as OasTypes.SchemaObject
211
216
 
212
217
  const union = factory.createUnionDeclaration({
213
218
  withParentheses: true,
214
219
  nodes: schema.oneOf
215
- .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {
216
- return this.#getBaseTypeFromSchema(item)
220
+ .map((item) => {
221
+ return item && this.#getBaseTypeFromSchema(item as OasTypes.SchemaObject)
217
222
  })
218
223
  .filter((item) => {
219
224
  return item && item !== factory.keywordTypeNodes.any
@@ -230,13 +235,13 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
230
235
  }
231
236
 
232
237
  if (schema.anyOf) {
233
- const schemaWithoutAnyOf = { ...schema, anyOf: undefined }
238
+ const schemaWithoutAnyOf = { ...schema, anyOf: undefined } as OasTypes.SchemaObject
234
239
 
235
240
  const union = factory.createUnionDeclaration({
236
241
  withParentheses: true,
237
242
  nodes: schema.anyOf
238
- .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {
239
- return this.#getBaseTypeFromSchema(item)
243
+ .map((item) => {
244
+ return item && this.#getBaseTypeFromSchema(item as OasTypes.SchemaObject)
240
245
  })
241
246
  .filter((item) => {
242
247
  return item && item !== factory.keywordTypeNodes.any
@@ -253,13 +258,13 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
253
258
  }
254
259
  if (schema.allOf) {
255
260
  // intersection/add
256
- const schemaWithoutAllOf = { ...schema, allOf: undefined }
261
+ const schemaWithoutAllOf = { ...schema, allOf: undefined } as OasTypes.SchemaObject
257
262
 
258
263
  const and = factory.createIntersectionDeclaration({
259
264
  withParentheses: true,
260
265
  nodes: schema.allOf
261
- .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {
262
- return this.#getBaseTypeFromSchema(item)
266
+ .map((item) => {
267
+ return item && this.#getBaseTypeFromSchema(item as OasTypes.SchemaObject)
263
268
  })
264
269
  .filter((item) => {
265
270
  return item && item !== factory.keywordTypeNodes.any
@@ -285,7 +290,7 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
285
290
 
286
291
  if ('x-enumNames' in schema) {
287
292
  enums = [...new Set(schema['x-enumNames'] as string[])].map((key: string, index) => {
288
- return [key, schema.enum?.[index]]
293
+ return [key, schema.enum?.[index] as string]
289
294
  })
290
295
  }
291
296
 
@@ -302,7 +307,7 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
302
307
 
303
308
  if (schema.enum) {
304
309
  return factory.createUnionDeclaration({
305
- nodes: schema.enum.map((name: string) => {
310
+ nodes: schema.enum.map((name) => {
306
311
  return factory.createLiteralTypeNode(typeof name === 'number' ? factory.createNumericLiteral(name) : factory.createStringLiteral(`${name}`))
307
312
  }) as unknown as Array<ts.TypeNode>,
308
313
  })
@@ -310,17 +315,19 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
310
315
 
311
316
  if ('items' in schema) {
312
317
  // items -> array
313
- const node = this.#getTypeFromSchema(schema.items as OpenAPIV3.SchemaObject, baseName)
318
+ const node = this.#getTypeFromSchema(schema.items as OasTypes.SchemaObject, baseName)
314
319
  if (node) {
315
320
  return factory.createArrayTypeNode(node)
316
321
  }
317
322
  }
323
+
318
324
  /**
319
325
  * OpenAPI 3.1
320
326
  * @link https://json-schema.org/understanding-json-schema/reference/array.html#tuple-validation
321
327
  */
328
+
322
329
  if ('prefixItems' in schema) {
323
- const prefixItems = schema.prefixItems as OpenAPIV3.SchemaObject[]
330
+ const prefixItems = schema.prefixItems as OasTypes.SchemaObject[]
324
331
 
325
332
  return factory.createTupleDeclaration({
326
333
  nodes: prefixItems.map((item) => {
@@ -338,7 +345,7 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
338
345
  if (schema.type) {
339
346
  if (Array.isArray(schema.type)) {
340
347
  // OPENAPI v3.1.0: https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0
341
- const [type, nullable] = schema.type as Array<OpenAPIV3.NonArraySchemaObjectType>
348
+ const [type, nullable] = schema.type as Array<OpenAPIV3_1.NonArraySchemaObjectType>
342
349
 
343
350
  return factory.createUnionDeclaration({
344
351
  nodes: [
@@ -369,7 +376,7 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
369
376
  }
370
377
 
371
378
  // detect assertion "const" and define the type property as a Literal
372
- if ('const' in schema && schema['const'] !== undefined && typeof schema['const'] === 'string') {
379
+ if (version === '3.1' && typeof schema['const'] === 'string') {
373
380
  return factory.createLiteralTypeNode(factory.createStringLiteral(schema['const']))
374
381
  }
375
382
 
package/src/plugin.ts CHANGED
@@ -10,7 +10,7 @@ import { TypeBuilder } from './builders/index.ts'
10
10
  import { OperationGenerator } from './generators/index.ts'
11
11
 
12
12
  import type { KubbFile, KubbPlugin } from '@kubb/core'
13
- import type { OpenAPIV3, PluginOptions as SwaggerPluginOptions } from '@kubb/swagger'
13
+ import type { OasTypes, PluginOptions as SwaggerPluginOptions } from '@kubb/swagger'
14
14
  import type { PluginOptions } from './types.ts'
15
15
 
16
16
  export const pluginName = 'swagger-ts' satisfies PluginOptions['name']
@@ -106,8 +106,9 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {
106
106
  enumType,
107
107
  dateType,
108
108
  optionalType,
109
+ oas,
109
110
  }).configure()
110
- Object.entries(schemas).forEach(([name, schema]: [string, OpenAPIV3.SchemaObject]) => {
111
+ Object.entries(schemas).forEach(([name, schema]: [string, OasTypes.SchemaObject]) => {
111
112
  // generate and pass through new code back to the core so it can be write to that file
112
113
  return builder.add({
113
114
  schema,
@@ -115,7 +116,7 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {
115
116
  })
116
117
  })
117
118
 
118
- const mapFolderSchema = async ([name]: [string, OpenAPIV3.SchemaObject]) => {
119
+ const mapFolderSchema = async ([name]: [string, OasTypes.SchemaObject]) => {
119
120
  const resolvedPath = this.resolvePath({ baseName: `${this.resolveName({ name, pluginKey: this.plugin.key })}.ts`, pluginKey: this.plugin.key })
120
121
 
121
122
  if (!resolvedPath) {
@@ -146,8 +147,9 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {
146
147
  enumType,
147
148
  dateType,
148
149
  optionalType,
150
+ oas,
149
151
  }).configure()
150
- Object.entries(schemas).forEach(([name, schema]: [string, OpenAPIV3.SchemaObject]) => {
152
+ Object.entries(schemas).forEach(([name, schema]: [string, OasTypes.SchemaObject]) => {
151
153
  // generate and pass through new code back to the core so it can be write to that file
152
154
  return builder.add({
153
155
  schema,