@kubb/swagger-ts 1.15.0-canary.20231020T203015 → 1.15.0-canary.20231022T192359
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/README.md +18 -20
- package/dist/index.cjs +1 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -32
- package/dist/index.d.ts +32 -32
- package/dist/index.js +2 -5
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
@@ -1,26 +1,24 @@
|
|
1
1
|
<div align="center">
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
<!-- <img src="assets/logo.png" alt="logo" width="200" height="auto" /> -->
|
4
|
+
<h1>@kubb/swagger-ts</h1>
|
5
|
+
|
6
|
+
<p>
|
7
7
|
Swagger integration for TypeScript to generate all the different types based on an OpenAPI specification.
|
8
8
|
</p>
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
<h4>
|
9
|
+
|
10
|
+
<img src="https://raw.githubusercontent.com/kubb-project/kubb/main/assets/banner.png" alt="logo" height="auto" />
|
11
|
+
|
12
|
+
[![npm version][npm-version-src]][npm-version-href]
|
13
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
14
|
+
[![Coverage][coverage-src]][coverage-href]
|
15
|
+
[![License][license-src]][license-href]
|
16
|
+
|
17
|
+
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
18
|
+
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
19
|
+
</p>
|
20
|
+
|
21
|
+
<h4>
|
24
22
|
<a href="https://codesandbox.io/s/github/kubb-project/kubb/tree/main/examples/typescript" target="_blank">View Demo</a>
|
25
23
|
<span> · </span>
|
26
24
|
<a href="https://kubb.dev/" target="_blank">Documentation</a>
|
@@ -44,4 +42,4 @@
|
|
44
42
|
[minified-src]: https://img.shields.io/bundlephobia/min/@kubb/swagger-ts?style=flat&colorA=18181B&colorB=f58517
|
45
43
|
[minified-href]: https://www.npmjs.com/package/@kubb/swagger-ts
|
46
44
|
[coverage-src]: https://img.shields.io/codecov/c/github/kubb-project/kubb?style=flat&colorA=18181B&colorB=f58517
|
47
|
-
[coverage-href]: https://www.npmjs.com/package/@kubb/swagger-ts
|
45
|
+
[coverage-href]: https://www.npmjs.com/package/@kubb/swagger-ts
|
package/dist/index.cjs
CHANGED
@@ -585,10 +585,7 @@ var definePlugin = core.createPlugin((options) => {
|
|
585
585
|
await core.timeout(100);
|
586
586
|
}
|
587
587
|
const root = pathParser__default.default.resolve(this.config.root, this.config.output.path);
|
588
|
-
|
589
|
-
if (files) {
|
590
|
-
await this.addFile(...files);
|
591
|
-
}
|
588
|
+
await this.fileManager.addIndexes(root, ".ts");
|
592
589
|
}
|
593
590
|
};
|
594
591
|
});
|
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/utils/resolve.ts","../src/generators/OperationGenerator.ts","../src/hooks/useResolve.ts","../src/index.ts"],"names":["getRelativePath","camelCase","ts","factory","node","resolve","options","root"],"mappings":";AAAA,OAAO,gBAAgB;AAEvB,SAAS,cAAc,oBAAoB,YAAY,aAAa,mBAAAA,kBAAiB,gBAAgB,eAAe;AACpH,SAAS,cAAc,yBAAyB;AAEhD,SAAS,aAAAC,YAAW,yBAAyB,YAAY,gCAAgC;;;ACJzF,SAAS,cAAc,kBAAkB;AACzC,SAAS,yBAAyB,aAAa;AAC/C,SAAS,kBAAkB,kBAAkB;;;ACH7C,SAAS,eAAe,uBAAuB;AAC/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA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,qBAAqB,IAAI;AAAA,QAC7B;AAAA,UACE;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,QACA;AAAA,UACE;AAAA,UACA,eAAe,KAAK;AAAA,UACpB,aAAa,cAAc,IAAI;AAAA,UAC/B;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAEA,YAAM,QAAQ,MAAM,mBAAmB,MAAM;AAC7C,YAAM,KAAK,QAAQ,GAAG,KAAK;AAAA,IAC7B;AAAA,IACA,MAAM,WAAW;AACf,UAAI,KAAK,OAAO,OAAO,UAAU,OAAO;AACtC;AAAA,MACF;AAEA,aAAO,KAAK,YAAY,aAAa;AACnC,cAAM,QAAQ,GAAG;AAAA,MACnB;AAEA,YAAM,OAAO,WAAW,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,IAAI;AACzE,YAAM,QAAQ,MAAM,WAAW,MAAM,EAAE,YAAY,QAAQ,SAAS,CAAC,WAAW,MAAM,EAAE,CAAC;AAEzF,UAAI,OAAO;AACT,cAAM,KAAK,QAAQ,GAAG,KAAK;AAAA,MAC7B;AAAA,IACF;AAAA,EACF;AACF,CAAC;;;AMnMD,SAAS,cAAc,yBAAyB;AAQzC,SAAS,WAAW,QAAe,CAAC,GAAa;AACtD,SAAO,kBAAkB,EAAE,YAAY,GAAG,MAAM,CAAC;AACnD;;;ACAA,IAAO,cAAQ","sourcesContent":["import pathParser from 'node:path'\n\nimport { createPlugin, getDependedPlugins, getIndexes, getPathMode, getRelativePath, renderTemplate, timeout } from '@kubb/core'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\n\nimport { camelCase, camelCaseTransformMerge, pascalCase, pascalCaseTransformMerge } from 'change-case'\n\nimport { TypeBuilder } from './builders/index.ts'\nimport { OperationGenerator } from './generators/index.ts'\n\nimport type { OpenAPIV3, PluginOptions as SwaggerPluginOptions } from '@kubb/swagger'\nimport type { PluginOptions } from './types.ts'\n\nexport const pluginName: PluginOptions['name'] = 'swagger-ts' as const\n\nexport const definePlugin = createPlugin<PluginOptions>((options) => {\n const {\n output = 'types',\n groupBy,\n skipBy = [],\n overrideBy = [],\n enumType = 'asConst',\n dateType = 'string',\n optionalType = 'questionToken',\n transformers = {},\n } = options\n const template = groupBy?.output ? groupBy.output : `${output}/{{tag}}Controller`\n let pluginsOptions: [SwaggerPluginOptions]\n\n return {\n name: pluginName,\n options,\n kind: 'schema',\n validate(plugins) {\n pluginsOptions = getDependedPlugins<[SwaggerPluginOptions]>(plugins, [swaggerPluginName])\n\n return true\n },\n resolvePath(baseName, directory, options) {\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(root, output))\n\n if (mode === 'file') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return pathParser.resolve(root, output)\n }\n\n if (options?.tag && groupBy?.type === 'tag') {\n const tag = camelCase(options.tag, { delimiter: '', transform: camelCaseTransformMerge })\n\n return pathParser.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return pathParser.resolve(root, output, baseName)\n },\n resolveName(name) {\n const resolvedName = pascalCase(name, { delimiter: '', stripRegexp: /[^A-Z0-9$]/gi, transform: pascalCaseTransformMerge })\n\n return transformers?.name?.(resolvedName) || resolvedName\n },\n async writeFile(source, path) {\n if (!path.endsWith('.ts') || !source) {\n return\n }\n\n await this.fileManager.write(source, path)\n },\n async buildStart() {\n const [swaggerPlugin] = pluginsOptions\n\n const oas = await swaggerPlugin.api.getOas()\n\n const schemas = await swaggerPlugin.api.getSchemas()\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(root, output))\n\n if (mode === 'directory') {\n const builder = await new TypeBuilder({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n fileResolver: (name) => {\n const resolvedTypeId = this.resolvePath({\n baseName: `${name}.ts`,\n pluginName,\n })\n\n const root = this.resolvePath({ baseName: ``, pluginName })\n\n return getRelativePath(root, resolvedTypeId)\n },\n withJSDocs: true,\n enumType,\n dateType,\n optionalType,\n }).configure()\n Object.entries(schemas).forEach(([name, schema]: [string, OpenAPIV3.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const mapFolderSchema = async ([name]: [string, OpenAPIV3.SchemaObject]) => {\n const path = this.resolvePath({ baseName: `${this.resolveName({ name, pluginName })}.ts`, pluginName })\n\n if (!path) {\n return null\n }\n\n return this.addFile({\n path,\n baseName: `${this.resolveName({ name, pluginName })}.ts`,\n source: builder.print(name),\n meta: {\n pluginName,\n },\n })\n }\n\n const promises = Object.entries(schemas).map(mapFolderSchema)\n\n await Promise.all(promises)\n }\n\n if (mode === 'file') {\n // outside the loop because we need to add files to just one instance to have the correct sorting, see refsSorter\n const builder = new TypeBuilder({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n withJSDocs: true,\n enumType,\n dateType,\n optionalType,\n }).configure()\n Object.entries(schemas).forEach(([name, schema]: [string, OpenAPIV3.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const path = this.resolvePath({ baseName: '', pluginName })\n if (!path) {\n return\n }\n\n await this.addFile({\n path,\n baseName: `${this.resolveName({ name: output, pluginName })}.ts`,\n source: builder.print(),\n meta: {\n pluginName,\n },\n })\n }\n\n const operationGenerator = new OperationGenerator(\n {\n mode,\n enumType,\n dateType,\n optionalType,\n },\n {\n oas,\n pluginManager: this.pluginManager,\n contentType: swaggerPlugin.api.contentType,\n skipBy,\n overrideBy,\n },\n )\n\n const files = await operationGenerator.build()\n await this.addFile(...files)\n },\n async buildEnd() {\n if (this.config.output.write === false) {\n return\n }\n\n while (this.fileManager.isExecuting) {\n await timeout(100)\n }\n\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const files = await getIndexes(root, { extensions: /\\.ts/, exclude: [/schemas/, /json/] })\n\n if (files) {\n await this.addFile(...files)\n }\n },\n }\n})\n","/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { combineCodes, nameSorter } from '@kubb/core'\nimport { createImportDeclaration, print } from '@kubb/parser'\nimport { ImportsGenerator, OasBuilder } from '@kubb/swagger'\n\nimport { TypeGenerator } from '../generators/TypeGenerator.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { FileResolver, Refs } from '@kubb/swagger'\nimport type ts from 'typescript'\n\ntype Generated = { import: { refs: Refs; name: string }; sources: ts.Node[] }\ntype Options = {\n resolveName: PluginContext['resolveName']\n fileResolver?: FileResolver\n withJSDocs?: boolean\n withImports?: boolean\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n dateType: 'string' | 'date'\n optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'\n}\n\n// TODO create another function that sort based on the refs(first the ones without refs)\nfunction refsSorter(a: Generated, b: Generated) {\n if (Object.keys(a.import.refs)?.length < Object.keys(b.import.refs)?.length) {\n return -1\n }\n if (Object.keys(a.import.refs)?.length > Object.keys(b.import.refs)?.length) {\n return 1\n }\n return 0\n}\n\nexport class TypeBuilder extends OasBuilder<Options, never> {\n configure(options?: Options) {\n if (options) {\n this.options = options\n }\n\n if (this.options.fileResolver) {\n this.options.withImports = true\n }\n\n return this\n }\n\n print(name?: string): string {\n const codes: string[] = []\n\n const generated = this.items\n .filter((operationSchema) => (name ? operationSchema.name === name : true))\n .sort(nameSorter)\n .map((operationSchema) => {\n const generator = new TypeGenerator({\n withJSDocs: this.options.withJSDocs,\n resolveName: this.options.resolveName,\n enumType: this.options.enumType,\n dateType: this.options.dateType,\n optionalType: this.options.optionalType,\n })\n const sources = generator.build({\n schema: operationSchema.schema,\n baseName: operationSchema.name,\n description: operationSchema.description,\n keysToOmit: operationSchema.keysToOmit,\n })\n\n return {\n import: {\n refs: generator.refs,\n name: operationSchema.name,\n },\n sources,\n }\n })\n .sort(refsSorter)\n\n generated.forEach((item) => {\n codes.push(print(item.sources))\n })\n\n if (this.options.withImports) {\n const importsGenerator = new ImportsGenerator({ fileResolver: this.options.fileResolver })\n const importMeta = importsGenerator.build(generated.map((item) => item.import))\n\n if (importMeta) {\n const nodes = importMeta.map((item) => {\n return createImportDeclaration({\n name: [{ propertyName: item.ref.propertyName }],\n path: item.path,\n isTypeOnly: true,\n })\n })\n\n codes.unshift(print(nodes))\n }\n }\n\n return combineCodes(codes)\n }\n}\n","import { getUniqueName, SchemaGenerator } from '@kubb/core'\nimport {\n appendJSDocToNode,\n createEnumDeclaration,\n createIndexSignature,\n createIntersectionDeclaration,\n createOmitDeclaration,\n createPropertySignature,\n createTupleDeclaration,\n createTypeAliasDeclaration,\n createUnionDeclaration,\n modifiers,\n} from '@kubb/parser'\nimport { isReference } from '@kubb/swagger'\n\nimport { camelCase } from 'change-case'\nimport ts from 'typescript'\n\nimport { pluginName } from '../plugin.ts'\nimport { keywordTypeNodes } from '../utils/index.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { ArrayTwoOrMore } from '@kubb/parser'\nimport type { OpenAPIV3, Refs } from '@kubb/swagger'\nimport type { Options as CaseOptions } from 'change-case'\n\nconst { factory } = ts\n\n// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n\ntype Options = {\n withJSDocs?: boolean\n resolveName: PluginContext['resolveName']\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n dateType: 'string' | 'date'\n optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'\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 caseOptions: CaseOptions = {\n delimiter: '',\n stripRegexp: /[^A-Z0-9$]/gi,\n }\n\n constructor(\n options: Options = { withJSDocs: true, resolveName: ({ name }) => name, enumType: 'asConst', dateType: 'string', optionalType: 'questionToken' },\n ) {\n super(options)\n\n return this\n }\n\n build({\n schema,\n baseName,\n description,\n keysToOmit,\n }: {\n schema: OpenAPIV3.SchemaObject\n baseName: string\n description?: string\n keysToOmit?: string[]\n }): ts.Node[] {\n const nodes: ts.Node[] = []\n const type = this.#getTypeFromSchema(schema, baseName)\n\n if (!type) {\n return this.extraNodes\n }\n\n const node = createTypeAliasDeclaration({\n modifiers: [modifiers.export],\n name: this.options.resolveName({ name: baseName, pluginName }) || baseName,\n type: keysToOmit?.length ? createOmitDeclaration({ keys: keysToOmit, type, nonNullable: true }) : 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 #getTypeFromSchema(schema?: OpenAPIV3.SchemaObject, name?: string): ts.TypeNode | null {\n const type = this.#getBaseTypeFromSchema(schema, name)\n\n if (!type) {\n return null\n }\n\n if (schema && !schema.nullable) {\n return type\n }\n\n return createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] })\n }\n\n /**\n * Recursively creates a type literal with the given props.\n */\n #getTypeFromProperties(baseSchema?: OpenAPIV3.SchemaObject, baseName?: string) {\n const { optionalType } = this.options\n const properties = baseSchema?.properties || {}\n const required = baseSchema?.required\n const additionalProperties = baseSchema?.additionalProperties\n\n const members: Array<ts.TypeElement | null> = Object.keys(properties).map((name) => {\n const schema = properties[name] as OpenAPIV3.SchemaObject\n\n const isRequired = required && required.includes(name)\n let type = this.#getTypeFromSchema(schema, this.options.resolveName({ name: `${baseName || ''} ${name}`, pluginName }))\n\n if (!type) {\n return null\n }\n\n if (!isRequired && ['undefined', 'questionTokenAndUndefined'].includes(optionalType)) {\n type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] })\n }\n const propertySignature = createPropertySignature({\n questionToken: ['questionToken', 'questionTokenAndUndefined'].includes(optionalType) && !isRequired,\n name,\n type: type as ts.TypeNode,\n readOnly: schema.readOnly,\n })\n if (this.options.withJSDocs) {\n return appendJSDocToNode({\n node: propertySignature,\n comments: [\n schema.description ? `@description ${schema.description}` : undefined,\n schema.type ? `@type ${schema.type}${isRequired ? '' : ' | undefined'} ${schema.format || ''}` : undefined,\n schema.example ? `@example ${schema.example as string}` : undefined,\n schema.deprecated ? `@deprecated` : undefined,\n schema.default !== undefined && typeof schema.default === 'string' ? `@default '${schema.default}'` : undefined,\n schema.default !== undefined && typeof schema.default !== 'string' ? `@default ${schema.default as string}` : undefined,\n ].filter(Boolean),\n })\n }\n\n return propertySignature\n })\n if (additionalProperties) {\n const type = additionalProperties === true ? keywordTypeNodes.any : this.#getTypeFromSchema(additionalProperties as OpenAPIV3.SchemaObject)\n\n if (type) {\n members.push(createIndexSignature(type))\n }\n }\n return factory.createTypeLiteralNode(members.filter(Boolean))\n }\n\n /**\n * Create a type alias for the schema referenced by the given ReferenceObject\n */\n #getRefAlias(obj: OpenAPIV3.ReferenceObject, baseName?: string) {\n const { $ref } = obj\n let ref = this.refs[$ref]\n\n if (ref) {\n return factory.createTypeReferenceNode(ref.propertyName, undefined)\n }\n\n const originalName = getUniqueName($ref.replace(/.+\\//, ''), this.usedAliasNames)\n const propertyName = this.options.resolveName({ name: originalName, pluginName }) || originalName\n\n ref = this.refs[$ref] = {\n propertyName,\n originalName,\n }\n\n return factory.createTypeReferenceNode(ref.propertyName, undefined)\n }\n\n /**\n * This is the very core of the OpenAPI to TS conversion - it takes a\n * schema and returns the appropriate type.\n */\n #getBaseTypeFromSchema(schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined, baseName?: string): ts.TypeNode | null {\n if (!schema) {\n return keywordTypeNodes.any\n }\n\n if (isReference(schema)) {\n return this.#getRefAlias(schema, baseName)\n }\n\n if (schema.oneOf) {\n // union\n const schemaWithoutOneOf = { ...schema, oneOf: undefined }\n\n const union = createUnionDeclaration({\n withParentheses: true,\n nodes: schema.oneOf\n .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {\n return this.#getBaseTypeFromSchema(item)\n })\n .filter((item) => {\n return item && item !== keywordTypeNodes.any\n }) as ArrayTwoOrMore<ts.TypeNode>,\n })\n\n if (schemaWithoutOneOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n return union\n }\n\n if (schema.anyOf) {\n const schemaWithoutAnyOf = { ...schema, anyOf: undefined }\n\n const union = createUnionDeclaration({\n withParentheses: true,\n nodes: schema.anyOf\n .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {\n return this.#getBaseTypeFromSchema(item)\n })\n .filter((item) => {\n return item && item !== keywordTypeNodes.any\n }) as ArrayTwoOrMore<ts.TypeNode>,\n })\n\n if (schemaWithoutAnyOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutAnyOf, baseName), union].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n return union\n }\n if (schema.allOf) {\n // intersection/add\n const schemaWithoutAllOf = { ...schema, allOf: undefined }\n\n const and = createIntersectionDeclaration({\n withParentheses: true,\n nodes: schema.allOf\n .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {\n return this.#getBaseTypeFromSchema(item)\n })\n .filter((item) => {\n return item && item !== keywordTypeNodes.any\n }) as ArrayTwoOrMore<ts.TypeNode>,\n })\n\n if (schemaWithoutAllOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n return and\n }\n\n /**\n * Enum will be defined outside the baseType(hints the baseName check)\n */\n if (schema.enum && baseName) {\n const enumName = getUniqueName(baseName, TypeGenerator.usedEnumNames)\n\n let enums: [key: string, value: string | number][] = [...new Set(schema.enum)].map((key) => [key, key])\n\n if ('x-enumNames' in schema) {\n enums = [...new Set(schema['x-enumNames'] as string[])].map((key: string, index) => {\n return [key, schema.enum?.[index]]\n })\n }\n\n this.extraNodes.push(\n ...createEnumDeclaration({\n name: camelCase(enumName, this.caseOptions),\n typeName: this.options.resolveName({ name: enumName, pluginName }),\n enums,\n type: this.options.enumType,\n }),\n )\n return factory.createTypeReferenceNode(this.options.resolveName({ name: enumName, pluginName }), undefined)\n }\n\n if (schema.enum) {\n return createUnionDeclaration({\n nodes: schema.enum.map((name: string) => {\n return factory.createLiteralTypeNode(typeof name === 'number' ? factory.createNumericLiteral(name) : factory.createStringLiteral(`${name}`))\n }) as unknown as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n if ('items' in schema) {\n // items -> array\n const node = this.#getTypeFromSchema(schema.items as OpenAPIV3.SchemaObject, baseName)\n if (node) {\n return factory.createArrayTypeNode(node)\n }\n }\n /**\n * OpenAPI 3.1\n * @link https://json-schema.org/understanding-json-schema/reference/array.html#tuple-validation\n */\n if ('prefixItems' in schema) {\n const prefixItems = schema.prefixItems as OpenAPIV3.SchemaObject[]\n\n return createTupleDeclaration({\n nodes: prefixItems.map((item) => {\n // no baseType so we can fall back on an union when using enum\n return this.#getBaseTypeFromSchema(item, undefined)\n }) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n if (schema.properties || schema.additionalProperties) {\n // properties -> literal type\n return this.#getTypeFromProperties(schema, baseName)\n }\n\n if (schema.type) {\n if (Array.isArray(schema.type)) {\n // OPENAPI v3.1.0: https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0\n const [type, nullable] = schema.type as Array<OpenAPIV3.NonArraySchemaObjectType>\n\n return createUnionDeclaration({\n nodes: [\n this.#getBaseTypeFromSchema(\n {\n ...schema,\n type,\n },\n baseName,\n ),\n nullable ? factory.createLiteralTypeNode(factory.createNull()) : undefined,\n ].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n if (this.options.dateType === 'date' && ['date', 'date-time'].some((item) => item === schema.format)) {\n return factory.createTypeReferenceNode(factory.createIdentifier('Date'))\n }\n\n // string, boolean, null, number\n if (schema.type in 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 { resolve as swaggerResolve } from '@kubb/swagger'\n\nimport { pluginName } from '../plugin.ts'\n\nimport type { ResolveProps, Resolver } from '@kubb/swagger'\n\ntype Props = ResolveProps & { pluginName?: never }\n\nexport function resolve(props: Props): Resolver {\n return swaggerResolve({ ...props, pluginName })\n}\n","import { getRelativePath } from '@kubb/core'\nimport { OperationGenerator as Generator, resolve } from '@kubb/swagger'\n\nimport { TypeBuilder } from '../builders/index.ts'\nimport { pluginName } from '../plugin.ts'\n\nimport type { KubbFile } from '@kubb/core'\nimport type { FileResolver, Operation, OperationSchemas, Resolver } from '@kubb/swagger'\nimport type { FileMeta, Options as PluginOptions } from '../types.ts'\n\ntype Options = {\n mode: KubbFile.Mode\n enumType: NonNullable<PluginOptions['enumType']>\n dateType: NonNullable<PluginOptions['dateType']>\n optionalType: NonNullable<PluginOptions['optionalType']>\n}\n\nexport class OperationGenerator extends Generator<Options> {\n resolve(operation: Operation): Resolver {\n const { pluginManager } = this.context\n\n return resolve({\n operation,\n resolveName: pluginManager.resolveName,\n resolvePath: pluginManager.resolvePath,\n pluginName,\n })\n }\n\n async all(): Promise<KubbFile.File | null> {\n return null\n }\n\n async get(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n const { mode, enumType, dateType, optionalType } = options\n const { pluginManager } = this.context\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const root = pluginManager.resolvePath({ baseName: type.baseName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = pluginManager.resolvePath({\n baseName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder({\n fileResolver: mode === 'file' ? undefined : fileResolver,\n withJSDocs: true,\n resolveName: pluginManager.resolveName,\n enumType,\n optionalType,\n dateType,\n })\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.headerParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure()\n .print()\n\n return {\n path: type.path,\n baseName: type.baseName,\n source,\n meta: {\n pluginName,\n tag: operation.getTags()[0]?.name,\n },\n }\n }\n\n async post(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n const { mode, enumType, dateType, optionalType } = options\n const { pluginManager } = this.context\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const root = pluginManager.resolvePath({ baseName: type.baseName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = pluginManager.resolvePath({\n baseName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder({\n fileResolver: mode === 'file' ? undefined : fileResolver,\n withJSDocs: true,\n resolveName: pluginManager.resolveName,\n enumType,\n optionalType,\n dateType,\n })\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.headerParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure()\n .print()\n\n return {\n path: type.path,\n baseName: type.baseName,\n source,\n meta: {\n pluginName,\n tag: operation.getTags()[0]?.name,\n },\n }\n }\n\n async put(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n async patch(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n async delete(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n}\n","import { useResolve as useResolveSwagger } from '@kubb/swagger'\n\nimport { pluginName } from '../plugin.ts'\n\nimport type { Resolver, UseResolveProps } from '@kubb/swagger'\n\ntype Props = UseResolveProps & { pluginName?: never }\n\nexport function useResolve(props: Props = {}): Resolver {\n return useResolveSwagger({ pluginName, ...props })\n}\n","import { definePlugin } from './plugin.ts'\n\nexport * from './plugin.ts'\nexport * from './types.ts'\n\nexport * from './generators/index.ts'\nexport * from './builders/index.ts'\nexport * from './utils/index.ts'\nexport * from './hooks/index.ts'\n\nexport default definePlugin\n"]}
|
1
|
+
{"version":3,"sources":["../src/plugin.ts","../src/builders/TypeBuilder.ts","../src/generators/TypeGenerator.ts","../src/utils/keywordTypeNodes.ts","../src/utils/resolve.ts","../src/generators/OperationGenerator.ts","../src/hooks/useResolve.ts","../src/index.ts"],"names":["getRelativePath","camelCase","ts","factory","node","resolve","options","root"],"mappings":";AAAA,OAAO,gBAAgB;AAEvB,SAAS,cAAc,oBAAoB,aAAa,mBAAAA,kBAAiB,gBAAgB,eAAe;AACxG,SAAS,cAAc,yBAAyB;AAEhD,SAAS,aAAAC,YAAW,yBAAyB,YAAY,gCAAgC;;;ACJzF,SAAS,cAAc,kBAAkB;AACzC,SAAS,yBAAyB,aAAa;AAC/C,SAAS,kBAAkB,kBAAkB;;;ACH7C,SAAS,eAAe,uBAAuB;AAC/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAE5B,SAAS,iBAAiB;AAC1B,OAAOC,SAAQ;;;AChBf,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;;;ACbA,SAAS,WAAW,sBAAsB;AAQnC,SAAS,QAAQ,OAAwB;AAC9C,SAAO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AAG,MAAM,CAAC;AACnD;;;ACDA,IAAO,cAAQ","sourcesContent":["import pathParser from 'node:path'\n\nimport { createPlugin, getDependedPlugins, getPathMode, getRelativePath, renderTemplate, timeout } from '@kubb/core'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\n\nimport { camelCase, camelCaseTransformMerge, pascalCase, pascalCaseTransformMerge } from 'change-case'\n\nimport { TypeBuilder } from './builders/index.ts'\nimport { OperationGenerator } from './generators/index.ts'\n\nimport type { OpenAPIV3, PluginOptions as SwaggerPluginOptions } from '@kubb/swagger'\nimport type { PluginOptions } from './types.ts'\n\nexport const pluginName: PluginOptions['name'] = 'swagger-ts' as const\n\nexport const definePlugin = createPlugin<PluginOptions>((options) => {\n const {\n output = 'types',\n groupBy,\n skipBy = [],\n overrideBy = [],\n enumType = 'asConst',\n dateType = 'string',\n optionalType = 'questionToken',\n transformers = {},\n } = options\n const template = groupBy?.output ? groupBy.output : `${output}/{{tag}}Controller`\n let pluginsOptions: [SwaggerPluginOptions]\n\n return {\n name: pluginName,\n options,\n kind: 'schema',\n validate(plugins) {\n pluginsOptions = getDependedPlugins<SwaggerPluginOptions>(plugins, [swaggerPluginName])\n\n return true\n },\n resolvePath(baseName, directory, options) {\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(root, output))\n\n if (mode === 'file') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return pathParser.resolve(root, output)\n }\n\n if (options?.tag && groupBy?.type === 'tag') {\n const tag = camelCase(options.tag, { delimiter: '', transform: camelCaseTransformMerge })\n\n return pathParser.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return pathParser.resolve(root, output, baseName)\n },\n resolveName(name) {\n const resolvedName = pascalCase(name, { delimiter: '', stripRegexp: /[^A-Z0-9$]/gi, transform: pascalCaseTransformMerge })\n\n return transformers?.name?.(resolvedName) || resolvedName\n },\n async writeFile(source, path) {\n if (!path.endsWith('.ts') || !source) {\n return\n }\n\n await this.fileManager.write(source, path)\n },\n async buildStart() {\n const [swaggerPlugin] = pluginsOptions\n\n const oas = await swaggerPlugin.api.getOas()\n\n const schemas = await swaggerPlugin.api.getSchemas()\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(root, output))\n\n if (mode === 'directory') {\n const builder = await new TypeBuilder({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n fileResolver: (name) => {\n const resolvedTypeId = this.resolvePath({\n baseName: `${name}.ts`,\n pluginName,\n })\n\n const root = this.resolvePath({ baseName: ``, pluginName })\n\n return getRelativePath(root, resolvedTypeId)\n },\n withJSDocs: true,\n enumType,\n dateType,\n optionalType,\n }).configure()\n Object.entries(schemas).forEach(([name, schema]: [string, OpenAPIV3.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const mapFolderSchema = async ([name]: [string, OpenAPIV3.SchemaObject]) => {\n const path = this.resolvePath({ baseName: `${this.resolveName({ name, pluginName })}.ts`, pluginName })\n\n if (!path) {\n return null\n }\n\n return this.addFile({\n path,\n baseName: `${this.resolveName({ name, pluginName })}.ts`,\n source: builder.print(name),\n meta: {\n pluginName,\n },\n })\n }\n\n const promises = Object.entries(schemas).map(mapFolderSchema)\n\n await Promise.all(promises)\n }\n\n if (mode === 'file') {\n // outside the loop because we need to add files to just one instance to have the correct sorting, see refsSorter\n const builder = new TypeBuilder({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n withJSDocs: true,\n enumType,\n dateType,\n optionalType,\n }).configure()\n Object.entries(schemas).forEach(([name, schema]: [string, OpenAPIV3.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const path = this.resolvePath({ baseName: '', pluginName })\n if (!path) {\n return\n }\n\n await this.addFile({\n path,\n baseName: `${this.resolveName({ name: output, pluginName })}.ts`,\n source: builder.print(),\n meta: {\n pluginName,\n },\n })\n }\n\n const operationGenerator = new OperationGenerator(\n {\n mode,\n enumType,\n dateType,\n optionalType,\n },\n {\n oas,\n pluginManager: this.pluginManager,\n contentType: swaggerPlugin.api.contentType,\n skipBy,\n overrideBy,\n },\n )\n\n const files = await operationGenerator.build()\n await this.addFile(...files)\n },\n async buildEnd() {\n if (this.config.output.write === false) {\n return\n }\n\n while (this.fileManager.isExecuting) {\n await timeout(100)\n }\n\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n\n await this.fileManager.addIndexes(root, '.ts')\n },\n }\n})\n","/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { combineCodes, nameSorter } from '@kubb/core'\nimport { createImportDeclaration, print } from '@kubb/parser'\nimport { ImportsGenerator, OasBuilder } from '@kubb/swagger'\n\nimport { TypeGenerator } from '../generators/TypeGenerator.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { FileResolver, Refs } from '@kubb/swagger'\nimport type ts from 'typescript'\n\ntype Generated = { import: { refs: Refs; name: string }; sources: ts.Node[] }\ntype Options = {\n resolveName: PluginContext['resolveName']\n fileResolver?: FileResolver\n withJSDocs?: boolean\n withImports?: boolean\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n dateType: 'string' | 'date'\n optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'\n}\n\n// TODO create another function that sort based on the refs(first the ones without refs)\nfunction refsSorter(a: Generated, b: Generated) {\n if (Object.keys(a.import.refs)?.length < Object.keys(b.import.refs)?.length) {\n return -1\n }\n if (Object.keys(a.import.refs)?.length > Object.keys(b.import.refs)?.length) {\n return 1\n }\n return 0\n}\n\nexport class TypeBuilder extends OasBuilder<Options, never> {\n configure(options?: Options) {\n if (options) {\n this.options = options\n }\n\n if (this.options.fileResolver) {\n this.options.withImports = true\n }\n\n return this\n }\n\n print(name?: string): string {\n const codes: string[] = []\n\n const generated = this.items\n .filter((operationSchema) => (name ? operationSchema.name === name : true))\n .sort(nameSorter)\n .map((operationSchema) => {\n const generator = new TypeGenerator({\n withJSDocs: this.options.withJSDocs,\n resolveName: this.options.resolveName,\n enumType: this.options.enumType,\n dateType: this.options.dateType,\n optionalType: this.options.optionalType,\n })\n const sources = generator.build({\n schema: operationSchema.schema,\n baseName: operationSchema.name,\n description: operationSchema.description,\n keysToOmit: operationSchema.keysToOmit,\n })\n\n return {\n import: {\n refs: generator.refs,\n name: operationSchema.name,\n },\n sources,\n }\n })\n .sort(refsSorter)\n\n generated.forEach((item) => {\n codes.push(print(item.sources))\n })\n\n if (this.options.withImports) {\n const importsGenerator = new ImportsGenerator({ fileResolver: this.options.fileResolver })\n const importMeta = importsGenerator.build(generated.map((item) => item.import))\n\n if (importMeta) {\n const nodes = importMeta.map((item) => {\n return createImportDeclaration({\n name: [{ propertyName: item.ref.propertyName }],\n path: item.path,\n isTypeOnly: true,\n })\n })\n\n codes.unshift(print(nodes))\n }\n }\n\n return combineCodes(codes)\n }\n}\n","import { getUniqueName, SchemaGenerator } from '@kubb/core'\nimport {\n appendJSDocToNode,\n createEnumDeclaration,\n createIndexSignature,\n createIntersectionDeclaration,\n createOmitDeclaration,\n createPropertySignature,\n createTupleDeclaration,\n createTypeAliasDeclaration,\n createUnionDeclaration,\n modifiers,\n} from '@kubb/parser'\nimport { isReference } from '@kubb/swagger'\n\nimport { camelCase } from 'change-case'\nimport ts from 'typescript'\n\nimport { pluginName } from '../plugin.ts'\nimport { keywordTypeNodes } from '../utils/index.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { ArrayTwoOrMore } from '@kubb/parser'\nimport type { OpenAPIV3, Refs } from '@kubb/swagger'\nimport type { Options as CaseOptions } from 'change-case'\n\nconst { factory } = ts\n\n// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n\ntype Options = {\n withJSDocs?: boolean\n resolveName: PluginContext['resolveName']\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n dateType: 'string' | 'date'\n optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'\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 caseOptions: CaseOptions = {\n delimiter: '',\n stripRegexp: /[^A-Z0-9$]/gi,\n }\n\n constructor(\n options: Options = { withJSDocs: true, resolveName: ({ name }) => name, enumType: 'asConst', dateType: 'string', optionalType: 'questionToken' },\n ) {\n super(options)\n\n return this\n }\n\n build({\n schema,\n baseName,\n description,\n keysToOmit,\n }: {\n schema: OpenAPIV3.SchemaObject\n baseName: string\n description?: string\n keysToOmit?: string[]\n }): ts.Node[] {\n const nodes: ts.Node[] = []\n const type = this.#getTypeFromSchema(schema, baseName)\n\n if (!type) {\n return this.extraNodes\n }\n\n const node = createTypeAliasDeclaration({\n modifiers: [modifiers.export],\n name: this.options.resolveName({ name: baseName, pluginName }) || baseName,\n type: keysToOmit?.length ? createOmitDeclaration({ keys: keysToOmit, type, nonNullable: true }) : 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 #getTypeFromSchema(schema?: OpenAPIV3.SchemaObject, name?: string): ts.TypeNode | null {\n const type = this.#getBaseTypeFromSchema(schema, name)\n\n if (!type) {\n return null\n }\n\n if (schema && !schema.nullable) {\n return type\n }\n\n return createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] })\n }\n\n /**\n * Recursively creates a type literal with the given props.\n */\n #getTypeFromProperties(baseSchema?: OpenAPIV3.SchemaObject, baseName?: string) {\n const { optionalType } = this.options\n const properties = baseSchema?.properties || {}\n const required = baseSchema?.required\n const additionalProperties = baseSchema?.additionalProperties\n\n const members: Array<ts.TypeElement | null> = Object.keys(properties).map((name) => {\n const schema = properties[name] as OpenAPIV3.SchemaObject\n\n const isRequired = required && required.includes(name)\n let type = this.#getTypeFromSchema(schema, this.options.resolveName({ name: `${baseName || ''} ${name}`, pluginName }))\n\n if (!type) {\n return null\n }\n\n if (!isRequired && ['undefined', 'questionTokenAndUndefined'].includes(optionalType)) {\n type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] })\n }\n const propertySignature = createPropertySignature({\n questionToken: ['questionToken', 'questionTokenAndUndefined'].includes(optionalType) && !isRequired,\n name,\n type: type as ts.TypeNode,\n readOnly: schema.readOnly,\n })\n if (this.options.withJSDocs) {\n return appendJSDocToNode({\n node: propertySignature,\n comments: [\n schema.description ? `@description ${schema.description}` : undefined,\n schema.type ? `@type ${schema.type}${isRequired ? '' : ' | undefined'} ${schema.format || ''}` : undefined,\n schema.example ? `@example ${schema.example as string}` : undefined,\n schema.deprecated ? `@deprecated` : undefined,\n schema.default !== undefined && typeof schema.default === 'string' ? `@default '${schema.default}'` : undefined,\n schema.default !== undefined && typeof schema.default !== 'string' ? `@default ${schema.default as string}` : undefined,\n ].filter(Boolean),\n })\n }\n\n return propertySignature\n })\n if (additionalProperties) {\n const type = additionalProperties === true ? keywordTypeNodes.any : this.#getTypeFromSchema(additionalProperties as OpenAPIV3.SchemaObject)\n\n if (type) {\n members.push(createIndexSignature(type))\n }\n }\n return factory.createTypeLiteralNode(members.filter(Boolean))\n }\n\n /**\n * Create a type alias for the schema referenced by the given ReferenceObject\n */\n #getRefAlias(obj: OpenAPIV3.ReferenceObject, baseName?: string) {\n const { $ref } = obj\n let ref = this.refs[$ref]\n\n if (ref) {\n return factory.createTypeReferenceNode(ref.propertyName, undefined)\n }\n\n const originalName = getUniqueName($ref.replace(/.+\\//, ''), this.usedAliasNames)\n const propertyName = this.options.resolveName({ name: originalName, pluginName }) || originalName\n\n ref = this.refs[$ref] = {\n propertyName,\n originalName,\n }\n\n return factory.createTypeReferenceNode(ref.propertyName, undefined)\n }\n\n /**\n * This is the very core of the OpenAPI to TS conversion - it takes a\n * schema and returns the appropriate type.\n */\n #getBaseTypeFromSchema(schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined, baseName?: string): ts.TypeNode | null {\n if (!schema) {\n return keywordTypeNodes.any\n }\n\n if (isReference(schema)) {\n return this.#getRefAlias(schema, baseName)\n }\n\n if (schema.oneOf) {\n // union\n const schemaWithoutOneOf = { ...schema, oneOf: undefined }\n\n const union = createUnionDeclaration({\n withParentheses: true,\n nodes: schema.oneOf\n .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {\n return this.#getBaseTypeFromSchema(item)\n })\n .filter((item) => {\n return item && item !== keywordTypeNodes.any\n }) as ArrayTwoOrMore<ts.TypeNode>,\n })\n\n if (schemaWithoutOneOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n return union\n }\n\n if (schema.anyOf) {\n const schemaWithoutAnyOf = { ...schema, anyOf: undefined }\n\n const union = createUnionDeclaration({\n withParentheses: true,\n nodes: schema.anyOf\n .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {\n return this.#getBaseTypeFromSchema(item)\n })\n .filter((item) => {\n return item && item !== keywordTypeNodes.any\n }) as ArrayTwoOrMore<ts.TypeNode>,\n })\n\n if (schemaWithoutAnyOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutAnyOf, baseName), union].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n return union\n }\n if (schema.allOf) {\n // intersection/add\n const schemaWithoutAllOf = { ...schema, allOf: undefined }\n\n const and = createIntersectionDeclaration({\n withParentheses: true,\n nodes: schema.allOf\n .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {\n return this.#getBaseTypeFromSchema(item)\n })\n .filter((item) => {\n return item && item !== keywordTypeNodes.any\n }) as ArrayTwoOrMore<ts.TypeNode>,\n })\n\n if (schemaWithoutAllOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n return and\n }\n\n /**\n * Enum will be defined outside the baseType(hints the baseName check)\n */\n if (schema.enum && baseName) {\n const enumName = getUniqueName(baseName, TypeGenerator.usedEnumNames)\n\n let enums: [key: string, value: string | number][] = [...new Set(schema.enum)].map((key) => [key, key])\n\n if ('x-enumNames' in schema) {\n enums = [...new Set(schema['x-enumNames'] as string[])].map((key: string, index) => {\n return [key, schema.enum?.[index]]\n })\n }\n\n this.extraNodes.push(\n ...createEnumDeclaration({\n name: camelCase(enumName, this.caseOptions),\n typeName: this.options.resolveName({ name: enumName, pluginName }),\n enums,\n type: this.options.enumType,\n }),\n )\n return factory.createTypeReferenceNode(this.options.resolveName({ name: enumName, pluginName }), undefined)\n }\n\n if (schema.enum) {\n return createUnionDeclaration({\n nodes: schema.enum.map((name: string) => {\n return factory.createLiteralTypeNode(typeof name === 'number' ? factory.createNumericLiteral(name) : factory.createStringLiteral(`${name}`))\n }) as unknown as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n if ('items' in schema) {\n // items -> array\n const node = this.#getTypeFromSchema(schema.items as OpenAPIV3.SchemaObject, baseName)\n if (node) {\n return factory.createArrayTypeNode(node)\n }\n }\n /**\n * OpenAPI 3.1\n * @link https://json-schema.org/understanding-json-schema/reference/array.html#tuple-validation\n */\n if ('prefixItems' in schema) {\n const prefixItems = schema.prefixItems as OpenAPIV3.SchemaObject[]\n\n return createTupleDeclaration({\n nodes: prefixItems.map((item) => {\n // no baseType so we can fall back on an union when using enum\n return this.#getBaseTypeFromSchema(item, undefined)\n }) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n if (schema.properties || schema.additionalProperties) {\n // properties -> literal type\n return this.#getTypeFromProperties(schema, baseName)\n }\n\n if (schema.type) {\n if (Array.isArray(schema.type)) {\n // OPENAPI v3.1.0: https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0\n const [type, nullable] = schema.type as Array<OpenAPIV3.NonArraySchemaObjectType>\n\n return createUnionDeclaration({\n nodes: [\n this.#getBaseTypeFromSchema(\n {\n ...schema,\n type,\n },\n baseName,\n ),\n nullable ? factory.createLiteralTypeNode(factory.createNull()) : undefined,\n ].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n if (this.options.dateType === 'date' && ['date', 'date-time'].some((item) => item === schema.format)) {\n return factory.createTypeReferenceNode(factory.createIdentifier('Date'))\n }\n\n // string, boolean, null, number\n if (schema.type in 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 { resolve as swaggerResolve } from '@kubb/swagger'\n\nimport { pluginName } from '../plugin.ts'\n\nimport type { ResolveProps, Resolver } from '@kubb/swagger'\n\ntype Props = ResolveProps & { pluginName?: never }\n\nexport function resolve(props: Props): Resolver {\n return swaggerResolve({ ...props, pluginName })\n}\n","import { getRelativePath } from '@kubb/core'\nimport { OperationGenerator as Generator, resolve } from '@kubb/swagger'\n\nimport { TypeBuilder } from '../builders/index.ts'\nimport { pluginName } from '../plugin.ts'\n\nimport type { KubbFile } from '@kubb/core'\nimport type { FileResolver, Operation, OperationSchemas, Resolver } from '@kubb/swagger'\nimport type { FileMeta, Options as PluginOptions } from '../types.ts'\n\ntype Options = {\n mode: KubbFile.Mode\n enumType: NonNullable<PluginOptions['enumType']>\n dateType: NonNullable<PluginOptions['dateType']>\n optionalType: NonNullable<PluginOptions['optionalType']>\n}\n\nexport class OperationGenerator extends Generator<Options> {\n resolve(operation: Operation): Resolver {\n const { pluginManager } = this.context\n\n return resolve({\n operation,\n resolveName: pluginManager.resolveName,\n resolvePath: pluginManager.resolvePath,\n pluginName,\n })\n }\n\n async all(): Promise<KubbFile.File | null> {\n return null\n }\n\n async get(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n const { mode, enumType, dateType, optionalType } = options\n const { pluginManager } = this.context\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const root = pluginManager.resolvePath({ baseName: type.baseName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = pluginManager.resolvePath({\n baseName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder({\n fileResolver: mode === 'file' ? undefined : fileResolver,\n withJSDocs: true,\n resolveName: pluginManager.resolveName,\n enumType,\n optionalType,\n dateType,\n })\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.headerParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure()\n .print()\n\n return {\n path: type.path,\n baseName: type.baseName,\n source,\n meta: {\n pluginName,\n tag: operation.getTags()[0]?.name,\n },\n }\n }\n\n async post(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n const { mode, enumType, dateType, optionalType } = options\n const { pluginManager } = this.context\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const root = pluginManager.resolvePath({ baseName: type.baseName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = pluginManager.resolvePath({\n baseName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder({\n fileResolver: mode === 'file' ? undefined : fileResolver,\n withJSDocs: true,\n resolveName: pluginManager.resolveName,\n enumType,\n optionalType,\n dateType,\n })\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.headerParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure()\n .print()\n\n return {\n path: type.path,\n baseName: type.baseName,\n source,\n meta: {\n pluginName,\n tag: operation.getTags()[0]?.name,\n },\n }\n }\n\n async put(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n async patch(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n async delete(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n}\n","import { useResolve as useResolveSwagger } from '@kubb/swagger'\n\nimport { pluginName } from '../plugin.ts'\n\nimport type { Resolver, UseResolveProps } from '@kubb/swagger'\n\ntype Props = UseResolveProps & { pluginName?: never }\n\nexport function useResolve(props: Props = {}): Resolver {\n return useResolveSwagger({ pluginName, ...props })\n}\n","import { definePlugin } from './plugin.ts'\n\nexport * from './builders/index.ts'\nexport * from './generators/index.ts'\nexport * from './hooks/index.ts'\nexport * from './plugin.ts'\nexport * from './types.ts'\nexport * from './utils/index.ts'\n\nexport default definePlugin\n"]}
|
package/dist/index.d.cts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
2
|
-
import { PluginFactoryOptions,
|
3
|
-
import { SkipBy, OverrideBy, ResolvePathOptions,
|
2
|
+
import { PluginFactoryOptions, PluginContext, KubbFile, SchemaGenerator } from '@kubb/core';
|
3
|
+
import { SkipBy, OverrideBy, ResolvePathOptions, OasBuilder, FileResolver, OperationGenerator as OperationGenerator$1, Operation, Resolver, OperationSchemas, OpenAPIV3, Refs, UseResolveProps, ResolveProps } from '@kubb/swagger';
|
4
4
|
import ts from 'typescript';
|
5
5
|
import { Options as Options$4 } from 'change-case';
|
6
6
|
|
@@ -65,33 +65,23 @@ type FileMeta = {
|
|
65
65
|
pluginName?: string;
|
66
66
|
tag?: string;
|
67
67
|
};
|
68
|
-
type PluginOptions = PluginFactoryOptions<'swagger-ts', Options$3, false,
|
68
|
+
type PluginOptions = PluginFactoryOptions<'swagger-ts', Options$3, false, never, ResolvePathOptions>;
|
69
69
|
|
70
70
|
declare const pluginName: PluginOptions['name'];
|
71
71
|
declare const definePlugin: (options: Options$3) => _kubb_core.KubbUserPlugin<PluginOptions>;
|
72
72
|
|
73
73
|
type Options$2 = {
|
74
|
-
withJSDocs?: boolean;
|
75
74
|
resolveName: PluginContext['resolveName'];
|
75
|
+
fileResolver?: FileResolver;
|
76
|
+
withJSDocs?: boolean;
|
77
|
+
withImports?: boolean;
|
76
78
|
enumType: 'enum' | 'asConst' | 'asPascalConst';
|
77
79
|
dateType: 'string' | 'date';
|
78
80
|
optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
79
81
|
};
|
80
|
-
declare class
|
81
|
-
|
82
|
-
|
83
|
-
refs: Refs;
|
84
|
-
extraNodes: ts.Node[];
|
85
|
-
aliases: ts.TypeAliasDeclaration[];
|
86
|
-
usedAliasNames: Record<string, number>;
|
87
|
-
caseOptions: Options$4;
|
88
|
-
constructor(options?: Options$2);
|
89
|
-
build({ schema, baseName, description, keysToOmit, }: {
|
90
|
-
schema: OpenAPIV3.SchemaObject;
|
91
|
-
baseName: string;
|
92
|
-
description?: string;
|
93
|
-
keysToOmit?: string[];
|
94
|
-
}): ts.Node[];
|
82
|
+
declare class TypeBuilder extends OasBuilder<Options$2, never> {
|
83
|
+
configure(options?: Options$2): this;
|
84
|
+
print(name?: string): string;
|
95
85
|
}
|
96
86
|
|
97
87
|
type Options$1 = {
|
@@ -111,19 +101,34 @@ declare class OperationGenerator extends OperationGenerator$1<Options$1> {
|
|
111
101
|
}
|
112
102
|
|
113
103
|
type Options = {
|
114
|
-
resolveName: PluginContext['resolveName'];
|
115
|
-
fileResolver?: FileResolver;
|
116
104
|
withJSDocs?: boolean;
|
117
|
-
|
105
|
+
resolveName: PluginContext['resolveName'];
|
118
106
|
enumType: 'enum' | 'asConst' | 'asPascalConst';
|
119
107
|
dateType: 'string' | 'date';
|
120
108
|
optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
121
109
|
};
|
122
|
-
declare class
|
123
|
-
|
124
|
-
|
110
|
+
declare class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObject, ts.Node[]> {
|
111
|
+
#private;
|
112
|
+
static usedEnumNames: Record<string, number>;
|
113
|
+
refs: Refs;
|
114
|
+
extraNodes: ts.Node[];
|
115
|
+
aliases: ts.TypeAliasDeclaration[];
|
116
|
+
usedAliasNames: Record<string, number>;
|
117
|
+
caseOptions: Options$4;
|
118
|
+
constructor(options?: Options);
|
119
|
+
build({ schema, baseName, description, keysToOmit, }: {
|
120
|
+
schema: OpenAPIV3.SchemaObject;
|
121
|
+
baseName: string;
|
122
|
+
description?: string;
|
123
|
+
keysToOmit?: string[];
|
124
|
+
}): ts.Node[];
|
125
125
|
}
|
126
126
|
|
127
|
+
type Props$1 = UseResolveProps & {
|
128
|
+
pluginName?: never;
|
129
|
+
};
|
130
|
+
declare function useResolve(props?: Props$1): Resolver;
|
131
|
+
|
127
132
|
declare const keywordTypeNodes: {
|
128
133
|
readonly any: ts.KeywordTypeNode<ts.SyntaxKind.AnyKeyword>;
|
129
134
|
readonly number: ts.KeywordTypeNode<ts.SyntaxKind.NumberKeyword>;
|
@@ -135,14 +140,9 @@ declare const keywordTypeNodes: {
|
|
135
140
|
readonly null: ts.LiteralTypeNode;
|
136
141
|
};
|
137
142
|
|
138
|
-
type Props
|
139
|
-
pluginName?: never;
|
140
|
-
};
|
141
|
-
declare function resolve(props: Props$1): Resolver;
|
142
|
-
|
143
|
-
type Props = UseResolveProps & {
|
143
|
+
type Props = ResolveProps & {
|
144
144
|
pluginName?: never;
|
145
145
|
};
|
146
|
-
declare function
|
146
|
+
declare function resolve(props: Props): Resolver;
|
147
147
|
|
148
148
|
export { FileMeta, OperationGenerator, Options$3 as Options, PluginOptions, TypeBuilder, TypeGenerator, definePlugin as default, definePlugin, keywordTypeNodes, pluginName, resolve, useResolve };
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
2
|
-
import { PluginFactoryOptions,
|
3
|
-
import { SkipBy, OverrideBy, ResolvePathOptions,
|
2
|
+
import { PluginFactoryOptions, PluginContext, KubbFile, SchemaGenerator } from '@kubb/core';
|
3
|
+
import { SkipBy, OverrideBy, ResolvePathOptions, OasBuilder, FileResolver, OperationGenerator as OperationGenerator$1, Operation, Resolver, OperationSchemas, OpenAPIV3, Refs, UseResolveProps, ResolveProps } from '@kubb/swagger';
|
4
4
|
import ts from 'typescript';
|
5
5
|
import { Options as Options$4 } from 'change-case';
|
6
6
|
|
@@ -65,33 +65,23 @@ type FileMeta = {
|
|
65
65
|
pluginName?: string;
|
66
66
|
tag?: string;
|
67
67
|
};
|
68
|
-
type PluginOptions = PluginFactoryOptions<'swagger-ts', Options$3, false,
|
68
|
+
type PluginOptions = PluginFactoryOptions<'swagger-ts', Options$3, false, never, ResolvePathOptions>;
|
69
69
|
|
70
70
|
declare const pluginName: PluginOptions['name'];
|
71
71
|
declare const definePlugin: (options: Options$3) => _kubb_core.KubbUserPlugin<PluginOptions>;
|
72
72
|
|
73
73
|
type Options$2 = {
|
74
|
-
withJSDocs?: boolean;
|
75
74
|
resolveName: PluginContext['resolveName'];
|
75
|
+
fileResolver?: FileResolver;
|
76
|
+
withJSDocs?: boolean;
|
77
|
+
withImports?: boolean;
|
76
78
|
enumType: 'enum' | 'asConst' | 'asPascalConst';
|
77
79
|
dateType: 'string' | 'date';
|
78
80
|
optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
79
81
|
};
|
80
|
-
declare class
|
81
|
-
|
82
|
-
|
83
|
-
refs: Refs;
|
84
|
-
extraNodes: ts.Node[];
|
85
|
-
aliases: ts.TypeAliasDeclaration[];
|
86
|
-
usedAliasNames: Record<string, number>;
|
87
|
-
caseOptions: Options$4;
|
88
|
-
constructor(options?: Options$2);
|
89
|
-
build({ schema, baseName, description, keysToOmit, }: {
|
90
|
-
schema: OpenAPIV3.SchemaObject;
|
91
|
-
baseName: string;
|
92
|
-
description?: string;
|
93
|
-
keysToOmit?: string[];
|
94
|
-
}): ts.Node[];
|
82
|
+
declare class TypeBuilder extends OasBuilder<Options$2, never> {
|
83
|
+
configure(options?: Options$2): this;
|
84
|
+
print(name?: string): string;
|
95
85
|
}
|
96
86
|
|
97
87
|
type Options$1 = {
|
@@ -111,19 +101,34 @@ declare class OperationGenerator extends OperationGenerator$1<Options$1> {
|
|
111
101
|
}
|
112
102
|
|
113
103
|
type Options = {
|
114
|
-
resolveName: PluginContext['resolveName'];
|
115
|
-
fileResolver?: FileResolver;
|
116
104
|
withJSDocs?: boolean;
|
117
|
-
|
105
|
+
resolveName: PluginContext['resolveName'];
|
118
106
|
enumType: 'enum' | 'asConst' | 'asPascalConst';
|
119
107
|
dateType: 'string' | 'date';
|
120
108
|
optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
121
109
|
};
|
122
|
-
declare class
|
123
|
-
|
124
|
-
|
110
|
+
declare class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObject, ts.Node[]> {
|
111
|
+
#private;
|
112
|
+
static usedEnumNames: Record<string, number>;
|
113
|
+
refs: Refs;
|
114
|
+
extraNodes: ts.Node[];
|
115
|
+
aliases: ts.TypeAliasDeclaration[];
|
116
|
+
usedAliasNames: Record<string, number>;
|
117
|
+
caseOptions: Options$4;
|
118
|
+
constructor(options?: Options);
|
119
|
+
build({ schema, baseName, description, keysToOmit, }: {
|
120
|
+
schema: OpenAPIV3.SchemaObject;
|
121
|
+
baseName: string;
|
122
|
+
description?: string;
|
123
|
+
keysToOmit?: string[];
|
124
|
+
}): ts.Node[];
|
125
125
|
}
|
126
126
|
|
127
|
+
type Props$1 = UseResolveProps & {
|
128
|
+
pluginName?: never;
|
129
|
+
};
|
130
|
+
declare function useResolve(props?: Props$1): Resolver;
|
131
|
+
|
127
132
|
declare const keywordTypeNodes: {
|
128
133
|
readonly any: ts.KeywordTypeNode<ts.SyntaxKind.AnyKeyword>;
|
129
134
|
readonly number: ts.KeywordTypeNode<ts.SyntaxKind.NumberKeyword>;
|
@@ -135,14 +140,9 @@ declare const keywordTypeNodes: {
|
|
135
140
|
readonly null: ts.LiteralTypeNode;
|
136
141
|
};
|
137
142
|
|
138
|
-
type Props
|
139
|
-
pluginName?: never;
|
140
|
-
};
|
141
|
-
declare function resolve(props: Props$1): Resolver;
|
142
|
-
|
143
|
-
type Props = UseResolveProps & {
|
143
|
+
type Props = ResolveProps & {
|
144
144
|
pluginName?: never;
|
145
145
|
};
|
146
|
-
declare function
|
146
|
+
declare function resolve(props: Props): Resolver;
|
147
147
|
|
148
148
|
export { FileMeta, OperationGenerator, Options$3 as Options, PluginOptions, TypeBuilder, TypeGenerator, definePlugin as default, definePlugin, keywordTypeNodes, pluginName, resolve, useResolve };
|
package/dist/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { createRequire } from 'module';
|
2
2
|
import pathParser from 'path';
|
3
|
-
import { createPlugin, getDependedPlugins, getPathMode, renderTemplate, getRelativePath, timeout,
|
3
|
+
import { createPlugin, getDependedPlugins, getPathMode, renderTemplate, getRelativePath, timeout, SchemaGenerator, getUniqueName, nameSorter, combineCodes } from '@kubb/core';
|
4
4
|
import { pluginName as pluginName$1, resolve as resolve$1, isReference, OasBuilder, ImportsGenerator, OperationGenerator as OperationGenerator$1, useResolve as useResolve$1 } from '@kubb/swagger';
|
5
5
|
import { camelCase, camelCaseTransformMerge, pascalCase, pascalCaseTransformMerge } from 'change-case';
|
6
6
|
import { createTypeAliasDeclaration, modifiers, createOmitDeclaration, appendJSDocToNode, createUnionDeclaration, createPropertySignature, createIndexSignature, createIntersectionDeclaration, createEnumDeclaration, createTupleDeclaration, print, createImportDeclaration } from '@kubb/parser';
|
@@ -577,10 +577,7 @@ var definePlugin = createPlugin((options) => {
|
|
577
577
|
await timeout(100);
|
578
578
|
}
|
579
579
|
const root = pathParser.resolve(this.config.root, this.config.output.path);
|
580
|
-
|
581
|
-
if (files) {
|
582
|
-
await this.addFile(...files);
|
583
|
-
}
|
580
|
+
await this.fileManager.addIndexes(root, ".ts");
|
584
581
|
}
|
585
582
|
};
|
586
583
|
});
|
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/utils/resolve.ts","../src/generators/OperationGenerator.ts","../src/hooks/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AkB,EAAE,YAAY,GAAG,MAAM,CAAC;AACnD;;;ACAA,IAAO,cAAQ","sourcesContent":["import pathParser from 'node:path'\n\nimport { createPlugin, getDependedPlugins, getIndexes, getPathMode, getRelativePath, renderTemplate, timeout } from '@kubb/core'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\n\nimport { camelCase, camelCaseTransformMerge, pascalCase, pascalCaseTransformMerge } from 'change-case'\n\nimport { TypeBuilder } from './builders/index.ts'\nimport { OperationGenerator } from './generators/index.ts'\n\nimport type { OpenAPIV3, PluginOptions as SwaggerPluginOptions } from '@kubb/swagger'\nimport type { PluginOptions } from './types.ts'\n\nexport const pluginName: PluginOptions['name'] = 'swagger-ts' as const\n\nexport const definePlugin = createPlugin<PluginOptions>((options) => {\n const {\n output = 'types',\n groupBy,\n skipBy = [],\n overrideBy = [],\n enumType = 'asConst',\n dateType = 'string',\n optionalType = 'questionToken',\n transformers = {},\n } = options\n const template = groupBy?.output ? groupBy.output : `${output}/{{tag}}Controller`\n let pluginsOptions: [SwaggerPluginOptions]\n\n return {\n name: pluginName,\n options,\n kind: 'schema',\n validate(plugins) {\n pluginsOptions = getDependedPlugins<[SwaggerPluginOptions]>(plugins, [swaggerPluginName])\n\n return true\n },\n resolvePath(baseName, directory, options) {\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(root, output))\n\n if (mode === 'file') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return pathParser.resolve(root, output)\n }\n\n if (options?.tag && groupBy?.type === 'tag') {\n const tag = camelCase(options.tag, { delimiter: '', transform: camelCaseTransformMerge })\n\n return pathParser.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return pathParser.resolve(root, output, baseName)\n },\n resolveName(name) {\n const resolvedName = pascalCase(name, { delimiter: '', stripRegexp: /[^A-Z0-9$]/gi, transform: pascalCaseTransformMerge })\n\n return transformers?.name?.(resolvedName) || resolvedName\n },\n async writeFile(source, path) {\n if (!path.endsWith('.ts') || !source) {\n return\n }\n\n await this.fileManager.write(source, path)\n },\n async buildStart() {\n const [swaggerPlugin] = pluginsOptions\n\n const oas = await swaggerPlugin.api.getOas()\n\n const schemas = await swaggerPlugin.api.getSchemas()\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(root, output))\n\n if (mode === 'directory') {\n const builder = await new TypeBuilder({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n fileResolver: (name) => {\n const resolvedTypeId = this.resolvePath({\n baseName: `${name}.ts`,\n pluginName,\n })\n\n const root = this.resolvePath({ baseName: ``, pluginName })\n\n return getRelativePath(root, resolvedTypeId)\n },\n withJSDocs: true,\n enumType,\n dateType,\n optionalType,\n }).configure()\n Object.entries(schemas).forEach(([name, schema]: [string, OpenAPIV3.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const mapFolderSchema = async ([name]: [string, OpenAPIV3.SchemaObject]) => {\n const path = this.resolvePath({ baseName: `${this.resolveName({ name, pluginName })}.ts`, pluginName })\n\n if (!path) {\n return null\n }\n\n return this.addFile({\n path,\n baseName: `${this.resolveName({ name, pluginName })}.ts`,\n source: builder.print(name),\n meta: {\n pluginName,\n },\n })\n }\n\n const promises = Object.entries(schemas).map(mapFolderSchema)\n\n await Promise.all(promises)\n }\n\n if (mode === 'file') {\n // outside the loop because we need to add files to just one instance to have the correct sorting, see refsSorter\n const builder = new TypeBuilder({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n withJSDocs: true,\n enumType,\n dateType,\n optionalType,\n }).configure()\n Object.entries(schemas).forEach(([name, schema]: [string, OpenAPIV3.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const path = this.resolvePath({ baseName: '', pluginName })\n if (!path) {\n return\n }\n\n await this.addFile({\n path,\n baseName: `${this.resolveName({ name: output, pluginName })}.ts`,\n source: builder.print(),\n meta: {\n pluginName,\n },\n })\n }\n\n const operationGenerator = new OperationGenerator(\n {\n mode,\n enumType,\n dateType,\n optionalType,\n },\n {\n oas,\n pluginManager: this.pluginManager,\n contentType: swaggerPlugin.api.contentType,\n skipBy,\n overrideBy,\n },\n )\n\n const files = await operationGenerator.build()\n await this.addFile(...files)\n },\n async buildEnd() {\n if (this.config.output.write === false) {\n return\n }\n\n while (this.fileManager.isExecuting) {\n await timeout(100)\n }\n\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const files = await getIndexes(root, { extensions: /\\.ts/, exclude: [/schemas/, /json/] })\n\n if (files) {\n await this.addFile(...files)\n }\n },\n }\n})\n","/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { combineCodes, nameSorter } from '@kubb/core'\nimport { createImportDeclaration, print } from '@kubb/parser'\nimport { ImportsGenerator, OasBuilder } from '@kubb/swagger'\n\nimport { TypeGenerator } from '../generators/TypeGenerator.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { FileResolver, Refs } from '@kubb/swagger'\nimport type ts from 'typescript'\n\ntype Generated = { import: { refs: Refs; name: string }; sources: ts.Node[] }\ntype Options = {\n resolveName: PluginContext['resolveName']\n fileResolver?: FileResolver\n withJSDocs?: boolean\n withImports?: boolean\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n dateType: 'string' | 'date'\n optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'\n}\n\n// TODO create another function that sort based on the refs(first the ones without refs)\nfunction refsSorter(a: Generated, b: Generated) {\n if (Object.keys(a.import.refs)?.length < Object.keys(b.import.refs)?.length) {\n return -1\n }\n if (Object.keys(a.import.refs)?.length > Object.keys(b.import.refs)?.length) {\n return 1\n }\n return 0\n}\n\nexport class TypeBuilder extends OasBuilder<Options, never> {\n configure(options?: Options) {\n if (options) {\n this.options = options\n }\n\n if (this.options.fileResolver) {\n this.options.withImports = true\n }\n\n return this\n }\n\n print(name?: string): string {\n const codes: string[] = []\n\n const generated = this.items\n .filter((operationSchema) => (name ? operationSchema.name === name : true))\n .sort(nameSorter)\n .map((operationSchema) => {\n const generator = new TypeGenerator({\n withJSDocs: this.options.withJSDocs,\n resolveName: this.options.resolveName,\n enumType: this.options.enumType,\n dateType: this.options.dateType,\n optionalType: this.options.optionalType,\n })\n const sources = generator.build({\n schema: operationSchema.schema,\n baseName: operationSchema.name,\n description: operationSchema.description,\n keysToOmit: operationSchema.keysToOmit,\n })\n\n return {\n import: {\n refs: generator.refs,\n name: operationSchema.name,\n },\n sources,\n }\n })\n .sort(refsSorter)\n\n generated.forEach((item) => {\n codes.push(print(item.sources))\n })\n\n if (this.options.withImports) {\n const importsGenerator = new ImportsGenerator({ fileResolver: this.options.fileResolver })\n const importMeta = importsGenerator.build(generated.map((item) => item.import))\n\n if (importMeta) {\n const nodes = importMeta.map((item) => {\n return createImportDeclaration({\n name: [{ propertyName: item.ref.propertyName }],\n path: item.path,\n isTypeOnly: true,\n })\n })\n\n codes.unshift(print(nodes))\n }\n }\n\n return combineCodes(codes)\n }\n}\n","import { getUniqueName, SchemaGenerator } from '@kubb/core'\nimport {\n appendJSDocToNode,\n createEnumDeclaration,\n createIndexSignature,\n createIntersectionDeclaration,\n createOmitDeclaration,\n createPropertySignature,\n createTupleDeclaration,\n createTypeAliasDeclaration,\n createUnionDeclaration,\n modifiers,\n} from '@kubb/parser'\nimport { isReference } from '@kubb/swagger'\n\nimport { camelCase } from 'change-case'\nimport ts from 'typescript'\n\nimport { pluginName } from '../plugin.ts'\nimport { keywordTypeNodes } from '../utils/index.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { ArrayTwoOrMore } from '@kubb/parser'\nimport type { OpenAPIV3, Refs } from '@kubb/swagger'\nimport type { Options as CaseOptions } from 'change-case'\n\nconst { factory } = ts\n\n// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n\ntype Options = {\n withJSDocs?: boolean\n resolveName: PluginContext['resolveName']\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n dateType: 'string' | 'date'\n optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'\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 caseOptions: CaseOptions = {\n delimiter: '',\n stripRegexp: /[^A-Z0-9$]/gi,\n }\n\n constructor(\n options: Options = { withJSDocs: true, resolveName: ({ name }) => name, enumType: 'asConst', dateType: 'string', optionalType: 'questionToken' },\n ) {\n super(options)\n\n return this\n }\n\n build({\n schema,\n baseName,\n description,\n keysToOmit,\n }: {\n schema: OpenAPIV3.SchemaObject\n baseName: string\n description?: string\n keysToOmit?: string[]\n }): ts.Node[] {\n const nodes: ts.Node[] = []\n const type = this.#getTypeFromSchema(schema, baseName)\n\n if (!type) {\n return this.extraNodes\n }\n\n const node = createTypeAliasDeclaration({\n modifiers: [modifiers.export],\n name: this.options.resolveName({ name: baseName, pluginName }) || baseName,\n type: keysToOmit?.length ? createOmitDeclaration({ keys: keysToOmit, type, nonNullable: true }) : 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 #getTypeFromSchema(schema?: OpenAPIV3.SchemaObject, name?: string): ts.TypeNode | null {\n const type = this.#getBaseTypeFromSchema(schema, name)\n\n if (!type) {\n return null\n }\n\n if (schema && !schema.nullable) {\n return type\n }\n\n return createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] })\n }\n\n /**\n * Recursively creates a type literal with the given props.\n */\n #getTypeFromProperties(baseSchema?: OpenAPIV3.SchemaObject, baseName?: string) {\n const { optionalType } = this.options\n const properties = baseSchema?.properties || {}\n const required = baseSchema?.required\n const additionalProperties = baseSchema?.additionalProperties\n\n const members: Array<ts.TypeElement | null> = Object.keys(properties).map((name) => {\n const schema = properties[name] as OpenAPIV3.SchemaObject\n\n const isRequired = required && required.includes(name)\n let type = this.#getTypeFromSchema(schema, this.options.resolveName({ name: `${baseName || ''} ${name}`, pluginName }))\n\n if (!type) {\n return null\n }\n\n if (!isRequired && ['undefined', 'questionTokenAndUndefined'].includes(optionalType)) {\n type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] })\n }\n const propertySignature = createPropertySignature({\n questionToken: ['questionToken', 'questionTokenAndUndefined'].includes(optionalType) && !isRequired,\n name,\n type: type as ts.TypeNode,\n readOnly: schema.readOnly,\n })\n if (this.options.withJSDocs) {\n return appendJSDocToNode({\n node: propertySignature,\n comments: [\n schema.description ? `@description ${schema.description}` : undefined,\n schema.type ? `@type ${schema.type}${isRequired ? '' : ' | undefined'} ${schema.format || ''}` : undefined,\n schema.example ? `@example ${schema.example as string}` : undefined,\n schema.deprecated ? `@deprecated` : undefined,\n schema.default !== undefined && typeof schema.default === 'string' ? `@default '${schema.default}'` : undefined,\n schema.default !== undefined && typeof schema.default !== 'string' ? `@default ${schema.default as string}` : undefined,\n ].filter(Boolean),\n })\n }\n\n return propertySignature\n })\n if (additionalProperties) {\n const type = additionalProperties === true ? keywordTypeNodes.any : this.#getTypeFromSchema(additionalProperties as OpenAPIV3.SchemaObject)\n\n if (type) {\n members.push(createIndexSignature(type))\n }\n }\n return factory.createTypeLiteralNode(members.filter(Boolean))\n }\n\n /**\n * Create a type alias for the schema referenced by the given ReferenceObject\n */\n #getRefAlias(obj: OpenAPIV3.ReferenceObject, baseName?: string) {\n const { $ref } = obj\n let ref = this.refs[$ref]\n\n if (ref) {\n return factory.createTypeReferenceNode(ref.propertyName, undefined)\n }\n\n const originalName = getUniqueName($ref.replace(/.+\\//, ''), this.usedAliasNames)\n const propertyName = this.options.resolveName({ name: originalName, pluginName }) || originalName\n\n ref = this.refs[$ref] = {\n propertyName,\n originalName,\n }\n\n return factory.createTypeReferenceNode(ref.propertyName, undefined)\n }\n\n /**\n * This is the very core of the OpenAPI to TS conversion - it takes a\n * schema and returns the appropriate type.\n */\n #getBaseTypeFromSchema(schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined, baseName?: string): ts.TypeNode | null {\n if (!schema) {\n return keywordTypeNodes.any\n }\n\n if (isReference(schema)) {\n return this.#getRefAlias(schema, baseName)\n }\n\n if (schema.oneOf) {\n // union\n const schemaWithoutOneOf = { ...schema, oneOf: undefined }\n\n const union = createUnionDeclaration({\n withParentheses: true,\n nodes: schema.oneOf\n .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {\n return this.#getBaseTypeFromSchema(item)\n })\n .filter((item) => {\n return item && item !== keywordTypeNodes.any\n }) as ArrayTwoOrMore<ts.TypeNode>,\n })\n\n if (schemaWithoutOneOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n return union\n }\n\n if (schema.anyOf) {\n const schemaWithoutAnyOf = { ...schema, anyOf: undefined }\n\n const union = createUnionDeclaration({\n withParentheses: true,\n nodes: schema.anyOf\n .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {\n return this.#getBaseTypeFromSchema(item)\n })\n .filter((item) => {\n return item && item !== keywordTypeNodes.any\n }) as ArrayTwoOrMore<ts.TypeNode>,\n })\n\n if (schemaWithoutAnyOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutAnyOf, baseName), union].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n return union\n }\n if (schema.allOf) {\n // intersection/add\n const schemaWithoutAllOf = { ...schema, allOf: undefined }\n\n const and = createIntersectionDeclaration({\n withParentheses: true,\n nodes: schema.allOf\n .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {\n return this.#getBaseTypeFromSchema(item)\n })\n .filter((item) => {\n return item && item !== keywordTypeNodes.any\n }) as ArrayTwoOrMore<ts.TypeNode>,\n })\n\n if (schemaWithoutAllOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n return and\n }\n\n /**\n * Enum will be defined outside the baseType(hints the baseName check)\n */\n if (schema.enum && baseName) {\n const enumName = getUniqueName(baseName, TypeGenerator.usedEnumNames)\n\n let enums: [key: string, value: string | number][] = [...new Set(schema.enum)].map((key) => [key, key])\n\n if ('x-enumNames' in schema) {\n enums = [...new Set(schema['x-enumNames'] as string[])].map((key: string, index) => {\n return [key, schema.enum?.[index]]\n })\n }\n\n this.extraNodes.push(\n ...createEnumDeclaration({\n name: camelCase(enumName, this.caseOptions),\n typeName: this.options.resolveName({ name: enumName, pluginName }),\n enums,\n type: this.options.enumType,\n }),\n )\n return factory.createTypeReferenceNode(this.options.resolveName({ name: enumName, pluginName }), undefined)\n }\n\n if (schema.enum) {\n return createUnionDeclaration({\n nodes: schema.enum.map((name: string) => {\n return factory.createLiteralTypeNode(typeof name === 'number' ? factory.createNumericLiteral(name) : factory.createStringLiteral(`${name}`))\n }) as unknown as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n if ('items' in schema) {\n // items -> array\n const node = this.#getTypeFromSchema(schema.items as OpenAPIV3.SchemaObject, baseName)\n if (node) {\n return factory.createArrayTypeNode(node)\n }\n }\n /**\n * OpenAPI 3.1\n * @link https://json-schema.org/understanding-json-schema/reference/array.html#tuple-validation\n */\n if ('prefixItems' in schema) {\n const prefixItems = schema.prefixItems as OpenAPIV3.SchemaObject[]\n\n return createTupleDeclaration({\n nodes: prefixItems.map((item) => {\n // no baseType so we can fall back on an union when using enum\n return this.#getBaseTypeFromSchema(item, undefined)\n }) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n if (schema.properties || schema.additionalProperties) {\n // properties -> literal type\n return this.#getTypeFromProperties(schema, baseName)\n }\n\n if (schema.type) {\n if (Array.isArray(schema.type)) {\n // OPENAPI v3.1.0: https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0\n const [type, nullable] = schema.type as Array<OpenAPIV3.NonArraySchemaObjectType>\n\n return createUnionDeclaration({\n nodes: [\n this.#getBaseTypeFromSchema(\n {\n ...schema,\n type,\n },\n baseName,\n ),\n nullable ? factory.createLiteralTypeNode(factory.createNull()) : undefined,\n ].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n if (this.options.dateType === 'date' && ['date', 'date-time'].some((item) => item === schema.format)) {\n return factory.createTypeReferenceNode(factory.createIdentifier('Date'))\n }\n\n // string, boolean, null, number\n if (schema.type in 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 { resolve as swaggerResolve } from '@kubb/swagger'\n\nimport { pluginName } from '../plugin.ts'\n\nimport type { ResolveProps, Resolver } from '@kubb/swagger'\n\ntype Props = ResolveProps & { pluginName?: never }\n\nexport function resolve(props: Props): Resolver {\n return swaggerResolve({ ...props, pluginName })\n}\n","import { getRelativePath } from '@kubb/core'\nimport { OperationGenerator as Generator, resolve } from '@kubb/swagger'\n\nimport { TypeBuilder } from '../builders/index.ts'\nimport { pluginName } from '../plugin.ts'\n\nimport type { KubbFile } from '@kubb/core'\nimport type { FileResolver, Operation, OperationSchemas, Resolver } from '@kubb/swagger'\nimport type { FileMeta, Options as PluginOptions } from '../types.ts'\n\ntype Options = {\n mode: KubbFile.Mode\n enumType: NonNullable<PluginOptions['enumType']>\n dateType: NonNullable<PluginOptions['dateType']>\n optionalType: NonNullable<PluginOptions['optionalType']>\n}\n\nexport class OperationGenerator extends Generator<Options> {\n resolve(operation: Operation): Resolver {\n const { pluginManager } = this.context\n\n return resolve({\n operation,\n resolveName: pluginManager.resolveName,\n resolvePath: pluginManager.resolvePath,\n pluginName,\n })\n }\n\n async all(): Promise<KubbFile.File | null> {\n return null\n }\n\n async get(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n const { mode, enumType, dateType, optionalType } = options\n const { pluginManager } = this.context\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const root = pluginManager.resolvePath({ baseName: type.baseName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = pluginManager.resolvePath({\n baseName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder({\n fileResolver: mode === 'file' ? undefined : fileResolver,\n withJSDocs: true,\n resolveName: pluginManager.resolveName,\n enumType,\n optionalType,\n dateType,\n })\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.headerParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure()\n .print()\n\n return {\n path: type.path,\n baseName: type.baseName,\n source,\n meta: {\n pluginName,\n tag: operation.getTags()[0]?.name,\n },\n }\n }\n\n async post(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n const { mode, enumType, dateType, optionalType } = options\n const { pluginManager } = this.context\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const root = pluginManager.resolvePath({ baseName: type.baseName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = pluginManager.resolvePath({\n baseName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder({\n fileResolver: mode === 'file' ? undefined : fileResolver,\n withJSDocs: true,\n resolveName: pluginManager.resolveName,\n enumType,\n optionalType,\n dateType,\n })\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.headerParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure()\n .print()\n\n return {\n path: type.path,\n baseName: type.baseName,\n source,\n meta: {\n pluginName,\n tag: operation.getTags()[0]?.name,\n },\n }\n }\n\n async put(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n async patch(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n async delete(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n}\n","import { useResolve as useResolveSwagger } from '@kubb/swagger'\n\nimport { pluginName } from '../plugin.ts'\n\nimport type { Resolver, UseResolveProps } from '@kubb/swagger'\n\ntype Props = UseResolveProps & { pluginName?: never }\n\nexport function useResolve(props: Props = {}): Resolver {\n return useResolveSwagger({ pluginName, ...props })\n}\n","import { definePlugin } from './plugin.ts'\n\nexport * from './plugin.ts'\nexport * from './types.ts'\n\nexport * from './generators/index.ts'\nexport * from './builders/index.ts'\nexport * from './utils/index.ts'\nexport * from './hooks/index.ts'\n\nexport default definePlugin\n"]}
|
1
|
+
{"version":3,"sources":["../src/plugin.ts","../src/builders/TypeBuilder.ts","../src/generators/TypeGenerator.ts","../src/utils/keywordTypeNodes.ts","../src/utils/resolve.ts","../src/generators/OperationGenerator.ts","../src/hooks/useResolve.ts","../src/index.ts"],"names":["getRelativePath","camelCase","ts","factory","node","resolve","options","root"],"mappings":";;;;;;AAAA,OAAO,gBAAgB;AAEvB,SAAS,cAAc,oBAAoB,aAAa,mBAAAA,kBAAiB,gBAAgB,eAAe;AACxG,SAAS,cAAc,yBAAyB;AAEhD,SAAS,aAAAC,YAAW,yBAAyB,YAAY,gCAAgC;;;ACJzF,SAAS,cAAc,kBAAkB;AACzC,SAAS,yBAAyB,aAAa;AAC/C,SAAS,kBAAkB,kBAAkB;;;ACH7C,SAAS,eAAe,uBAAuB;AAC/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAE5B,SAAS,iBAAiB;AAC1B,OAAOC,SAAQ;;;AChBf,OAAO,QAAQ;AAEf,IAAM,EAAE,QAAQ,IAAI;AAEb,IAAM,mBAAmB;AAAA,EAC9B,KAAK,QAAQ,sBAAsB,GAAG,WAAW,UAAU;AAAA,EAC3D,QAAQ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YAAM,KAAK,QAAQ,GAAG,KAAK;AAAA,IAC7B;AAAA,IACA,MAAM,WAAW;AACf,UAAI,KAAK,OAAO,OAAO,UAAU,OAAO;AACtC;AAAA,MACF;AAEA,aAAO,KAAK,YAAY,aAAa;AACnC,cAAM,QAAQ,GAAG;AAAA,MACnB;AAEA,YAAM,OAAO,WAAW,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,IAAI;AAEzE,YAAM,KAAK,YAAY,WAAW,MAAM,KAAK;AAAA,IAC/C;AAAA,EACF;AACF,CAAC;;;AMhMD,SAAS,cAAc,yBAAyB;AAQzC,SAAS,WAAW,QAAe,CAAC,GAAa;AACtD,SAAO,kBAAkB,EAAE,YAAY,GAAG,MAAM,CAAC;AACnD;;;ACDA,IAAO,cAAQ","sourcesContent":["import pathParser from 'node:path'\n\nimport { createPlugin, getDependedPlugins, getPathMode, getRelativePath, renderTemplate, timeout } from '@kubb/core'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\n\nimport { camelCase, camelCaseTransformMerge, pascalCase, pascalCaseTransformMerge } from 'change-case'\n\nimport { TypeBuilder } from './builders/index.ts'\nimport { OperationGenerator } from './generators/index.ts'\n\nimport type { OpenAPIV3, PluginOptions as SwaggerPluginOptions } from '@kubb/swagger'\nimport type { PluginOptions } from './types.ts'\n\nexport const pluginName: PluginOptions['name'] = 'swagger-ts' as const\n\nexport const definePlugin = createPlugin<PluginOptions>((options) => {\n const {\n output = 'types',\n groupBy,\n skipBy = [],\n overrideBy = [],\n enumType = 'asConst',\n dateType = 'string',\n optionalType = 'questionToken',\n transformers = {},\n } = options\n const template = groupBy?.output ? groupBy.output : `${output}/{{tag}}Controller`\n let pluginsOptions: [SwaggerPluginOptions]\n\n return {\n name: pluginName,\n options,\n kind: 'schema',\n validate(plugins) {\n pluginsOptions = getDependedPlugins<SwaggerPluginOptions>(plugins, [swaggerPluginName])\n\n return true\n },\n resolvePath(baseName, directory, options) {\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(root, output))\n\n if (mode === 'file') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return pathParser.resolve(root, output)\n }\n\n if (options?.tag && groupBy?.type === 'tag') {\n const tag = camelCase(options.tag, { delimiter: '', transform: camelCaseTransformMerge })\n\n return pathParser.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return pathParser.resolve(root, output, baseName)\n },\n resolveName(name) {\n const resolvedName = pascalCase(name, { delimiter: '', stripRegexp: /[^A-Z0-9$]/gi, transform: pascalCaseTransformMerge })\n\n return transformers?.name?.(resolvedName) || resolvedName\n },\n async writeFile(source, path) {\n if (!path.endsWith('.ts') || !source) {\n return\n }\n\n await this.fileManager.write(source, path)\n },\n async buildStart() {\n const [swaggerPlugin] = pluginsOptions\n\n const oas = await swaggerPlugin.api.getOas()\n\n const schemas = await swaggerPlugin.api.getSchemas()\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(root, output))\n\n if (mode === 'directory') {\n const builder = await new TypeBuilder({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n fileResolver: (name) => {\n const resolvedTypeId = this.resolvePath({\n baseName: `${name}.ts`,\n pluginName,\n })\n\n const root = this.resolvePath({ baseName: ``, pluginName })\n\n return getRelativePath(root, resolvedTypeId)\n },\n withJSDocs: true,\n enumType,\n dateType,\n optionalType,\n }).configure()\n Object.entries(schemas).forEach(([name, schema]: [string, OpenAPIV3.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const mapFolderSchema = async ([name]: [string, OpenAPIV3.SchemaObject]) => {\n const path = this.resolvePath({ baseName: `${this.resolveName({ name, pluginName })}.ts`, pluginName })\n\n if (!path) {\n return null\n }\n\n return this.addFile({\n path,\n baseName: `${this.resolveName({ name, pluginName })}.ts`,\n source: builder.print(name),\n meta: {\n pluginName,\n },\n })\n }\n\n const promises = Object.entries(schemas).map(mapFolderSchema)\n\n await Promise.all(promises)\n }\n\n if (mode === 'file') {\n // outside the loop because we need to add files to just one instance to have the correct sorting, see refsSorter\n const builder = new TypeBuilder({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n withJSDocs: true,\n enumType,\n dateType,\n optionalType,\n }).configure()\n Object.entries(schemas).forEach(([name, schema]: [string, OpenAPIV3.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const path = this.resolvePath({ baseName: '', pluginName })\n if (!path) {\n return\n }\n\n await this.addFile({\n path,\n baseName: `${this.resolveName({ name: output, pluginName })}.ts`,\n source: builder.print(),\n meta: {\n pluginName,\n },\n })\n }\n\n const operationGenerator = new OperationGenerator(\n {\n mode,\n enumType,\n dateType,\n optionalType,\n },\n {\n oas,\n pluginManager: this.pluginManager,\n contentType: swaggerPlugin.api.contentType,\n skipBy,\n overrideBy,\n },\n )\n\n const files = await operationGenerator.build()\n await this.addFile(...files)\n },\n async buildEnd() {\n if (this.config.output.write === false) {\n return\n }\n\n while (this.fileManager.isExecuting) {\n await timeout(100)\n }\n\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n\n await this.fileManager.addIndexes(root, '.ts')\n },\n }\n})\n","/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { combineCodes, nameSorter } from '@kubb/core'\nimport { createImportDeclaration, print } from '@kubb/parser'\nimport { ImportsGenerator, OasBuilder } from '@kubb/swagger'\n\nimport { TypeGenerator } from '../generators/TypeGenerator.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { FileResolver, Refs } from '@kubb/swagger'\nimport type ts from 'typescript'\n\ntype Generated = { import: { refs: Refs; name: string }; sources: ts.Node[] }\ntype Options = {\n resolveName: PluginContext['resolveName']\n fileResolver?: FileResolver\n withJSDocs?: boolean\n withImports?: boolean\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n dateType: 'string' | 'date'\n optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'\n}\n\n// TODO create another function that sort based on the refs(first the ones without refs)\nfunction refsSorter(a: Generated, b: Generated) {\n if (Object.keys(a.import.refs)?.length < Object.keys(b.import.refs)?.length) {\n return -1\n }\n if (Object.keys(a.import.refs)?.length > Object.keys(b.import.refs)?.length) {\n return 1\n }\n return 0\n}\n\nexport class TypeBuilder extends OasBuilder<Options, never> {\n configure(options?: Options) {\n if (options) {\n this.options = options\n }\n\n if (this.options.fileResolver) {\n this.options.withImports = true\n }\n\n return this\n }\n\n print(name?: string): string {\n const codes: string[] = []\n\n const generated = this.items\n .filter((operationSchema) => (name ? operationSchema.name === name : true))\n .sort(nameSorter)\n .map((operationSchema) => {\n const generator = new TypeGenerator({\n withJSDocs: this.options.withJSDocs,\n resolveName: this.options.resolveName,\n enumType: this.options.enumType,\n dateType: this.options.dateType,\n optionalType: this.options.optionalType,\n })\n const sources = generator.build({\n schema: operationSchema.schema,\n baseName: operationSchema.name,\n description: operationSchema.description,\n keysToOmit: operationSchema.keysToOmit,\n })\n\n return {\n import: {\n refs: generator.refs,\n name: operationSchema.name,\n },\n sources,\n }\n })\n .sort(refsSorter)\n\n generated.forEach((item) => {\n codes.push(print(item.sources))\n })\n\n if (this.options.withImports) {\n const importsGenerator = new ImportsGenerator({ fileResolver: this.options.fileResolver })\n const importMeta = importsGenerator.build(generated.map((item) => item.import))\n\n if (importMeta) {\n const nodes = importMeta.map((item) => {\n return createImportDeclaration({\n name: [{ propertyName: item.ref.propertyName }],\n path: item.path,\n isTypeOnly: true,\n })\n })\n\n codes.unshift(print(nodes))\n }\n }\n\n return combineCodes(codes)\n }\n}\n","import { getUniqueName, SchemaGenerator } from '@kubb/core'\nimport {\n appendJSDocToNode,\n createEnumDeclaration,\n createIndexSignature,\n createIntersectionDeclaration,\n createOmitDeclaration,\n createPropertySignature,\n createTupleDeclaration,\n createTypeAliasDeclaration,\n createUnionDeclaration,\n modifiers,\n} from '@kubb/parser'\nimport { isReference } from '@kubb/swagger'\n\nimport { camelCase } from 'change-case'\nimport ts from 'typescript'\n\nimport { pluginName } from '../plugin.ts'\nimport { keywordTypeNodes } from '../utils/index.ts'\n\nimport type { PluginContext } from '@kubb/core'\nimport type { ArrayTwoOrMore } from '@kubb/parser'\nimport type { OpenAPIV3, Refs } from '@kubb/swagger'\nimport type { Options as CaseOptions } from 'change-case'\n\nconst { factory } = ts\n\n// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n\ntype Options = {\n withJSDocs?: boolean\n resolveName: PluginContext['resolveName']\n enumType: 'enum' | 'asConst' | 'asPascalConst'\n dateType: 'string' | 'date'\n optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'\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 caseOptions: CaseOptions = {\n delimiter: '',\n stripRegexp: /[^A-Z0-9$]/gi,\n }\n\n constructor(\n options: Options = { withJSDocs: true, resolveName: ({ name }) => name, enumType: 'asConst', dateType: 'string', optionalType: 'questionToken' },\n ) {\n super(options)\n\n return this\n }\n\n build({\n schema,\n baseName,\n description,\n keysToOmit,\n }: {\n schema: OpenAPIV3.SchemaObject\n baseName: string\n description?: string\n keysToOmit?: string[]\n }): ts.Node[] {\n const nodes: ts.Node[] = []\n const type = this.#getTypeFromSchema(schema, baseName)\n\n if (!type) {\n return this.extraNodes\n }\n\n const node = createTypeAliasDeclaration({\n modifiers: [modifiers.export],\n name: this.options.resolveName({ name: baseName, pluginName }) || baseName,\n type: keysToOmit?.length ? createOmitDeclaration({ keys: keysToOmit, type, nonNullable: true }) : 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 #getTypeFromSchema(schema?: OpenAPIV3.SchemaObject, name?: string): ts.TypeNode | null {\n const type = this.#getBaseTypeFromSchema(schema, name)\n\n if (!type) {\n return null\n }\n\n if (schema && !schema.nullable) {\n return type\n }\n\n return createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] })\n }\n\n /**\n * Recursively creates a type literal with the given props.\n */\n #getTypeFromProperties(baseSchema?: OpenAPIV3.SchemaObject, baseName?: string) {\n const { optionalType } = this.options\n const properties = baseSchema?.properties || {}\n const required = baseSchema?.required\n const additionalProperties = baseSchema?.additionalProperties\n\n const members: Array<ts.TypeElement | null> = Object.keys(properties).map((name) => {\n const schema = properties[name] as OpenAPIV3.SchemaObject\n\n const isRequired = required && required.includes(name)\n let type = this.#getTypeFromSchema(schema, this.options.resolveName({ name: `${baseName || ''} ${name}`, pluginName }))\n\n if (!type) {\n return null\n }\n\n if (!isRequired && ['undefined', 'questionTokenAndUndefined'].includes(optionalType)) {\n type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] })\n }\n const propertySignature = createPropertySignature({\n questionToken: ['questionToken', 'questionTokenAndUndefined'].includes(optionalType) && !isRequired,\n name,\n type: type as ts.TypeNode,\n readOnly: schema.readOnly,\n })\n if (this.options.withJSDocs) {\n return appendJSDocToNode({\n node: propertySignature,\n comments: [\n schema.description ? `@description ${schema.description}` : undefined,\n schema.type ? `@type ${schema.type}${isRequired ? '' : ' | undefined'} ${schema.format || ''}` : undefined,\n schema.example ? `@example ${schema.example as string}` : undefined,\n schema.deprecated ? `@deprecated` : undefined,\n schema.default !== undefined && typeof schema.default === 'string' ? `@default '${schema.default}'` : undefined,\n schema.default !== undefined && typeof schema.default !== 'string' ? `@default ${schema.default as string}` : undefined,\n ].filter(Boolean),\n })\n }\n\n return propertySignature\n })\n if (additionalProperties) {\n const type = additionalProperties === true ? keywordTypeNodes.any : this.#getTypeFromSchema(additionalProperties as OpenAPIV3.SchemaObject)\n\n if (type) {\n members.push(createIndexSignature(type))\n }\n }\n return factory.createTypeLiteralNode(members.filter(Boolean))\n }\n\n /**\n * Create a type alias for the schema referenced by the given ReferenceObject\n */\n #getRefAlias(obj: OpenAPIV3.ReferenceObject, baseName?: string) {\n const { $ref } = obj\n let ref = this.refs[$ref]\n\n if (ref) {\n return factory.createTypeReferenceNode(ref.propertyName, undefined)\n }\n\n const originalName = getUniqueName($ref.replace(/.+\\//, ''), this.usedAliasNames)\n const propertyName = this.options.resolveName({ name: originalName, pluginName }) || originalName\n\n ref = this.refs[$ref] = {\n propertyName,\n originalName,\n }\n\n return factory.createTypeReferenceNode(ref.propertyName, undefined)\n }\n\n /**\n * This is the very core of the OpenAPI to TS conversion - it takes a\n * schema and returns the appropriate type.\n */\n #getBaseTypeFromSchema(schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined, baseName?: string): ts.TypeNode | null {\n if (!schema) {\n return keywordTypeNodes.any\n }\n\n if (isReference(schema)) {\n return this.#getRefAlias(schema, baseName)\n }\n\n if (schema.oneOf) {\n // union\n const schemaWithoutOneOf = { ...schema, oneOf: undefined }\n\n const union = createUnionDeclaration({\n withParentheses: true,\n nodes: schema.oneOf\n .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {\n return this.#getBaseTypeFromSchema(item)\n })\n .filter((item) => {\n return item && item !== keywordTypeNodes.any\n }) as ArrayTwoOrMore<ts.TypeNode>,\n })\n\n if (schemaWithoutOneOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n return union\n }\n\n if (schema.anyOf) {\n const schemaWithoutAnyOf = { ...schema, anyOf: undefined }\n\n const union = createUnionDeclaration({\n withParentheses: true,\n nodes: schema.anyOf\n .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {\n return this.#getBaseTypeFromSchema(item)\n })\n .filter((item) => {\n return item && item !== keywordTypeNodes.any\n }) as ArrayTwoOrMore<ts.TypeNode>,\n })\n\n if (schemaWithoutAnyOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutAnyOf, baseName), union].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n return union\n }\n if (schema.allOf) {\n // intersection/add\n const schemaWithoutAllOf = { ...schema, allOf: undefined }\n\n const and = createIntersectionDeclaration({\n withParentheses: true,\n nodes: schema.allOf\n .map((item: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject) => {\n return this.#getBaseTypeFromSchema(item)\n })\n .filter((item) => {\n return item && item !== keywordTypeNodes.any\n }) as ArrayTwoOrMore<ts.TypeNode>,\n })\n\n if (schemaWithoutAllOf.properties) {\n return createIntersectionDeclaration({\n nodes: [this.#getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n return and\n }\n\n /**\n * Enum will be defined outside the baseType(hints the baseName check)\n */\n if (schema.enum && baseName) {\n const enumName = getUniqueName(baseName, TypeGenerator.usedEnumNames)\n\n let enums: [key: string, value: string | number][] = [...new Set(schema.enum)].map((key) => [key, key])\n\n if ('x-enumNames' in schema) {\n enums = [...new Set(schema['x-enumNames'] as string[])].map((key: string, index) => {\n return [key, schema.enum?.[index]]\n })\n }\n\n this.extraNodes.push(\n ...createEnumDeclaration({\n name: camelCase(enumName, this.caseOptions),\n typeName: this.options.resolveName({ name: enumName, pluginName }),\n enums,\n type: this.options.enumType,\n }),\n )\n return factory.createTypeReferenceNode(this.options.resolveName({ name: enumName, pluginName }), undefined)\n }\n\n if (schema.enum) {\n return createUnionDeclaration({\n nodes: schema.enum.map((name: string) => {\n return factory.createLiteralTypeNode(typeof name === 'number' ? factory.createNumericLiteral(name) : factory.createStringLiteral(`${name}`))\n }) as unknown as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n if ('items' in schema) {\n // items -> array\n const node = this.#getTypeFromSchema(schema.items as OpenAPIV3.SchemaObject, baseName)\n if (node) {\n return factory.createArrayTypeNode(node)\n }\n }\n /**\n * OpenAPI 3.1\n * @link https://json-schema.org/understanding-json-schema/reference/array.html#tuple-validation\n */\n if ('prefixItems' in schema) {\n const prefixItems = schema.prefixItems as OpenAPIV3.SchemaObject[]\n\n return createTupleDeclaration({\n nodes: prefixItems.map((item) => {\n // no baseType so we can fall back on an union when using enum\n return this.#getBaseTypeFromSchema(item, undefined)\n }) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n if (schema.properties || schema.additionalProperties) {\n // properties -> literal type\n return this.#getTypeFromProperties(schema, baseName)\n }\n\n if (schema.type) {\n if (Array.isArray(schema.type)) {\n // OPENAPI v3.1.0: https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0\n const [type, nullable] = schema.type as Array<OpenAPIV3.NonArraySchemaObjectType>\n\n return createUnionDeclaration({\n nodes: [\n this.#getBaseTypeFromSchema(\n {\n ...schema,\n type,\n },\n baseName,\n ),\n nullable ? factory.createLiteralTypeNode(factory.createNull()) : undefined,\n ].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,\n })\n }\n\n if (this.options.dateType === 'date' && ['date', 'date-time'].some((item) => item === schema.format)) {\n return factory.createTypeReferenceNode(factory.createIdentifier('Date'))\n }\n\n // string, boolean, null, number\n if (schema.type in 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 { resolve as swaggerResolve } from '@kubb/swagger'\n\nimport { pluginName } from '../plugin.ts'\n\nimport type { ResolveProps, Resolver } from '@kubb/swagger'\n\ntype Props = ResolveProps & { pluginName?: never }\n\nexport function resolve(props: Props): Resolver {\n return swaggerResolve({ ...props, pluginName })\n}\n","import { getRelativePath } from '@kubb/core'\nimport { OperationGenerator as Generator, resolve } from '@kubb/swagger'\n\nimport { TypeBuilder } from '../builders/index.ts'\nimport { pluginName } from '../plugin.ts'\n\nimport type { KubbFile } from '@kubb/core'\nimport type { FileResolver, Operation, OperationSchemas, Resolver } from '@kubb/swagger'\nimport type { FileMeta, Options as PluginOptions } from '../types.ts'\n\ntype Options = {\n mode: KubbFile.Mode\n enumType: NonNullable<PluginOptions['enumType']>\n dateType: NonNullable<PluginOptions['dateType']>\n optionalType: NonNullable<PluginOptions['optionalType']>\n}\n\nexport class OperationGenerator extends Generator<Options> {\n resolve(operation: Operation): Resolver {\n const { pluginManager } = this.context\n\n return resolve({\n operation,\n resolveName: pluginManager.resolveName,\n resolvePath: pluginManager.resolvePath,\n pluginName,\n })\n }\n\n async all(): Promise<KubbFile.File | null> {\n return null\n }\n\n async get(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n const { mode, enumType, dateType, optionalType } = options\n const { pluginManager } = this.context\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const root = pluginManager.resolvePath({ baseName: type.baseName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = pluginManager.resolvePath({\n baseName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder({\n fileResolver: mode === 'file' ? undefined : fileResolver,\n withJSDocs: true,\n resolveName: pluginManager.resolveName,\n enumType,\n optionalType,\n dateType,\n })\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.headerParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure()\n .print()\n\n return {\n path: type.path,\n baseName: type.baseName,\n source,\n meta: {\n pluginName,\n tag: operation.getTags()[0]?.name,\n },\n }\n }\n\n async post(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n const { mode, enumType, dateType, optionalType } = options\n const { pluginManager } = this.context\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const root = pluginManager.resolvePath({ baseName: type.baseName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = pluginManager.resolvePath({\n baseName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(root, resolvedTypeId)\n }\n\n const source = new TypeBuilder({\n fileResolver: mode === 'file' ? undefined : fileResolver,\n withJSDocs: true,\n resolveName: pluginManager.resolveName,\n enumType,\n optionalType,\n dateType,\n })\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.headerParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure()\n .print()\n\n return {\n path: type.path,\n baseName: type.baseName,\n source,\n meta: {\n pluginName,\n tag: operation.getTags()[0]?.name,\n },\n }\n }\n\n async put(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n async patch(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n async delete(operation: Operation, schemas: OperationSchemas, options: Options): Promise<KubbFile.File<FileMeta> | null> {\n return this.post(operation, schemas, options)\n }\n}\n","import { useResolve as useResolveSwagger } from '@kubb/swagger'\n\nimport { pluginName } from '../plugin.ts'\n\nimport type { Resolver, UseResolveProps } from '@kubb/swagger'\n\ntype Props = UseResolveProps & { pluginName?: never }\n\nexport function useResolve(props: Props = {}): Resolver {\n return useResolveSwagger({ pluginName, ...props })\n}\n","import { definePlugin } from './plugin.ts'\n\nexport * from './builders/index.ts'\nexport * from './generators/index.ts'\nexport * from './hooks/index.ts'\nexport * from './plugin.ts'\nexport * from './types.ts'\nexport * from './utils/index.ts'\n\nexport default definePlugin\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@kubb/swagger-ts",
|
3
|
-
"version": "1.15.0-canary.
|
3
|
+
"version": "1.15.0-canary.20231022T192359",
|
4
4
|
"description": "Generator swagger-ts",
|
5
5
|
"keywords": [
|
6
6
|
"typescript",
|
@@ -39,12 +39,12 @@
|
|
39
39
|
"dependencies": {
|
40
40
|
"change-case": "^4.1.2",
|
41
41
|
"typescript": "^5.2.2",
|
42
|
-
"@kubb/core": "1.
|
43
|
-
"@kubb/parser": "1.
|
44
|
-
"@kubb/swagger": "1.
|
42
|
+
"@kubb/core": "1.15.0-canary.20231022T192242",
|
43
|
+
"@kubb/parser": "1.15.0-canary.20231022T192224",
|
44
|
+
"@kubb/swagger": "1.15.0-canary.20231022T192321"
|
45
45
|
},
|
46
46
|
"devDependencies": {
|
47
|
-
"eslint": "^8.
|
47
|
+
"eslint": "^8.52.0",
|
48
48
|
"tsup": "^7.2.0",
|
49
49
|
"@kubb/eslint-config": "1.1.8",
|
50
50
|
"@kubb/ts-config": "0.1.0",
|