@kubb/swagger-ts 2.0.0-alpha.2 → 2.0.0-alpha.4
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/hooks.cjs +67 -2
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.js +67 -2
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +67 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +67 -2
- package/dist/index.js.map +1 -1
- package/package.json +8 -7
- package/src/builders/TypeBuilder.ts +93 -0
- package/src/builders/index.ts +1 -0
- package/src/generators/OperationGenerator.ts +211 -0
- package/src/generators/TypeGenerator.ts +378 -0
- package/src/generators/index.ts +2 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useResolve.ts +10 -0
- package/src/index.ts +7 -0
- package/src/plugin.ts +223 -0
- package/src/resolve.ts +9 -0
- package/src/types.ts +77 -0
package/dist/hooks.cjs
CHANGED
@@ -384,7 +384,12 @@ var TypeBuilder = class extends swagger.OasBuilder {
|
|
384
384
|
return utils.transformers.combineCodes(codes);
|
385
385
|
}
|
386
386
|
};
|
387
|
+
var _printCombinedSchema, printCombinedSchema_fn;
|
387
388
|
var OperationGenerator = class extends swagger.OperationGenerator {
|
389
|
+
constructor() {
|
390
|
+
super(...arguments);
|
391
|
+
__privateAdd(this, _printCombinedSchema);
|
392
|
+
}
|
388
393
|
resolve(operation) {
|
389
394
|
const { pluginManager, plugin } = this.context;
|
390
395
|
return swagger.resolve({
|
@@ -418,10 +423,11 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
418
423
|
optionalType,
|
419
424
|
dateType
|
420
425
|
}).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.response).add(schemas.errors).configure().print();
|
426
|
+
const combinedSchemaSource = __privateMethod(this, _printCombinedSchema, printCombinedSchema_fn).call(this, type.name, operation, schemas);
|
421
427
|
return {
|
422
428
|
path: type.path,
|
423
429
|
baseName: type.baseName,
|
424
|
-
source,
|
430
|
+
source: [source, combinedSchemaSource].join("\n"),
|
425
431
|
meta: {
|
426
432
|
pluginKey: plugin.key,
|
427
433
|
tag: operation.getTags()[0]?.name
|
@@ -449,10 +455,11 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
449
455
|
optionalType,
|
450
456
|
dateType
|
451
457
|
}).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.request).add(schemas.response).add(schemas.errors).configure().print();
|
458
|
+
const combinedSchemaSource = __privateMethod(this, _printCombinedSchema, printCombinedSchema_fn).call(this, type.name, operation, schemas);
|
452
459
|
return {
|
453
460
|
path: type.path,
|
454
461
|
baseName: type.baseName,
|
455
|
-
source,
|
462
|
+
source: [source, combinedSchemaSource].join("\n"),
|
456
463
|
meta: {
|
457
464
|
pluginKey: plugin.key,
|
458
465
|
tag: operation.getTags()[0]?.name
|
@@ -469,6 +476,64 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
469
476
|
return this.post(operation, schemas, options);
|
470
477
|
}
|
471
478
|
};
|
479
|
+
_printCombinedSchema = new WeakSet();
|
480
|
+
printCombinedSchema_fn = function(name, operation, schemas) {
|
481
|
+
const properties = {
|
482
|
+
"response": factory__namespace.createTypeReferenceNode(
|
483
|
+
factory__namespace.createIdentifier(schemas.response.name),
|
484
|
+
void 0
|
485
|
+
)
|
486
|
+
};
|
487
|
+
if (schemas.request) {
|
488
|
+
properties["request"] = factory__namespace.createTypeReferenceNode(
|
489
|
+
factory__namespace.createIdentifier(schemas.request.name),
|
490
|
+
void 0
|
491
|
+
);
|
492
|
+
}
|
493
|
+
if (schemas.pathParams) {
|
494
|
+
properties["pathParams"] = factory__namespace.createTypeReferenceNode(
|
495
|
+
factory__namespace.createIdentifier(schemas.pathParams.name),
|
496
|
+
void 0
|
497
|
+
);
|
498
|
+
}
|
499
|
+
if (schemas.queryParams) {
|
500
|
+
properties["queryParams"] = factory__namespace.createTypeReferenceNode(
|
501
|
+
factory__namespace.createIdentifier(schemas.queryParams.name),
|
502
|
+
void 0
|
503
|
+
);
|
504
|
+
}
|
505
|
+
if (schemas.headerParams) {
|
506
|
+
properties["headerParams"] = factory__namespace.createTypeReferenceNode(
|
507
|
+
factory__namespace.createIdentifier(schemas.headerParams.name),
|
508
|
+
void 0
|
509
|
+
);
|
510
|
+
}
|
511
|
+
if (schemas.errors) {
|
512
|
+
properties["errors"] = factory__namespace.createUnionDeclaration({
|
513
|
+
nodes: schemas.errors.map((error) => {
|
514
|
+
return factory__namespace.createTypeReferenceNode(
|
515
|
+
factory__namespace.createIdentifier(error.name),
|
516
|
+
void 0
|
517
|
+
);
|
518
|
+
})
|
519
|
+
});
|
520
|
+
}
|
521
|
+
const namespaceNode = factory__namespace.createNamespaceDeclaration({
|
522
|
+
name: operation.method === "get" ? `${name}Query` : `${name}Mutation`,
|
523
|
+
statements: Object.keys(properties).map((key) => {
|
524
|
+
const type = properties[key];
|
525
|
+
if (!type) {
|
526
|
+
return void 0;
|
527
|
+
}
|
528
|
+
return factory__namespace.createTypeAliasDeclaration({
|
529
|
+
modifiers: [factory__namespace.modifiers.export],
|
530
|
+
name: changeCase.pascalCase(key),
|
531
|
+
type
|
532
|
+
});
|
533
|
+
}).filter(Boolean)
|
534
|
+
});
|
535
|
+
return parser.print(namespaceNode);
|
536
|
+
};
|
472
537
|
|
473
538
|
// src/plugin.ts
|
474
539
|
var pluginName = "swagger-ts";
|
package/dist/hooks.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useResolve.ts","../src/plugin.ts","../src/builders/TypeBuilder.ts","../src/generators/TypeGenerator.ts","../src/generators/OperationGenerator.ts"],"names":["getRelativePath","camelCase","factory","node","transformers","options","root"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,SAAS,cAAc,yBAAyB;;;ACAhD,OAAO,UAAU;AAEjB,SAAS,cAAc,aAAa,qBAAqB;AACzD,SAAS,mBAAAA,kBAAiB,sBAAsB;AAChD,SA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pB,QAAQ,KAAK;AAAA,UACb,aAAa,cAAc,IAAI;AAAA,UAC/B;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;;;ADvNM,SAAS,WAAW,QAAyB,CAAC,GAAa;AAChE,SAAO,kBAAkB,EAAE,WAAW,GAAG,MAAM,CAAC;AAClD","sourcesContent":["import { useResolve as useResolveSwagger } from '@kubb/swagger/hooks'\n\nimport { pluginKey } from '../plugin.ts'\n\nimport type { Resolver } from '@kubb/swagger'\nimport type { UseResolveProps } from '@kubb/swagger/hooks'\n\nexport function useResolve(props: UseResolveProps = {}): Resolver {\n return useResolveSwagger({ pluginKey, ...props })\n}\n","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 groupBy,\n skipBy = [],\n overrideBy = [],\n enumType = 'asConst',\n dateType = 'string',\n optionalType = 'questionToken',\n transformers = {},\n exportAs,\n } = options\n const template = groupBy?.output ? groupBy.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 && groupBy?.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) {\n const resolvedName = pascalCase(name, { delimiter: '', stripRegexp: /[^A-Z0-9$]/gi, transform: pascalCaseTransformMerge })\n\n return transformers?.name?.(resolvedName) || 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 skipBy,\n overrideBy,\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 { OpenAPIV3, Refs } from '@kubb/swagger'\nimport type { Options as CaseOptions } from 'change-case'\nimport type ts from 'typescript'\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 { OperationGenerator as Generator, resolve } from '@kubb/swagger'\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 { FileMeta, Options as PluginOptions } from '../types.ts'\n\ntype Options = {\n usedEnumNames: Record<string, number>\n\n mode: KubbFile.Mode\n enumType: NonNullable<PluginOptions['enumType']>\n dateType: NonNullable<PluginOptions['dateType']>\n optionalType: NonNullable<PluginOptions['optionalType']>\n}\n\nexport class OperationGenerator extends Generator<Options> {\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 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 return {\n path: type.path,\n baseName: type.baseName,\n source,\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 return {\n path: type.path,\n baseName: type.baseName,\n source,\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"]}
|
1
|
+
{"version":3,"sources":["../src/hooks/useResolve.ts","../src/plugin.ts","../src/builders/TypeBuilder.ts","../src/generators/TypeGenerator.ts","../src/generators/OperationGenerator.ts"],"names":["getRelativePath","camelCase","pascalCase","factory","node","print","transformers","options","root"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,SAAS,cAAc,yBAAyB;;;ACAhD,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,SA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useResolve as useResolveSwagger } from '@kubb/swagger/hooks'\n\nimport { pluginKey } from '../plugin.ts'\n\nimport type { Resolver } from '@kubb/swagger'\nimport type { UseResolveProps } from '@kubb/swagger/hooks'\n\nexport function useResolve(props: UseResolveProps = {}): Resolver {\n return useResolveSwagger({ pluginKey, ...props })\n}\n","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 groupBy,\n skipBy = [],\n overrideBy = [],\n enumType = 'asConst',\n dateType = 'string',\n optionalType = 'questionToken',\n transformers = {},\n exportAs,\n } = options\n const template = groupBy?.output ? groupBy.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 && groupBy?.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) {\n const resolvedName = pascalCase(name, { delimiter: '', stripRegexp: /[^A-Z0-9$]/gi, transform: pascalCaseTransformMerge })\n\n return transformers?.name?.(resolvedName) || 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 skipBy,\n overrideBy,\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, Options as PluginOptions } from '../types.ts'\n\ntype Options = {\n usedEnumNames: Record<string, number>\n\n mode: KubbFile.Mode\n enumType: NonNullable<PluginOptions['enumType']>\n dateType: NonNullable<PluginOptions['dateType']>\n optionalType: NonNullable<PluginOptions['optionalType']>\n}\n\nexport class OperationGenerator extends Generator<Options> {\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"]}
|
package/dist/hooks.js
CHANGED
@@ -362,7 +362,12 @@ var TypeBuilder = class extends OasBuilder {
|
|
362
362
|
return transformers.combineCodes(codes);
|
363
363
|
}
|
364
364
|
};
|
365
|
+
var _printCombinedSchema, printCombinedSchema_fn;
|
365
366
|
var OperationGenerator = class extends OperationGenerator$1 {
|
367
|
+
constructor() {
|
368
|
+
super(...arguments);
|
369
|
+
__privateAdd(this, _printCombinedSchema);
|
370
|
+
}
|
366
371
|
resolve(operation) {
|
367
372
|
const { pluginManager, plugin } = this.context;
|
368
373
|
return resolve({
|
@@ -396,10 +401,11 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
396
401
|
optionalType,
|
397
402
|
dateType
|
398
403
|
}).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.response).add(schemas.errors).configure().print();
|
404
|
+
const combinedSchemaSource = __privateMethod(this, _printCombinedSchema, printCombinedSchema_fn).call(this, type.name, operation, schemas);
|
399
405
|
return {
|
400
406
|
path: type.path,
|
401
407
|
baseName: type.baseName,
|
402
|
-
source,
|
408
|
+
source: [source, combinedSchemaSource].join("\n"),
|
403
409
|
meta: {
|
404
410
|
pluginKey: plugin.key,
|
405
411
|
tag: operation.getTags()[0]?.name
|
@@ -427,10 +433,11 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
427
433
|
optionalType,
|
428
434
|
dateType
|
429
435
|
}).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.request).add(schemas.response).add(schemas.errors).configure().print();
|
436
|
+
const combinedSchemaSource = __privateMethod(this, _printCombinedSchema, printCombinedSchema_fn).call(this, type.name, operation, schemas);
|
430
437
|
return {
|
431
438
|
path: type.path,
|
432
439
|
baseName: type.baseName,
|
433
|
-
source,
|
440
|
+
source: [source, combinedSchemaSource].join("\n"),
|
434
441
|
meta: {
|
435
442
|
pluginKey: plugin.key,
|
436
443
|
tag: operation.getTags()[0]?.name
|
@@ -447,6 +454,64 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
447
454
|
return this.post(operation, schemas, options);
|
448
455
|
}
|
449
456
|
};
|
457
|
+
_printCombinedSchema = new WeakSet();
|
458
|
+
printCombinedSchema_fn = function(name, operation, schemas) {
|
459
|
+
const properties = {
|
460
|
+
"response": factory.createTypeReferenceNode(
|
461
|
+
factory.createIdentifier(schemas.response.name),
|
462
|
+
void 0
|
463
|
+
)
|
464
|
+
};
|
465
|
+
if (schemas.request) {
|
466
|
+
properties["request"] = factory.createTypeReferenceNode(
|
467
|
+
factory.createIdentifier(schemas.request.name),
|
468
|
+
void 0
|
469
|
+
);
|
470
|
+
}
|
471
|
+
if (schemas.pathParams) {
|
472
|
+
properties["pathParams"] = factory.createTypeReferenceNode(
|
473
|
+
factory.createIdentifier(schemas.pathParams.name),
|
474
|
+
void 0
|
475
|
+
);
|
476
|
+
}
|
477
|
+
if (schemas.queryParams) {
|
478
|
+
properties["queryParams"] = factory.createTypeReferenceNode(
|
479
|
+
factory.createIdentifier(schemas.queryParams.name),
|
480
|
+
void 0
|
481
|
+
);
|
482
|
+
}
|
483
|
+
if (schemas.headerParams) {
|
484
|
+
properties["headerParams"] = factory.createTypeReferenceNode(
|
485
|
+
factory.createIdentifier(schemas.headerParams.name),
|
486
|
+
void 0
|
487
|
+
);
|
488
|
+
}
|
489
|
+
if (schemas.errors) {
|
490
|
+
properties["errors"] = factory.createUnionDeclaration({
|
491
|
+
nodes: schemas.errors.map((error) => {
|
492
|
+
return factory.createTypeReferenceNode(
|
493
|
+
factory.createIdentifier(error.name),
|
494
|
+
void 0
|
495
|
+
);
|
496
|
+
})
|
497
|
+
});
|
498
|
+
}
|
499
|
+
const namespaceNode = factory.createNamespaceDeclaration({
|
500
|
+
name: operation.method === "get" ? `${name}Query` : `${name}Mutation`,
|
501
|
+
statements: Object.keys(properties).map((key) => {
|
502
|
+
const type = properties[key];
|
503
|
+
if (!type) {
|
504
|
+
return void 0;
|
505
|
+
}
|
506
|
+
return factory.createTypeAliasDeclaration({
|
507
|
+
modifiers: [factory.modifiers.export],
|
508
|
+
name: pascalCase(key),
|
509
|
+
type
|
510
|
+
});
|
511
|
+
}).filter(Boolean)
|
512
|
+
});
|
513
|
+
return print(namespaceNode);
|
514
|
+
};
|
450
515
|
|
451
516
|
// src/plugin.ts
|
452
517
|
var pluginName = "swagger-ts";
|