@kubb/swagger-ts 1.0.0-beta.11 → 1.0.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +64 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -10
- package/dist/index.js +65 -68
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/generators/ImportsGenerator.ts +1 -1
- package/src/generators/OperationGenerator.ts +41 -33
- package/src/generators/TypeGenerator.ts +0 -5
- package/src/plugin.ts +31 -43
- package/src/types.ts +1 -5
package/dist/index.cjs
CHANGED
|
@@ -224,11 +224,6 @@ var _TypeGenerator = class extends core.SchemaGenerator {
|
|
|
224
224
|
return this.getTypeFromProperties(schema, name);
|
|
225
225
|
}
|
|
226
226
|
if (schema.type) {
|
|
227
|
-
if (schema.type === "object") {
|
|
228
|
-
if (!schema.additionalProperties && !schema.properties && schema.type === "object") {
|
|
229
|
-
return null;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
227
|
if (Array.isArray(schema.type)) {
|
|
233
228
|
const [type, nullable] = schema.type;
|
|
234
229
|
return factory2.createUnionTypeNode(
|
|
@@ -275,7 +270,7 @@ var ImportsGenerator = class extends core.Generator {
|
|
|
275
270
|
);
|
|
276
271
|
}).map(async ($ref) => {
|
|
277
272
|
const { name } = refs[$ref];
|
|
278
|
-
const path =
|
|
273
|
+
const path = this.options.fileResolver?.(name) || `./${name}`;
|
|
279
274
|
if (path === "./" || path === ".") {
|
|
280
275
|
return void 0;
|
|
281
276
|
}
|
|
@@ -289,11 +284,11 @@ var ImportsGenerator = class extends core.Generator {
|
|
|
289
284
|
}
|
|
290
285
|
};
|
|
291
286
|
var OperationGenerator = class extends swagger.OperationGenerator {
|
|
292
|
-
|
|
293
|
-
const {
|
|
287
|
+
resolve(operation) {
|
|
288
|
+
const { resolvePath, resolveName } = this.options;
|
|
294
289
|
const name = resolveName({ name: operation.getOperationId(), pluginName });
|
|
295
290
|
const fileName = `${name}.ts`;
|
|
296
|
-
const filePath =
|
|
291
|
+
const filePath = resolvePath({ fileName, pluginName, options: { tag: operation.getTags()[0]?.name } });
|
|
297
292
|
if (!filePath || !name) {
|
|
298
293
|
throw new Error("Filepath should be defined");
|
|
299
294
|
}
|
|
@@ -307,14 +302,17 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
|
307
302
|
return null;
|
|
308
303
|
}
|
|
309
304
|
async get(operation, schemas) {
|
|
310
|
-
const { resolvePath,
|
|
311
|
-
const type =
|
|
312
|
-
const fileResolver =
|
|
313
|
-
const filePath =
|
|
314
|
-
const resolvedTypeId =
|
|
305
|
+
const { resolvePath, mode, resolveName, oas, enumType } = this.options;
|
|
306
|
+
const type = this.resolve(operation);
|
|
307
|
+
const fileResolver = (name) => {
|
|
308
|
+
const filePath = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } });
|
|
309
|
+
const resolvedTypeId = resolvePath({
|
|
310
|
+
fileName: `${name}.ts`,
|
|
311
|
+
pluginName
|
|
312
|
+
});
|
|
315
313
|
return core.getRelativePath(filePath, resolvedTypeId);
|
|
316
314
|
};
|
|
317
|
-
const source = await new TypeBuilder(oas).add(schemas.pathParams).add(schemas.queryParams).add(schemas.response).add(schemas.errors).configure({ fileResolver, withJSDocs: true, resolveName, enumType }).print();
|
|
315
|
+
const source = await new TypeBuilder(oas).add(schemas.pathParams).add(schemas.queryParams).add(schemas.response).add(schemas.errors).configure({ fileResolver: mode === "file" ? void 0 : fileResolver, withJSDocs: true, resolveName, enumType }).print();
|
|
318
316
|
return {
|
|
319
317
|
path: type.filePath,
|
|
320
318
|
fileName: type.fileName,
|
|
@@ -322,14 +320,17 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
|
322
320
|
};
|
|
323
321
|
}
|
|
324
322
|
async post(operation, schemas) {
|
|
325
|
-
const { resolvePath,
|
|
326
|
-
const type =
|
|
327
|
-
const fileResolver =
|
|
328
|
-
const filePath =
|
|
329
|
-
const resolvedTypeId =
|
|
323
|
+
const { resolvePath, mode, resolveName, oas, enumType } = this.options;
|
|
324
|
+
const type = this.resolve(operation);
|
|
325
|
+
const fileResolver = (name) => {
|
|
326
|
+
const filePath = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } });
|
|
327
|
+
const resolvedTypeId = resolvePath({
|
|
328
|
+
fileName: `${name}.ts`,
|
|
329
|
+
pluginName
|
|
330
|
+
});
|
|
330
331
|
return core.getRelativePath(filePath, resolvedTypeId);
|
|
331
332
|
};
|
|
332
|
-
const source = await new TypeBuilder(oas).add(schemas.pathParams).add(schemas.queryParams).add(schemas.request).add(schemas.response).add(schemas.errors).configure({ fileResolver, withJSDocs: true, resolveName, enumType }).print();
|
|
333
|
+
const source = await new TypeBuilder(oas).add(schemas.pathParams).add(schemas.queryParams).add(schemas.request).add(schemas.response).add(schemas.errors).configure({ fileResolver: mode === "file" ? void 0 : fileResolver, withJSDocs: true, resolveName, enumType }).print();
|
|
333
334
|
return {
|
|
334
335
|
path: type.filePath,
|
|
335
336
|
fileName: type.fileName,
|
|
@@ -337,14 +338,17 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
|
337
338
|
};
|
|
338
339
|
}
|
|
339
340
|
async put(operation, schemas) {
|
|
340
|
-
const { resolvePath,
|
|
341
|
-
const type =
|
|
342
|
-
const fileResolver =
|
|
343
|
-
const filePath =
|
|
344
|
-
const resolvedTypeId =
|
|
341
|
+
const { resolvePath, mode, resolveName, oas, enumType } = this.options;
|
|
342
|
+
const type = this.resolve(operation);
|
|
343
|
+
const fileResolver = (name) => {
|
|
344
|
+
const filePath = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } });
|
|
345
|
+
const resolvedTypeId = resolvePath({
|
|
346
|
+
fileName: `${name}.ts`,
|
|
347
|
+
pluginName
|
|
348
|
+
});
|
|
345
349
|
return core.getRelativePath(filePath, resolvedTypeId);
|
|
346
350
|
};
|
|
347
|
-
const source = await new TypeBuilder(oas).add(schemas.pathParams).add(schemas.queryParams).add(schemas.request).add(schemas.response).add(schemas.errors).configure({ fileResolver, withJSDocs: true, resolveName, enumType }).print();
|
|
351
|
+
const source = await new TypeBuilder(oas).add(schemas.pathParams).add(schemas.queryParams).add(schemas.request).add(schemas.response).add(schemas.errors).configure({ fileResolver: mode === "file" ? void 0 : fileResolver, withJSDocs: true, resolveName, enumType }).print();
|
|
348
352
|
return {
|
|
349
353
|
path: type.filePath,
|
|
350
354
|
fileName: type.fileName,
|
|
@@ -352,14 +356,17 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
|
352
356
|
};
|
|
353
357
|
}
|
|
354
358
|
async delete(operation, schemas) {
|
|
355
|
-
const { resolvePath,
|
|
356
|
-
const type =
|
|
357
|
-
const fileResolver =
|
|
358
|
-
const filePath =
|
|
359
|
-
const resolvedTypeId =
|
|
359
|
+
const { resolvePath, mode, resolveName, oas, enumType } = this.options;
|
|
360
|
+
const type = this.resolve(operation);
|
|
361
|
+
const fileResolver = (name) => {
|
|
362
|
+
const filePath = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } });
|
|
363
|
+
const resolvedTypeId = resolvePath({
|
|
364
|
+
fileName: `${name}.ts`,
|
|
365
|
+
pluginName
|
|
366
|
+
});
|
|
360
367
|
return core.getRelativePath(filePath, resolvedTypeId);
|
|
361
368
|
};
|
|
362
|
-
const source = await new TypeBuilder(oas).add(schemas.pathParams).add(schemas.request).add(schemas.queryParams).add(schemas.response).add(schemas.errors).configure({ fileResolver, withJSDocs: true, resolveName, enumType }).print();
|
|
369
|
+
const source = await new TypeBuilder(oas).add(schemas.pathParams).add(schemas.request).add(schemas.queryParams).add(schemas.response).add(schemas.errors).configure({ fileResolver: mode === "file" ? void 0 : fileResolver, withJSDocs: true, resolveName, enumType }).print();
|
|
363
370
|
return {
|
|
364
371
|
path: type.filePath,
|
|
365
372
|
fileName: type.fileName,
|
|
@@ -420,27 +427,10 @@ var pluginName = "swagger-ts";
|
|
|
420
427
|
var definePlugin = core.createPlugin((options) => {
|
|
421
428
|
const { output = "models", groupBy, enumType = "asConst" } = options;
|
|
422
429
|
let swaggerApi;
|
|
423
|
-
const api = {
|
|
424
|
-
resolvePath(fileName, directory, options2) {
|
|
425
|
-
if (!directory) {
|
|
426
|
-
return null;
|
|
427
|
-
}
|
|
428
|
-
const mode = core.getPathMode(pathParser__default.default.resolve(directory, output));
|
|
429
|
-
if (mode === "file") {
|
|
430
|
-
return pathParser__default.default.resolve(directory, output);
|
|
431
|
-
}
|
|
432
|
-
if (options2?.tag && groupBy?.type === "tag") {
|
|
433
|
-
const template = groupBy.output ? groupBy.output : `${output}/{{tag}}Controller`;
|
|
434
|
-
return pathParser__default.default.resolve(directory, core.renderTemplate(template, { tag: options2.tag }), fileName);
|
|
435
|
-
}
|
|
436
|
-
return pathParser__default.default.resolve(directory, output, fileName);
|
|
437
|
-
}
|
|
438
|
-
};
|
|
439
430
|
return {
|
|
440
431
|
name: pluginName,
|
|
441
432
|
options,
|
|
442
433
|
kind: "schema",
|
|
443
|
-
api,
|
|
444
434
|
validate(plugins) {
|
|
445
435
|
const valid = core.validatePlugins(plugins, [swagger.pluginName]);
|
|
446
436
|
if (valid) {
|
|
@@ -449,7 +439,16 @@ var definePlugin = core.createPlugin((options) => {
|
|
|
449
439
|
return valid;
|
|
450
440
|
},
|
|
451
441
|
resolvePath(fileName, directory, options2) {
|
|
452
|
-
|
|
442
|
+
const root = pathParser__default.default.resolve(this.config.root, this.config.output.path);
|
|
443
|
+
const mode = core.getPathMode(pathParser__default.default.resolve(root, output));
|
|
444
|
+
if (mode === "file") {
|
|
445
|
+
return pathParser__default.default.resolve(root, output);
|
|
446
|
+
}
|
|
447
|
+
if (options2?.tag && groupBy?.type === "tag") {
|
|
448
|
+
const template = groupBy.output ? groupBy.output : `${output}/{{tag}}Controller`;
|
|
449
|
+
return pathParser__default.default.resolve(root, core.renderTemplate(template, { tag: options2.tag }), fileName);
|
|
450
|
+
}
|
|
451
|
+
return pathParser__default.default.resolve(root, output, fileName);
|
|
453
452
|
},
|
|
454
453
|
resolveName(name) {
|
|
455
454
|
return changeCase.pascalCase(name, { delimiter: "", transform: changeCase.pascalCaseTransformMerge });
|
|
@@ -463,19 +462,18 @@ var definePlugin = core.createPlugin((options) => {
|
|
|
463
462
|
async buildStart() {
|
|
464
463
|
const oas = await swaggerApi.getOas(this.config);
|
|
465
464
|
const schemas = oas.getDefinition().components?.schemas || {};
|
|
466
|
-
const
|
|
467
|
-
const mode = core.getPathMode(pathParser__default.default.resolve(
|
|
465
|
+
const root = pathParser__default.default.resolve(this.config.root, this.config.output.path);
|
|
466
|
+
const mode = core.getPathMode(pathParser__default.default.resolve(root, output));
|
|
468
467
|
if (mode === "directory") {
|
|
469
468
|
const builder = await new TypeBuilder(oas).configure({
|
|
470
469
|
resolveName: (params) => this.resolveName({ pluginName, ...params }),
|
|
471
|
-
fileResolver:
|
|
472
|
-
const resolvedTypeId =
|
|
470
|
+
fileResolver: (name) => {
|
|
471
|
+
const resolvedTypeId = this.resolvePath({
|
|
473
472
|
fileName: `${name}.ts`,
|
|
474
|
-
directory,
|
|
475
473
|
pluginName
|
|
476
474
|
});
|
|
477
|
-
const
|
|
478
|
-
return core.getRelativePath(
|
|
475
|
+
const root2 = this.resolvePath({ fileName: ``, pluginName });
|
|
476
|
+
return core.getRelativePath(root2, resolvedTypeId);
|
|
479
477
|
},
|
|
480
478
|
withJSDocs: true,
|
|
481
479
|
enumType
|
|
@@ -487,7 +485,7 @@ var definePlugin = core.createPlugin((options) => {
|
|
|
487
485
|
});
|
|
488
486
|
});
|
|
489
487
|
const mapFolderSchema = async ([name]) => {
|
|
490
|
-
const path =
|
|
488
|
+
const path = this.resolvePath({ fileName: `${this.resolveName({ name, pluginName })}.ts`, pluginName });
|
|
491
489
|
if (!path) {
|
|
492
490
|
return null;
|
|
493
491
|
}
|
|
@@ -512,7 +510,7 @@ var definePlugin = core.createPlugin((options) => {
|
|
|
512
510
|
name
|
|
513
511
|
});
|
|
514
512
|
});
|
|
515
|
-
const path =
|
|
513
|
+
const path = this.resolvePath({ fileName: "", pluginName });
|
|
516
514
|
if (!path) {
|
|
517
515
|
return;
|
|
518
516
|
}
|
|
@@ -525,20 +523,19 @@ var definePlugin = core.createPlugin((options) => {
|
|
|
525
523
|
const operationGenerator = new OperationGenerator({
|
|
526
524
|
oas,
|
|
527
525
|
mode,
|
|
528
|
-
|
|
529
|
-
fileManager: this.fileManager,
|
|
530
|
-
resolvePath: api.resolvePath.bind(this),
|
|
526
|
+
resolvePath: (params) => this.resolvePath({ pluginName, ...params }),
|
|
531
527
|
resolveName: (params) => this.resolveName({ pluginName, ...params }),
|
|
532
528
|
enumType
|
|
533
529
|
});
|
|
534
|
-
await operationGenerator.build();
|
|
530
|
+
const files = await operationGenerator.build();
|
|
531
|
+
await this.addFile(...files);
|
|
535
532
|
},
|
|
536
533
|
async buildEnd() {
|
|
537
534
|
if (this.config.output.write || this.config.output.write === void 0) {
|
|
538
535
|
const files = await tsCodegen.writeIndexes(this.config.root, this.config.output.path, { extensions: /\.ts/, exclude: [/schemas/, /json/] });
|
|
539
|
-
files
|
|
540
|
-
this.
|
|
541
|
-
}
|
|
536
|
+
if (files) {
|
|
537
|
+
await this.addFile(...files);
|
|
538
|
+
}
|
|
542
539
|
}
|
|
543
540
|
}
|
|
544
541
|
};
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts","../src/builders/TypeBuilder.ts","../src/generators/TypeGenerator.ts","../src/utils/keywordTypeNodes.ts","../src/generators/ImportsGenerator.ts","../src/generators/OperationGenerator.ts","../src/index.ts"],"names":["pascalCase","getRelativePath","ts","factory","node","uniq","Generator","options"],"mappings":";;;;;;;;;AAIA,OAAO,gBAAgB;AAEvB,SAAS,cAAAA,aAAY,gCAAgC;AAGrD,SAAS,mBAAAC,kBAAiB,cAAc,aAAa,iB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AQ,MAAM,aAAa,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,MAAM,EAAE,YAAY,QAAQ,SAAS,CAAC,WAAW,MAAM,EAAE,CAAC;AAChI,eAAO,QAAQ,CAAC,SAAS;AACvB,eAAK,YAAY,YAAY,IAAI;AAAA,QACnC,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF,CAAC;;;AMhLD,IAAO,cAAQ","sourcesContent":["/* eslint-disable @typescript-eslint/ban-types */\n/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-console */\n\nimport pathParser from 'path'\n\nimport { pascalCase, pascalCaseTransformMerge } from 'change-case'\n\nimport type { PluginContext } from '@kubb/core'\nimport { getRelativePath, createPlugin, getPathMode, validatePlugins, renderTemplate } from '@kubb/core'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\nimport type { Api as SwaggerApi, OpenAPIV3 } from '@kubb/swagger'\nimport { writeIndexes } from '@kubb/ts-codegen'\n\nimport { TypeBuilder } from './builders'\nimport { OperationGenerator } from './generators/OperationGenerator'\n\nimport type { Api, PluginOptions } from './types'\n\nexport const pluginName = 'swagger-ts' as const\n\n// Register your plugin for maximum type safety\ndeclare module '@kubb/core' {\n interface Register {\n ['@kubb/swagger-ts']: PluginOptions['options']\n }\n}\n\nexport const definePlugin = createPlugin<PluginOptions>((options) => {\n const { output = 'models', groupBy, enumType = 'asConst' } = options\n let swaggerApi: SwaggerApi\n\n const api: Api = {\n resolvePath(this: PluginContext, fileName, directory, options) {\n if (!directory) {\n return null\n }\n\n const mode = getPathMode(pathParser.resolve(directory, output))\n\n if (mode === 'file') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return pathParser.resolve(directory, output)\n }\n\n if (options?.tag && groupBy?.type === 'tag') {\n const template = groupBy.output ? groupBy.output : `${output}/{{tag}}Controller`\n\n return pathParser.resolve(directory, renderTemplate(template, { tag: options.tag }), fileName)\n }\n\n return pathParser.resolve(directory, output, fileName)\n },\n }\n\n return {\n name: pluginName,\n options,\n kind: 'schema',\n api,\n validate(plugins) {\n const valid = validatePlugins(plugins, [swaggerPluginName])\n if (valid) {\n swaggerApi = plugins.find((plugin) => plugin.name === swaggerPluginName)?.api\n }\n\n return valid\n },\n resolvePath(fileName, directory, options) {\n return api.resolvePath.call(this, fileName, directory, options)\n },\n resolveName(name) {\n return pascalCase(name, { delimiter: '', transform: pascalCaseTransformMerge })\n },\n async writeFile(source, path) {\n if (!path.endsWith('.ts') || !source) {\n return\n }\n\n await this.fileManager.write(source, path)\n },\n async buildStart() {\n const oas = await swaggerApi.getOas(this.config)\n\n const schemas = oas.getDefinition().components?.schemas || {}\n const directory = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(directory, output))\n\n if (mode === 'directory') {\n const builder = await new TypeBuilder(oas).configure({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n fileResolver: async (name) => {\n const resolvedTypeId = await this.resolvePath({\n fileName: `${name}.ts`,\n directory,\n pluginName,\n })\n\n const root = await this.resolvePath({ fileName: ``, directory, pluginName })\n\n return getRelativePath(root, resolvedTypeId)\n },\n withJSDocs: true,\n enumType,\n })\n Object.entries(schemas).forEach(([name, schema]: [string, OpenAPIV3.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const mapFolderSchema = async ([name]: [string, OpenAPIV3.SchemaObject]) => {\n const path = await this.resolvePath({ fileName: `${this.resolveName({ name, pluginName })}.ts`, directory, pluginName })\n\n if (!path) {\n return null\n }\n\n return this.addFile({\n path,\n fileName: `${this.resolveName({ name, pluginName })}.ts`,\n source: await builder.print(name),\n })\n }\n\n const promises = Object.entries(schemas).map(mapFolderSchema)\n\n await Promise.all(promises)\n }\n\n if (mode === 'file') {\n // outside the loop because we need to add files to just one instance to have the correct sorting, see refsSorter\n const builder = new TypeBuilder(oas).configure({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n withJSDocs: true,\n enumType,\n })\n Object.entries(schemas).forEach(([name, schema]: [string, OpenAPIV3.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const path = await this.resolvePath({ fileName: '', directory, pluginName })\n if (!path) {\n return\n }\n\n await this.addFile({\n path,\n fileName: `${this.resolveName({ name: output, pluginName })}.ts`,\n source: await builder.print(),\n })\n }\n\n const operationGenerator = new OperationGenerator({\n oas,\n mode,\n directory,\n fileManager: this.fileManager,\n resolvePath: api.resolvePath.bind(this),\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n enumType,\n })\n\n await operationGenerator.build()\n },\n async buildEnd() {\n if (this.config.output.write || this.config.output.write === undefined) {\n const files = await writeIndexes(this.config.root, this.config.output.path, { extensions: /\\.ts/, exclude: [/schemas/, /json/] })\n files?.forEach((file) => {\n this.fileManager.addOrAppend(file)\n })\n }\n },\n }\n})\n","import { OasBuilder } from '@kubb/swagger'\nimport type { FileResolver } from '@kubb/swagger'\nimport type { PluginContext } from '@kubb/core'\nimport { nameSorter } from '@kubb/core'\nimport { print } from '@kubb/ts-codegen'\n\nimport { ImportsGenerator, TypeGenerator } from '../generators'\n\nimport type ts from 'typescript'\nimport type { Refs } from '../generators'\n\ntype Generated = { refs: Refs; name: string; sources: ts.Node[] }\ntype Config = {\n resolveName: PluginContext['resolveName']\n fileResolver?: FileResolver\n withJSDocs?: boolean\n withImports?: boolean\n enumType: 'enum' | 'asConst'\n}\n\n// TODO create another function that sort based on the refs(first the ones without refs)\nfunction refsSorter(a: Generated, b: Generated) {\n if (Object.keys(a.refs)?.length < Object.keys(b.refs)?.length) {\n return -1\n }\n if (Object.keys(a.refs)?.length > Object.keys(b.refs)?.length) {\n return 1\n }\n return 0\n}\n\nexport class TypeBuilder extends OasBuilder<Config> {\n configure(config: Config) {\n this.config = config\n\n if (this.config.fileResolver) {\n this.config.withImports = true\n }\n\n return this\n }\n\n async print(name?: string) {\n const codes: string[] = []\n\n const generated = this.items\n .filter((gen) => (name ? gen.name === name : true))\n .sort(nameSorter)\n .map((gen) => {\n const generator = new TypeGenerator(this.oas, {\n withJSDocs: this.config.withJSDocs,\n resolveName: this.config.resolveName,\n enumType: this.config.enumType,\n })\n const nodes = generator.build(gen.schema, gen.name, gen.description)\n\n return {\n refs: generator.refs,\n name: gen.name,\n sources: nodes,\n }\n })\n .sort(refsSorter)\n\n generated.forEach((item) => {\n codes.push(print(item.sources))\n })\n\n if (this.config.withImports) {\n const importsGenerator = new ImportsGenerator({ fileResolver: this.config.fileResolver })\n const codeImports = await importsGenerator.build(generated)\n\n if (codeImports) {\n codes.unshift(print(codeImports))\n }\n }\n\n return codes.join('\\n')\n }\n}\n","/* eslint-disable no-param-reassign */\nimport ts from 'typescript'\nimport { pascalCase, camelCase } from 'change-case'\nimport uniq from 'lodash.uniq'\n\nimport type { PluginContext } from '@kubb/core'\nimport { getUniqueName, SchemaGenerator } from '@kubb/core'\nimport type { Oas, OpenAPIV3 } from '@kubb/swagger'\nimport { isReference } from '@kubb/swagger'\nimport {\n appendJSDocToNode,\n createEnumDeclaration,\n createIndexSignature,\n createIntersectionDeclaration,\n createPropertySignature,\n createTypeAliasDeclaration,\n modifier,\n} from '@kubb/ts-codegen'\n\nimport { keywordTypeNodes } from '../utils'\nimport { pluginName } from '../plugin'\n\nconst { factory } = ts\n\n// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n\n/**\n * Name is the ref name + resolved with the nameResolver\n * Key is the original name used\n */\nexport type Refs = Record<string, { name: string; key: string }>\n\ntype Options = {\n withJSDocs?: boolean\n resolveName: PluginContext['resolveName']\n enumType: 'enum' | 'asConst'\n}\nexport class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObject, ts.Node[]> {\n // Collect the types of all referenced schemas so we can export them later\n public static usedEnumNames: Record<string, number> = {}\n\n refs: Refs = {}\n\n extraNodes: ts.Node[] = []\n\n aliases: ts.TypeAliasDeclaration[] = []\n\n // Keep track of already used type aliases\n usedAliasNames: Record<string, number> = {}\n\n constructor(public readonly oas: Oas, options: Options = { withJSDocs: true, resolveName: ({ name }) => name, enumType: 'asConst' }) {\n super(options)\n\n return this\n }\n\n build(schema: OpenAPIV3.SchemaObject, name: string, description?: string) {\n const nodes: ts.Node[] = []\n const type = this.getTypeFromSchema(schema, name)\n\n if (!type) {\n return this.extraNodes\n }\n\n const node = createTypeAliasDeclaration({\n modifiers: [modifier.export],\n name: this.options.resolveName({ name, pluginName }) || name,\n type,\n })\n\n if (description) {\n nodes.push(\n appendJSDocToNode({\n node,\n comments: [`@description ${description}`],\n })\n )\n } else {\n nodes.push(node)\n }\n\n // filter out if the export name is the same as one that we already defined in extraNodes(see enum)\n const filterdNodes = nodes.filter(\n (node: ts.Node) =>\n !this.extraNodes.some(\n (extraNode: ts.Node) => (extraNode as ts.TypeAliasDeclaration)?.name?.escapedText === (node as ts.TypeAliasDeclaration)?.name?.escapedText\n )\n )\n\n return [...this.extraNodes, ...filterdNodes]\n }\n\n /**\n * Creates a type node from a given schema.\n * Delegates to getBaseTypeFromSchema internally and\n * optionally adds a union with null.\n */\n private getTypeFromSchema(schema: OpenAPIV3.SchemaObject, name?: string): ts.TypeNode | null {\n const type = this.getBaseTypeFromSchema(schema, name)\n\n if (!type) {\n return null\n }\n\n if (schema) {\n return type\n }\n\n return factory.createUnionTypeNode([type, keywordTypeNodes.null])\n }\n\n /**\n * Recursively creates a type literal with the given props.\n */\n private getTypeFromProperties(baseSchema?: OpenAPIV3.SchemaObject, baseName?: string) {\n const props = baseSchema?.properties || {}\n const required = baseSchema?.required\n const additionalProperties = baseSchema?.additionalProperties\n\n const members: Array<ts.TypeElement | null> = Object.keys(props).map((name) => {\n const schema = props[name] as OpenAPIV3.SchemaObject\n\n const isRequired = required && required.includes(name)\n let type: ts.TypeNode | null\n if (schema.enum) {\n type = this.getTypeFromSchema(schema, pascalCase(`${baseName} ${name}`, { delimiter: '' }))\n } else {\n type = this.getTypeFromSchema(schema, pascalCase(`${baseName} ${name}`, { delimiter: '' }))\n }\n\n if (!type) {\n return null\n }\n\n if (!isRequired) {\n type = factory.createUnionTypeNode([type, keywordTypeNodes.undefined])\n }\n const propertySignature = createPropertySignature({\n questionToken: !isRequired,\n name,\n type,\n })\n if (this.options.withJSDocs) {\n return appendJSDocToNode({\n node: propertySignature,\n comments: [\n schema.description && `@description ${schema.description}`,\n schema.type && `@type ${schema.type}${isRequired ? '' : ' | undefined'} ${schema.format || ''}`,\n schema.example && `@example ${schema.example}`,\n ],\n })\n }\n\n return propertySignature\n })\n if (additionalProperties) {\n const type = additionalProperties === true ? keywordTypeNodes.any : this.getTypeFromSchema(additionalProperties as OpenAPIV3.SchemaObject)\n\n if (type) {\n members.push(createIndexSignature(type))\n }\n }\n return factory.createTypeLiteralNode(members.filter(Boolean) as ts.TypeElement[])\n }\n\n /**\n * Create a type alias for the schema referenced by the given ReferenceObject\n */\n private getRefAlias(obj: OpenAPIV3.ReferenceObject) {\n const { $ref } = obj\n let ref = this.refs[$ref]\n\n if (!ref) {\n const name = pascalCase(getUniqueName($ref.replace(/.+\\//, ''), this.usedAliasNames), { delimiter: '' })\n\n // eslint-disable-next-line no-multi-assign\n ref = this.refs[$ref] = {\n name: this.options.resolveName({ name, pluginName }) || name,\n key: name,\n }\n }\n\n return factory.createTypeReferenceNode(ref.name, undefined)\n }\n\n /**\n * This is the very core of the OpenAPI to TS conversion - it takes a\n * schema and returns the appropriate type.\n */\n private getBaseTypeFromSchema(schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined, name?: string): ts.TypeNode | null {\n if (!schema) {\n return keywordTypeNodes.any\n }\n\n if (isReference(schema)) {\n return this.getRefAlias(schema)\n }\n\n if (schema.oneOf) {\n // union\n const schemaWithoutOneOf = { ...schema, oneOf: undefined }\n\n return createIntersectionDeclaration({\n nodes: [\n this.getBaseTypeFromSchema(schemaWithoutOneOf, name),\n factory.createParenthesizedType(\n factory.createUnionTypeNode(\n schema.oneOf\n .map((item) => {\n return this.getBaseTypeFromSchema(item)\n })\n .filter(Boolean) as ts.TypeNode[]\n )\n ),\n ].filter(Boolean) as ts.TypeNode[],\n })\n }\n\n if (schema.anyOf) {\n // TODO anyOf -> union\n }\n if (schema.allOf) {\n // intersection/add\n const schemaWithoutAllOf = { ...schema, allOf: undefined }\n\n return createIntersectionDeclaration({\n nodes: [\n this.getBaseTypeFromSchema(schemaWithoutAllOf, name),\n factory.createParenthesizedType(\n factory.createIntersectionTypeNode(\n schema.allOf\n .map((item) => {\n return this.getBaseTypeFromSchema(item)\n })\n .filter(Boolean) as ts.TypeNode[]\n )\n ),\n ].filter(Boolean) as ts.TypeNode[],\n })\n }\n\n if (schema.enum && name) {\n const enumName = getUniqueName(name, TypeGenerator.usedEnumNames)\n\n let enums: [key: string, value: string | number][] = uniq(schema.enum)!.map((key) => [key, key])\n\n if ('x-enumNames' in schema) {\n enums = uniq(schema['x-enumNames'] as string[]).map((key: string, index) => {\n return [key, schema.enum![index]]\n })\n }\n\n this.extraNodes.push(\n ...createEnumDeclaration({\n name: camelCase(enumName, { delimiter: '' }),\n typeName: pascalCase(enumName, { delimiter: '' }),\n enums,\n type: this.options.enumType,\n })\n )\n return factory.createTypeReferenceNode(pascalCase(enumName, { delimiter: '' }), undefined)\n }\n\n if ('items' in schema) {\n // items -> array\n const node = this.getTypeFromSchema(schema.items as OpenAPIV3.SchemaObject, name)\n if (node) {\n return factory.createArrayTypeNode(node)\n }\n }\n\n if (schema.properties || schema.additionalProperties) {\n // properties -> literal type\n return this.getTypeFromProperties(schema, name)\n }\n\n if (schema.type) {\n if (schema.type === 'object') {\n if (!schema.additionalProperties && !schema.properties && schema.type === 'object') {\n return null\n }\n }\n if (Array.isArray(schema.type)) {\n // OPENAPI v3.1.0: https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0\n const [type, nullable] = schema.type\n\n return factory.createUnionTypeNode(\n [\n this.getBaseTypeFromSchema(\n {\n ...schema,\n type,\n },\n name\n )!,\n nullable ? factory.createLiteralTypeNode(factory.createNull()) : undefined,\n ].filter(Boolean) as ts.TypeNode[]\n )\n }\n // string, boolean, null, number\n if (schema.type in keywordTypeNodes) {\n return keywordTypeNodes[schema.type as keyof typeof keywordTypeNodes]\n }\n }\n\n if (schema.format === 'binary') {\n return factory.createTypeReferenceNode('Blob', [])\n }\n\n return keywordTypeNodes.any\n }\n}\n","import ts from 'typescript'\n\nconst { factory } = ts\n\nexport const keywordTypeNodes = {\n any: factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),\n number: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n integer: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n object: factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword),\n string: factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n boolean: factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),\n undefined: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n null: factory.createLiteralTypeNode(factory.createToken(ts.SyntaxKind.NullKeyword)),\n} as const\n","import uniq from 'lodash.uniq'\n\nimport { Generator } from '@kubb/core'\nimport type { FileResolver } from '@kubb/swagger'\nimport { createImportDeclaration } from '@kubb/ts-codegen'\n\nimport type { Refs } from './TypeGenerator'\nimport type ts from 'typescript'\n\ntype Options = {\n fileResolver?: FileResolver\n}\nexport class ImportsGenerator extends Generator<Options> {\n async build(items: Array<{ refs: Refs; sources: ts.Node[]; name: string }>): Promise<Array<ts.ImportDeclaration> | undefined> {\n const refs = items.reduce((acc, currentValue) => {\n return {\n ...acc,\n ...currentValue.refs,\n }\n }, {} as Refs)\n\n if (Object.keys(refs).length === 0) {\n return undefined\n }\n\n // add imports based on $ref\n const importPromises = uniq(Object.keys(refs))\n .filter(($ref: string) => {\n // when using a $ref inside a type we should not repeat that import\n const { key } = refs[$ref]\n return !items.find((item) =>\n item.sources.find((node: ts.Node) => (node as ts.TypeAliasDeclaration).name?.escapedText.toString().toLowerCase() === key.toLowerCase())\n )\n })\n .map(async ($ref: string) => {\n const { name } = refs[$ref]\n\n const path = (await this.options.fileResolver?.(name)) || `./${name}`\n\n // TODO weird hacky fix\n if (path === './' || path === '.') {\n return undefined\n }\n\n return createImportDeclaration({\n name: [name],\n path: path.replace('./../', '../'),\n })\n })\n\n const nodes = await Promise.all(importPromises)\n\n return nodes.filter(Boolean) as ts.ImportDeclaration[]\n }\n}\n","import type { File, FileManager, PathMode, PluginContext } from '@kubb/core'\nimport { getRelativePath } from '@kubb/core'\nimport { OperationGenerator as Generator } from '@kubb/swagger'\nimport type { FileResolver, Oas, Operation, OperationSchemas, Resolver } from '@kubb/swagger'\n\nimport { TypeBuilder } from '../builders'\nimport { pluginName } from '../plugin'\n\nimport type { Api } from '../types'\n\ntype Options = {\n oas: Oas\n resolvePath: Api['resolvePath']\n resolveName: PluginContext['resolveName']\n mode: PathMode\n fileManager: FileManager\n directory: string\n enumType: 'enum' | 'asConst'\n}\n\nexport class OperationGenerator extends Generator<Options> {\n async resolve(operation: Operation): Promise<Resolver> {\n const { directory, resolvePath, resolveName } = this.options\n\n const name = resolveName({ name: operation.getOperationId(), pluginName })\n const fileName = `${name}.ts`\n const filePath = await resolvePath(fileName, directory, { tag: operation.getTags()[0]?.name })\n\n if (!filePath || !name) {\n throw new Error('Filepath should be defined')\n }\n\n return {\n name,\n fileName,\n filePath,\n }\n }\n\n async all(): Promise<File | null> {\n return null\n }\n\n async get(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, directory, mode, resolveName, oas, enumType } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory, { tag: operation.getTags()[0]?.name })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n\n async post(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, directory, mode, resolveName, oas, enumType } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory, { tag: operation.getTags()[0]?.name })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n\n async put(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, directory, mode, resolveName, oas, enumType } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory, { tag: operation.getTags()[0]?.name })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n\n async delete(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, directory, mode, resolveName, oas, enumType } = this.options\n\n const type = await this.resolve(operation)\n\n const fileResolver: FileResolver = async (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = await resolvePath(mode === 'file' ? '' : type.name, directory, { tag: operation.getTags()[0]?.name })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = await resolvePath(`${name}.ts`, directory)\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.request)\n .add(schemas.queryParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n}\n","import { definePlugin } from './plugin'\n\nexport * from './plugin'\nexport * from './generators'\nexport * from './builders'\nexport * from './types'\nexport * from './utils'\nexport default definePlugin\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts","../src/builders/TypeBuilder.ts","../src/generators/TypeGenerator.ts","../src/utils/keywordTypeNodes.ts","../src/generators/ImportsGenerator.ts","../src/generators/OperationGenerator.ts","../src/index.ts"],"names":["pascalCase","getRelativePath","ts","factory","node","uniq","Generator","options","root"],"mappings":";;;;;;;;;AAIA,OAAO,gBAAgB;AAEvB,SAAS,cAAAA,aAAY,gCAAgC;AAErD,SAAS,mBAAAC,kBAAiB,cAAc,aAAa,iBAAiB,sBAAsB;AAC5F,SAAS,cAAc,yBAAyB;AAEhD,SAAS,oBAAoB;;;ACX7B,SAAS,kBAAkB;AAG3B,SAAS,kBAAkB;AAC3B,SAAS,aAAa;;;ACHtB,OAAOC,SAAQ;AACf,SAAS,YAAY,iBAAiB;AACtC,OAAO,UAAU;AAGjB,SAAS,eAAe,uBAAuB;AAE/C,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;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ACD,eAAO,QAAQ,OAAO,EAAE,QAAQ,CAAC,CAAC,MAAM,MAAM,MAAwC;AAEpF,iBAAO,QAAQ,IAAI;AAAA,YACjB;AAAA,YACA;AAAA,UACF,CAAC;AAAA,QACH,CAAC;AAED,cAAM,OAAO,KAAK,YAAY,EAAE,UAAU,IAAI,WAAW,CAAC;AAC1D,YAAI,CAAC,MAAM;AACT;AAAA,QACF;AAEA,cAAM,KAAK,QAAQ;AAAA,UACjB;AAAA,UACA,UAAU,GAAG,KAAK,YAAY,EAAE,MAAM,QAAQ,WAAW,CAAC;AAAA,UAC1D,QAAQ,MAAM,QAAQ,MAAM;AAAA,QAC9B,CAAC;AAAA,MACH;AAEA,YAAM,qBAAqB,IAAI,mBAAmB;AAAA,QAChD;AAAA,QACA;AAAA,QACA,aAAa,CAAC,WAAW,KAAK,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC;AAAA,QACnE,aAAa,CAAC,WAAW,KAAK,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC;AAAA,QACnE;AAAA,MACF,CAAC;AAED,YAAM,QAAQ,MAAM,mBAAmB,MAAM;AAC7C,YAAM,KAAK,QAAQ,GAAG,KAAK;AAAA,IAC7B;AAAA,IACA,MAAM,WAAW;AACf,UAAI,KAAK,OAAO,OAAO,SAAS,KAAK,OAAO,OAAO,UAAU,QAAW;AACtE,cAAM,QAAQ,MAAM,aAAa,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,MAAM,EAAE,YAAY,QAAQ,SAAS,CAAC,WAAW,MAAM,EAAE,CAAC;AAEhI,YAAI,OAAO;AACT,gBAAM,KAAK,QAAQ,GAAG,KAAK;AAAA,QAC7B;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;;;AMpKD,IAAO,cAAQ","sourcesContent":["/* eslint-disable @typescript-eslint/ban-types */\n/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-console */\n\nimport pathParser from 'path'\n\nimport { pascalCase, pascalCaseTransformMerge } from 'change-case'\n\nimport { getRelativePath, createPlugin, getPathMode, validatePlugins, renderTemplate } from '@kubb/core'\nimport { pluginName as swaggerPluginName } from '@kubb/swagger'\nimport type { Api as SwaggerApi, OpenAPIV3 } from '@kubb/swagger'\nimport { writeIndexes } from '@kubb/ts-codegen'\n\nimport { TypeBuilder } from './builders'\nimport { OperationGenerator } from './generators/OperationGenerator'\n\nimport type { PluginOptions } from './types'\n\nexport const pluginName = 'swagger-ts' as const\n\n// Register your plugin for maximum type safety\ndeclare module '@kubb/core' {\n interface Register {\n ['@kubb/swagger-ts']: PluginOptions['options']\n }\n}\n\nexport const definePlugin = createPlugin<PluginOptions>((options) => {\n const { output = 'models', groupBy, enumType = 'asConst' } = options\n let swaggerApi: SwaggerApi\n\n return {\n name: pluginName,\n options,\n kind: 'schema',\n validate(plugins) {\n const valid = validatePlugins(plugins, [swaggerPluginName])\n if (valid) {\n swaggerApi = plugins.find((plugin) => plugin.name === swaggerPluginName)?.api\n }\n\n return valid\n },\n resolvePath(fileName, directory, options) {\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(root, output))\n\n if (mode === 'file') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return pathParser.resolve(root, output)\n }\n\n if (options?.tag && groupBy?.type === 'tag') {\n const template = groupBy.output ? groupBy.output : `${output}/{{tag}}Controller`\n\n return pathParser.resolve(root, renderTemplate(template, { tag: options.tag }), fileName)\n }\n\n return pathParser.resolve(root, output, fileName)\n },\n resolveName(name) {\n return pascalCase(name, { delimiter: '', transform: pascalCaseTransformMerge })\n },\n async writeFile(source, path) {\n if (!path.endsWith('.ts') || !source) {\n return\n }\n\n await this.fileManager.write(source, path)\n },\n async buildStart() {\n const oas = await swaggerApi.getOas(this.config)\n\n const schemas = oas.getDefinition().components?.schemas || {}\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n const mode = getPathMode(pathParser.resolve(root, output))\n\n if (mode === 'directory') {\n const builder = await new TypeBuilder(oas).configure({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n fileResolver: (name) => {\n const resolvedTypeId = this.resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n const root = this.resolvePath({ fileName: ``, pluginName })\n\n return getRelativePath(root, resolvedTypeId)\n },\n withJSDocs: true,\n enumType,\n })\n Object.entries(schemas).forEach(([name, schema]: [string, OpenAPIV3.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const mapFolderSchema = async ([name]: [string, OpenAPIV3.SchemaObject]) => {\n const path = this.resolvePath({ fileName: `${this.resolveName({ name, pluginName })}.ts`, pluginName })\n\n if (!path) {\n return null\n }\n\n return this.addFile({\n path,\n fileName: `${this.resolveName({ name, pluginName })}.ts`,\n source: await builder.print(name),\n })\n }\n\n const promises = Object.entries(schemas).map(mapFolderSchema)\n\n await Promise.all(promises)\n }\n\n if (mode === 'file') {\n // outside the loop because we need to add files to just one instance to have the correct sorting, see refsSorter\n const builder = new TypeBuilder(oas).configure({\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n withJSDocs: true,\n enumType,\n })\n Object.entries(schemas).forEach(([name, schema]: [string, OpenAPIV3.SchemaObject]) => {\n // generate and pass through new code back to the core so it can be write to that file\n return builder.add({\n schema,\n name,\n })\n })\n\n const path = this.resolvePath({ fileName: '', pluginName })\n if (!path) {\n return\n }\n\n await this.addFile({\n path,\n fileName: `${this.resolveName({ name: output, pluginName })}.ts`,\n source: await builder.print(),\n })\n }\n\n const operationGenerator = new OperationGenerator({\n oas,\n mode,\n resolvePath: (params) => this.resolvePath({ pluginName, ...params }),\n resolveName: (params) => this.resolveName({ pluginName, ...params }),\n enumType,\n })\n\n const files = await operationGenerator.build()\n await this.addFile(...files)\n },\n async buildEnd() {\n if (this.config.output.write || this.config.output.write === undefined) {\n const files = await writeIndexes(this.config.root, this.config.output.path, { extensions: /\\.ts/, exclude: [/schemas/, /json/] })\n\n if (files) {\n await this.addFile(...files)\n }\n }\n },\n }\n})\n","import { OasBuilder } from '@kubb/swagger'\nimport type { FileResolver } from '@kubb/swagger'\nimport type { PluginContext } from '@kubb/core'\nimport { nameSorter } from '@kubb/core'\nimport { print } from '@kubb/ts-codegen'\n\nimport { ImportsGenerator, TypeGenerator } from '../generators'\n\nimport type ts from 'typescript'\nimport type { Refs } from '../generators'\n\ntype Generated = { refs: Refs; name: string; sources: ts.Node[] }\ntype Config = {\n resolveName: PluginContext['resolveName']\n fileResolver?: FileResolver\n withJSDocs?: boolean\n withImports?: boolean\n enumType: 'enum' | 'asConst'\n}\n\n// TODO create another function that sort based on the refs(first the ones without refs)\nfunction refsSorter(a: Generated, b: Generated) {\n if (Object.keys(a.refs)?.length < Object.keys(b.refs)?.length) {\n return -1\n }\n if (Object.keys(a.refs)?.length > Object.keys(b.refs)?.length) {\n return 1\n }\n return 0\n}\n\nexport class TypeBuilder extends OasBuilder<Config> {\n configure(config: Config) {\n this.config = config\n\n if (this.config.fileResolver) {\n this.config.withImports = true\n }\n\n return this\n }\n\n async print(name?: string) {\n const codes: string[] = []\n\n const generated = this.items\n .filter((gen) => (name ? gen.name === name : true))\n .sort(nameSorter)\n .map((gen) => {\n const generator = new TypeGenerator(this.oas, {\n withJSDocs: this.config.withJSDocs,\n resolveName: this.config.resolveName,\n enumType: this.config.enumType,\n })\n const nodes = generator.build(gen.schema, gen.name, gen.description)\n\n return {\n refs: generator.refs,\n name: gen.name,\n sources: nodes,\n }\n })\n .sort(refsSorter)\n\n generated.forEach((item) => {\n codes.push(print(item.sources))\n })\n\n if (this.config.withImports) {\n const importsGenerator = new ImportsGenerator({ fileResolver: this.config.fileResolver })\n const codeImports = await importsGenerator.build(generated)\n\n if (codeImports) {\n codes.unshift(print(codeImports))\n }\n }\n\n return codes.join('\\n')\n }\n}\n","/* eslint-disable no-param-reassign */\nimport ts from 'typescript'\nimport { pascalCase, camelCase } from 'change-case'\nimport uniq from 'lodash.uniq'\n\nimport type { PluginContext } from '@kubb/core'\nimport { getUniqueName, SchemaGenerator } from '@kubb/core'\nimport type { Oas, OpenAPIV3 } from '@kubb/swagger'\nimport { isReference } from '@kubb/swagger'\nimport {\n appendJSDocToNode,\n createEnumDeclaration,\n createIndexSignature,\n createIntersectionDeclaration,\n createPropertySignature,\n createTypeAliasDeclaration,\n modifier,\n} from '@kubb/ts-codegen'\n\nimport { keywordTypeNodes } from '../utils'\nimport { pluginName } from '../plugin'\n\nconst { factory } = ts\n\n// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n\n/**\n * Name is the ref name + resolved with the nameResolver\n * Key is the original name used\n */\nexport type Refs = Record<string, { name: string; key: string }>\n\ntype Options = {\n withJSDocs?: boolean\n resolveName: PluginContext['resolveName']\n enumType: 'enum' | 'asConst'\n}\nexport class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObject, ts.Node[]> {\n // Collect the types of all referenced schemas so we can export them later\n public static usedEnumNames: Record<string, number> = {}\n\n refs: Refs = {}\n\n extraNodes: ts.Node[] = []\n\n aliases: ts.TypeAliasDeclaration[] = []\n\n // Keep track of already used type aliases\n usedAliasNames: Record<string, number> = {}\n\n constructor(public readonly oas: Oas, options: Options = { withJSDocs: true, resolveName: ({ name }) => name, enumType: 'asConst' }) {\n super(options)\n\n return this\n }\n\n build(schema: OpenAPIV3.SchemaObject, name: string, description?: string) {\n const nodes: ts.Node[] = []\n const type = this.getTypeFromSchema(schema, name)\n\n if (!type) {\n return this.extraNodes\n }\n\n const node = createTypeAliasDeclaration({\n modifiers: [modifier.export],\n name: this.options.resolveName({ name, pluginName }) || name,\n type,\n })\n\n if (description) {\n nodes.push(\n appendJSDocToNode({\n node,\n comments: [`@description ${description}`],\n })\n )\n } else {\n nodes.push(node)\n }\n\n // filter out if the export name is the same as one that we already defined in extraNodes(see enum)\n const filterdNodes = nodes.filter(\n (node: ts.Node) =>\n !this.extraNodes.some(\n (extraNode: ts.Node) => (extraNode as ts.TypeAliasDeclaration)?.name?.escapedText === (node as ts.TypeAliasDeclaration)?.name?.escapedText\n )\n )\n\n return [...this.extraNodes, ...filterdNodes]\n }\n\n /**\n * Creates a type node from a given schema.\n * Delegates to getBaseTypeFromSchema internally and\n * optionally adds a union with null.\n */\n private getTypeFromSchema(schema: OpenAPIV3.SchemaObject, name?: string): ts.TypeNode | null {\n const type = this.getBaseTypeFromSchema(schema, name)\n\n if (!type) {\n return null\n }\n\n if (schema) {\n return type\n }\n\n return factory.createUnionTypeNode([type, keywordTypeNodes.null])\n }\n\n /**\n * Recursively creates a type literal with the given props.\n */\n private getTypeFromProperties(baseSchema?: OpenAPIV3.SchemaObject, baseName?: string) {\n const props = baseSchema?.properties || {}\n const required = baseSchema?.required\n const additionalProperties = baseSchema?.additionalProperties\n\n const members: Array<ts.TypeElement | null> = Object.keys(props).map((name) => {\n const schema = props[name] as OpenAPIV3.SchemaObject\n\n const isRequired = required && required.includes(name)\n let type: ts.TypeNode | null\n if (schema.enum) {\n type = this.getTypeFromSchema(schema, pascalCase(`${baseName} ${name}`, { delimiter: '' }))\n } else {\n type = this.getTypeFromSchema(schema, pascalCase(`${baseName} ${name}`, { delimiter: '' }))\n }\n\n if (!type) {\n return null\n }\n\n if (!isRequired) {\n type = factory.createUnionTypeNode([type, keywordTypeNodes.undefined])\n }\n const propertySignature = createPropertySignature({\n questionToken: !isRequired,\n name,\n type,\n })\n if (this.options.withJSDocs) {\n return appendJSDocToNode({\n node: propertySignature,\n comments: [\n schema.description && `@description ${schema.description}`,\n schema.type && `@type ${schema.type}${isRequired ? '' : ' | undefined'} ${schema.format || ''}`,\n schema.example && `@example ${schema.example}`,\n ],\n })\n }\n\n return propertySignature\n })\n if (additionalProperties) {\n const type = additionalProperties === true ? keywordTypeNodes.any : this.getTypeFromSchema(additionalProperties as OpenAPIV3.SchemaObject)\n\n if (type) {\n members.push(createIndexSignature(type))\n }\n }\n return factory.createTypeLiteralNode(members.filter(Boolean) as ts.TypeElement[])\n }\n\n /**\n * Create a type alias for the schema referenced by the given ReferenceObject\n */\n private getRefAlias(obj: OpenAPIV3.ReferenceObject) {\n const { $ref } = obj\n let ref = this.refs[$ref]\n\n if (!ref) {\n const name = pascalCase(getUniqueName($ref.replace(/.+\\//, ''), this.usedAliasNames), { delimiter: '' })\n\n // eslint-disable-next-line no-multi-assign\n ref = this.refs[$ref] = {\n name: this.options.resolveName({ name, pluginName }) || name,\n key: name,\n }\n }\n\n return factory.createTypeReferenceNode(ref.name, undefined)\n }\n\n /**\n * This is the very core of the OpenAPI to TS conversion - it takes a\n * schema and returns the appropriate type.\n */\n private getBaseTypeFromSchema(schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined, name?: string): ts.TypeNode | null {\n if (!schema) {\n return keywordTypeNodes.any\n }\n\n if (isReference(schema)) {\n return this.getRefAlias(schema)\n }\n\n if (schema.oneOf) {\n // union\n const schemaWithoutOneOf = { ...schema, oneOf: undefined }\n\n return createIntersectionDeclaration({\n nodes: [\n this.getBaseTypeFromSchema(schemaWithoutOneOf, name),\n factory.createParenthesizedType(\n factory.createUnionTypeNode(\n schema.oneOf\n .map((item) => {\n return this.getBaseTypeFromSchema(item)\n })\n .filter(Boolean) as ts.TypeNode[]\n )\n ),\n ].filter(Boolean) as ts.TypeNode[],\n })\n }\n\n if (schema.anyOf) {\n // TODO anyOf -> union\n }\n if (schema.allOf) {\n // intersection/add\n const schemaWithoutAllOf = { ...schema, allOf: undefined }\n\n return createIntersectionDeclaration({\n nodes: [\n this.getBaseTypeFromSchema(schemaWithoutAllOf, name),\n factory.createParenthesizedType(\n factory.createIntersectionTypeNode(\n schema.allOf\n .map((item) => {\n return this.getBaseTypeFromSchema(item)\n })\n .filter(Boolean) as ts.TypeNode[]\n )\n ),\n ].filter(Boolean) as ts.TypeNode[],\n })\n }\n\n if (schema.enum && name) {\n const enumName = getUniqueName(name, TypeGenerator.usedEnumNames)\n\n let enums: [key: string, value: string | number][] = uniq(schema.enum)!.map((key) => [key, key])\n\n if ('x-enumNames' in schema) {\n enums = uniq(schema['x-enumNames'] as string[]).map((key: string, index) => {\n return [key, schema.enum![index]]\n })\n }\n\n this.extraNodes.push(\n ...createEnumDeclaration({\n name: camelCase(enumName, { delimiter: '' }),\n typeName: pascalCase(enumName, { delimiter: '' }),\n enums,\n type: this.options.enumType,\n })\n )\n return factory.createTypeReferenceNode(pascalCase(enumName, { delimiter: '' }), undefined)\n }\n\n if ('items' in schema) {\n // items -> array\n const node = this.getTypeFromSchema(schema.items as OpenAPIV3.SchemaObject, name)\n if (node) {\n return factory.createArrayTypeNode(node)\n }\n }\n\n if (schema.properties || schema.additionalProperties) {\n // properties -> literal type\n return this.getTypeFromProperties(schema, name)\n }\n\n if (schema.type) {\n if (Array.isArray(schema.type)) {\n // OPENAPI v3.1.0: https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0\n const [type, nullable] = schema.type\n\n return factory.createUnionTypeNode(\n [\n this.getBaseTypeFromSchema(\n {\n ...schema,\n type,\n },\n name\n )!,\n nullable ? factory.createLiteralTypeNode(factory.createNull()) : undefined,\n ].filter(Boolean) as ts.TypeNode[]\n )\n }\n // string, boolean, null, number\n if (schema.type in keywordTypeNodes) {\n return keywordTypeNodes[schema.type as keyof typeof keywordTypeNodes]\n }\n }\n\n if (schema.format === 'binary') {\n return factory.createTypeReferenceNode('Blob', [])\n }\n\n return keywordTypeNodes.any\n }\n}\n","import ts from 'typescript'\n\nconst { factory } = ts\n\nexport const keywordTypeNodes = {\n any: factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),\n number: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n integer: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n object: factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword),\n string: factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n boolean: factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),\n undefined: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n null: factory.createLiteralTypeNode(factory.createToken(ts.SyntaxKind.NullKeyword)),\n} as const\n","import uniq from 'lodash.uniq'\n\nimport { Generator } from '@kubb/core'\nimport type { FileResolver } from '@kubb/swagger'\nimport { createImportDeclaration } from '@kubb/ts-codegen'\n\nimport type { Refs } from './TypeGenerator'\nimport type ts from 'typescript'\n\ntype Options = {\n fileResolver?: FileResolver\n}\nexport class ImportsGenerator extends Generator<Options> {\n async build(items: Array<{ refs: Refs; sources: ts.Node[]; name: string }>): Promise<Array<ts.ImportDeclaration> | undefined> {\n const refs = items.reduce((acc, currentValue) => {\n return {\n ...acc,\n ...currentValue.refs,\n }\n }, {} as Refs)\n\n if (Object.keys(refs).length === 0) {\n return undefined\n }\n\n // add imports based on $ref\n const importPromises = uniq(Object.keys(refs))\n .filter(($ref: string) => {\n // when using a $ref inside a type we should not repeat that import\n const { key } = refs[$ref]\n return !items.find((item) =>\n item.sources.find((node: ts.Node) => (node as ts.TypeAliasDeclaration).name?.escapedText.toString().toLowerCase() === key.toLowerCase())\n )\n })\n .map(async ($ref: string) => {\n const { name } = refs[$ref]\n\n const path = this.options.fileResolver?.(name) || `./${name}`\n\n // TODO weird hacky fix\n if (path === './' || path === '.') {\n return undefined\n }\n\n return createImportDeclaration({\n name: [name],\n path: path.replace('./../', '../'),\n })\n })\n\n const nodes = await Promise.all(importPromises)\n\n return nodes.filter(Boolean) as ts.ImportDeclaration[]\n }\n}\n","import type { File, PathMode, PluginContext } from '@kubb/core'\nimport { getRelativePath } from '@kubb/core'\nimport { OperationGenerator as Generator } from '@kubb/swagger'\nimport type { FileResolver, Oas, Operation, OperationSchemas, Resolver } from '@kubb/swagger'\n\nimport { TypeBuilder } from '../builders'\nimport { pluginName } from '../plugin'\n\ntype Options = {\n oas: Oas\n resolvePath: PluginContext['resolvePath']\n resolveName: PluginContext['resolveName']\n mode: PathMode\n enumType: 'enum' | 'asConst'\n}\n\nexport class OperationGenerator extends Generator<Options> {\n resolve(operation: Operation): Resolver {\n const { resolvePath, resolveName } = this.options\n\n const name = resolveName({ name: operation.getOperationId(), pluginName })\n const fileName = `${name}.ts`\n const filePath = resolvePath({ fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n\n if (!filePath || !name) {\n throw new Error('Filepath should be defined')\n }\n\n return {\n name,\n fileName,\n filePath,\n }\n }\n\n async all(): Promise<File | null> {\n return null\n }\n\n async get(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n\n async post(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n\n async put(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.queryParams)\n .add(schemas.request)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n\n async delete(operation: Operation, schemas: OperationSchemas): Promise<File | null> {\n const { resolvePath, mode, resolveName, oas, enumType } = this.options\n\n const type = this.resolve(operation)\n\n const fileResolver: FileResolver = (name) => {\n // Used when a react-query type(request, response, params) has an import of a global type\n const filePath = resolvePath({ fileName: type.fileName, pluginName, options: { tag: operation.getTags()[0]?.name } })\n // refs import, will always been created with the SwaggerTS plugin, our global type\n const resolvedTypeId = resolvePath({\n fileName: `${name}.ts`,\n pluginName,\n })\n\n return getRelativePath(filePath, resolvedTypeId)\n }\n\n const source = await new TypeBuilder(oas)\n .add(schemas.pathParams)\n .add(schemas.request)\n .add(schemas.queryParams)\n .add(schemas.response)\n .add(schemas.errors)\n .configure({ fileResolver: mode === 'file' ? undefined : fileResolver, withJSDocs: true, resolveName, enumType })\n .print()\n\n return {\n path: type.filePath,\n fileName: type.fileName,\n source,\n }\n }\n}\n","import { definePlugin } from './plugin'\n\nexport * from './plugin'\nexport * from './generators'\nexport * from './builders'\nexport * from './types'\nexport * from './utils'\nexport default definePlugin\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
|
2
|
-
import { PluginFactoryOptions, SchemaGenerator, PluginContext, Generator, File, PathMode
|
|
2
|
+
import { PluginFactoryOptions, SchemaGenerator, PluginContext, Generator, File, PathMode } from '@kubb/core';
|
|
3
3
|
import ts from 'typescript';
|
|
4
4
|
import { OpenAPIV3, Oas, FileResolver, OperationGenerator as OperationGenerator$1, Operation, Resolver, OperationSchemas, OasBuilder } from '@kubb/swagger';
|
|
5
5
|
|
|
6
|
-
type Api = {
|
|
7
|
-
resolvePath: (fileName: string, directory: string | undefined, options?: ResolvePathOptions) => string | null;
|
|
8
|
-
};
|
|
9
6
|
type Options$3 = {
|
|
10
7
|
/**
|
|
11
8
|
* Relative path to save the TypeScript types.
|
|
@@ -39,7 +36,7 @@ type Options$3 = {
|
|
|
39
36
|
type ResolvePathOptions = {
|
|
40
37
|
tag?: string;
|
|
41
38
|
};
|
|
42
|
-
type PluginOptions = PluginFactoryOptions<Options$3, false,
|
|
39
|
+
type PluginOptions = PluginFactoryOptions<Options$3, false, unknown, ResolvePathOptions>;
|
|
43
40
|
|
|
44
41
|
declare const pluginName: "swagger-ts";
|
|
45
42
|
declare module '@kubb/core' {
|
|
@@ -105,15 +102,13 @@ declare class ImportsGenerator extends Generator<Options$1> {
|
|
|
105
102
|
|
|
106
103
|
type Options = {
|
|
107
104
|
oas: Oas;
|
|
108
|
-
resolvePath:
|
|
105
|
+
resolvePath: PluginContext['resolvePath'];
|
|
109
106
|
resolveName: PluginContext['resolveName'];
|
|
110
107
|
mode: PathMode;
|
|
111
|
-
fileManager: FileManager;
|
|
112
|
-
directory: string;
|
|
113
108
|
enumType: 'enum' | 'asConst';
|
|
114
109
|
};
|
|
115
110
|
declare class OperationGenerator extends OperationGenerator$1<Options> {
|
|
116
|
-
resolve(operation: Operation):
|
|
111
|
+
resolve(operation: Operation): Resolver;
|
|
117
112
|
all(): Promise<File | null>;
|
|
118
113
|
get(operation: Operation, schemas: OperationSchemas): Promise<File | null>;
|
|
119
114
|
post(operation: Operation, schemas: OperationSchemas): Promise<File | null>;
|
|
@@ -144,4 +139,4 @@ declare const keywordTypeNodes: {
|
|
|
144
139
|
readonly null: ts.LiteralTypeNode;
|
|
145
140
|
};
|
|
146
141
|
|
|
147
|
-
export {
|
|
142
|
+
export { ImportsGenerator, OperationGenerator, Options$3 as Options, PluginOptions, Refs, ResolvePathOptions, TypeBuilder, TypeGenerator, definePlugin as default, definePlugin, keywordTypeNodes, pluginName };
|