@kubb/swagger-ts 1.0.0-beta.7 → 1.0.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +12 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +16 -3
- package/dist/index.js +12 -9
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/generators/OperationGenerator.ts +5 -5
- package/src/plugin.ts +16 -5
- package/src/types.ts +9 -2
package/dist/index.cjs
CHANGED
|
@@ -292,7 +292,7 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
|
292
292
|
const { directory, resolvePath, resolveName } = this.options;
|
|
293
293
|
const name = resolveName({ name: operation.getOperationId(), pluginName });
|
|
294
294
|
const fileName = `${name}.ts`;
|
|
295
|
-
const filePath = await resolvePath(fileName, directory);
|
|
295
|
+
const filePath = await resolvePath(fileName, directory, { tag: operation.getTags()[0]?.name });
|
|
296
296
|
if (!filePath || !name) {
|
|
297
297
|
throw new Error("Filepath should be defined");
|
|
298
298
|
}
|
|
@@ -309,7 +309,7 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
|
309
309
|
const { resolvePath, directory, mode, resolveName, oas } = this.options;
|
|
310
310
|
const type = await this.resolve(operation);
|
|
311
311
|
const fileResolver = async (name) => {
|
|
312
|
-
const filePath = await resolvePath(mode === "file" ? "" : type.name, directory);
|
|
312
|
+
const filePath = await resolvePath(mode === "file" ? "" : type.name, directory, { tag: operation.getTags()[0]?.name });
|
|
313
313
|
const resolvedTypeId = await resolvePath(`${name}.ts`, directory);
|
|
314
314
|
return core.getRelativePath(filePath, resolvedTypeId);
|
|
315
315
|
};
|
|
@@ -324,7 +324,7 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
|
324
324
|
const { resolvePath, directory, mode, resolveName, oas } = this.options;
|
|
325
325
|
const type = await this.resolve(operation);
|
|
326
326
|
const fileResolver = async (name) => {
|
|
327
|
-
const filePath = await resolvePath(mode === "file" ? "" : type.name, directory);
|
|
327
|
+
const filePath = await resolvePath(mode === "file" ? "" : type.name, directory, { tag: operation.getTags()[0]?.name });
|
|
328
328
|
const resolvedTypeId = await resolvePath(`${name}.ts`, directory);
|
|
329
329
|
return core.getRelativePath(filePath, resolvedTypeId);
|
|
330
330
|
};
|
|
@@ -339,7 +339,7 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
|
339
339
|
const { resolvePath, directory, mode, resolveName, oas } = this.options;
|
|
340
340
|
const type = await this.resolve(operation);
|
|
341
341
|
const fileResolver = async (name) => {
|
|
342
|
-
const filePath = await resolvePath(mode === "file" ? "" : type.name, directory);
|
|
342
|
+
const filePath = await resolvePath(mode === "file" ? "" : type.name, directory, { tag: operation.getTags()[0]?.name });
|
|
343
343
|
const resolvedTypeId = await resolvePath(`${name}.ts`, directory);
|
|
344
344
|
return core.getRelativePath(filePath, resolvedTypeId);
|
|
345
345
|
};
|
|
@@ -354,7 +354,7 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
|
354
354
|
const { resolvePath, directory, mode, resolveName, oas } = this.options;
|
|
355
355
|
const type = await this.resolve(operation);
|
|
356
356
|
const fileResolver = async (name) => {
|
|
357
|
-
const filePath = await resolvePath(mode === "file" ? "" : type.name, directory);
|
|
357
|
+
const filePath = await resolvePath(mode === "file" ? "" : type.name, directory, { tag: operation.getTags()[0]?.name });
|
|
358
358
|
const resolvedTypeId = await resolvePath(`${name}.ts`, directory);
|
|
359
359
|
return core.getRelativePath(filePath, resolvedTypeId);
|
|
360
360
|
};
|
|
@@ -413,10 +413,10 @@ var TypeBuilder = class extends swagger.OasBuilder {
|
|
|
413
413
|
// src/plugin.ts
|
|
414
414
|
var pluginName = "swagger-ts";
|
|
415
415
|
var definePlugin = core.createPlugin((options) => {
|
|
416
|
-
const { output = "models" } = options;
|
|
416
|
+
const { output = "models", groupBy } = options;
|
|
417
417
|
let swaggerApi;
|
|
418
418
|
const api = {
|
|
419
|
-
resolvePath(fileName, directory) {
|
|
419
|
+
resolvePath(fileName, directory, options2) {
|
|
420
420
|
if (!directory) {
|
|
421
421
|
return null;
|
|
422
422
|
}
|
|
@@ -424,6 +424,9 @@ var definePlugin = core.createPlugin((options) => {
|
|
|
424
424
|
if (mode === "file") {
|
|
425
425
|
return pathParser__default.default.resolve(directory, output);
|
|
426
426
|
}
|
|
427
|
+
if (options2?.tag && groupBy === "tag") {
|
|
428
|
+
return pathParser__default.default.resolve(directory, output, changeCase.camelCase(`${options2.tag}Controller`), fileName);
|
|
429
|
+
}
|
|
427
430
|
return pathParser__default.default.resolve(directory, output, fileName);
|
|
428
431
|
}
|
|
429
432
|
};
|
|
@@ -439,8 +442,8 @@ var definePlugin = core.createPlugin((options) => {
|
|
|
439
442
|
}
|
|
440
443
|
return valid;
|
|
441
444
|
},
|
|
442
|
-
resolvePath(fileName, directory) {
|
|
443
|
-
return api.resolvePath(fileName, directory);
|
|
445
|
+
resolvePath(fileName, directory, options2) {
|
|
446
|
+
return api.resolvePath(fileName, directory, options2);
|
|
444
447
|
},
|
|
445
448
|
resolveName(name) {
|
|
446
449
|
return changeCase.pascalCase(name, { delimiter: "" });
|
package/dist/index.cjs.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/ImportsGenerator.ts","../src/generators/OperationGenerator.ts","../src/index.ts"],"names":["pascalCase","getRelativePath","pluginName","ts","factory","node","uniq","Generator"],"mappings":";;;;;;;;;AAIA,OAAO,gBAAgB;AAEvB,SAAS,cAAAA,mBAAkB;AAE3B,SAAS,mBAAAC,kBAAiB,cAAc,aAAa,uBAAuB;AAC5E,SAAS,cAAc,yBAAyB;AAEhD,SAAS,oBAAoB;;;ACX7B,SAAS,YAAY,cAAAC,mBAAkB;AAGvC,SAAS,kBAAkB;AAC3B,SAAS,aAAa;;;ACHtB,OAAOC,SAAQ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Aa,IAAI;AAAA,QACjB,aAAa,CAAC,WAAW,KAAK,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC;AAAA,MACrE,CAAC;AAED,YAAM,mBAAmB,MAAM;AAAA,IACjC;AAAA,IACA,MAAM,WAAW;AACf,YAAM,aAAa,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,MAAM,EAAE,YAAY,QAAQ,SAAS,CAAC,WAAW,MAAM,EAAE,CAAC;AAAA,IACpH;AAAA,EACF;AACF,CAAC;;;AM1JD,IAAO,cAAQ","sourcesContent":["/* eslint-disable @typescript-eslint/ban-types */\n/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-console */\n\nimport pathParser from 'path'\n\nimport { pascalCase } from 'change-case'\n\nimport { getRelativePath, createPlugin, getPathMode, validatePlugins } from '@kubb/core'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\nimport type { Api as SwaggerApi, OpenAPIV3 } from '@kubb/swagger'\nimport { writeIndexes } from '@kubb/ts-codegen'\n\nimport { TypeBuilder } from './builders'\nimport { OperationGenerator } from './generators/OperationGenerator'\n\nimport type { Api, PluginOptions } from './types'\n\nexport const pluginName = 'swagger-ts' as const\n\nexport const definePlugin = createPlugin<PluginOptions>((options) => {\n const { output = 'models' } = options\n let swaggerApi: SwaggerApi\n\n const api: Api = {\n resolvePath(fileName, directory) {\n if (!directory) {\n return null\n }\n\n const mode = getPathMode(pathParser.resolve(directory, 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(directory, output)\n }\n\n return pathParser.resolve(directory, output, fileName)\n },\n }\n\n return {\n name: pluginName,\n options,\n kind: 'schema',\n api,\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) {\n return api.resolvePath(fileName, directory)\n },\n resolveName(name) {\n return pascalCase(name, { delimiter: '' })\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 directory = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(directory, output))\n\n if (mode === 'directory') {\n const builder = await new TypeBuilder(oas).configure({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n fileResolver: async (name) => {\n const resolvedTypeId = await this.resolvePath({\n fileName: `${name}.ts`,\n directory,\n pluginName,\n })\n\n const root = await this.resolvePath({ fileName: ``, directory, pluginName })\n\n return getRelativePath(root, resolvedTypeId)\n },\n withJSDocs: true,\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 = await this.resolvePath({ fileName: `${this.resolveName({ name, pluginName })}.ts`, directory, 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: await 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 })\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 = await this.resolvePath({ fileName: '', directory, pluginName })\n if (!path) {\n return\n }\n\n await this.addFile({\n path,\n fileName: `${this.resolveName({ name: output, pluginName })}.ts`,\n source: await builder.print(),\n })\n }\n\n const operationGenerator = new OperationGenerator({\n oas,\n mode,\n directory,\n fileManager: this.fileManager,\n resolvePath: api.resolvePath,\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n })\n\n await operationGenerator.build()\n },\n async buildEnd() {\n await writeIndexes(this.config.root, this.config.output.path, { extensions: /\\.ts/, exclude: [/schemas/, /json/] })\n },\n }\n})\n","import { OasBuilder, pluginName } from '@kubb/swagger'\nimport type { FileResolver } from '@kubb/swagger'\nimport type { PluginContext } from '@kubb/core'\nimport { nameSorter } from '@kubb/core'\nimport { print } from '@kubb/ts-codegen'\n\nimport { ImportsGenerator, TypeGenerator } from '../generators'\n\nimport type ts from 'typescript'\nimport type { Refs } from '../generators'\n\ntype Generated = { refs: Refs; name: string; sources: ts.Node[] }\ntype Config = {\n resolveName: PluginContext['resolveName']\n fileResolver?: FileResolver\n withJSDocs?: boolean\n withImports?: boolean\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.refs)?.length < Object.keys(b.refs)?.length) {\n return -1\n }\n if (Object.keys(a.refs)?.length > Object.keys(b.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 async print(name?: string) {\n const codes: string[] = []\n\n const generated = this.items\n .filter((gen) => (name ? gen.name === name : true))\n .sort(nameSorter)\n .map((gen) => {\n const generator = new TypeGenerator(this.oas, { withJSDocs: this.config.withJSDocs, resolveName: this.config.resolveName })\n const nodes = generator.build(gen.schema, this.config.resolveName({ name: gen.name, pluginName }) || gen.name, gen.description)\n\n return {\n refs: generator.refs,\n name: gen.name,\n sources: nodes,\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 codeImports = await importsGenerator.build(generated)\n\n if (codeImports) {\n codes.unshift(print(codeImports))\n }\n }\n\n return codes.join('\\n')\n }\n}\n","/* eslint-disable no-param-reassign */\nimport ts from 'typescript'\nimport { pascalCase, camelCase } from 'change-case'\nimport uniq from 'lodash.uniq'\n\nimport type { PluginContext } from '@kubb/core'\nimport { getUniqueName, SchemaGenerator } from '@kubb/core'\nimport type { Oas, OpenAPIV3 } from '@kubb/swagger'\nimport { isReference } from '@kubb/swagger'\nimport {\n appendJSDocToNode,\n createEnumDeclaration,\n createIndexSignature,\n createIntersectionDeclaration,\n createPropertySignature,\n createTypeAliasDeclaration,\n modifier,\n} from '@kubb/ts-codegen'\n\nimport { keywordTypeNodes } from '../utils'\nimport { pluginName } from '../plugin'\n\nconst { factory } = ts\n\n// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n\n/**\n * Name is the ref name + resolved with the nameResolver\n * Key is the original name used\n */\nexport type Refs = Record<string, { name: string; key: string }>\n\ntype Options = {\n withJSDocs?: boolean\n resolveName: PluginContext['resolveName']\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 }) {\n super(options)\n\n return this\n }\n\n build(schema: OpenAPIV3.SchemaObject, name: string, description?: string) {\n const nodes: ts.Node[] = []\n const type = this.getTypeFromSchema(schema, name)\n\n if (!type) {\n return this.extraNodes\n }\n\n const node = createTypeAliasDeclaration({\n modifiers: [modifier.export],\n name,\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 factory.createUnionTypeNode([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: ts.TypeNode | null\n if (schema.enum) {\n type = this.getTypeFromSchema(schema, pascalCase(`${baseName} ${name}`, { delimiter: '' }))\n } else {\n type = this.getTypeFromSchema(schema, pascalCase(`${baseName} ${name}`, { delimiter: '' }))\n }\n\n if (!type) {\n return null\n }\n\n if (!isRequired) {\n type = factory.createUnionTypeNode([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 ],\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) {\n const { $ref } = obj\n let ref = this.refs[$ref]\n\n if (!ref) {\n const name = pascalCase(getUniqueName($ref.replace(/.+\\//, ''), this.usedAliasNames), { delimiter: '' })\n\n // eslint-disable-next-line no-multi-assign\n ref = this.refs[$ref] = {\n name: this.options.resolveName({ name, pluginName }) || name,\n key: name,\n }\n }\n\n return factory.createTypeReferenceNode(ref.name, 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, name?: string): ts.TypeNode | null {\n if (!schema) {\n return keywordTypeNodes.any\n }\n\n if (isReference(schema)) {\n return this.getRefAlias(schema)\n }\n\n if (schema.oneOf) {\n // union\n const schemaWithoutOneOf = { ...schema, oneOf: undefined }\n\n return createIntersectionDeclaration({\n nodes: [\n this.getBaseTypeFromSchema(schemaWithoutOneOf, name),\n factory.createParenthesizedType(\n factory.createUnionTypeNode(\n schema.oneOf\n .map((item) => {\n return this.getBaseTypeFromSchema(item)\n })\n .filter(Boolean) as ts.TypeNode[]\n )\n ),\n ].filter(Boolean) as ts.TypeNode[],\n })\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 return createIntersectionDeclaration({\n nodes: [\n this.getBaseTypeFromSchema(schemaWithoutAllOf, name),\n factory.createParenthesizedType(\n factory.createIntersectionTypeNode(\n schema.allOf\n .map((item) => {\n return this.getBaseTypeFromSchema(item)\n })\n .filter(Boolean) as ts.TypeNode[]\n )\n ),\n ].filter(Boolean) as ts.TypeNode[],\n })\n }\n\n if (schema.enum && name) {\n const enumName = getUniqueName(name, TypeGenerator.usedEnumNames)\n\n let enums: [key: string, value: string | number][] = uniq(schema.enum)!.map((key) => [key, key])\n\n if ('x-enumNames' in schema) {\n enums = uniq(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 })\n )\n return factory.createTypeReferenceNode(pascalCase(enumName, { delimiter: '' }), undefined)\n }\n\n if ('items' in schema) {\n // items -> array\n const node = this.getTypeFromSchema(schema.items as OpenAPIV3.SchemaObject, name)\n if (node) {\n return factory.createArrayTypeNode(node)\n }\n }\n\n if (schema.properties || schema.additionalProperties) {\n // properties -> literal type\n return this.getTypeFromProperties(schema, name)\n }\n\n if (schema.type) {\n if (schema.type === 'object') {\n if (!schema.additionalProperties && !schema.properties && schema.type === 'object') {\n return null\n }\n }\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 factory.createUnionTypeNode(\n [\n this.getBaseTypeFromSchema(\n {\n ...schema,\n type,\n },\n name\n )!,\n nullable ? factory.createLiteralTypeNode(factory.createNull()) : undefined,\n ].filter(Boolean) as 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 uniq from 'lodash.uniq'\n\nimport { Generator } from '@kubb/core'\nimport type { FileResolver } from '@kubb/swagger'\nimport { createImportDeclaration } from '@kubb/ts-codegen'\n\nimport type { Refs } from './TypeGenerator'\nimport type ts from 'typescript'\n\ntype Options = {\n fileResolver?: FileResolver\n}\nexport class ImportsGenerator extends Generator<Options> {\n async build(items: Array<{ refs: Refs; sources: ts.Node[]; name: string }>): Promise<Array<ts.ImportDeclaration> | undefined> {\n const refs = items.reduce((acc, currentValue) => {\n return {\n ...acc,\n ...currentValue.refs,\n }\n }, {} as Refs)\n\n if (Object.keys(refs).length === 0) {\n return undefined\n }\n\n // add imports based on $ref\n const importPromises = uniq(Object.keys(refs))\n .filter(($ref: string) => {\n // when using a $ref inside a type we should not repeat that import\n const { key } = refs[$ref]\n return !items.find((item) =>\n item.sources.find((node: ts.Node) => (node as ts.TypeAliasDeclaration).name?.escapedText.toString().toLowerCase() === key.toLowerCase())\n )\n })\n .map(async ($ref: string) => {\n const { name } = refs[$ref]\n\n const path = (await this.options.fileResolver?.(name)) || `./${name}`\n\n // TODO weird hacky fix\n if (path === './' || path === '.') {\n return undefined\n }\n\n return createImportDeclaration({\n name: [name],\n path: path.replace('./../', '../'),\n })\n })\n\n const nodes = await Promise.all(importPromises)\n\n return nodes.filter(Boolean) as ts.ImportDeclaration[]\n }\n}\n","import type { File, FileManager, PathMode, PluginContext } from '@kubb/core'\nimport { getRelativePath } from '@kubb/core'\nimport { OperationGenerator as Generator } from '@kubb/swagger'\nimport type { FileResolver, Oas, Operation, OperationSchemas, Resolver } from '@kubb/swagger'\n\nimport { TypeBuilder } from '../builders'\nimport { pluginName } from '../plugin'\n\nimport type { Api } from '../types'\n\ntype Options = {\n oas: Oas\n resolvePath: Api['resolvePath']\n resolveName: PluginContext['resolveName']\n mode: PathMode\n fileManager: FileManager\n directory: string\n}\n\nexport class OperationGenerator extends Generator<Options> {\n async resolve(operation: Operation): Promise<Resolver> {\n const { directory, resolvePath, resolveName } = this.options\n\n const name = resolveName({ name: operation.getOperationId(), pluginName })\n const fileName = `${name}.ts`\n const filePath = await resolvePath(fileName, directory)\n\n if (!filePath || !name) {\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, directory, mode, resolveName, oas } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory)\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.response)\n .configure({ fileResolver, withJSDocs: true, resolveName })\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, directory, mode, resolveName, oas } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory)\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .configure({ fileResolver, withJSDocs: true, resolveName })\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, directory, mode, resolveName, oas } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory)\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .configure({ fileResolver, withJSDocs: true, resolveName })\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, directory, mode, resolveName, oas } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory)\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.request)\n .add(schemas.response)\n .configure({ fileResolver, withJSDocs: true, resolveName })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n}\n","import { definePlugin } from './plugin'\n\nexport * from './plugin'\nexport * from './generators'\nexport * from './builders'\nexport * from './types'\nexport * from './utils'\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/ImportsGenerator.ts","../src/generators/OperationGenerator.ts","../src/index.ts"],"names":["camelCase","pascalCase","getRelativePath","pluginName","ts","factory","node","uniq","Generator","options"],"mappings":";;;;;;;;;AAIA,OAAO,gBAAgB;AAEvB,SAAS,aAAAA,YAAW,cAAAC,mBAAkB;AAEtC,SAAS,mBAAAC,kBAAiB,cAAc,aAAa,uBAAuB;AAC5E,SAAS,cAAc,yBAAyB;AAEhD,SAAS,oBAAoB;;;ACX7B,SAAS,YAAY,cAAAC,mBAAkB;AAGvC,SAAS,kBAAkB;AAC3B,SAAS,aAAa;;;ACHtB,OAAOC,SAAQ;AACf,SAAS,YAAY,iBAAiB;AACtC,OAAO,UAAU;AAGjB,SAAS,eAAe,uBAAuB;AAE/C,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACjBP,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,YAAY,GAAG,WAAW,WAAW,CAAC;AACpF;;;ADSA,IAAM,EAAE,SAAAC,SAAQ,IAAID;AAcb,IAAM,iBAAN,cAA4B,gBAA4D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ban-types */\n/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-console */\n\nimport pathParser from 'path'\n\nimport { camelCase, pascalCase } from 'change-case'\n\nimport { getRelativePath, createPlugin, getPathMode, validatePlugins } from '@kubb/core'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\nimport type { Api as SwaggerApi, OpenAPIV3 } from '@kubb/swagger'\nimport { writeIndexes } from '@kubb/ts-codegen'\n\nimport { TypeBuilder } from './builders'\nimport { OperationGenerator } from './generators/OperationGenerator'\n\nimport type { Api, PluginOptions } from './types'\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 } = options\n let swaggerApi: SwaggerApi\n\n const api: Api = {\n resolvePath(fileName, directory, options) {\n if (!directory) {\n return null\n }\n\n const mode = getPathMode(pathParser.resolve(directory, 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(directory, output)\n }\n\n if (options?.tag && groupBy === 'tag') {\n return pathParser.resolve(directory, output, camelCase(`${options.tag}Controller`), fileName)\n }\n\n return pathParser.resolve(directory, output, fileName)\n },\n }\n\n return {\n name: pluginName,\n options,\n kind: 'schema',\n api,\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 return api.resolvePath(fileName, directory, options)\n },\n resolveName(name) {\n return pascalCase(name, { delimiter: '' })\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 directory = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(directory, output))\n\n if (mode === 'directory') {\n const builder = await new TypeBuilder(oas).configure({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n fileResolver: async (name) => {\n const resolvedTypeId = await this.resolvePath({\n fileName: `${name}.ts`,\n directory,\n pluginName,\n })\n\n const root = await this.resolvePath({ fileName: ``, directory, pluginName })\n\n return getRelativePath(root, resolvedTypeId)\n },\n withJSDocs: true,\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 = await this.resolvePath({ fileName: `${this.resolveName({ name, pluginName })}.ts`, directory, 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: await 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 })\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 = await this.resolvePath({ fileName: '', directory, pluginName })\n if (!path) {\n return\n }\n\n await this.addFile({\n path,\n fileName: `${this.resolveName({ name: output, pluginName })}.ts`,\n source: await builder.print(),\n })\n }\n\n const operationGenerator = new OperationGenerator({\n oas,\n mode,\n directory,\n fileManager: this.fileManager,\n resolvePath: api.resolvePath,\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n })\n\n await operationGenerator.build()\n },\n async buildEnd() {\n await writeIndexes(this.config.root, this.config.output.path, { extensions: /\\.ts/, exclude: [/schemas/, /json/] })\n },\n }\n})\n","import { OasBuilder, pluginName } from '@kubb/swagger'\nimport type { FileResolver } from '@kubb/swagger'\nimport type { PluginContext } from '@kubb/core'\nimport { nameSorter } from '@kubb/core'\nimport { print } from '@kubb/ts-codegen'\n\nimport { ImportsGenerator, TypeGenerator } from '../generators'\n\nimport type ts from 'typescript'\nimport type { Refs } from '../generators'\n\ntype Generated = { refs: Refs; name: string; sources: ts.Node[] }\ntype Config = {\n resolveName: PluginContext['resolveName']\n fileResolver?: FileResolver\n withJSDocs?: boolean\n withImports?: boolean\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.refs)?.length < Object.keys(b.refs)?.length) {\n return -1\n }\n if (Object.keys(a.refs)?.length > Object.keys(b.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 async print(name?: string) {\n const codes: string[] = []\n\n const generated = this.items\n .filter((gen) => (name ? gen.name === name : true))\n .sort(nameSorter)\n .map((gen) => {\n const generator = new TypeGenerator(this.oas, { withJSDocs: this.config.withJSDocs, resolveName: this.config.resolveName })\n const nodes = generator.build(gen.schema, this.config.resolveName({ name: gen.name, pluginName }) || gen.name, gen.description)\n\n return {\n refs: generator.refs,\n name: gen.name,\n sources: nodes,\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 codeImports = await importsGenerator.build(generated)\n\n if (codeImports) {\n codes.unshift(print(codeImports))\n }\n }\n\n return codes.join('\\n')\n }\n}\n","/* eslint-disable no-param-reassign */\nimport ts from 'typescript'\nimport { pascalCase, camelCase } from 'change-case'\nimport uniq from 'lodash.uniq'\n\nimport type { PluginContext } from '@kubb/core'\nimport { getUniqueName, SchemaGenerator } from '@kubb/core'\nimport type { Oas, OpenAPIV3 } from '@kubb/swagger'\nimport { isReference } from '@kubb/swagger'\nimport {\n appendJSDocToNode,\n createEnumDeclaration,\n createIndexSignature,\n createIntersectionDeclaration,\n createPropertySignature,\n createTypeAliasDeclaration,\n modifier,\n} from '@kubb/ts-codegen'\n\nimport { keywordTypeNodes } from '../utils'\nimport { pluginName } from '../plugin'\n\nconst { factory } = ts\n\n// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n\n/**\n * Name is the ref name + resolved with the nameResolver\n * Key is the original name used\n */\nexport type Refs = Record<string, { name: string; key: string }>\n\ntype Options = {\n withJSDocs?: boolean\n resolveName: PluginContext['resolveName']\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 }) {\n super(options)\n\n return this\n }\n\n build(schema: OpenAPIV3.SchemaObject, name: string, description?: string) {\n const nodes: ts.Node[] = []\n const type = this.getTypeFromSchema(schema, name)\n\n if (!type) {\n return this.extraNodes\n }\n\n const node = createTypeAliasDeclaration({\n modifiers: [modifier.export],\n name,\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 factory.createUnionTypeNode([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: ts.TypeNode | null\n if (schema.enum) {\n type = this.getTypeFromSchema(schema, pascalCase(`${baseName} ${name}`, { delimiter: '' }))\n } else {\n type = this.getTypeFromSchema(schema, pascalCase(`${baseName} ${name}`, { delimiter: '' }))\n }\n\n if (!type) {\n return null\n }\n\n if (!isRequired) {\n type = factory.createUnionTypeNode([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 ],\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) {\n const { $ref } = obj\n let ref = this.refs[$ref]\n\n if (!ref) {\n const name = pascalCase(getUniqueName($ref.replace(/.+\\//, ''), this.usedAliasNames), { delimiter: '' })\n\n // eslint-disable-next-line no-multi-assign\n ref = this.refs[$ref] = {\n name: this.options.resolveName({ name, pluginName }) || name,\n key: name,\n }\n }\n\n return factory.createTypeReferenceNode(ref.name, 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, name?: string): ts.TypeNode | null {\n if (!schema) {\n return keywordTypeNodes.any\n }\n\n if (isReference(schema)) {\n return this.getRefAlias(schema)\n }\n\n if (schema.oneOf) {\n // union\n const schemaWithoutOneOf = { ...schema, oneOf: undefined }\n\n return createIntersectionDeclaration({\n nodes: [\n this.getBaseTypeFromSchema(schemaWithoutOneOf, name),\n factory.createParenthesizedType(\n factory.createUnionTypeNode(\n schema.oneOf\n .map((item) => {\n return this.getBaseTypeFromSchema(item)\n })\n .filter(Boolean) as ts.TypeNode[]\n )\n ),\n ].filter(Boolean) as ts.TypeNode[],\n })\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 return createIntersectionDeclaration({\n nodes: [\n this.getBaseTypeFromSchema(schemaWithoutAllOf, name),\n factory.createParenthesizedType(\n factory.createIntersectionTypeNode(\n schema.allOf\n .map((item) => {\n return this.getBaseTypeFromSchema(item)\n })\n .filter(Boolean) as ts.TypeNode[]\n )\n ),\n ].filter(Boolean) as ts.TypeNode[],\n })\n }\n\n if (schema.enum && name) {\n const enumName = getUniqueName(name, TypeGenerator.usedEnumNames)\n\n let enums: [key: string, value: string | number][] = uniq(schema.enum)!.map((key) => [key, key])\n\n if ('x-enumNames' in schema) {\n enums = uniq(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 })\n )\n return factory.createTypeReferenceNode(pascalCase(enumName, { delimiter: '' }), undefined)\n }\n\n if ('items' in schema) {\n // items -> array\n const node = this.getTypeFromSchema(schema.items as OpenAPIV3.SchemaObject, name)\n if (node) {\n return factory.createArrayTypeNode(node)\n }\n }\n\n if (schema.properties || schema.additionalProperties) {\n // properties -> literal type\n return this.getTypeFromProperties(schema, name)\n }\n\n if (schema.type) {\n if (schema.type === 'object') {\n if (!schema.additionalProperties && !schema.properties && schema.type === 'object') {\n return null\n }\n }\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 factory.createUnionTypeNode(\n [\n this.getBaseTypeFromSchema(\n {\n ...schema,\n type,\n },\n name\n )!,\n nullable ? factory.createLiteralTypeNode(factory.createNull()) : undefined,\n ].filter(Boolean) as 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 uniq from 'lodash.uniq'\n\nimport { Generator } from '@kubb/core'\nimport type { FileResolver } from '@kubb/swagger'\nimport { createImportDeclaration } from '@kubb/ts-codegen'\n\nimport type { Refs } from './TypeGenerator'\nimport type ts from 'typescript'\n\ntype Options = {\n fileResolver?: FileResolver\n}\nexport class ImportsGenerator extends Generator<Options> {\n async build(items: Array<{ refs: Refs; sources: ts.Node[]; name: string }>): Promise<Array<ts.ImportDeclaration> | undefined> {\n const refs = items.reduce((acc, currentValue) => {\n return {\n ...acc,\n ...currentValue.refs,\n }\n }, {} as Refs)\n\n if (Object.keys(refs).length === 0) {\n return undefined\n }\n\n // add imports based on $ref\n const importPromises = uniq(Object.keys(refs))\n .filter(($ref: string) => {\n // when using a $ref inside a type we should not repeat that import\n const { key } = refs[$ref]\n return !items.find((item) =>\n item.sources.find((node: ts.Node) => (node as ts.TypeAliasDeclaration).name?.escapedText.toString().toLowerCase() === key.toLowerCase())\n )\n })\n .map(async ($ref: string) => {\n const { name } = refs[$ref]\n\n const path = (await this.options.fileResolver?.(name)) || `./${name}`\n\n // TODO weird hacky fix\n if (path === './' || path === '.') {\n return undefined\n }\n\n return createImportDeclaration({\n name: [name],\n path: path.replace('./../', '../'),\n })\n })\n\n const nodes = await Promise.all(importPromises)\n\n return nodes.filter(Boolean) as ts.ImportDeclaration[]\n }\n}\n","import type { File, FileManager, PathMode, PluginContext } from '@kubb/core'\nimport { getRelativePath } from '@kubb/core'\nimport { OperationGenerator as Generator } from '@kubb/swagger'\nimport type { FileResolver, Oas, Operation, OperationSchemas, Resolver } from '@kubb/swagger'\n\nimport { TypeBuilder } from '../builders'\nimport { pluginName } from '../plugin'\n\nimport type { Api } from '../types'\n\ntype Options = {\n oas: Oas\n resolvePath: Api['resolvePath']\n resolveName: PluginContext['resolveName']\n mode: PathMode\n fileManager: FileManager\n directory: string\n}\n\nexport class OperationGenerator extends Generator<Options> {\n async resolve(operation: Operation): Promise<Resolver> {\n const { directory, resolvePath, resolveName } = this.options\n\n const name = resolveName({ name: operation.getOperationId(), pluginName })\n const fileName = `${name}.ts`\n const filePath = await resolvePath(fileName, directory, { tag: operation.getTags()[0]?.name })\n\n if (!filePath || !name) {\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, directory, mode, resolveName, oas } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory, { tag: operation.getTags()[0]?.name })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.response)\n .configure({ fileResolver, withJSDocs: true, resolveName })\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, directory, mode, resolveName, oas } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory, { tag: operation.getTags()[0]?.name })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .configure({ fileResolver, withJSDocs: true, resolveName })\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, directory, mode, resolveName, oas } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory, { tag: operation.getTags()[0]?.name })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .configure({ fileResolver, withJSDocs: true, resolveName })\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, directory, mode, resolveName, oas } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory, { tag: operation.getTags()[0]?.name })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.request)\n .add(schemas.response)\n .configure({ fileResolver, withJSDocs: true, resolveName })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n}\n","import { definePlugin } from './plugin'\n\nexport * from './plugin'\nexport * from './generators'\nexport * from './builders'\nexport * from './types'\nexport * from './utils'\nexport default definePlugin\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import ts from 'typescript';
|
|
|
4
4
|
import { OpenAPIV3, Oas, FileResolver, OperationGenerator as OperationGenerator$1, Operation, Resolver, OperationSchemas, OasBuilder } from '@kubb/swagger';
|
|
5
5
|
|
|
6
6
|
type Api = {
|
|
7
|
-
resolvePath: (fileName: string, directory: string | undefined) => string | null;
|
|
7
|
+
resolvePath: (fileName: string, directory: string | undefined, options?: ResolvePathOptions) => string | null;
|
|
8
8
|
};
|
|
9
9
|
type Options$3 = {
|
|
10
10
|
/**
|
|
@@ -13,10 +13,23 @@ type Options$3 = {
|
|
|
13
13
|
* @default 'models'
|
|
14
14
|
*/
|
|
15
15
|
output?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Group the react-query hooks based on the provided name.
|
|
18
|
+
* Tag will group based on the operation tag inside the Swagger file
|
|
19
|
+
*/
|
|
20
|
+
groupBy?: 'tag';
|
|
16
21
|
};
|
|
17
|
-
type
|
|
22
|
+
type ResolvePathOptions = {
|
|
23
|
+
tag?: string;
|
|
24
|
+
};
|
|
25
|
+
type PluginOptions = PluginFactoryOptions<Options$3, false, Api, ResolvePathOptions>;
|
|
18
26
|
|
|
19
27
|
declare const pluginName: "swagger-ts";
|
|
28
|
+
declare module '@kubb/core' {
|
|
29
|
+
interface Register {
|
|
30
|
+
['@kubb/swagger-ts']: PluginOptions['options'];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
20
33
|
declare const definePlugin: (options: Options$3) => _kubb_core.KubbPlugin<PluginOptions>;
|
|
21
34
|
|
|
22
35
|
/**
|
|
@@ -111,4 +124,4 @@ declare const keywordTypeNodes: {
|
|
|
111
124
|
readonly null: ts.LiteralTypeNode;
|
|
112
125
|
};
|
|
113
126
|
|
|
114
|
-
export { Api, ImportsGenerator, OperationGenerator, Options$3 as Options, PluginOptions, Refs, TypeBuilder, TypeGenerator, definePlugin as default, definePlugin, keywordTypeNodes, pluginName };
|
|
127
|
+
export { Api, ImportsGenerator, OperationGenerator, Options$3 as Options, PluginOptions, Refs, ResolvePathOptions, TypeBuilder, TypeGenerator, definePlugin as default, definePlugin, keywordTypeNodes, pluginName };
|
package/dist/index.js
CHANGED
|
@@ -282,7 +282,7 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
|
282
282
|
const { directory, resolvePath, resolveName } = this.options;
|
|
283
283
|
const name = resolveName({ name: operation.getOperationId(), pluginName });
|
|
284
284
|
const fileName = `${name}.ts`;
|
|
285
|
-
const filePath = await resolvePath(fileName, directory);
|
|
285
|
+
const filePath = await resolvePath(fileName, directory, { tag: operation.getTags()[0]?.name });
|
|
286
286
|
if (!filePath || !name) {
|
|
287
287
|
throw new Error("Filepath should be defined");
|
|
288
288
|
}
|
|
@@ -299,7 +299,7 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
|
299
299
|
const { resolvePath, directory, mode, resolveName, oas } = this.options;
|
|
300
300
|
const type = await this.resolve(operation);
|
|
301
301
|
const fileResolver = async (name) => {
|
|
302
|
-
const filePath = await resolvePath(mode === "file" ? "" : type.name, directory);
|
|
302
|
+
const filePath = await resolvePath(mode === "file" ? "" : type.name, directory, { tag: operation.getTags()[0]?.name });
|
|
303
303
|
const resolvedTypeId = await resolvePath(`${name}.ts`, directory);
|
|
304
304
|
return getRelativePath(filePath, resolvedTypeId);
|
|
305
305
|
};
|
|
@@ -314,7 +314,7 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
|
314
314
|
const { resolvePath, directory, mode, resolveName, oas } = this.options;
|
|
315
315
|
const type = await this.resolve(operation);
|
|
316
316
|
const fileResolver = async (name) => {
|
|
317
|
-
const filePath = await resolvePath(mode === "file" ? "" : type.name, directory);
|
|
317
|
+
const filePath = await resolvePath(mode === "file" ? "" : type.name, directory, { tag: operation.getTags()[0]?.name });
|
|
318
318
|
const resolvedTypeId = await resolvePath(`${name}.ts`, directory);
|
|
319
319
|
return getRelativePath(filePath, resolvedTypeId);
|
|
320
320
|
};
|
|
@@ -329,7 +329,7 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
|
329
329
|
const { resolvePath, directory, mode, resolveName, oas } = this.options;
|
|
330
330
|
const type = await this.resolve(operation);
|
|
331
331
|
const fileResolver = async (name) => {
|
|
332
|
-
const filePath = await resolvePath(mode === "file" ? "" : type.name, directory);
|
|
332
|
+
const filePath = await resolvePath(mode === "file" ? "" : type.name, directory, { tag: operation.getTags()[0]?.name });
|
|
333
333
|
const resolvedTypeId = await resolvePath(`${name}.ts`, directory);
|
|
334
334
|
return getRelativePath(filePath, resolvedTypeId);
|
|
335
335
|
};
|
|
@@ -344,7 +344,7 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
|
344
344
|
const { resolvePath, directory, mode, resolveName, oas } = this.options;
|
|
345
345
|
const type = await this.resolve(operation);
|
|
346
346
|
const fileResolver = async (name) => {
|
|
347
|
-
const filePath = await resolvePath(mode === "file" ? "" : type.name, directory);
|
|
347
|
+
const filePath = await resolvePath(mode === "file" ? "" : type.name, directory, { tag: operation.getTags()[0]?.name });
|
|
348
348
|
const resolvedTypeId = await resolvePath(`${name}.ts`, directory);
|
|
349
349
|
return getRelativePath(filePath, resolvedTypeId);
|
|
350
350
|
};
|
|
@@ -403,10 +403,10 @@ var TypeBuilder = class extends OasBuilder {
|
|
|
403
403
|
// src/plugin.ts
|
|
404
404
|
var pluginName = "swagger-ts";
|
|
405
405
|
var definePlugin = createPlugin((options) => {
|
|
406
|
-
const { output = "models" } = options;
|
|
406
|
+
const { output = "models", groupBy } = options;
|
|
407
407
|
let swaggerApi;
|
|
408
408
|
const api = {
|
|
409
|
-
resolvePath(fileName, directory) {
|
|
409
|
+
resolvePath(fileName, directory, options2) {
|
|
410
410
|
if (!directory) {
|
|
411
411
|
return null;
|
|
412
412
|
}
|
|
@@ -414,6 +414,9 @@ var definePlugin = createPlugin((options) => {
|
|
|
414
414
|
if (mode === "file") {
|
|
415
415
|
return pathParser.resolve(directory, output);
|
|
416
416
|
}
|
|
417
|
+
if (options2?.tag && groupBy === "tag") {
|
|
418
|
+
return pathParser.resolve(directory, output, camelCase(`${options2.tag}Controller`), fileName);
|
|
419
|
+
}
|
|
417
420
|
return pathParser.resolve(directory, output, fileName);
|
|
418
421
|
}
|
|
419
422
|
};
|
|
@@ -429,8 +432,8 @@ var definePlugin = createPlugin((options) => {
|
|
|
429
432
|
}
|
|
430
433
|
return valid;
|
|
431
434
|
},
|
|
432
|
-
resolvePath(fileName, directory) {
|
|
433
|
-
return api.resolvePath(fileName, directory);
|
|
435
|
+
resolvePath(fileName, directory, options2) {
|
|
436
|
+
return api.resolvePath(fileName, directory, options2);
|
|
434
437
|
},
|
|
435
438
|
resolveName(name) {
|
|
436
439
|
return pascalCase(name, { delimiter: "" });
|
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/ImportsGenerator.ts","../src/generators/OperationGenerator.ts","../src/index.ts"],"names":["pascalCase","getRelativePath","pluginName","ts","factory","node","uniq","Generator"],"mappings":";;;;;;;;;AAIA,OAAO,gBAAgB;AAEvB,SAAS,cAAAA,mBAAkB;AAE3B,SAAS,mBAAAC,kBAAiB,cAAc,aAAa,uBAAuB;AAC5E,SAAS,cAAc,yBAAyB;AAEhD,SAAS,oBAAoB;;;ACX7B,SAAS,YAAY,cAAAC,mBAAkB;AAGvC,SAAS,kBAAkB;AAC3B,SAAS,aAAa;;;ACHtB,OAAOC,SAAQ;AACf,SAAS,YAAY,iBAAiB;AACtC,OAAO,UAAU;AAGjB,SAAS,eAAe,uBAAuB;AAE/C,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACjBP,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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int-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-console */\n\nimport pathParser from 'path'\n\nimport { pascalCase } from 'change-case'\n\nimport { getRelativePath, createPlugin, getPathMode, validatePlugins } from '@kubb/core'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\nimport type { Api as SwaggerApi, OpenAPIV3 } from '@kubb/swagger'\nimport { writeIndexes } from '@kubb/ts-codegen'\n\nimport { TypeBuilder } from './builders'\nimport { OperationGenerator } from './generators/OperationGenerator'\n\nimport type { Api, PluginOptions } from './types'\n\nexport const pluginName = 'swagger-ts' as const\n\nexport const definePlugin = createPlugin<PluginOptions>((options) => {\n const { output = 'models' } = options\n let swaggerApi: SwaggerApi\n\n const api: Api = {\n resolvePath(fileName, directory) {\n if (!directory) {\n return null\n }\n\n const mode = getPathMode(pathParser.resolve(directory, 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(directory, output)\n }\n\n return pathParser.resolve(directory, output, fileName)\n },\n }\n\n return {\n name: pluginName,\n options,\n kind: 'schema',\n api,\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) {\n return api.resolvePath(fileName, directory)\n },\n resolveName(name) {\n return pascalCase(name, { delimiter: '' })\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 directory = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(directory, output))\n\n if (mode === 'directory') {\n const builder = await new TypeBuilder(oas).configure({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n fileResolver: async (name) => {\n const resolvedTypeId = await this.resolvePath({\n fileName: `${name}.ts`,\n directory,\n pluginName,\n })\n\n const root = await this.resolvePath({ fileName: ``, directory, pluginName })\n\n return getRelativePath(root, resolvedTypeId)\n },\n withJSDocs: true,\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 = await this.resolvePath({ fileName: `${this.resolveName({ name, pluginName })}.ts`, directory, 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: await 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 })\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 = await this.resolvePath({ fileName: '', directory, pluginName })\n if (!path) {\n return\n }\n\n await this.addFile({\n path,\n fileName: `${this.resolveName({ name: output, pluginName })}.ts`,\n source: await builder.print(),\n })\n }\n\n const operationGenerator = new OperationGenerator({\n oas,\n mode,\n directory,\n fileManager: this.fileManager,\n resolvePath: api.resolvePath,\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n })\n\n await operationGenerator.build()\n },\n async buildEnd() {\n await writeIndexes(this.config.root, this.config.output.path, { extensions: /\\.ts/, exclude: [/schemas/, /json/] })\n },\n }\n})\n","import { OasBuilder, pluginName } from '@kubb/swagger'\nimport type { FileResolver } from '@kubb/swagger'\nimport type { PluginContext } from '@kubb/core'\nimport { nameSorter } from '@kubb/core'\nimport { print } from '@kubb/ts-codegen'\n\nimport { ImportsGenerator, TypeGenerator } from '../generators'\n\nimport type ts from 'typescript'\nimport type { Refs } from '../generators'\n\ntype Generated = { refs: Refs; name: string; sources: ts.Node[] }\ntype Config = {\n resolveName: PluginContext['resolveName']\n fileResolver?: FileResolver\n withJSDocs?: boolean\n withImports?: boolean\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.refs)?.length < Object.keys(b.refs)?.length) {\n return -1\n }\n if (Object.keys(a.refs)?.length > Object.keys(b.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 async print(name?: string) {\n const codes: string[] = []\n\n const generated = this.items\n .filter((gen) => (name ? gen.name === name : true))\n .sort(nameSorter)\n .map((gen) => {\n const generator = new TypeGenerator(this.oas, { withJSDocs: this.config.withJSDocs, resolveName: this.config.resolveName })\n const nodes = generator.build(gen.schema, this.config.resolveName({ name: gen.name, pluginName }) || gen.name, gen.description)\n\n return {\n refs: generator.refs,\n name: gen.name,\n sources: nodes,\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 codeImports = await importsGenerator.build(generated)\n\n if (codeImports) {\n codes.unshift(print(codeImports))\n }\n }\n\n return codes.join('\\n')\n }\n}\n","/* eslint-disable no-param-reassign */\nimport ts from 'typescript'\nimport { pascalCase, camelCase } from 'change-case'\nimport uniq from 'lodash.uniq'\n\nimport type { PluginContext } from '@kubb/core'\nimport { getUniqueName, SchemaGenerator } from '@kubb/core'\nimport type { Oas, OpenAPIV3 } from '@kubb/swagger'\nimport { isReference } from '@kubb/swagger'\nimport {\n appendJSDocToNode,\n createEnumDeclaration,\n createIndexSignature,\n createIntersectionDeclaration,\n createPropertySignature,\n createTypeAliasDeclaration,\n modifier,\n} from '@kubb/ts-codegen'\n\nimport { keywordTypeNodes } from '../utils'\nimport { pluginName } from '../plugin'\n\nconst { factory } = ts\n\n// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n\n/**\n * Name is the ref name + resolved with the nameResolver\n * Key is the original name used\n */\nexport type Refs = Record<string, { name: string; key: string }>\n\ntype Options = {\n withJSDocs?: boolean\n resolveName: PluginContext['resolveName']\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 }) {\n super(options)\n\n return this\n }\n\n build(schema: OpenAPIV3.SchemaObject, name: string, description?: string) {\n const nodes: ts.Node[] = []\n const type = this.getTypeFromSchema(schema, name)\n\n if (!type) {\n return this.extraNodes\n }\n\n const node = createTypeAliasDeclaration({\n modifiers: [modifier.export],\n name,\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 factory.createUnionTypeNode([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: ts.TypeNode | null\n if (schema.enum) {\n type = this.getTypeFromSchema(schema, pascalCase(`${baseName} ${name}`, { delimiter: '' }))\n } else {\n type = this.getTypeFromSchema(schema, pascalCase(`${baseName} ${name}`, { delimiter: '' }))\n }\n\n if (!type) {\n return null\n }\n\n if (!isRequired) {\n type = factory.createUnionTypeNode([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 ],\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) {\n const { $ref } = obj\n let ref = this.refs[$ref]\n\n if (!ref) {\n const name = pascalCase(getUniqueName($ref.replace(/.+\\//, ''), this.usedAliasNames), { delimiter: '' })\n\n // eslint-disable-next-line no-multi-assign\n ref = this.refs[$ref] = {\n name: this.options.resolveName({ name, pluginName }) || name,\n key: name,\n }\n }\n\n return factory.createTypeReferenceNode(ref.name, 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, name?: string): ts.TypeNode | null {\n if (!schema) {\n return keywordTypeNodes.any\n }\n\n if (isReference(schema)) {\n return this.getRefAlias(schema)\n }\n\n if (schema.oneOf) {\n // union\n const schemaWithoutOneOf = { ...schema, oneOf: undefined }\n\n return createIntersectionDeclaration({\n nodes: [\n this.getBaseTypeFromSchema(schemaWithoutOneOf, name),\n factory.createParenthesizedType(\n factory.createUnionTypeNode(\n schema.oneOf\n .map((item) => {\n return this.getBaseTypeFromSchema(item)\n })\n .filter(Boolean) as ts.TypeNode[]\n )\n ),\n ].filter(Boolean) as ts.TypeNode[],\n })\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 return createIntersectionDeclaration({\n nodes: [\n this.getBaseTypeFromSchema(schemaWithoutAllOf, name),\n factory.createParenthesizedType(\n factory.createIntersectionTypeNode(\n schema.allOf\n .map((item) => {\n return this.getBaseTypeFromSchema(item)\n })\n .filter(Boolean) as ts.TypeNode[]\n )\n ),\n ].filter(Boolean) as ts.TypeNode[],\n })\n }\n\n if (schema.enum && name) {\n const enumName = getUniqueName(name, TypeGenerator.usedEnumNames)\n\n let enums: [key: string, value: string | number][] = uniq(schema.enum)!.map((key) => [key, key])\n\n if ('x-enumNames' in schema) {\n enums = uniq(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 })\n )\n return factory.createTypeReferenceNode(pascalCase(enumName, { delimiter: '' }), undefined)\n }\n\n if ('items' in schema) {\n // items -> array\n const node = this.getTypeFromSchema(schema.items as OpenAPIV3.SchemaObject, name)\n if (node) {\n return factory.createArrayTypeNode(node)\n }\n }\n\n if (schema.properties || schema.additionalProperties) {\n // properties -> literal type\n return this.getTypeFromProperties(schema, name)\n }\n\n if (schema.type) {\n if (schema.type === 'object') {\n if (!schema.additionalProperties && !schema.properties && schema.type === 'object') {\n return null\n }\n }\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 factory.createUnionTypeNode(\n [\n this.getBaseTypeFromSchema(\n {\n ...schema,\n type,\n },\n name\n )!,\n nullable ? factory.createLiteralTypeNode(factory.createNull()) : undefined,\n ].filter(Boolean) as 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 uniq from 'lodash.uniq'\n\nimport { Generator } from '@kubb/core'\nimport type { FileResolver } from '@kubb/swagger'\nimport { createImportDeclaration } from '@kubb/ts-codegen'\n\nimport type { Refs } from './TypeGenerator'\nimport type ts from 'typescript'\n\ntype Options = {\n fileResolver?: FileResolver\n}\nexport class ImportsGenerator extends Generator<Options> {\n async build(items: Array<{ refs: Refs; sources: ts.Node[]; name: string }>): Promise<Array<ts.ImportDeclaration> | undefined> {\n const refs = items.reduce((acc, currentValue) => {\n return {\n ...acc,\n ...currentValue.refs,\n }\n }, {} as Refs)\n\n if (Object.keys(refs).length === 0) {\n return undefined\n }\n\n // add imports based on $ref\n const importPromises = uniq(Object.keys(refs))\n .filter(($ref: string) => {\n // when using a $ref inside a type we should not repeat that import\n const { key } = refs[$ref]\n return !items.find((item) =>\n item.sources.find((node: ts.Node) => (node as ts.TypeAliasDeclaration).name?.escapedText.toString().toLowerCase() === key.toLowerCase())\n )\n })\n .map(async ($ref: string) => {\n const { name } = refs[$ref]\n\n const path = (await this.options.fileResolver?.(name)) || `./${name}`\n\n // TODO weird hacky fix\n if (path === './' || path === '.') {\n return undefined\n }\n\n return createImportDeclaration({\n name: [name],\n path: path.replace('./../', '../'),\n })\n })\n\n const nodes = await Promise.all(importPromises)\n\n return nodes.filter(Boolean) as ts.ImportDeclaration[]\n }\n}\n","import type { File, FileManager, PathMode, PluginContext } from '@kubb/core'\nimport { getRelativePath } from '@kubb/core'\nimport { OperationGenerator as Generator } from '@kubb/swagger'\nimport type { FileResolver, Oas, Operation, OperationSchemas, Resolver } from '@kubb/swagger'\n\nimport { TypeBuilder } from '../builders'\nimport { pluginName } from '../plugin'\n\nimport type { Api } from '../types'\n\ntype Options = {\n oas: Oas\n resolvePath: Api['resolvePath']\n resolveName: PluginContext['resolveName']\n mode: PathMode\n fileManager: FileManager\n directory: string\n}\n\nexport class OperationGenerator extends Generator<Options> {\n async resolve(operation: Operation): Promise<Resolver> {\n const { directory, resolvePath, resolveName } = this.options\n\n const name = resolveName({ name: operation.getOperationId(), pluginName })\n const fileName = `${name}.ts`\n const filePath = await resolvePath(fileName, directory)\n\n if (!filePath || !name) {\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, directory, mode, resolveName, oas } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory)\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.response)\n .configure({ fileResolver, withJSDocs: true, resolveName })\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, directory, mode, resolveName, oas } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory)\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .configure({ fileResolver, withJSDocs: true, resolveName })\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, directory, mode, resolveName, oas } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory)\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .configure({ fileResolver, withJSDocs: true, resolveName })\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, directory, mode, resolveName, oas } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory)\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.request)\n .add(schemas.response)\n .configure({ fileResolver, withJSDocs: true, resolveName })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n}\n","import { definePlugin } from './plugin'\n\nexport * from './plugin'\nexport * from './generators'\nexport * from './builders'\nexport * from './types'\nexport * from './utils'\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/ImportsGenerator.ts","../src/generators/OperationGenerator.ts","../src/index.ts"],"names":["camelCase","pascalCase","getRelativePath","pluginName","ts","factory","node","uniq","Generator","options"],"mappings":";;;;;;;;;AAIA,OAAO,gBAAgB;AAEvB,SAAS,aAAAA,YAAW,cAAAC,mBAAkB;AAEtC,SAAS,mBAAAC,kBAAiB,cAAc,aAAa,uBAAuB;AAC5E,SAAS,cAAc,yBAAyB;AAEhD,SAAS,oBAAoB;;;ACX7B,SAAS,YAAY,cAAAC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C,MAAM,MAAM,MAAwC;AAEpF,iBAAO,QAAQ,IAAI;AAAA,YACjB;AAAA,YACA;AAAA,UACF,CAAC;AAAA,QACH,CAAC;AAED,cAAM,OAAO,MAAM,KAAK,YAAY,EAAE,UAAU,IAAI,WAAW,WAAW,CAAC;AAC3E,YAAI,CAAC,MAAM;AACT;AAAA,QACF;AAEA,cAAM,KAAK,QAAQ;AAAA,UACjB;AAAA,UACA,UAAU,GAAG,KAAK,YAAY,EAAE,MAAM,QAAQ,WAAW,CAAC;AAAA,UAC1D,QAAQ,MAAM,QAAQ,MAAM;AAAA,QAC9B,CAAC;AAAA,MACH;AAEA,YAAM,qBAAqB,IAAI,mBAAmB;AAAA,QAChD;AAAA,QACA;AAAA,QACA;AAAA,QACA,aAAa,KAAK;AAAA,QAClB,aAAa,IAAI;AAAA,QACjB,aAAa,CAAC,WAAW,KAAK,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC;AAAA,MACrE,CAAC;AAED,YAAM,mBAAmB,MAAM;AAAA,IACjC;AAAA,IACA,MAAM,WAAW;AACf,YAAM,aAAa,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,MAAM,EAAE,YAAY,QAAQ,SAAS,CAAC,WAAW,MAAM,EAAE,CAAC;AAAA,IACpH;AAAA,EACF;AACF,CAAC;;;AMrKD,IAAO,cAAQ","sourcesContent":["/* eslint-disable @typescript-eslint/ban-types */\n/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-console */\n\nimport pathParser from 'path'\n\nimport { camelCase, pascalCase } from 'change-case'\n\nimport { getRelativePath, createPlugin, getPathMode, validatePlugins } from '@kubb/core'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\nimport type { Api as SwaggerApi, OpenAPIV3 } from '@kubb/swagger'\nimport { writeIndexes } from '@kubb/ts-codegen'\n\nimport { TypeBuilder } from './builders'\nimport { OperationGenerator } from './generators/OperationGenerator'\n\nimport type { Api, PluginOptions } from './types'\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 } = options\n let swaggerApi: SwaggerApi\n\n const api: Api = {\n resolvePath(fileName, directory, options) {\n if (!directory) {\n return null\n }\n\n const mode = getPathMode(pathParser.resolve(directory, 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(directory, output)\n }\n\n if (options?.tag && groupBy === 'tag') {\n return pathParser.resolve(directory, output, camelCase(`${options.tag}Controller`), fileName)\n }\n\n return pathParser.resolve(directory, output, fileName)\n },\n }\n\n return {\n name: pluginName,\n options,\n kind: 'schema',\n api,\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 return api.resolvePath(fileName, directory, options)\n },\n resolveName(name) {\n return pascalCase(name, { delimiter: '' })\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 directory = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(directory, output))\n\n if (mode === 'directory') {\n const builder = await new TypeBuilder(oas).configure({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n fileResolver: async (name) => {\n const resolvedTypeId = await this.resolvePath({\n fileName: `${name}.ts`,\n directory,\n pluginName,\n })\n\n const root = await this.resolvePath({ fileName: ``, directory, pluginName })\n\n return getRelativePath(root, resolvedTypeId)\n },\n withJSDocs: true,\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 = await this.resolvePath({ fileName: `${this.resolveName({ name, pluginName })}.ts`, directory, 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: await 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 })\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 = await this.resolvePath({ fileName: '', directory, pluginName })\n if (!path) {\n return\n }\n\n await this.addFile({\n path,\n fileName: `${this.resolveName({ name: output, pluginName })}.ts`,\n source: await builder.print(),\n })\n }\n\n const operationGenerator = new OperationGenerator({\n oas,\n mode,\n directory,\n fileManager: this.fileManager,\n resolvePath: api.resolvePath,\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n })\n\n await operationGenerator.build()\n },\n async buildEnd() {\n await writeIndexes(this.config.root, this.config.output.path, { extensions: /\\.ts/, exclude: [/schemas/, /json/] })\n },\n }\n})\n","import { OasBuilder, pluginName } from '@kubb/swagger'\nimport type { FileResolver } from '@kubb/swagger'\nimport type { PluginContext } from '@kubb/core'\nimport { nameSorter } from '@kubb/core'\nimport { print } from '@kubb/ts-codegen'\n\nimport { ImportsGenerator, TypeGenerator } from '../generators'\n\nimport type ts from 'typescript'\nimport type { Refs } from '../generators'\n\ntype Generated = { refs: Refs; name: string; sources: ts.Node[] }\ntype Config = {\n resolveName: PluginContext['resolveName']\n fileResolver?: FileResolver\n withJSDocs?: boolean\n withImports?: boolean\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.refs)?.length < Object.keys(b.refs)?.length) {\n return -1\n }\n if (Object.keys(a.refs)?.length > Object.keys(b.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 async print(name?: string) {\n const codes: string[] = []\n\n const generated = this.items\n .filter((gen) => (name ? gen.name === name : true))\n .sort(nameSorter)\n .map((gen) => {\n const generator = new TypeGenerator(this.oas, { withJSDocs: this.config.withJSDocs, resolveName: this.config.resolveName })\n const nodes = generator.build(gen.schema, this.config.resolveName({ name: gen.name, pluginName }) || gen.name, gen.description)\n\n return {\n refs: generator.refs,\n name: gen.name,\n sources: nodes,\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 codeImports = await importsGenerator.build(generated)\n\n if (codeImports) {\n codes.unshift(print(codeImports))\n }\n }\n\n return codes.join('\\n')\n }\n}\n","/* eslint-disable no-param-reassign */\nimport ts from 'typescript'\nimport { pascalCase, camelCase } from 'change-case'\nimport uniq from 'lodash.uniq'\n\nimport type { PluginContext } from '@kubb/core'\nimport { getUniqueName, SchemaGenerator } from '@kubb/core'\nimport type { Oas, OpenAPIV3 } from '@kubb/swagger'\nimport { isReference } from '@kubb/swagger'\nimport {\n appendJSDocToNode,\n createEnumDeclaration,\n createIndexSignature,\n createIntersectionDeclaration,\n createPropertySignature,\n createTypeAliasDeclaration,\n modifier,\n} from '@kubb/ts-codegen'\n\nimport { keywordTypeNodes } from '../utils'\nimport { pluginName } from '../plugin'\n\nconst { factory } = ts\n\n// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n\n/**\n * Name is the ref name + resolved with the nameResolver\n * Key is the original name used\n */\nexport type Refs = Record<string, { name: string; key: string }>\n\ntype Options = {\n withJSDocs?: boolean\n resolveName: PluginContext['resolveName']\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 }) {\n super(options)\n\n return this\n }\n\n build(schema: OpenAPIV3.SchemaObject, name: string, description?: string) {\n const nodes: ts.Node[] = []\n const type = this.getTypeFromSchema(schema, name)\n\n if (!type) {\n return this.extraNodes\n }\n\n const node = createTypeAliasDeclaration({\n modifiers: [modifier.export],\n name,\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 factory.createUnionTypeNode([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: ts.TypeNode | null\n if (schema.enum) {\n type = this.getTypeFromSchema(schema, pascalCase(`${baseName} ${name}`, { delimiter: '' }))\n } else {\n type = this.getTypeFromSchema(schema, pascalCase(`${baseName} ${name}`, { delimiter: '' }))\n }\n\n if (!type) {\n return null\n }\n\n if (!isRequired) {\n type = factory.createUnionTypeNode([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 ],\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) {\n const { $ref } = obj\n let ref = this.refs[$ref]\n\n if (!ref) {\n const name = pascalCase(getUniqueName($ref.replace(/.+\\//, ''), this.usedAliasNames), { delimiter: '' })\n\n // eslint-disable-next-line no-multi-assign\n ref = this.refs[$ref] = {\n name: this.options.resolveName({ name, pluginName }) || name,\n key: name,\n }\n }\n\n return factory.createTypeReferenceNode(ref.name, 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, name?: string): ts.TypeNode | null {\n if (!schema) {\n return keywordTypeNodes.any\n }\n\n if (isReference(schema)) {\n return this.getRefAlias(schema)\n }\n\n if (schema.oneOf) {\n // union\n const schemaWithoutOneOf = { ...schema, oneOf: undefined }\n\n return createIntersectionDeclaration({\n nodes: [\n this.getBaseTypeFromSchema(schemaWithoutOneOf, name),\n factory.createParenthesizedType(\n factory.createUnionTypeNode(\n schema.oneOf\n .map((item) => {\n return this.getBaseTypeFromSchema(item)\n })\n .filter(Boolean) as ts.TypeNode[]\n )\n ),\n ].filter(Boolean) as ts.TypeNode[],\n })\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 return createIntersectionDeclaration({\n nodes: [\n this.getBaseTypeFromSchema(schemaWithoutAllOf, name),\n factory.createParenthesizedType(\n factory.createIntersectionTypeNode(\n schema.allOf\n .map((item) => {\n return this.getBaseTypeFromSchema(item)\n })\n .filter(Boolean) as ts.TypeNode[]\n )\n ),\n ].filter(Boolean) as ts.TypeNode[],\n })\n }\n\n if (schema.enum && name) {\n const enumName = getUniqueName(name, TypeGenerator.usedEnumNames)\n\n let enums: [key: string, value: string | number][] = uniq(schema.enum)!.map((key) => [key, key])\n\n if ('x-enumNames' in schema) {\n enums = uniq(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 })\n )\n return factory.createTypeReferenceNode(pascalCase(enumName, { delimiter: '' }), undefined)\n }\n\n if ('items' in schema) {\n // items -> array\n const node = this.getTypeFromSchema(schema.items as OpenAPIV3.SchemaObject, name)\n if (node) {\n return factory.createArrayTypeNode(node)\n }\n }\n\n if (schema.properties || schema.additionalProperties) {\n // properties -> literal type\n return this.getTypeFromProperties(schema, name)\n }\n\n if (schema.type) {\n if (schema.type === 'object') {\n if (!schema.additionalProperties && !schema.properties && schema.type === 'object') {\n return null\n }\n }\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 factory.createUnionTypeNode(\n [\n this.getBaseTypeFromSchema(\n {\n ...schema,\n type,\n },\n name\n )!,\n nullable ? factory.createLiteralTypeNode(factory.createNull()) : undefined,\n ].filter(Boolean) as 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 uniq from 'lodash.uniq'\n\nimport { Generator } from '@kubb/core'\nimport type { FileResolver } from '@kubb/swagger'\nimport { createImportDeclaration } from '@kubb/ts-codegen'\n\nimport type { Refs } from './TypeGenerator'\nimport type ts from 'typescript'\n\ntype Options = {\n fileResolver?: FileResolver\n}\nexport class ImportsGenerator extends Generator<Options> {\n async build(items: Array<{ refs: Refs; sources: ts.Node[]; name: string }>): Promise<Array<ts.ImportDeclaration> | undefined> {\n const refs = items.reduce((acc, currentValue) => {\n return {\n ...acc,\n ...currentValue.refs,\n }\n }, {} as Refs)\n\n if (Object.keys(refs).length === 0) {\n return undefined\n }\n\n // add imports based on $ref\n const importPromises = uniq(Object.keys(refs))\n .filter(($ref: string) => {\n // when using a $ref inside a type we should not repeat that import\n const { key } = refs[$ref]\n return !items.find((item) =>\n item.sources.find((node: ts.Node) => (node as ts.TypeAliasDeclaration).name?.escapedText.toString().toLowerCase() === key.toLowerCase())\n )\n })\n .map(async ($ref: string) => {\n const { name } = refs[$ref]\n\n const path = (await this.options.fileResolver?.(name)) || `./${name}`\n\n // TODO weird hacky fix\n if (path === './' || path === '.') {\n return undefined\n }\n\n return createImportDeclaration({\n name: [name],\n path: path.replace('./../', '../'),\n })\n })\n\n const nodes = await Promise.all(importPromises)\n\n return nodes.filter(Boolean) as ts.ImportDeclaration[]\n }\n}\n","import type { File, FileManager, PathMode, PluginContext } from '@kubb/core'\nimport { getRelativePath } from '@kubb/core'\nimport { OperationGenerator as Generator } from '@kubb/swagger'\nimport type { FileResolver, Oas, Operation, OperationSchemas, Resolver } from '@kubb/swagger'\n\nimport { TypeBuilder } from '../builders'\nimport { pluginName } from '../plugin'\n\nimport type { Api } from '../types'\n\ntype Options = {\n oas: Oas\n resolvePath: Api['resolvePath']\n resolveName: PluginContext['resolveName']\n mode: PathMode\n fileManager: FileManager\n directory: string\n}\n\nexport class OperationGenerator extends Generator<Options> {\n async resolve(operation: Operation): Promise<Resolver> {\n const { directory, resolvePath, resolveName } = this.options\n\n const name = resolveName({ name: operation.getOperationId(), pluginName })\n const fileName = `${name}.ts`\n const filePath = await resolvePath(fileName, directory, { tag: operation.getTags()[0]?.name })\n\n if (!filePath || !name) {\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, directory, mode, resolveName, oas } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory, { tag: operation.getTags()[0]?.name })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.response)\n .configure({ fileResolver, withJSDocs: true, resolveName })\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, directory, mode, resolveName, oas } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory, { tag: operation.getTags()[0]?.name })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .configure({ fileResolver, withJSDocs: true, resolveName })\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, directory, mode, resolveName, oas } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory, { tag: operation.getTags()[0]?.name })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .configure({ fileResolver, withJSDocs: true, resolveName })\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, directory, mode, resolveName, oas } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory, { tag: operation.getTags()[0]?.name })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.request)\n .add(schemas.response)\n .configure({ fileResolver, withJSDocs: true, resolveName })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n}\n","import { definePlugin } from './plugin'\n\nexport * from './plugin'\nexport * from './generators'\nexport * from './builders'\nexport * from './types'\nexport * from './utils'\nexport default definePlugin\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/swagger-ts",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.9",
|
|
4
4
|
"description": "Generator swagger-ts",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"!/**/__tests__/**"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@kubb/core": "1.0.0-beta.
|
|
42
|
-
"@kubb/swagger": "1.0.0-beta.
|
|
43
|
-
"@kubb/ts-codegen": "1.0.0-beta.
|
|
41
|
+
"@kubb/core": "1.0.0-beta.9",
|
|
42
|
+
"@kubb/swagger": "1.0.0-beta.9",
|
|
43
|
+
"@kubb/ts-codegen": "1.0.0-beta.9",
|
|
44
44
|
"change-case": "^4.1.2",
|
|
45
45
|
"lodash.uniq": "^4.5.0",
|
|
46
46
|
"typescript": "^5.0.3"
|
|
@@ -23,7 +23,7 @@ export class OperationGenerator extends Generator<Options> {
|
|
|
23
23
|
|
|
24
24
|
const name = resolveName({ name: operation.getOperationId(), pluginName })
|
|
25
25
|
const fileName = `${name}.ts`
|
|
26
|
-
const filePath = await resolvePath(fileName, directory)
|
|
26
|
+
const filePath = await resolvePath(fileName, directory, { tag: operation.getTags()[0]?.name })
|
|
27
27
|
|
|
28
28
|
if (!filePath || !name) {
|
|
29
29
|
throw new Error('Filepath should be defined')
|
|
@@ -47,7 +47,7 @@ export class OperationGenerator extends Generator<Options> {
|
|
|
47
47
|
|
|
48
48
|
const fileResolver: FileResolver = async (name) => {
|
|
49
49
|
// Used when a react-query type(request, response, params) has an import of a global type
|
|
50
|
-
const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory)
|
|
50
|
+
const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory, { tag: operation.getTags()[0]?.name })
|
|
51
51
|
// refs import, will always been created with the SwaggerTS plugin, our global type
|
|
52
52
|
const resolvedTypeId = await resolvePath(`${name}.ts`, directory)
|
|
53
53
|
|
|
@@ -75,7 +75,7 @@ export class OperationGenerator extends Generator<Options> {
|
|
|
75
75
|
|
|
76
76
|
const fileResolver: FileResolver = async (name) => {
|
|
77
77
|
// Used when a react-query type(request, response, params) has an import of a global type
|
|
78
|
-
const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory)
|
|
78
|
+
const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory, { tag: operation.getTags()[0]?.name })
|
|
79
79
|
// refs import, will always been created with the SwaggerTS plugin, our global type
|
|
80
80
|
const resolvedTypeId = await resolvePath(`${name}.ts`, directory)
|
|
81
81
|
|
|
@@ -104,7 +104,7 @@ export class OperationGenerator extends Generator<Options> {
|
|
|
104
104
|
|
|
105
105
|
const fileResolver: FileResolver = async (name) => {
|
|
106
106
|
// Used when a react-query type(request, response, params) has an import of a global type
|
|
107
|
-
const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory)
|
|
107
|
+
const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory, { tag: operation.getTags()[0]?.name })
|
|
108
108
|
// refs import, will always been created with the SwaggerTS plugin, our global type
|
|
109
109
|
const resolvedTypeId = await resolvePath(`${name}.ts`, directory)
|
|
110
110
|
|
|
@@ -133,7 +133,7 @@ export class OperationGenerator extends Generator<Options> {
|
|
|
133
133
|
|
|
134
134
|
const fileResolver: FileResolver = async (name) => {
|
|
135
135
|
// Used when a react-query type(request, response, params) has an import of a global type
|
|
136
|
-
const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory)
|
|
136
|
+
const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory, { tag: operation.getTags()[0]?.name })
|
|
137
137
|
// refs import, will always been created with the SwaggerTS plugin, our global type
|
|
138
138
|
const resolvedTypeId = await resolvePath(`${name}.ts`, directory)
|
|
139
139
|
|
package/src/plugin.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import pathParser from 'path'
|
|
6
6
|
|
|
7
|
-
import { pascalCase } from 'change-case'
|
|
7
|
+
import { camelCase, pascalCase } from 'change-case'
|
|
8
8
|
|
|
9
9
|
import { getRelativePath, createPlugin, getPathMode, validatePlugins } from '@kubb/core'
|
|
10
10
|
import { pluginName as swaggerPluginName } from '@kubb/swagger'
|
|
@@ -18,12 +18,19 @@ import type { Api, PluginOptions } from './types'
|
|
|
18
18
|
|
|
19
19
|
export const pluginName = 'swagger-ts' as const
|
|
20
20
|
|
|
21
|
+
// Register your plugin for maximum type safety
|
|
22
|
+
declare module '@kubb/core' {
|
|
23
|
+
interface Register {
|
|
24
|
+
['@kubb/swagger-ts']: PluginOptions['options']
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
21
28
|
export const definePlugin = createPlugin<PluginOptions>((options) => {
|
|
22
|
-
const { output = 'models' } = options
|
|
29
|
+
const { output = 'models', groupBy } = options
|
|
23
30
|
let swaggerApi: SwaggerApi
|
|
24
31
|
|
|
25
32
|
const api: Api = {
|
|
26
|
-
resolvePath(fileName, directory) {
|
|
33
|
+
resolvePath(fileName, directory, options) {
|
|
27
34
|
if (!directory) {
|
|
28
35
|
return null
|
|
29
36
|
}
|
|
@@ -38,6 +45,10 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {
|
|
|
38
45
|
return pathParser.resolve(directory, output)
|
|
39
46
|
}
|
|
40
47
|
|
|
48
|
+
if (options?.tag && groupBy === 'tag') {
|
|
49
|
+
return pathParser.resolve(directory, output, camelCase(`${options.tag}Controller`), fileName)
|
|
50
|
+
}
|
|
51
|
+
|
|
41
52
|
return pathParser.resolve(directory, output, fileName)
|
|
42
53
|
},
|
|
43
54
|
}
|
|
@@ -55,8 +66,8 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {
|
|
|
55
66
|
|
|
56
67
|
return valid
|
|
57
68
|
},
|
|
58
|
-
resolvePath(fileName, directory) {
|
|
59
|
-
return api.resolvePath(fileName, directory)
|
|
69
|
+
resolvePath(fileName, directory, options) {
|
|
70
|
+
return api.resolvePath(fileName, directory, options)
|
|
60
71
|
},
|
|
61
72
|
resolveName(name) {
|
|
62
73
|
return pascalCase(name, { delimiter: '' })
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PluginFactoryOptions } from '@kubb/core'
|
|
2
2
|
|
|
3
3
|
export type Api = {
|
|
4
|
-
resolvePath: (fileName: string, directory: string | undefined) => string | null
|
|
4
|
+
resolvePath: (fileName: string, directory: string | undefined, options?: ResolvePathOptions) => string | null
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export type Options = {
|
|
@@ -11,6 +11,13 @@ export type Options = {
|
|
|
11
11
|
* @default 'models'
|
|
12
12
|
*/
|
|
13
13
|
output?: string
|
|
14
|
+
/**
|
|
15
|
+
* Group the react-query hooks based on the provided name.
|
|
16
|
+
* Tag will group based on the operation tag inside the Swagger file
|
|
17
|
+
*/
|
|
18
|
+
groupBy?: 'tag'
|
|
14
19
|
}
|
|
15
20
|
|
|
16
|
-
export type
|
|
21
|
+
export type ResolvePathOptions = { tag?: string }
|
|
22
|
+
|
|
23
|
+
export type PluginOptions = PluginFactoryOptions<Options, false, Api, ResolvePathOptions>
|