@kubb/swagger-ts 1.1.13 → 1.2.0

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin.ts","../src/builders/TypeBuilder.ts","../src/generators/TypeGenerator.ts","../src/utils/keywordTypeNodes.ts","../src/generators/OperationGenerator.ts","../src/index.ts"],"names":["getRelativePath","pascalCase","ts","factory","node","options","root"],"mappings":";;;;;;;;AAAA,OAAO,gBAAgB;AAEvB,SAAS,cAAc,aAAa,mBAAAA,kBAAiB,gBAAgB,iBAAiB,oBAAoB;AAC1G,SAAS,cAAc,yBAAyB;AAEhD,SAAS,cAAAC,aAAY,gCAAgC;;;ACLrD,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB,kBAAkB;AAC7C,SAAS,yBAAyB,aAAa;;;ACF/C,SAAS,eAAe,iBAAiB,gBAAgB;AACzD,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,WAAW,kBAAkB;AACtC,OAAOC,SAAQ;;;ACff,OAAO,QAAQ;AAEf,IAAM,EAAE,QAAQ,IAAI;AAEb,IAAM,mBAAmB;AAAA,EAC9B,KAAK,QAAQ,sBAAsB,GAAG,WAAW,UAAU;AAAA,EAC3D,QAAQ,QAAQ,sBAAsB,GAAG,WAAW,aAAa;AAAA,EACjE,SAAS,QAAQ,sBAAsB,GAAG,WAAW,aAAa;AAAA,EAClE,QAAQ,QAAQ,sBAAsB,GAAG,WAAW,aAAa;AAAA,EACjE,QAAQ,QAAQ,sBAAsB,GAAG,WAAW,aAAa;AAAA,EACjE,SAAS,QAAQ,sBAAsB,GAAG,WAAW,cAAc;AAAA,EACnE,WAAW,QAAQ,sBAAsB,GAAG,WAAW,gBAAgB;AAAA,EACvE,MAAM,QAAQ,sBAAs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AAA,QACF;AAEA,cAAM,KAAK,QAAQ;AAAA,UACjB;AAAA,UACA,UAAU,GAAG,KAAK,YAAY,EAAE,MAAM,QAAQ,WAAW,CAAC;AAAA,UAC1D,QAAQ,QAAQ,MAAM;AAAA,QACxB,CAAC;AAAA,MACH;AAEA,YAAM,qBAAqB,IAAI,mBAAmB;AAAA,QAChD;AAAA,QACA;AAAA,QACA,aAAa,CAAC,WAAW,KAAK,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC;AAAA,QACnE,aAAa,CAAC,WAAW,KAAK,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC;AAAA,QACnE;AAAA,MACF,CAAC;AAED,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,WAAW,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,IAAI;AACzE,YAAM,QAAQ,MAAM,aAAa,MAAM,EAAE,YAAY,QAAQ,SAAS,CAAC,WAAW,MAAM,EAAE,CAAC;AAE3F,UAAI,OAAO;AACT,cAAM,KAAK,QAAQ,GAAG,KAAK;AAAA,MAC7B;AAAA,IACF;AAAA,EACF;AACF,CAAC;;;AKjKD,IAAO,cAAQ","sourcesContent":["import pathParser from 'node:path'\n\nimport { createPlugin, getPathMode, getRelativePath, renderTemplate, validatePlugins, writeIndexes } from '@kubb/core'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\n\nimport { pascalCase, pascalCaseTransformMerge } from 'change-case'\n\nimport { TypeBuilder } from './builders/index.ts'\nimport { OperationGenerator } from './generators/index.ts'\n\nimport type { OpenAPIV3, API as SwaggerApi } from '@kubb/swagger'\nimport type { PluginOptions } from './types.ts'\n\nexport const pluginName = 'swagger-ts' as const\n\n// Register your plugin for maximum type safety\ndeclare module '@kubb/core' {\n interface Register {\n ['@kubb/swagger-ts']: PluginOptions['options']\n }\n}\n\nexport const definePlugin = createPlugin<PluginOptions>((options) => {\n const { output = 'models', groupBy, enumType = 'asConst' } = options\n let swaggerApi: SwaggerApi\n\n return {\n name: pluginName,\n options,\n kind: 'schema',\n validate(plugins) {\n const valid = validatePlugins(plugins, [swaggerPluginName])\n if (valid) {\n swaggerApi = plugins.find((plugin) => plugin.name === swaggerPluginName)?.api\n }\n\n return valid\n },\n resolvePath(fileName, directory, options) {\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.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 pathParser.resolve(root, output)\n }\n\n if (options?.tag && groupBy?.type === 'tag') {\n const template = groupBy.output ? groupBy.output : `${output}/{{tag}}Controller`\n\n return pathParser.resolve(root, renderTemplate(template, { tag: options.tag }), fileName)\n }\n\n return pathParser.resolve(root, output, fileName)\n },\n resolveName(name) {\n return pascalCase(name, { delimiter: '', transform: pascalCaseTransformMerge })\n },\n async writeFile(source, path) {\n if (!path.endsWith('.ts') || !source) {\n return\n }\n\n await this.fileManager.write(source, path)\n },\n async buildStart() {\n const oas = await swaggerApi.getOas(this.config)\n\n const schemas = oas.getDefinition().components?.schemas || {}\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(root, output))\n\n if (mode === 'directory') {\n const builder = await new TypeBuilder(oas).configure({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n fileResolver: (name) => {\n const resolvedTypeId = this.resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n const root = this.resolvePath({ fileName: ``, pluginName })\n\n return getRelativePath(root, resolvedTypeId)\n },\n withJSDocs: true,\n enumType,\n })\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 path = this.resolvePath({ fileName: `${this.resolveName({ name, pluginName })}.ts`, pluginName })\n\n if (!path) {\n return null\n }\n\n return this.addFile({\n path,\n fileName: `${this.resolveName({ name, pluginName })}.ts`,\n source: builder.print(name),\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(oas).configure({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n withJSDocs: true,\n enumType,\n })\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 path = this.resolvePath({ fileName: '', pluginName })\n if (!path) {\n return\n }\n\n await this.addFile({\n path,\n fileName: `${this.resolveName({ name: output, pluginName })}.ts`,\n source: builder.print(),\n })\n }\n\n const operationGenerator = new OperationGenerator({\n oas,\n mode,\n resolvePath: (params) => this.resolvePath({ pluginName, ...params }),\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n enumType,\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 = pathParser.resolve(this.config.root, this.config.output.path)\n const files = await writeIndexes(root, { extensions: /\\.ts/, exclude: [/schemas/, /json/] })\n\n if (files) {\n await this.addFile(...files)\n }\n },\n }\n})\n","import { nameSorter } from '@kubb/core'\nimport { ImportsGenerator, OasBuilder } from '@kubb/swagger'\nimport { createImportDeclaration, print } from '@kubb/ts-codegen'\n\nimport { TypeGenerator } from '../generators/TypeGenerator.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { FileResolver, Refs } from '@kubb/swagger'\nimport type ts from 'typescript'\n\ntype Generated = { import: { refs: Refs; name: string }; sources: ts.Node[] }\ntype Config = {\n resolveName: PluginContext['resolveName']\n fileResolver?: FileResolver\n withJSDocs?: boolean\n withImports?: boolean\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n}\n\n// TODO create another function that sort based on the refs(first the ones without refs)\nfunction refsSorter(a: Generated, b: Generated) {\n if (Object.keys(a.import.refs)?.length < Object.keys(b.import.refs)?.length) {\n return -1\n }\n if (Object.keys(a.import.refs)?.length > Object.keys(b.import.refs)?.length) {\n return 1\n }\n return 0\n}\n\nexport class TypeBuilder extends OasBuilder<Config> {\n configure(config: Config) {\n this.config = config\n\n if (this.config.fileResolver) {\n this.config.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(nameSorter)\n .map((operationSchema) => {\n const generator = new TypeGenerator(this.oas, {\n withJSDocs: this.config.withJSDocs,\n resolveName: this.config.resolveName,\n enumType: this.config.enumType,\n })\n const sources = generator.build({ schema: operationSchema.schema, baseName: operationSchema.name, description: operationSchema.description })\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.config.withImports) {\n const importsGenerator = new ImportsGenerator({ fileResolver: this.config.fileResolver })\n const importMeta = importsGenerator.build(generated.map((item) => item.import))\n\n if (importMeta) {\n const nodes = importMeta.map((item) => {\n return createImportDeclaration({\n name: [{ propertyName: item.ref.propertyName, name: item.ref.name }],\n path: item.path,\n isTypeOnly: true,\n })\n })\n\n codes.unshift(print(nodes))\n }\n }\n\n return codes.join('\\n')\n }\n}\n","import { getUniqueName, SchemaGenerator, uniqueId } from '@kubb/core'\nimport { isReference } from '@kubb/swagger'\nimport {\n appendJSDocToNode,\n createEnumDeclaration,\n createIndexSignature,\n createIntersectionDeclaration,\n createPropertySignature,\n createTupleDeclaration,\n createTypeAliasDeclaration,\n createUnionDeclaration,\n modifiers,\n} from '@kubb/ts-codegen'\n\nimport { camelCase, pascalCase } from 'change-case'\nimport ts from 'typescript'\n\nimport { pluginName } from '../plugin.ts'\nimport { keywordTypeNodes } from '../utils/index.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { Oas, OpenAPIV3, Refs } from '@kubb/swagger'\nimport type { ArrayTwoOrMore } from '@kubb/ts-codegen'\n\nconst { factory } = ts\n\n// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n\ntype Options = {\n withJSDocs?: boolean\n resolveName: PluginContext['resolveName']\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n}\nexport class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObject, ts.Node[]> {\n // Collect the types of all referenced schemas so we can export them later\n public static usedEnumNames: Record<string, number> = {}\n\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 constructor(public readonly oas: Oas, options: Options = { withJSDocs: true, resolveName: ({ name }) => name, enumType: 'asConst' }) {\n super(options)\n\n return this\n }\n\n build({ schema, baseName, description }: { schema: OpenAPIV3.SchemaObject; baseName: string; description?: string }) {\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 = createTypeAliasDeclaration({\n modifiers: [modifiers.export],\n name: this.options.resolveName({ name: baseName, pluginName }) || baseName,\n type,\n })\n\n if (description) {\n nodes.push(\n 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 private 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) {\n return type\n }\n\n return createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] })\n }\n\n /**\n * Recursively creates a type literal with the given props.\n */\n private getTypeFromProperties(baseSchema?: OpenAPIV3.SchemaObject, baseName?: string) {\n const props = baseSchema?.properties || {}\n const required = baseSchema?.required\n const additionalProperties = baseSchema?.additionalProperties\n\n const members: Array<ts.TypeElement | null> = Object.keys(props).map((name) => {\n const schema = props[name] as OpenAPIV3.SchemaObject\n\n const isRequired = required && required.includes(name)\n let type = this.getTypeFromSchema(schema, pascalCase(`${baseName} ${name}`, { delimiter: '' }))\n\n if (!type) {\n return null\n }\n\n if (!isRequired) {\n type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] })\n }\n const propertySignature = createPropertySignature({\n questionToken: !isRequired,\n name,\n type,\n })\n if (this.options.withJSDocs) {\n return appendJSDocToNode({\n node: propertySignature,\n comments: [\n schema.description && `@description ${schema.description}`,\n schema.type && `@type ${schema.type}${isRequired ? '' : ' | undefined'} ${schema.format || ''}`,\n schema.example && `@example ${schema.example}`,\n schema.deprecated && `@deprecated`,\n schema.default !== undefined && typeof schema.default === 'string' && `@default '${schema.default}'`,\n schema.default !== undefined && typeof schema.default !== 'string' && `@default ${schema.default}`,\n ],\n })\n }\n\n return propertySignature\n })\n if (additionalProperties) {\n const type = additionalProperties === true ? keywordTypeNodes.any : this.getTypeFromSchema(additionalProperties as OpenAPIV3.SchemaObject)\n\n if (type) {\n members.push(createIndexSignature(type))\n }\n }\n return factory.createTypeLiteralNode(members.filter(Boolean) as ts.TypeElement[])\n }\n\n /**\n * Create a type alias for the schema referenced by the given ReferenceObject\n */\n private 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.name ?? ref.propertyName, undefined)\n }\n\n const originalName = pascalCase(getUniqueName($ref.replace(/.+\\//, ''), this.usedAliasNames), { delimiter: '' })\n const propertyName = this.options.resolveName({ name: originalName, pluginName }) || originalName\n\n if (originalName === baseName) {\n ref = this.refs[$ref] = {\n propertyName,\n originalName,\n name: uniqueId(propertyName),\n }\n\n return factory.createTypeReferenceNode(ref.name!, undefined)\n }\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 private getBaseTypeFromSchema(schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined, baseName?: string): ts.TypeNode | null {\n if (!schema) {\n return 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.createParenthesizedType(\n createUnionDeclaration({\n nodes: schema.oneOf\n .map((item: any) => {\n return this.getBaseTypeFromSchema(item as OpenAPIV3.SchemaObject)\n })\n .filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n )\n\n if (schemaWithoutOneOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n return union\n }\n\n if (schema.anyOf) {\n // TODO anyOf -> union\n }\n if (schema.allOf) {\n // intersection/add\n const schemaWithoutAllOf = { ...schema, allOf: undefined }\n\n const and = factory.createParenthesizedType(\n factory.createIntersectionTypeNode(\n schema.allOf\n .map((item: any) => {\n return this.getBaseTypeFromSchema(item as OpenAPIV3.SchemaObject)\n })\n .filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>\n )\n )\n\n if (schemaWithoutAllOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\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, TypeGenerator.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 ...createEnumDeclaration({\n name: camelCase(enumName, { delimiter: '' }),\n typeName: pascalCase(enumName, { delimiter: '' }),\n enums,\n type: this.options.enumType,\n })\n )\n return factory.createTypeReferenceNode(pascalCase(enumName, { delimiter: '' }), undefined)\n }\n\n if (schema.enum) {\n return createUnionDeclaration({\n nodes: schema.enum.map((name: any) => {\n return factory.createLiteralTypeNode(typeof name === 'number' ? factory.createNumericLiteral(name) : factory.createStringLiteral(`${name}`))\n }) as unknown as ArrayTwoOrMore<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 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 ArrayTwoOrMore<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\n\n return 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) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n // string, boolean, null, number\n if (schema.type in keywordTypeNodes) {\n return keywordTypeNodes[schema.type as keyof typeof keywordTypeNodes]\n }\n }\n\n if (schema.format === 'binary') {\n return factory.createTypeReferenceNode('Blob', [])\n }\n\n return keywordTypeNodes.any\n }\n}\n","import ts from 'typescript'\n\nconst { factory } = ts\n\nexport const keywordTypeNodes = {\n any: factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),\n number: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n integer: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n object: factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword),\n string: factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n boolean: factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),\n undefined: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n null: factory.createLiteralTypeNode(factory.createToken(ts.SyntaxKind.NullKeyword)),\n} as const\n","import { getRelativePath } from '@kubb/core'\nimport { OperationGenerator as Generator } from '@kubb/swagger'\n\nimport { TypeBuilder } from '../builders/index.ts'\nimport { pluginName } from '../plugin.ts'\n\nimport type { File, PathMode, PluginContext } from '@kubb/core'\nimport type { FileResolver, Oas, Operation, OperationSchemas, Resolver } from '@kubb/swagger'\n\ntype Options = {\n oas: Oas\n resolvePath: PluginContext['resolvePath']\n resolveName: PluginContext['resolveName']\n mode: PathMode\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n}\n\nexport class OperationGenerator extends Generator<Options> {\n resolve(operation: Operation): Resolver {\n const { resolvePath, resolveName } = this.options\n\n const name = resolveName({ name: operation.getOperationId(), pluginName })\n\n if (!name) {\n throw new Error('Name should be defined')\n }\n\n const fileName = `${name}.ts`\n const filePath = resolvePath({ fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n\n if (!filePath) {\n throw new Error('Filepath should be defined')\n }\n\n return {\n name,\n fileName,\n filePath,\n }\n }\n\n async all(): Promise<File | null> {\n return null\n }\n\n async get(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\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 = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n\n async post(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\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 = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n\n async put(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\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 = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n\n async delete(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\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 = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.request)\n .add(schemas.queryParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n}\n","import { definePlugin } from './plugin.ts'\n\nexport * from './plugin.ts'\nexport * from './types.ts'\n\nexport * from './generators/index.ts'\nexport * from './builders/index.ts'\nexport * from './utils/index.ts'\nexport default definePlugin\n"]}
1
+ {"version":3,"sources":["../src/plugin.ts","../src/builders/TypeBuilder.ts","../src/generators/TypeGenerator.ts","../src/utils/keywordTypeNodes.ts","../src/generators/OperationGenerator.ts","../src/index.ts"],"names":["getRelativePath","pascalCase","ts","factory","node","options","root"],"mappings":";;;;;;;;AAAA,OAAO,gBAAgB;AAEvB,SAAS,cAAc,aAAa,mBAAAA,kBAAiB,gBAAgB,iBAAiB,oBAAoB;AAC1G,SAAS,cAAc,yBAAyB;AAEhD,SAAS,cAAAC,aAAY,gCAAgC;;;ACLrD,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB,kBAAkB;AAC7C,SAAS,yBAAyB,aAAa;;;ACF/C,SAAS,eAAe,iBAAiB,gBAAgB;AACzD,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,WAAW,kBAAkB;AACtC,OAAOC,SAAQ;;;ACff,OAAO,QAAQ;AAEf,IAAM,EAAE,QAAQ,IAAI;AAEb,IAAM,mBAAmB;AAAA,EAC9B,KAAK,QAAQ,sBAAsB,GAAG,WAAW,UAAU;AAAA,EAC3D,QAAQ,QAAQ,sBAAsB,GAAG,WAAW,aAAa;AAAA,EACjE,SAAS,QAAQ,sBAAsB,GAAG,WAAW,aAAa;AAAA,EAClE,QAAQ,QAAQ,sBAAsB,GAAG,WAAW,aAAa;AAAA,EACjE,QAAQ,QAAQ,sBAAsB,GAAG,WAAW,aAAa;AAAA,EACjE,SAAS,QAAQ,sBAAsB,GAAG,WAAW,cAAc;AAAA,EACnE,WAAW,QAAQ,sBAAsB,GAAG,WAAW,gBAAgB;AAAA,EACvE,MAAM,QAAQ,sBAAsB,QAAQ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ACF;AAEA,cAAM,KAAK,QAAQ;AAAA,UACjB;AAAA,UACA,UAAU,GAAG,KAAK,YAAY,EAAE,MAAM,QAAQ,WAAW,CAAC;AAAA,UAC1D,QAAQ,QAAQ,MAAM;AAAA,QACxB,CAAC;AAAA,MACH;AAEA,YAAM,qBAAqB,IAAI,mBAAmB;AAAA,QAChD;AAAA,QACA;AAAA,QACA,aAAa,CAAC,WAAW,KAAK,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC;AAAA,QACnE,aAAa,CAAC,WAAW,KAAK,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC;AAAA,QACnE;AAAA,MACF,CAAC;AAED,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,WAAW,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,IAAI;AACzE,YAAM,QAAQ,MAAM,aAAa,MAAM,EAAE,YAAY,QAAQ,SAAS,CAAC,WAAW,MAAM,EAAE,CAAC;AAE3F,UAAI,OAAO;AACT,cAAM,KAAK,QAAQ,GAAG,KAAK;AAAA,MAC7B;AAAA,IACF;AAAA,EACF;AACF,CAAC;;;AKjKD,IAAO,cAAQ","sourcesContent":["import pathParser from 'node:path'\n\nimport { createPlugin, getPathMode, getRelativePath, renderTemplate, validatePlugins, writeIndexes } from '@kubb/core'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\n\nimport { pascalCase, pascalCaseTransformMerge } from 'change-case'\n\nimport { TypeBuilder } from './builders/index.ts'\nimport { OperationGenerator } from './generators/index.ts'\n\nimport type { OpenAPIV3, API as SwaggerApi } from '@kubb/swagger'\nimport type { PluginOptions } from './types.ts'\n\nexport const pluginName: PluginOptions['name'] = 'swagger-ts' as const\n\n// Register your plugin for maximum type safety\ndeclare module '@kubb/core' {\n interface Register {\n ['@kubb/swagger-ts']: PluginOptions['options']\n }\n}\n\nexport const definePlugin = createPlugin<PluginOptions>((options) => {\n const { output = 'models', groupBy, enumType = 'asConst' } = options\n let swaggerApi: SwaggerApi\n\n return {\n name: pluginName,\n options,\n kind: 'schema',\n validate(plugins) {\n const valid = validatePlugins(plugins, [swaggerPluginName])\n if (valid) {\n swaggerApi = plugins.find((plugin) => plugin.name === swaggerPluginName)?.api\n }\n\n return valid\n },\n resolvePath(fileName, directory, options) {\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.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 pathParser.resolve(root, output)\n }\n\n if (options?.tag && groupBy?.type === 'tag') {\n const template = groupBy.output ? groupBy.output : `${output}/{{tag}}Controller`\n\n return pathParser.resolve(root, renderTemplate(template, { tag: options.tag }), fileName)\n }\n\n return pathParser.resolve(root, output, fileName)\n },\n resolveName(name) {\n return pascalCase(name, { delimiter: '', transform: pascalCaseTransformMerge })\n },\n async writeFile(source, path) {\n if (!path.endsWith('.ts') || !source) {\n return\n }\n\n await this.fileManager.write(source, path)\n },\n async buildStart() {\n const oas = await swaggerApi.getOas(this.config)\n\n const schemas = oas.getDefinition().components?.schemas || {}\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(root, output))\n\n if (mode === 'directory') {\n const builder = await new TypeBuilder(oas).configure({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n fileResolver: (name) => {\n const resolvedTypeId = this.resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n const root = this.resolvePath({ fileName: ``, pluginName })\n\n return getRelativePath(root, resolvedTypeId)\n },\n withJSDocs: true,\n enumType,\n })\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 path = this.resolvePath({ fileName: `${this.resolveName({ name, pluginName })}.ts`, pluginName })\n\n if (!path) {\n return null\n }\n\n return this.addFile({\n path,\n fileName: `${this.resolveName({ name, pluginName })}.ts`,\n source: builder.print(name),\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(oas).configure({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n withJSDocs: true,\n enumType,\n })\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 path = this.resolvePath({ fileName: '', pluginName })\n if (!path) {\n return\n }\n\n await this.addFile({\n path,\n fileName: `${this.resolveName({ name: output, pluginName })}.ts`,\n source: builder.print(),\n })\n }\n\n const operationGenerator = new OperationGenerator({\n oas,\n mode,\n resolvePath: (params) => this.resolvePath({ pluginName, ...params }),\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n enumType,\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 = pathParser.resolve(this.config.root, this.config.output.path)\n const files = await writeIndexes(root, { extensions: /\\.ts/, exclude: [/schemas/, /json/] })\n\n if (files) {\n await this.addFile(...files)\n }\n },\n }\n})\n","import { nameSorter } from '@kubb/core'\nimport { ImportsGenerator, OasBuilder } from '@kubb/swagger'\nimport { createImportDeclaration, print } from '@kubb/ts-codegen'\n\nimport { TypeGenerator } from '../generators/TypeGenerator.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { FileResolver, Refs } from '@kubb/swagger'\nimport type ts from 'typescript'\n\ntype Generated = { import: { refs: Refs; name: string }; sources: ts.Node[] }\ntype Config = {\n resolveName: PluginContext['resolveName']\n fileResolver?: FileResolver\n withJSDocs?: boolean\n withImports?: boolean\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n}\n\n// TODO create another function that sort based on the refs(first the ones without refs)\nfunction refsSorter(a: Generated, b: Generated) {\n if (Object.keys(a.import.refs)?.length < Object.keys(b.import.refs)?.length) {\n return -1\n }\n if (Object.keys(a.import.refs)?.length > Object.keys(b.import.refs)?.length) {\n return 1\n }\n return 0\n}\n\nexport class TypeBuilder extends OasBuilder<Config> {\n configure(config: Config) {\n this.config = config\n\n if (this.config.fileResolver) {\n this.config.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(nameSorter)\n .map((operationSchema) => {\n const generator = new TypeGenerator(this.oas, {\n withJSDocs: this.config.withJSDocs,\n resolveName: this.config.resolveName,\n enumType: this.config.enumType,\n })\n const sources = generator.build({ schema: operationSchema.schema, baseName: operationSchema.name, description: operationSchema.description })\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.config.withImports) {\n const importsGenerator = new ImportsGenerator({ fileResolver: this.config.fileResolver })\n const importMeta = importsGenerator.build(generated.map((item) => item.import))\n\n if (importMeta) {\n const nodes = importMeta.map((item) => {\n return createImportDeclaration({\n name: [{ propertyName: item.ref.propertyName, name: item.ref.name }],\n path: item.path,\n isTypeOnly: true,\n })\n })\n\n codes.unshift(print(nodes))\n }\n }\n\n return codes.join('\\n')\n }\n}\n","import { getUniqueName, SchemaGenerator, uniqueId } from '@kubb/core'\nimport { isReference } from '@kubb/swagger'\nimport {\n appendJSDocToNode,\n createEnumDeclaration,\n createIndexSignature,\n createIntersectionDeclaration,\n createPropertySignature,\n createTupleDeclaration,\n createTypeAliasDeclaration,\n createUnionDeclaration,\n modifiers,\n} from '@kubb/ts-codegen'\n\nimport { camelCase, pascalCase } from 'change-case'\nimport ts from 'typescript'\n\nimport { pluginName } from '../plugin.ts'\nimport { keywordTypeNodes } from '../utils/index.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { Oas, OpenAPIV3, Refs } from '@kubb/swagger'\nimport type { ArrayTwoOrMore } from '@kubb/ts-codegen'\n\nconst { factory } = ts\n\n// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n\ntype Options = {\n withJSDocs?: boolean\n resolveName: PluginContext['resolveName']\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n}\nexport class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObject, ts.Node[]> {\n // Collect the types of all referenced schemas so we can export them later\n public static usedEnumNames: Record<string, number> = {}\n\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 constructor(public readonly oas: Oas, options: Options = { withJSDocs: true, resolveName: ({ name }) => name, enumType: 'asConst' }) {\n super(options)\n\n return this\n }\n\n build({ schema, baseName, description }: { schema: OpenAPIV3.SchemaObject; baseName: string; description?: string }) {\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 = createTypeAliasDeclaration({\n modifiers: [modifiers.export],\n name: this.options.resolveName({ name: baseName, pluginName }) || baseName,\n type,\n })\n\n if (description) {\n nodes.push(\n 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 private 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) {\n return type\n }\n\n return createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] })\n }\n\n /**\n * Recursively creates a type literal with the given props.\n */\n private getTypeFromProperties(baseSchema?: OpenAPIV3.SchemaObject, baseName?: string) {\n const props = baseSchema?.properties || {}\n const required = baseSchema?.required\n const additionalProperties = baseSchema?.additionalProperties\n\n const members: Array<ts.TypeElement | null> = Object.keys(props).map((name) => {\n const schema = props[name] as OpenAPIV3.SchemaObject\n\n const isRequired = required && required.includes(name)\n let type = this.getTypeFromSchema(schema, pascalCase(`${baseName} ${name}`, { delimiter: '' }))\n\n if (!type) {\n return null\n }\n\n if (!isRequired) {\n type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] })\n }\n const propertySignature = createPropertySignature({\n questionToken: !isRequired,\n name,\n type,\n })\n if (this.options.withJSDocs) {\n return appendJSDocToNode({\n node: propertySignature,\n comments: [\n schema.description && `@description ${schema.description}`,\n schema.type && `@type ${schema.type}${isRequired ? '' : ' | undefined'} ${schema.format || ''}`,\n schema.example && `@example ${schema.example}`,\n schema.deprecated && `@deprecated`,\n schema.default !== undefined && typeof schema.default === 'string' && `@default '${schema.default}'`,\n schema.default !== undefined && typeof schema.default !== 'string' && `@default ${schema.default}`,\n ],\n })\n }\n\n return propertySignature\n })\n if (additionalProperties) {\n const type = additionalProperties === true ? keywordTypeNodes.any : this.getTypeFromSchema(additionalProperties as OpenAPIV3.SchemaObject)\n\n if (type) {\n members.push(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 private 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.name ?? ref.propertyName, undefined)\n }\n\n const originalName = pascalCase(getUniqueName($ref.replace(/.+\\//, ''), this.usedAliasNames), { delimiter: '' })\n const propertyName = this.options.resolveName({ name: originalName, pluginName }) || originalName\n\n if (originalName === baseName) {\n ref = this.refs[$ref] = {\n propertyName,\n originalName,\n name: uniqueId(propertyName),\n }\n\n return factory.createTypeReferenceNode(ref.name!, undefined)\n }\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 private getBaseTypeFromSchema(schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined, baseName?: string): ts.TypeNode | null {\n if (!schema) {\n return 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.createParenthesizedType(\n createUnionDeclaration({\n nodes: schema.oneOf\n .map((item: any) => {\n return this.getBaseTypeFromSchema(item as OpenAPIV3.SchemaObject)\n })\n .filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n )\n\n if (schemaWithoutOneOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n return union\n }\n\n if (schema.anyOf) {\n // TODO anyOf -> union\n }\n if (schema.allOf) {\n // intersection/add\n const schemaWithoutAllOf = { ...schema, allOf: undefined }\n\n const and = factory.createParenthesizedType(\n factory.createIntersectionTypeNode(\n schema.allOf\n .map((item: any) => {\n return this.getBaseTypeFromSchema(item as OpenAPIV3.SchemaObject)\n })\n .filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>\n )\n )\n\n if (schemaWithoutAllOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\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, TypeGenerator.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 ...createEnumDeclaration({\n name: camelCase(enumName, { delimiter: '' }),\n typeName: pascalCase(enumName, { delimiter: '' }),\n enums,\n type: this.options.enumType,\n })\n )\n return factory.createTypeReferenceNode(pascalCase(enumName, { delimiter: '' }), undefined)\n }\n\n if (schema.enum) {\n return createUnionDeclaration({\n nodes: schema.enum.map((name: any) => {\n return factory.createLiteralTypeNode(typeof name === 'number' ? factory.createNumericLiteral(name) : factory.createStringLiteral(`${name}`))\n }) as unknown as ArrayTwoOrMore<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 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 ArrayTwoOrMore<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\n\n return 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) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n // string, boolean, null, number\n if (schema.type in keywordTypeNodes) {\n return keywordTypeNodes[schema.type as keyof typeof keywordTypeNodes]\n }\n }\n\n if (schema.format === 'binary') {\n return factory.createTypeReferenceNode('Blob', [])\n }\n\n return keywordTypeNodes.any\n }\n}\n","import ts from 'typescript'\n\nconst { factory } = ts\n\nexport const keywordTypeNodes = {\n any: factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),\n number: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n integer: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n object: factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword),\n string: factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n boolean: factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),\n undefined: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n null: factory.createLiteralTypeNode(factory.createToken(ts.SyntaxKind.NullKeyword)),\n} as const\n","import { getRelativePath } from '@kubb/core'\nimport { OperationGenerator as Generator } from '@kubb/swagger'\n\nimport { TypeBuilder } from '../builders/index.ts'\nimport { pluginName } from '../plugin.ts'\n\nimport type { File, PathMode, PluginContext } from '@kubb/core'\nimport type { FileResolver, Oas, Operation, OperationSchemas, Resolver } from '@kubb/swagger'\n\ntype Options = {\n oas: Oas\n resolvePath: PluginContext['resolvePath']\n resolveName: PluginContext['resolveName']\n mode: PathMode\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n}\n\nexport class OperationGenerator extends Generator<Options> {\n resolve(operation: Operation): Resolver {\n const { resolvePath, resolveName } = this.options\n\n const name = resolveName({ name: operation.getOperationId(), pluginName })\n\n if (!name) {\n throw new Error('Name should be defined')\n }\n\n const fileName = `${name}.ts`\n const filePath = resolvePath({ fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n\n if (!filePath) {\n throw new Error('Filepath should be defined')\n }\n\n return {\n name,\n fileName,\n filePath,\n }\n }\n\n async all(): Promise<File | null> {\n return null\n }\n\n async get(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\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 = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n\n async post(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\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 = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n\n async put(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\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 = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n\n async delete(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\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 = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.request)\n .add(schemas.queryParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n}\n","import { definePlugin } from './plugin.ts'\n\nexport * from './plugin.ts'\nexport * from './types.ts'\n\nexport * from './generators/index.ts'\nexport * from './builders/index.ts'\nexport * from './utils/index.ts'\nexport default definePlugin\n"]}
package/dist/index.d.ts CHANGED
@@ -36,9 +36,9 @@ type Options$2 = {
36
36
  type ResolvePathOptions = {
37
37
  tag?: string;
38
38
  };
39
- type PluginOptions = PluginFactoryOptions<Options$2, false, unknown, ResolvePathOptions>;
39
+ type PluginOptions = PluginFactoryOptions<'swagger-ts', Options$2, false, unknown, ResolvePathOptions>;
40
40
 
41
- declare const pluginName: "swagger-ts";
41
+ declare const pluginName: PluginOptions['name'];
42
42
  declare module '@kubb/core' {
43
43
  interface Register {
44
44
  ['@kubb/swagger-ts']: PluginOptions['options'];
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin.ts","../src/builders/TypeBuilder.ts","../src/generators/TypeGenerator.ts","../src/utils/keywordTypeNodes.ts","../src/generators/OperationGenerator.ts","../src/index.ts"],"names":["getRelativePath","pascalCase","ts","factory","node","options","root"],"mappings":";;;;;;;;;;;;AAAA,OAAO,gBAAgB;AAEvB,SAAS,cAAc,aAAa,mBAAAA,kBAAiB,gBAAgB,iBAAiB,oBAAoB;AAC1G,SAAS,cAAc,yBAAyB;AAEhD,SAAS,cAAAC,aAAY,gCAAgC;;;ACLrD,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB,kBAAkB;AAC7C,SAAS,yBAAyB,aAAa;;;ACF/C,SAAS,eAAe,iBAAiB,gBAAgB;AACzD,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,WAAW,kBAAkB;AACtC,OAAOC,SAAQ;;;ACff,OAAO,QAAQ;AAEf,IAAM,EAAE,QAAQ,IAAI;AAEb,IAAM,mBAAmB;AAAA,EAC9B,KAAK,QAAQ,sBAAsB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","sourcesContent":["import pathParser from 'node:path'\n\nimport { createPlugin, getPathMode, getRelativePath, renderTemplate, validatePlugins, writeIndexes } from '@kubb/core'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\n\nimport { pascalCase, pascalCaseTransformMerge } from 'change-case'\n\nimport { TypeBuilder } from './builders/index.ts'\nimport { OperationGenerator } from './generators/index.ts'\n\nimport type { OpenAPIV3, API as SwaggerApi } from '@kubb/swagger'\nimport type { PluginOptions } from './types.ts'\n\nexport const pluginName = 'swagger-ts' as const\n\n// Register your plugin for maximum type safety\ndeclare module '@kubb/core' {\n interface Register {\n ['@kubb/swagger-ts']: PluginOptions['options']\n }\n}\n\nexport const definePlugin = createPlugin<PluginOptions>((options) => {\n const { output = 'models', groupBy, enumType = 'asConst' } = options\n let swaggerApi: SwaggerApi\n\n return {\n name: pluginName,\n options,\n kind: 'schema',\n validate(plugins) {\n const valid = validatePlugins(plugins, [swaggerPluginName])\n if (valid) {\n swaggerApi = plugins.find((plugin) => plugin.name === swaggerPluginName)?.api\n }\n\n return valid\n },\n resolvePath(fileName, directory, options) {\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.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 pathParser.resolve(root, output)\n }\n\n if (options?.tag && groupBy?.type === 'tag') {\n const template = groupBy.output ? groupBy.output : `${output}/{{tag}}Controller`\n\n return pathParser.resolve(root, renderTemplate(template, { tag: options.tag }), fileName)\n }\n\n return pathParser.resolve(root, output, fileName)\n },\n resolveName(name) {\n return pascalCase(name, { delimiter: '', transform: pascalCaseTransformMerge })\n },\n async writeFile(source, path) {\n if (!path.endsWith('.ts') || !source) {\n return\n }\n\n await this.fileManager.write(source, path)\n },\n async buildStart() {\n const oas = await swaggerApi.getOas(this.config)\n\n const schemas = oas.getDefinition().components?.schemas || {}\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(root, output))\n\n if (mode === 'directory') {\n const builder = await new TypeBuilder(oas).configure({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n fileResolver: (name) => {\n const resolvedTypeId = this.resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n const root = this.resolvePath({ fileName: ``, pluginName })\n\n return getRelativePath(root, resolvedTypeId)\n },\n withJSDocs: true,\n enumType,\n })\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 path = this.resolvePath({ fileName: `${this.resolveName({ name, pluginName })}.ts`, pluginName })\n\n if (!path) {\n return null\n }\n\n return this.addFile({\n path,\n fileName: `${this.resolveName({ name, pluginName })}.ts`,\n source: builder.print(name),\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(oas).configure({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n withJSDocs: true,\n enumType,\n })\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 path = this.resolvePath({ fileName: '', pluginName })\n if (!path) {\n return\n }\n\n await this.addFile({\n path,\n fileName: `${this.resolveName({ name: output, pluginName })}.ts`,\n source: builder.print(),\n })\n }\n\n const operationGenerator = new OperationGenerator({\n oas,\n mode,\n resolvePath: (params) => this.resolvePath({ pluginName, ...params }),\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n enumType,\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 = pathParser.resolve(this.config.root, this.config.output.path)\n const files = await writeIndexes(root, { extensions: /\\.ts/, exclude: [/schemas/, /json/] })\n\n if (files) {\n await this.addFile(...files)\n }\n },\n }\n})\n","import { nameSorter } from '@kubb/core'\nimport { ImportsGenerator, OasBuilder } from '@kubb/swagger'\nimport { createImportDeclaration, print } from '@kubb/ts-codegen'\n\nimport { TypeGenerator } from '../generators/TypeGenerator.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { FileResolver, Refs } from '@kubb/swagger'\nimport type ts from 'typescript'\n\ntype Generated = { import: { refs: Refs; name: string }; sources: ts.Node[] }\ntype Config = {\n resolveName: PluginContext['resolveName']\n fileResolver?: FileResolver\n withJSDocs?: boolean\n withImports?: boolean\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n}\n\n// TODO create another function that sort based on the refs(first the ones without refs)\nfunction refsSorter(a: Generated, b: Generated) {\n if (Object.keys(a.import.refs)?.length < Object.keys(b.import.refs)?.length) {\n return -1\n }\n if (Object.keys(a.import.refs)?.length > Object.keys(b.import.refs)?.length) {\n return 1\n }\n return 0\n}\n\nexport class TypeBuilder extends OasBuilder<Config> {\n configure(config: Config) {\n this.config = config\n\n if (this.config.fileResolver) {\n this.config.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(nameSorter)\n .map((operationSchema) => {\n const generator = new TypeGenerator(this.oas, {\n withJSDocs: this.config.withJSDocs,\n resolveName: this.config.resolveName,\n enumType: this.config.enumType,\n })\n const sources = generator.build({ schema: operationSchema.schema, baseName: operationSchema.name, description: operationSchema.description })\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.config.withImports) {\n const importsGenerator = new ImportsGenerator({ fileResolver: this.config.fileResolver })\n const importMeta = importsGenerator.build(generated.map((item) => item.import))\n\n if (importMeta) {\n const nodes = importMeta.map((item) => {\n return createImportDeclaration({\n name: [{ propertyName: item.ref.propertyName, name: item.ref.name }],\n path: item.path,\n isTypeOnly: true,\n })\n })\n\n codes.unshift(print(nodes))\n }\n }\n\n return codes.join('\\n')\n }\n}\n","import { getUniqueName, SchemaGenerator, uniqueId } from '@kubb/core'\nimport { isReference } from '@kubb/swagger'\nimport {\n appendJSDocToNode,\n createEnumDeclaration,\n createIndexSignature,\n createIntersectionDeclaration,\n createPropertySignature,\n createTupleDeclaration,\n createTypeAliasDeclaration,\n createUnionDeclaration,\n modifiers,\n} from '@kubb/ts-codegen'\n\nimport { camelCase, pascalCase } from 'change-case'\nimport ts from 'typescript'\n\nimport { pluginName } from '../plugin.ts'\nimport { keywordTypeNodes } from '../utils/index.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { Oas, OpenAPIV3, Refs } from '@kubb/swagger'\nimport type { ArrayTwoOrMore } from '@kubb/ts-codegen'\n\nconst { factory } = ts\n\n// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n\ntype Options = {\n withJSDocs?: boolean\n resolveName: PluginContext['resolveName']\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n}\nexport class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObject, ts.Node[]> {\n // Collect the types of all referenced schemas so we can export them later\n public static usedEnumNames: Record<string, number> = {}\n\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 constructor(public readonly oas: Oas, options: Options = { withJSDocs: true, resolveName: ({ name }) => name, enumType: 'asConst' }) {\n super(options)\n\n return this\n }\n\n build({ schema, baseName, description }: { schema: OpenAPIV3.SchemaObject; baseName: string; description?: string }) {\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 = createTypeAliasDeclaration({\n modifiers: [modifiers.export],\n name: this.options.resolveName({ name: baseName, pluginName }) || baseName,\n type,\n })\n\n if (description) {\n nodes.push(\n 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 private 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) {\n return type\n }\n\n return createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] })\n }\n\n /**\n * Recursively creates a type literal with the given props.\n */\n private getTypeFromProperties(baseSchema?: OpenAPIV3.SchemaObject, baseName?: string) {\n const props = baseSchema?.properties || {}\n const required = baseSchema?.required\n const additionalProperties = baseSchema?.additionalProperties\n\n const members: Array<ts.TypeElement | null> = Object.keys(props).map((name) => {\n const schema = props[name] as OpenAPIV3.SchemaObject\n\n const isRequired = required && required.includes(name)\n let type = this.getTypeFromSchema(schema, pascalCase(`${baseName} ${name}`, { delimiter: '' }))\n\n if (!type) {\n return null\n }\n\n if (!isRequired) {\n type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] })\n }\n const propertySignature = createPropertySignature({\n questionToken: !isRequired,\n name,\n type,\n })\n if (this.options.withJSDocs) {\n return appendJSDocToNode({\n node: propertySignature,\n comments: [\n schema.description && `@description ${schema.description}`,\n schema.type && `@type ${schema.type}${isRequired ? '' : ' | undefined'} ${schema.format || ''}`,\n schema.example && `@example ${schema.example}`,\n schema.deprecated && `@deprecated`,\n schema.default !== undefined && typeof schema.default === 'string' && `@default '${schema.default}'`,\n schema.default !== undefined && typeof schema.default !== 'string' && `@default ${schema.default}`,\n ],\n })\n }\n\n return propertySignature\n })\n if (additionalProperties) {\n const type = additionalProperties === true ? keywordTypeNodes.any : this.getTypeFromSchema(additionalProperties as OpenAPIV3.SchemaObject)\n\n if (type) {\n members.push(createIndexSignature(type))\n }\n }\n return factory.createTypeLiteralNode(members.filter(Boolean) as ts.TypeElement[])\n }\n\n /**\n * Create a type alias for the schema referenced by the given ReferenceObject\n */\n private 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.name ?? ref.propertyName, undefined)\n }\n\n const originalName = pascalCase(getUniqueName($ref.replace(/.+\\//, ''), this.usedAliasNames), { delimiter: '' })\n const propertyName = this.options.resolveName({ name: originalName, pluginName }) || originalName\n\n if (originalName === baseName) {\n ref = this.refs[$ref] = {\n propertyName,\n originalName,\n name: uniqueId(propertyName),\n }\n\n return factory.createTypeReferenceNode(ref.name!, undefined)\n }\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 private getBaseTypeFromSchema(schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined, baseName?: string): ts.TypeNode | null {\n if (!schema) {\n return 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.createParenthesizedType(\n createUnionDeclaration({\n nodes: schema.oneOf\n .map((item: any) => {\n return this.getBaseTypeFromSchema(item as OpenAPIV3.SchemaObject)\n })\n .filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n )\n\n if (schemaWithoutOneOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n return union\n }\n\n if (schema.anyOf) {\n // TODO anyOf -> union\n }\n if (schema.allOf) {\n // intersection/add\n const schemaWithoutAllOf = { ...schema, allOf: undefined }\n\n const and = factory.createParenthesizedType(\n factory.createIntersectionTypeNode(\n schema.allOf\n .map((item: any) => {\n return this.getBaseTypeFromSchema(item as OpenAPIV3.SchemaObject)\n })\n .filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>\n )\n )\n\n if (schemaWithoutAllOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\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, TypeGenerator.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 ...createEnumDeclaration({\n name: camelCase(enumName, { delimiter: '' }),\n typeName: pascalCase(enumName, { delimiter: '' }),\n enums,\n type: this.options.enumType,\n })\n )\n return factory.createTypeReferenceNode(pascalCase(enumName, { delimiter: '' }), undefined)\n }\n\n if (schema.enum) {\n return createUnionDeclaration({\n nodes: schema.enum.map((name: any) => {\n return factory.createLiteralTypeNode(typeof name === 'number' ? factory.createNumericLiteral(name) : factory.createStringLiteral(`${name}`))\n }) as unknown as ArrayTwoOrMore<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 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 ArrayTwoOrMore<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\n\n return 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) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n // string, boolean, null, number\n if (schema.type in keywordTypeNodes) {\n return keywordTypeNodes[schema.type as keyof typeof keywordTypeNodes]\n }\n }\n\n if (schema.format === 'binary') {\n return factory.createTypeReferenceNode('Blob', [])\n }\n\n return keywordTypeNodes.any\n }\n}\n","import ts from 'typescript'\n\nconst { factory } = ts\n\nexport const keywordTypeNodes = {\n any: factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),\n number: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n integer: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n object: factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword),\n string: factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n boolean: factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),\n undefined: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n null: factory.createLiteralTypeNode(factory.createToken(ts.SyntaxKind.NullKeyword)),\n} as const\n","import { getRelativePath } from '@kubb/core'\nimport { OperationGenerator as Generator } from '@kubb/swagger'\n\nimport { TypeBuilder } from '../builders/index.ts'\nimport { pluginName } from '../plugin.ts'\n\nimport type { File, PathMode, PluginContext } from '@kubb/core'\nimport type { FileResolver, Oas, Operation, OperationSchemas, Resolver } from '@kubb/swagger'\n\ntype Options = {\n oas: Oas\n resolvePath: PluginContext['resolvePath']\n resolveName: PluginContext['resolveName']\n mode: PathMode\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n}\n\nexport class OperationGenerator extends Generator<Options> {\n resolve(operation: Operation): Resolver {\n const { resolvePath, resolveName } = this.options\n\n const name = resolveName({ name: operation.getOperationId(), pluginName })\n\n if (!name) {\n throw new Error('Name should be defined')\n }\n\n const fileName = `${name}.ts`\n const filePath = resolvePath({ fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n\n if (!filePath) {\n throw new Error('Filepath should be defined')\n }\n\n return {\n name,\n fileName,\n filePath,\n }\n }\n\n async all(): Promise<File | null> {\n return null\n }\n\n async get(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\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 = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n\n async post(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\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 = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n\n async put(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\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 = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n\n async delete(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\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 = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.request)\n .add(schemas.queryParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n}\n","import { definePlugin } from './plugin.ts'\n\nexport * from './plugin.ts'\nexport * from './types.ts'\n\nexport * from './generators/index.ts'\nexport * from './builders/index.ts'\nexport * from './utils/index.ts'\nexport default definePlugin\n"]}
1
+ {"version":3,"sources":["../src/plugin.ts","../src/builders/TypeBuilder.ts","../src/generators/TypeGenerator.ts","../src/utils/keywordTypeNodes.ts","../src/generators/OperationGenerator.ts","../src/index.ts"],"names":["getRelativePath","pascalCase","ts","factory","node","options","root"],"mappings":";;;;;;;;;;;;AAAA,OAAO,gBAAgB;AAEvB,SAAS,cAAc,aAAa,mBAAAA,kBAAiB,gBAAgB,iBAAiB,oBAAoB;AAC1G,SAAS,cAAc,yBAAyB;AAEhD,SAAS,cAAAC,aAAY,gCAAgC;;;ACLrD,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB,kBAAkB;AAC7C,SAAS,yBAAyB,aAAa;;;ACF/C,SAAS,eAAe,iBAAiB,gBAAgB;AACzD,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,WAAW,kBAAkB;AACtC,OAAOC,SAAQ;;;ACff,OAAO,QAAQ;AAEf,IAAM,EAAE,QAAQ,IAAI;AAEb,IAAM,mBAAmB;AAAA,EAC9B,KAAK,QAAQ,sBAAsB,GA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","sourcesContent":["import pathParser from 'node:path'\n\nimport { createPlugin, getPathMode, getRelativePath, renderTemplate, validatePlugins, writeIndexes } from '@kubb/core'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\n\nimport { pascalCase, pascalCaseTransformMerge } from 'change-case'\n\nimport { TypeBuilder } from './builders/index.ts'\nimport { OperationGenerator } from './generators/index.ts'\n\nimport type { OpenAPIV3, API as SwaggerApi } from '@kubb/swagger'\nimport type { PluginOptions } from './types.ts'\n\nexport const pluginName: PluginOptions['name'] = 'swagger-ts' as const\n\n// Register your plugin for maximum type safety\ndeclare module '@kubb/core' {\n interface Register {\n ['@kubb/swagger-ts']: PluginOptions['options']\n }\n}\n\nexport const definePlugin = createPlugin<PluginOptions>((options) => {\n const { output = 'models', groupBy, enumType = 'asConst' } = options\n let swaggerApi: SwaggerApi\n\n return {\n name: pluginName,\n options,\n kind: 'schema',\n validate(plugins) {\n const valid = validatePlugins(plugins, [swaggerPluginName])\n if (valid) {\n swaggerApi = plugins.find((plugin) => plugin.name === swaggerPluginName)?.api\n }\n\n return valid\n },\n resolvePath(fileName, directory, options) {\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.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 pathParser.resolve(root, output)\n }\n\n if (options?.tag && groupBy?.type === 'tag') {\n const template = groupBy.output ? groupBy.output : `${output}/{{tag}}Controller`\n\n return pathParser.resolve(root, renderTemplate(template, { tag: options.tag }), fileName)\n }\n\n return pathParser.resolve(root, output, fileName)\n },\n resolveName(name) {\n return pascalCase(name, { delimiter: '', transform: pascalCaseTransformMerge })\n },\n async writeFile(source, path) {\n if (!path.endsWith('.ts') || !source) {\n return\n }\n\n await this.fileManager.write(source, path)\n },\n async buildStart() {\n const oas = await swaggerApi.getOas(this.config)\n\n const schemas = oas.getDefinition().components?.schemas || {}\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(root, output))\n\n if (mode === 'directory') {\n const builder = await new TypeBuilder(oas).configure({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n fileResolver: (name) => {\n const resolvedTypeId = this.resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n const root = this.resolvePath({ fileName: ``, pluginName })\n\n return getRelativePath(root, resolvedTypeId)\n },\n withJSDocs: true,\n enumType,\n })\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 path = this.resolvePath({ fileName: `${this.resolveName({ name, pluginName })}.ts`, pluginName })\n\n if (!path) {\n return null\n }\n\n return this.addFile({\n path,\n fileName: `${this.resolveName({ name, pluginName })}.ts`,\n source: builder.print(name),\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(oas).configure({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n withJSDocs: true,\n enumType,\n })\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 path = this.resolvePath({ fileName: '', pluginName })\n if (!path) {\n return\n }\n\n await this.addFile({\n path,\n fileName: `${this.resolveName({ name: output, pluginName })}.ts`,\n source: builder.print(),\n })\n }\n\n const operationGenerator = new OperationGenerator({\n oas,\n mode,\n resolvePath: (params) => this.resolvePath({ pluginName, ...params }),\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n enumType,\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 = pathParser.resolve(this.config.root, this.config.output.path)\n const files = await writeIndexes(root, { extensions: /\\.ts/, exclude: [/schemas/, /json/] })\n\n if (files) {\n await this.addFile(...files)\n }\n },\n }\n})\n","import { nameSorter } from '@kubb/core'\nimport { ImportsGenerator, OasBuilder } from '@kubb/swagger'\nimport { createImportDeclaration, print } from '@kubb/ts-codegen'\n\nimport { TypeGenerator } from '../generators/TypeGenerator.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { FileResolver, Refs } from '@kubb/swagger'\nimport type ts from 'typescript'\n\ntype Generated = { import: { refs: Refs; name: string }; sources: ts.Node[] }\ntype Config = {\n resolveName: PluginContext['resolveName']\n fileResolver?: FileResolver\n withJSDocs?: boolean\n withImports?: boolean\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n}\n\n// TODO create another function that sort based on the refs(first the ones without refs)\nfunction refsSorter(a: Generated, b: Generated) {\n if (Object.keys(a.import.refs)?.length < Object.keys(b.import.refs)?.length) {\n return -1\n }\n if (Object.keys(a.import.refs)?.length > Object.keys(b.import.refs)?.length) {\n return 1\n }\n return 0\n}\n\nexport class TypeBuilder extends OasBuilder<Config> {\n configure(config: Config) {\n this.config = config\n\n if (this.config.fileResolver) {\n this.config.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(nameSorter)\n .map((operationSchema) => {\n const generator = new TypeGenerator(this.oas, {\n withJSDocs: this.config.withJSDocs,\n resolveName: this.config.resolveName,\n enumType: this.config.enumType,\n })\n const sources = generator.build({ schema: operationSchema.schema, baseName: operationSchema.name, description: operationSchema.description })\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.config.withImports) {\n const importsGenerator = new ImportsGenerator({ fileResolver: this.config.fileResolver })\n const importMeta = importsGenerator.build(generated.map((item) => item.import))\n\n if (importMeta) {\n const nodes = importMeta.map((item) => {\n return createImportDeclaration({\n name: [{ propertyName: item.ref.propertyName, name: item.ref.name }],\n path: item.path,\n isTypeOnly: true,\n })\n })\n\n codes.unshift(print(nodes))\n }\n }\n\n return codes.join('\\n')\n }\n}\n","import { getUniqueName, SchemaGenerator, uniqueId } from '@kubb/core'\nimport { isReference } from '@kubb/swagger'\nimport {\n appendJSDocToNode,\n createEnumDeclaration,\n createIndexSignature,\n createIntersectionDeclaration,\n createPropertySignature,\n createTupleDeclaration,\n createTypeAliasDeclaration,\n createUnionDeclaration,\n modifiers,\n} from '@kubb/ts-codegen'\n\nimport { camelCase, pascalCase } from 'change-case'\nimport ts from 'typescript'\n\nimport { pluginName } from '../plugin.ts'\nimport { keywordTypeNodes } from '../utils/index.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { Oas, OpenAPIV3, Refs } from '@kubb/swagger'\nimport type { ArrayTwoOrMore } from '@kubb/ts-codegen'\n\nconst { factory } = ts\n\n// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n\ntype Options = {\n withJSDocs?: boolean\n resolveName: PluginContext['resolveName']\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n}\nexport class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObject, ts.Node[]> {\n // Collect the types of all referenced schemas so we can export them later\n public static usedEnumNames: Record<string, number> = {}\n\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 constructor(public readonly oas: Oas, options: Options = { withJSDocs: true, resolveName: ({ name }) => name, enumType: 'asConst' }) {\n super(options)\n\n return this\n }\n\n build({ schema, baseName, description }: { schema: OpenAPIV3.SchemaObject; baseName: string; description?: string }) {\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 = createTypeAliasDeclaration({\n modifiers: [modifiers.export],\n name: this.options.resolveName({ name: baseName, pluginName }) || baseName,\n type,\n })\n\n if (description) {\n nodes.push(\n 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 private 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) {\n return type\n }\n\n return createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] })\n }\n\n /**\n * Recursively creates a type literal with the given props.\n */\n private getTypeFromProperties(baseSchema?: OpenAPIV3.SchemaObject, baseName?: string) {\n const props = baseSchema?.properties || {}\n const required = baseSchema?.required\n const additionalProperties = baseSchema?.additionalProperties\n\n const members: Array<ts.TypeElement | null> = Object.keys(props).map((name) => {\n const schema = props[name] as OpenAPIV3.SchemaObject\n\n const isRequired = required && required.includes(name)\n let type = this.getTypeFromSchema(schema, pascalCase(`${baseName} ${name}`, { delimiter: '' }))\n\n if (!type) {\n return null\n }\n\n if (!isRequired) {\n type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] })\n }\n const propertySignature = createPropertySignature({\n questionToken: !isRequired,\n name,\n type,\n })\n if (this.options.withJSDocs) {\n return appendJSDocToNode({\n node: propertySignature,\n comments: [\n schema.description && `@description ${schema.description}`,\n schema.type && `@type ${schema.type}${isRequired ? '' : ' | undefined'} ${schema.format || ''}`,\n schema.example && `@example ${schema.example}`,\n schema.deprecated && `@deprecated`,\n schema.default !== undefined && typeof schema.default === 'string' && `@default '${schema.default}'`,\n schema.default !== undefined && typeof schema.default !== 'string' && `@default ${schema.default}`,\n ],\n })\n }\n\n return propertySignature\n })\n if (additionalProperties) {\n const type = additionalProperties === true ? keywordTypeNodes.any : this.getTypeFromSchema(additionalProperties as OpenAPIV3.SchemaObject)\n\n if (type) {\n members.push(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 private 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.name ?? ref.propertyName, undefined)\n }\n\n const originalName = pascalCase(getUniqueName($ref.replace(/.+\\//, ''), this.usedAliasNames), { delimiter: '' })\n const propertyName = this.options.resolveName({ name: originalName, pluginName }) || originalName\n\n if (originalName === baseName) {\n ref = this.refs[$ref] = {\n propertyName,\n originalName,\n name: uniqueId(propertyName),\n }\n\n return factory.createTypeReferenceNode(ref.name!, undefined)\n }\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 private getBaseTypeFromSchema(schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined, baseName?: string): ts.TypeNode | null {\n if (!schema) {\n return 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.createParenthesizedType(\n createUnionDeclaration({\n nodes: schema.oneOf\n .map((item: any) => {\n return this.getBaseTypeFromSchema(item as OpenAPIV3.SchemaObject)\n })\n .filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n )\n\n if (schemaWithoutOneOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n return union\n }\n\n if (schema.anyOf) {\n // TODO anyOf -> union\n }\n if (schema.allOf) {\n // intersection/add\n const schemaWithoutAllOf = { ...schema, allOf: undefined }\n\n const and = factory.createParenthesizedType(\n factory.createIntersectionTypeNode(\n schema.allOf\n .map((item: any) => {\n return this.getBaseTypeFromSchema(item as OpenAPIV3.SchemaObject)\n })\n .filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>\n )\n )\n\n if (schemaWithoutAllOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\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, TypeGenerator.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 ...createEnumDeclaration({\n name: camelCase(enumName, { delimiter: '' }),\n typeName: pascalCase(enumName, { delimiter: '' }),\n enums,\n type: this.options.enumType,\n })\n )\n return factory.createTypeReferenceNode(pascalCase(enumName, { delimiter: '' }), undefined)\n }\n\n if (schema.enum) {\n return createUnionDeclaration({\n nodes: schema.enum.map((name: any) => {\n return factory.createLiteralTypeNode(typeof name === 'number' ? factory.createNumericLiteral(name) : factory.createStringLiteral(`${name}`))\n }) as unknown as ArrayTwoOrMore<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 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 ArrayTwoOrMore<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\n\n return 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) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n // string, boolean, null, number\n if (schema.type in keywordTypeNodes) {\n return keywordTypeNodes[schema.type as keyof typeof keywordTypeNodes]\n }\n }\n\n if (schema.format === 'binary') {\n return factory.createTypeReferenceNode('Blob', [])\n }\n\n return keywordTypeNodes.any\n }\n}\n","import ts from 'typescript'\n\nconst { factory } = ts\n\nexport const keywordTypeNodes = {\n any: factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),\n number: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n integer: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n object: factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword),\n string: factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n boolean: factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),\n undefined: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n null: factory.createLiteralTypeNode(factory.createToken(ts.SyntaxKind.NullKeyword)),\n} as const\n","import { getRelativePath } from '@kubb/core'\nimport { OperationGenerator as Generator } from '@kubb/swagger'\n\nimport { TypeBuilder } from '../builders/index.ts'\nimport { pluginName } from '../plugin.ts'\n\nimport type { File, PathMode, PluginContext } from '@kubb/core'\nimport type { FileResolver, Oas, Operation, OperationSchemas, Resolver } from '@kubb/swagger'\n\ntype Options = {\n oas: Oas\n resolvePath: PluginContext['resolvePath']\n resolveName: PluginContext['resolveName']\n mode: PathMode\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n}\n\nexport class OperationGenerator extends Generator<Options> {\n resolve(operation: Operation): Resolver {\n const { resolvePath, resolveName } = this.options\n\n const name = resolveName({ name: operation.getOperationId(), pluginName })\n\n if (!name) {\n throw new Error('Name should be defined')\n }\n\n const fileName = `${name}.ts`\n const filePath = resolvePath({ fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n\n if (!filePath) {\n throw new Error('Filepath should be defined')\n }\n\n return {\n name,\n fileName,\n filePath,\n }\n }\n\n async all(): Promise<File | null> {\n return null\n }\n\n async get(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\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 = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n\n async post(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\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 = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n\n async put(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\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 = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n\n async delete(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\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 = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.request)\n .add(schemas.queryParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n}\n","import { definePlugin } from './plugin.ts'\n\nexport * from './plugin.ts'\nexport * from './types.ts'\n\nexport * from './generators/index.ts'\nexport * from './builders/index.ts'\nexport * from './utils/index.ts'\nexport default definePlugin\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/swagger-ts",
3
- "version": "1.1.13",
3
+ "version": "1.2.0",
4
4
  "description": "Generator swagger-ts",
5
5
  "keywords": [
6
6
  "typescript",
@@ -26,7 +26,8 @@
26
26
  "module": "./dist/index.js",
27
27
  "default": "./dist/index.cjs"
28
28
  },
29
- "./package.json": "./package.json"
29
+ "./package.json": "./package.json",
30
+ "./*": "./*"
30
31
  },
31
32
  "main": "dist/index.js",
32
33
  "module": "dist/index.js",
@@ -39,9 +40,9 @@
39
40
  "dependencies": {
40
41
  "change-case": "^4.1.2",
41
42
  "typescript": "^5.1.3",
42
- "@kubb/core": "1.1.13",
43
- "@kubb/swagger": "1.1.13",
44
- "@kubb/ts-codegen": "1.1.13"
43
+ "@kubb/core": "1.2.0",
44
+ "@kubb/swagger": "1.2.0",
45
+ "@kubb/ts-codegen": "1.2.0"
45
46
  },
46
47
  "devDependencies": {
47
48
  "eslint": "^8.42.0",
@@ -65,12 +66,11 @@
65
66
  "scripts": {
66
67
  "build": "tsup",
67
68
  "clean": "rimraf ./dist",
68
- "lint": "eslint \"**/*.{ts,tsx}\"",
69
+ "lint": "eslint --format pretty ./src",
69
70
  "lint-fix": "bun run lint --quiet --fix",
70
71
  "release": "pnpm publish --no-git-check",
71
72
  "start": "tsup --watch",
72
73
  "test": "vitest --passWithNoTests",
73
- "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false",
74
- "upgrade": "pnpm update"
74
+ "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
75
75
  }
76
76
  }