@ps-aux/api-client-gen 0.7.0-rc.6 → 0.7.0-rc.8
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/bin.cjs +5 -5
- package/dist/bin.mjs +3 -3
- package/dist/{generateApiClient.cjs → generate.cjs} +366 -339
- package/dist/{generateApiClient.mjs → generate.mjs} +363 -336
- package/dist/index.cjs +8 -6
- package/dist/index.mjs +6 -4
- package/package.json +1 -1
- package/templates/{http-client.eta → legacy/http-client.eta} +2 -2
- package/templates/{procedure-call.ejs → legacy/procedure-call.ejs} +2 -2
- /package/templates/{api.ejs → legacy/api.ejs} +0 -0
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import Path$1 from 'path';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
3
4
|
import Path from 'node:path';
|
|
5
|
+
import 'c12';
|
|
6
|
+
import { generate } from 'ts-to-zod';
|
|
7
|
+
import fs$1, { mkdir, writeFile, readFile } from 'node:fs/promises';
|
|
4
8
|
import { generateApi } from 'swagger-typescript-api';
|
|
5
9
|
import { fileURLToPath } from 'node:url';
|
|
6
|
-
import fs$1, { readFile, mkdir, writeFile } from 'node:fs/promises';
|
|
7
|
-
import { generate } from 'ts-to-zod';
|
|
8
10
|
|
|
9
11
|
/** A special constant with type `never` */
|
|
10
12
|
function $constructor(name, initializer, params) {
|
|
@@ -4216,7 +4218,7 @@ const vNextOasGeneratorSchema = strictObject({
|
|
|
4216
4218
|
}).prefault({}),
|
|
4217
4219
|
codegen: strictObject({
|
|
4218
4220
|
unwrap: boolean().default(true),
|
|
4219
|
-
withRequestParams: boolean().default(
|
|
4221
|
+
withRequestParams: boolean().default(true),
|
|
4220
4222
|
pathParamsStyle: _enum(["object", "positional"]).default("positional"),
|
|
4221
4223
|
enumStyle: _enum(["enum", "union"]).default("enum"),
|
|
4222
4224
|
comments: strictObject({
|
|
@@ -11261,9 +11263,82 @@ class CodeFormatter {
|
|
|
11261
11263
|
}
|
|
11262
11264
|
}
|
|
11263
11265
|
|
|
11264
|
-
const
|
|
11265
|
-
const
|
|
11266
|
-
const
|
|
11266
|
+
const removeGenericTypes = (code) => {
|
|
11267
|
+
const declarations = [];
|
|
11268
|
+
const declarationStartRegex = /^export\s+(interface|enum|type)\s+[A-Za-z0-9_]+(?:<[^>\n]+>)?/gm;
|
|
11269
|
+
let match;
|
|
11270
|
+
while ((match = declarationStartRegex.exec(code)) !== null) {
|
|
11271
|
+
const declaration = extractDeclaration(code, match);
|
|
11272
|
+
if (!declaration) continue;
|
|
11273
|
+
declarations.push(declaration);
|
|
11274
|
+
declarationStartRegex.lastIndex = match.index + declaration.length;
|
|
11275
|
+
}
|
|
11276
|
+
return declarations.join("\n\n");
|
|
11277
|
+
};
|
|
11278
|
+
const extractDeclaration = (code, match) => {
|
|
11279
|
+
const header = match[0];
|
|
11280
|
+
if (header.includes("<")) return null;
|
|
11281
|
+
const kind = match[1];
|
|
11282
|
+
let cursor = match.index + header.length;
|
|
11283
|
+
if (kind === "type") {
|
|
11284
|
+
cursor = skipWhitespace(code, cursor);
|
|
11285
|
+
if (code[cursor] !== "=") return null;
|
|
11286
|
+
cursor = skipWhitespace(code, cursor + 1);
|
|
11287
|
+
if (code[cursor] !== "{") return null;
|
|
11288
|
+
} else {
|
|
11289
|
+
cursor = code.indexOf("{", cursor);
|
|
11290
|
+
if (cursor === -1) return null;
|
|
11291
|
+
}
|
|
11292
|
+
const end = findMatchingBrace(code, cursor);
|
|
11293
|
+
if (end === -1) return null;
|
|
11294
|
+
return code.slice(match.index, end + 1);
|
|
11295
|
+
};
|
|
11296
|
+
const skipWhitespace = (code, cursor) => {
|
|
11297
|
+
while (/\s/.test(code[cursor] ?? "")) {
|
|
11298
|
+
cursor += 1;
|
|
11299
|
+
}
|
|
11300
|
+
return cursor;
|
|
11301
|
+
};
|
|
11302
|
+
const findMatchingBrace = (code, openBraceIndex) => {
|
|
11303
|
+
let depth = 0;
|
|
11304
|
+
for (let i = openBraceIndex; i < code.length; i += 1) {
|
|
11305
|
+
if (code[i] === "{") depth += 1;
|
|
11306
|
+
if (code[i] === "}") {
|
|
11307
|
+
depth -= 1;
|
|
11308
|
+
if (depth === 0) return i;
|
|
11309
|
+
}
|
|
11310
|
+
}
|
|
11311
|
+
return -1;
|
|
11312
|
+
};
|
|
11313
|
+
|
|
11314
|
+
var __defProp$b = Object.defineProperty;
|
|
11315
|
+
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11316
|
+
var __publicField$b = (obj, key, value) => __defNormalProp$b(obj, key + "" , value);
|
|
11317
|
+
class ZodSchemaGenerator {
|
|
11318
|
+
constructor(codeFormatter) {
|
|
11319
|
+
this.codeFormatter = codeFormatter;
|
|
11320
|
+
__publicField$b(this, "generate", async ({
|
|
11321
|
+
sourceText,
|
|
11322
|
+
moduleImportPath,
|
|
11323
|
+
options = {}
|
|
11324
|
+
}) => {
|
|
11325
|
+
const { getZodSchemasFile } = generate({
|
|
11326
|
+
sourceText: removeGenericTypes(sourceText)
|
|
11327
|
+
});
|
|
11328
|
+
let generated = getZodSchemasFile(moduleImportPath);
|
|
11329
|
+
generated = generated.replaceAll(".optional()", ".nullable()");
|
|
11330
|
+
generated = generated.replaceAll(".int64()", ".int()");
|
|
11331
|
+
if (options.localDateTimes) {
|
|
11332
|
+
generated = generated.replaceAll(
|
|
11333
|
+
"z.string().datetime()",
|
|
11334
|
+
"z.string().datetime({local: true})"
|
|
11335
|
+
);
|
|
11336
|
+
}
|
|
11337
|
+
return this.codeFormatter.format(generated);
|
|
11338
|
+
});
|
|
11339
|
+
}
|
|
11340
|
+
}
|
|
11341
|
+
|
|
11267
11342
|
const findRelativePath = (src, dst) => {
|
|
11268
11343
|
const relativePath = Path$1.relative(Path$1.dirname(src), dst);
|
|
11269
11344
|
const withoutExtension = relativePath.replace(/\.ts$/u, "");
|
|
@@ -11271,6 +11346,62 @@ const findRelativePath = (src, dst) => {
|
|
|
11271
11346
|
return normalizedPath.startsWith(".") ? normalizedPath : `./${normalizedPath}`;
|
|
11272
11347
|
};
|
|
11273
11348
|
|
|
11349
|
+
const splitIdentifierWords$1 = (str) => str.replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[^a-zA-Z0-9]+/).filter(Boolean);
|
|
11350
|
+
const toPascalCaseIdentifier = (str) => splitIdentifierWords$1(str).map((word) => word[0].toUpperCase() + word.substring(1)).join("");
|
|
11351
|
+
const toKebabCaseIdentifier = (str) => splitIdentifierWords$1(str).map((word) => word.toLowerCase()).join("-");
|
|
11352
|
+
|
|
11353
|
+
var __defProp$a = Object.defineProperty;
|
|
11354
|
+
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11355
|
+
var __publicField$a = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
11356
|
+
class FileWriter {
|
|
11357
|
+
constructor(outputDir, opts = {}) {
|
|
11358
|
+
this.outputDir = outputDir;
|
|
11359
|
+
this.opts = opts;
|
|
11360
|
+
__publicField$a(this, "resolveName", (req, opts) => {
|
|
11361
|
+
let name = opts?.preserveCase ? req.name : this.setNameCase(req.name);
|
|
11362
|
+
if (this.opts.suffix && opts?.noSuffix !== true) {
|
|
11363
|
+
name = name + "." + this.opts.suffix;
|
|
11364
|
+
}
|
|
11365
|
+
if (this.opts.mapFileName)
|
|
11366
|
+
name = this.opts.mapFileName({
|
|
11367
|
+
name,
|
|
11368
|
+
ext: req.ext
|
|
11369
|
+
});
|
|
11370
|
+
return name;
|
|
11371
|
+
});
|
|
11372
|
+
__publicField$a(this, "resolvePath", (req, opts) => this.getResolvedPath(req, opts));
|
|
11373
|
+
__publicField$a(this, "write", async ({ content, ...req }, opts) => {
|
|
11374
|
+
const resolvedPath = this.getResolvedPath(req, opts);
|
|
11375
|
+
await mkdir(Path.dirname(resolvedPath), { recursive: true });
|
|
11376
|
+
await writeFile(resolvedPath, content, "utf8");
|
|
11377
|
+
return resolvedPath;
|
|
11378
|
+
});
|
|
11379
|
+
__publicField$a(this, "getResolvedPath", ({ path, ext, ...req }, opts) => Path.resolve(
|
|
11380
|
+
this.outputDir,
|
|
11381
|
+
...path ?? [],
|
|
11382
|
+
`${this.resolveName(
|
|
11383
|
+
{
|
|
11384
|
+
ext,
|
|
11385
|
+
...req
|
|
11386
|
+
},
|
|
11387
|
+
opts
|
|
11388
|
+
)}.${ext}`
|
|
11389
|
+
));
|
|
11390
|
+
__publicField$a(this, "setNameCase", (name) => {
|
|
11391
|
+
const [first, ...rest] = name.split(".");
|
|
11392
|
+
const converted = this.transformCase(first);
|
|
11393
|
+
return [converted, ...rest].join(".");
|
|
11394
|
+
});
|
|
11395
|
+
__publicField$a(this, "transformCase", (value) => {
|
|
11396
|
+
const nameCase = this.opts.case ?? "pascal";
|
|
11397
|
+
if (nameCase === "kebab") {
|
|
11398
|
+
return toKebabCaseIdentifier(value);
|
|
11399
|
+
}
|
|
11400
|
+
return toPascalCaseIdentifier(value);
|
|
11401
|
+
});
|
|
11402
|
+
}
|
|
11403
|
+
}
|
|
11404
|
+
|
|
11274
11405
|
const generateOpenApiClient = async (inputFile, {
|
|
11275
11406
|
name,
|
|
11276
11407
|
outputDir,
|
|
@@ -11323,7 +11454,7 @@ const generateOpenApiClient = async (inputFile, {
|
|
|
11323
11454
|
if (responseWrapper) {
|
|
11324
11455
|
await modifyHttpClientAsyncWrapper([dstFile], responseWrapper, log);
|
|
11325
11456
|
}
|
|
11326
|
-
return
|
|
11457
|
+
return dstFile;
|
|
11327
11458
|
};
|
|
11328
11459
|
const modifyHttpClientAsyncWrapper = async (filePaths, responseWrapper, log) => {
|
|
11329
11460
|
log(
|
|
@@ -11359,8 +11490,17 @@ const getThisScriptDirname = () => {
|
|
|
11359
11490
|
};
|
|
11360
11491
|
const getTemplatesDir = () => {
|
|
11361
11492
|
const currentDir = getThisScriptDirname();
|
|
11362
|
-
const
|
|
11363
|
-
|
|
11493
|
+
const templateDirCandidates = [
|
|
11494
|
+
Path$1.resolve(currentDir, "../../templates/legacy"),
|
|
11495
|
+
Path$1.resolve(currentDir, "../templates/legacy")
|
|
11496
|
+
];
|
|
11497
|
+
const templateDir = templateDirCandidates.find(existsSync);
|
|
11498
|
+
if (!templateDir) {
|
|
11499
|
+
throw new Error(
|
|
11500
|
+
`Legacy swagger-ts-api templates not found. Tried: ${templateDirCandidates.join(", ")}`
|
|
11501
|
+
);
|
|
11502
|
+
}
|
|
11503
|
+
return templateDir;
|
|
11364
11504
|
};
|
|
11365
11505
|
|
|
11366
11506
|
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -11417,9 +11557,9 @@ const resolveLocalRef = (root, ref) => {
|
|
|
11417
11557
|
return current;
|
|
11418
11558
|
};
|
|
11419
11559
|
|
|
11420
|
-
var __defProp$
|
|
11421
|
-
var __defNormalProp$
|
|
11422
|
-
var __publicField$
|
|
11560
|
+
var __defProp$9 = Object.defineProperty;
|
|
11561
|
+
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11562
|
+
var __publicField$9 = (obj, key, value) => __defNormalProp$9(obj, key + "" , value);
|
|
11423
11563
|
const PARAMETER_LOCATIONS = [
|
|
11424
11564
|
"path",
|
|
11425
11565
|
"query",
|
|
@@ -11445,7 +11585,7 @@ const mergeParameters = (base, override) => {
|
|
|
11445
11585
|
class OpenApiNormalizer {
|
|
11446
11586
|
constructor(doc) {
|
|
11447
11587
|
this.doc = doc;
|
|
11448
|
-
__publicField$
|
|
11588
|
+
__publicField$9(this, "problems", []);
|
|
11449
11589
|
}
|
|
11450
11590
|
load() {
|
|
11451
11591
|
const info = readRecord(this.doc, "info");
|
|
@@ -11788,24 +11928,24 @@ const syntheticOperationId = (method, path) => {
|
|
|
11788
11928
|
return `_${compact}`;
|
|
11789
11929
|
};
|
|
11790
11930
|
|
|
11791
|
-
var __defProp$
|
|
11792
|
-
var __defNormalProp$
|
|
11793
|
-
var __publicField$
|
|
11931
|
+
var __defProp$8 = Object.defineProperty;
|
|
11932
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11933
|
+
var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
11794
11934
|
class TsCodegen {
|
|
11795
11935
|
constructor(typeExprCodegen, docRenderer) {
|
|
11796
11936
|
this.typeExprCodegen = typeExprCodegen;
|
|
11797
|
-
__publicField$
|
|
11798
|
-
__publicField$
|
|
11799
|
-
__publicField$
|
|
11800
|
-
__publicField$
|
|
11937
|
+
__publicField$8(this, "usedTypeRefs", []);
|
|
11938
|
+
__publicField$8(this, "usedTypeRefKeys", /* @__PURE__ */ new Set());
|
|
11939
|
+
__publicField$8(this, "docRenderer");
|
|
11940
|
+
__publicField$8(this, "typeExpr", (typeExpr) => {
|
|
11801
11941
|
this.collectTypeRefsFromExpr(typeExpr);
|
|
11802
11942
|
return this.typeExprCodegen.toCode(typeExpr).code;
|
|
11803
11943
|
});
|
|
11804
|
-
__publicField$
|
|
11944
|
+
__publicField$8(this, "declaration", (name, declaration, options = {}) => {
|
|
11805
11945
|
this.collectTypeRefsFromDeclaration(declaration);
|
|
11806
11946
|
return this.toDeclarationCode(name, declaration, options);
|
|
11807
11947
|
});
|
|
11808
|
-
__publicField$
|
|
11948
|
+
__publicField$8(this, "toChunk", (name, code, exports$1, imports = []) => {
|
|
11809
11949
|
const exportedSymbols = new Set(exports$1);
|
|
11810
11950
|
const refs = this.getTypeRefs().filter((ref) => {
|
|
11811
11951
|
return ref.kind !== "internal" || !exportedSymbols.has(ref.name);
|
|
@@ -11818,17 +11958,17 @@ class TsCodegen {
|
|
|
11818
11958
|
imports
|
|
11819
11959
|
};
|
|
11820
11960
|
});
|
|
11821
|
-
__publicField$
|
|
11961
|
+
__publicField$8(this, "getTypeRefs", () => {
|
|
11822
11962
|
return this.usedTypeRefs.map((ref) => ({ ...ref }));
|
|
11823
11963
|
});
|
|
11824
|
-
__publicField$
|
|
11964
|
+
__publicField$8(this, "toDeclarationCode", (name, d, o) => {
|
|
11825
11965
|
let code = this.toDeclarationBodyCode(name, d);
|
|
11826
11966
|
if (o.exported) {
|
|
11827
11967
|
code = `export ${code}`;
|
|
11828
11968
|
}
|
|
11829
11969
|
return this.addDoc(code, d.doc);
|
|
11830
11970
|
});
|
|
11831
|
-
__publicField$
|
|
11971
|
+
__publicField$8(this, "toDeclarationBodyCode", (name, declaration) => {
|
|
11832
11972
|
switch (declaration.kind) {
|
|
11833
11973
|
case "typeAlias":
|
|
11834
11974
|
return `type ${name} = ${this.typeExprCodegen.toCode(declaration.typeExpr).code}`;
|
|
@@ -11849,7 +11989,7 @@ ${members}
|
|
|
11849
11989
|
}
|
|
11850
11990
|
}
|
|
11851
11991
|
});
|
|
11852
|
-
__publicField$
|
|
11992
|
+
__publicField$8(this, "addDoc", (code, doc) => {
|
|
11853
11993
|
if (!doc) return code;
|
|
11854
11994
|
const rendered = this.docRenderer.render(doc);
|
|
11855
11995
|
return rendered ? `${rendered}
|
|
@@ -11981,13 +12121,13 @@ const toTsPropertyKey = (value) => {
|
|
|
11981
12121
|
return isTsIdentifier(value) ? value : JSON.stringify(value);
|
|
11982
12122
|
};
|
|
11983
12123
|
|
|
11984
|
-
var __defProp$
|
|
11985
|
-
var __defNormalProp$
|
|
11986
|
-
var __publicField$
|
|
12124
|
+
var __defProp$7 = Object.defineProperty;
|
|
12125
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12126
|
+
var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
11987
12127
|
class TypeExprCodegen {
|
|
11988
12128
|
constructor(docRenderer) {
|
|
11989
|
-
__publicField$
|
|
11990
|
-
__publicField$
|
|
12129
|
+
__publicField$7(this, "docRenderer");
|
|
12130
|
+
__publicField$7(this, "toCode", (typeExpr) => {
|
|
11991
12131
|
switch (typeExpr.kind) {
|
|
11992
12132
|
case "reference":
|
|
11993
12133
|
return this.toReferenceCode(typeExpr);
|
|
@@ -12003,7 +12143,7 @@ class TypeExprCodegen {
|
|
|
12003
12143
|
}
|
|
12004
12144
|
}
|
|
12005
12145
|
});
|
|
12006
|
-
__publicField$
|
|
12146
|
+
__publicField$7(this, "toReferenceCode", (typeExpr) => {
|
|
12007
12147
|
if (!typeExpr.typeArgs?.length) {
|
|
12008
12148
|
return {
|
|
12009
12149
|
code: typeExpr.ref.name,
|
|
@@ -12016,7 +12156,7 @@ class TypeExprCodegen {
|
|
|
12016
12156
|
ref: typeExpr.ref
|
|
12017
12157
|
};
|
|
12018
12158
|
});
|
|
12019
|
-
__publicField$
|
|
12159
|
+
__publicField$7(this, "toInlineCode", (expr) => {
|
|
12020
12160
|
switch (expr.node) {
|
|
12021
12161
|
case "scalar":
|
|
12022
12162
|
return expr.name === "integer" ? "number" : expr.name;
|
|
@@ -12041,25 +12181,25 @@ class TypeExprCodegen {
|
|
|
12041
12181
|
}
|
|
12042
12182
|
}
|
|
12043
12183
|
});
|
|
12044
|
-
__publicField$
|
|
12184
|
+
__publicField$7(this, "toIntersectionMemberCode", (typeExpr) => {
|
|
12045
12185
|
const rendered = this.toCode(typeExpr).code;
|
|
12046
12186
|
return this.isUnion(typeExpr) ? `(${rendered})` : rendered;
|
|
12047
12187
|
});
|
|
12048
|
-
__publicField$
|
|
12188
|
+
__publicField$7(this, "toArrayElementCode", (typeExpr) => {
|
|
12049
12189
|
const rendered = this.toCode(typeExpr).code;
|
|
12050
12190
|
return this.needsGroupingForArrayElement(typeExpr) ? `(${rendered})` : rendered;
|
|
12051
12191
|
});
|
|
12052
|
-
__publicField$
|
|
12192
|
+
__publicField$7(this, "isUnion", (typeExpr) => {
|
|
12053
12193
|
return typeExpr.kind === "inline" && typeExpr.expr.node === "union";
|
|
12054
12194
|
});
|
|
12055
|
-
__publicField$
|
|
12195
|
+
__publicField$7(this, "needsGroupingForArrayElement", (typeExpr) => {
|
|
12056
12196
|
return typeExpr.kind === "inline" && (typeExpr.expr.node === "union" || typeExpr.expr.node === "intersection");
|
|
12057
12197
|
});
|
|
12058
|
-
__publicField$
|
|
12198
|
+
__publicField$7(this, "toLiteralCode", (value) => {
|
|
12059
12199
|
if (value === null) return "null";
|
|
12060
12200
|
return JSON.stringify(value);
|
|
12061
12201
|
});
|
|
12062
|
-
__publicField$
|
|
12202
|
+
__publicField$7(this, "toObjectCode", (properties, additionalProperties) => {
|
|
12063
12203
|
const members = properties.map(
|
|
12064
12204
|
(property) => this.toPropertyCode(property)
|
|
12065
12205
|
);
|
|
@@ -12074,7 +12214,7 @@ class TypeExprCodegen {
|
|
|
12074
12214
|
${members.join("\n")}
|
|
12075
12215
|
}`;
|
|
12076
12216
|
});
|
|
12077
|
-
__publicField$
|
|
12217
|
+
__publicField$7(this, "toPropertyCode", (property) => {
|
|
12078
12218
|
const name = toTsPropertyKey(property.name);
|
|
12079
12219
|
const optional = property.required ? "" : "?";
|
|
12080
12220
|
const propertyCode = `${name}${optional}: ${this.toCode(property.typeExpr).code}`;
|
|
@@ -12089,14 +12229,14 @@ ${renderedProperty}` : renderedProperty;
|
|
|
12089
12229
|
}
|
|
12090
12230
|
}
|
|
12091
12231
|
|
|
12092
|
-
var __defProp$
|
|
12093
|
-
var __defNormalProp$
|
|
12094
|
-
var __publicField$
|
|
12232
|
+
var __defProp$6 = Object.defineProperty;
|
|
12233
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12234
|
+
var __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
12095
12235
|
class TsCodegenFactory {
|
|
12096
12236
|
constructor(docRenderer) {
|
|
12097
|
-
__publicField$
|
|
12098
|
-
__publicField$
|
|
12099
|
-
__publicField$
|
|
12237
|
+
__publicField$6(this, "typeExprCodegen");
|
|
12238
|
+
__publicField$6(this, "docRenderer");
|
|
12239
|
+
__publicField$6(this, "forNewChunk", () => {
|
|
12100
12240
|
return new TsCodegen(this.typeExprCodegen, this.docRenderer);
|
|
12101
12241
|
});
|
|
12102
12242
|
this.docRenderer = docRenderer;
|
|
@@ -12149,13 +12289,13 @@ const isReservedWord = (value) => {
|
|
|
12149
12289
|
return RESERVED_WORDS.has(value);
|
|
12150
12290
|
};
|
|
12151
12291
|
|
|
12152
|
-
var __defProp$
|
|
12153
|
-
var __defNormalProp$
|
|
12154
|
-
var __publicField$
|
|
12292
|
+
var __defProp$5 = Object.defineProperty;
|
|
12293
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12294
|
+
var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
12155
12295
|
class ParamsConstructor {
|
|
12156
12296
|
constructor(options) {
|
|
12157
12297
|
this.options = options;
|
|
12158
|
-
__publicField$
|
|
12298
|
+
__publicField$5(this, "process", (params, httpPath) => {
|
|
12159
12299
|
const pathParamSpec = validatePathParams(params, httpPath);
|
|
12160
12300
|
const pathParamBindings = pathParamSpec?.bindings;
|
|
12161
12301
|
const funParams = params.flatMap(
|
|
@@ -12175,7 +12315,7 @@ class ParamsConstructor {
|
|
|
12175
12315
|
hasQuery
|
|
12176
12316
|
};
|
|
12177
12317
|
});
|
|
12178
|
-
__publicField$
|
|
12318
|
+
__publicField$5(this, "renderOperationParams", (param, pathParamSpec) => {
|
|
12179
12319
|
if (param.kind !== "path" || !pathParamSpec) {
|
|
12180
12320
|
return [
|
|
12181
12321
|
{
|
|
@@ -12199,7 +12339,7 @@ class ParamsConstructor {
|
|
|
12199
12339
|
}
|
|
12200
12340
|
];
|
|
12201
12341
|
});
|
|
12202
|
-
__publicField$
|
|
12342
|
+
__publicField$5(this, "renderPathTemplateLiteral", (path, pathParamVarName, pathParamBindings) => {
|
|
12203
12343
|
const escapedPath = path.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
12204
12344
|
const pathWithParams = escapedPath.replace(
|
|
12205
12345
|
/\{([^}]+)\}/g,
|
|
@@ -12213,7 +12353,7 @@ class ParamsConstructor {
|
|
|
12213
12353
|
);
|
|
12214
12354
|
return `\`${pathWithParams}\``;
|
|
12215
12355
|
});
|
|
12216
|
-
__publicField$
|
|
12356
|
+
__publicField$5(this, "renderPathParamDestructuring", (pathParamBindings) => {
|
|
12217
12357
|
const members = Object.entries(pathParamBindings).map(
|
|
12218
12358
|
([paramName, binding]) => {
|
|
12219
12359
|
const key = toTsPropertyKey(paramName);
|
|
@@ -12222,7 +12362,7 @@ class ParamsConstructor {
|
|
|
12222
12362
|
);
|
|
12223
12363
|
return `{ ${members.join(", ")} }`;
|
|
12224
12364
|
});
|
|
12225
|
-
__publicField$
|
|
12365
|
+
__publicField$5(this, "paramName", (p) => {
|
|
12226
12366
|
switch (p.kind) {
|
|
12227
12367
|
case "body":
|
|
12228
12368
|
return this.options.paramNames.body;
|
|
@@ -12343,9 +12483,9 @@ const indentBlock = (value, indent) => {
|
|
|
12343
12483
|
|
|
12344
12484
|
const consolidateObjectShorthandProperties = (code) => code.replace(/\b([A-Za-z_$][A-Za-z0-9_$]*)\s*:\s*\1\b/g, "$1");
|
|
12345
12485
|
|
|
12346
|
-
var __defProp$
|
|
12347
|
-
var __defNormalProp$
|
|
12348
|
-
var __publicField$
|
|
12486
|
+
var __defProp$4 = Object.defineProperty;
|
|
12487
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12488
|
+
var __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
12349
12489
|
const REQUEST_PARAMS_TYPE = "RequestParams";
|
|
12350
12490
|
const REQUEST_PARAMS_DEFAULT = "never";
|
|
12351
12491
|
const REQUEST_PARAMS_ARG = "params";
|
|
@@ -12356,7 +12496,7 @@ class ApiClientCodegen {
|
|
|
12356
12496
|
this.opts = opts;
|
|
12357
12497
|
this.tsCodegenFactory = tsCodegenFactory;
|
|
12358
12498
|
this.docRenderer = docRenderer;
|
|
12359
|
-
__publicField$
|
|
12499
|
+
__publicField$4(this, "generate", (apiName, operations, doc) => {
|
|
12360
12500
|
const tsCodegen = this.tsCodegenFactory.forNewChunk();
|
|
12361
12501
|
let httpClientType = tsCodegen.typeExpr({
|
|
12362
12502
|
kind: "reference",
|
|
@@ -12381,7 +12521,7 @@ ${code}`;
|
|
|
12381
12521
|
}
|
|
12382
12522
|
return tsCodegen.toChunk("api", code, [apiName], methodsCode.imports);
|
|
12383
12523
|
});
|
|
12384
|
-
__publicField$
|
|
12524
|
+
__publicField$4(this, "groupsOpsCode", (codegen, groupedOps) => combineRenderedCode(
|
|
12385
12525
|
Object.entries(groupedOps).map(([groupName, ops]) => {
|
|
12386
12526
|
const methodsCode = this.opsCode(codegen, ops, "object");
|
|
12387
12527
|
return {
|
|
@@ -12395,7 +12535,7 @@ ${code}`;
|
|
|
12395
12535
|
}),
|
|
12396
12536
|
"\n\n"
|
|
12397
12537
|
));
|
|
12398
|
-
__publicField$
|
|
12538
|
+
__publicField$4(this, "opsCode", (codegen, operations, target = "class") => {
|
|
12399
12539
|
const separator = target === "object" ? `,
|
|
12400
12540
|
${EMPTY_LINE_MARKER}
|
|
12401
12541
|
` : "\n\n";
|
|
@@ -12404,7 +12544,7 @@ ${EMPTY_LINE_MARKER}
|
|
|
12404
12544
|
separator
|
|
12405
12545
|
);
|
|
12406
12546
|
});
|
|
12407
|
-
__publicField$
|
|
12547
|
+
__publicField$4(this, "renderOp", (op, tsCodegen, target) => {
|
|
12408
12548
|
const { signature: sig, http } = op;
|
|
12409
12549
|
const paramNames = {
|
|
12410
12550
|
path: "path",
|
|
@@ -12446,14 +12586,14 @@ ${EMPTY_LINE_MARKER}
|
|
|
12446
12586
|
target
|
|
12447
12587
|
});
|
|
12448
12588
|
});
|
|
12449
|
-
__publicField$
|
|
12589
|
+
__publicField$4(this, "wrapInResponseWrapper", (typeExpr, tsCodegen) => {
|
|
12450
12590
|
return tsCodegen.typeExpr({
|
|
12451
12591
|
kind: "reference",
|
|
12452
12592
|
ref: this.opts.httpClient.responseWrapper,
|
|
12453
12593
|
typeArgs: [typeExpr]
|
|
12454
12594
|
});
|
|
12455
12595
|
});
|
|
12456
|
-
__publicField$
|
|
12596
|
+
__publicField$4(this, "renderFunctionCode", ({
|
|
12457
12597
|
doc,
|
|
12458
12598
|
funName,
|
|
12459
12599
|
responseType,
|
|
@@ -12502,11 +12642,11 @@ ${functionCode}` : functionCode,
|
|
|
12502
12642
|
imports
|
|
12503
12643
|
};
|
|
12504
12644
|
});
|
|
12505
|
-
__publicField$
|
|
12645
|
+
__publicField$4(this, "renderOperationDoc", (doc, indent = "") => {
|
|
12506
12646
|
if (!doc) return null;
|
|
12507
12647
|
return indentBlock(this.docRenderer.render(this.toTsDoc(doc)), indent);
|
|
12508
12648
|
});
|
|
12509
|
-
__publicField$
|
|
12649
|
+
__publicField$4(this, "renderApiClientDoc", (doc) => {
|
|
12510
12650
|
if (!doc) return null;
|
|
12511
12651
|
return this.docRenderer.render({
|
|
12512
12652
|
nodes: [
|
|
@@ -12522,7 +12662,7 @@ ${functionCode}` : functionCode,
|
|
|
12522
12662
|
]
|
|
12523
12663
|
});
|
|
12524
12664
|
});
|
|
12525
|
-
__publicField$
|
|
12665
|
+
__publicField$4(this, "toTsDoc", (doc) => {
|
|
12526
12666
|
const nodes = [
|
|
12527
12667
|
{
|
|
12528
12668
|
key: "id",
|
|
@@ -12564,7 +12704,7 @@ const combineRenderedCode = (fragments, separator) => ({
|
|
|
12564
12704
|
imports: fragments.flatMap((fragment) => fragment.imports)
|
|
12565
12705
|
});
|
|
12566
12706
|
|
|
12567
|
-
var httpClientPromiseTypesSource = "import type {
|
|
12707
|
+
var httpClientPromiseTypesSource = "import type { HttpRequest, HttpResponse } from './common-types'\n\nexport type HttpClient<RequestParams = never> = {\n request: <Data>(\n req: HttpRequest,\n params?: RequestParams\n ) => Promise<HttpResponse<Data>>\n}\n";
|
|
12568
12708
|
|
|
12569
12709
|
const promiseHttpClientRenderSpec = () => ({
|
|
12570
12710
|
typeName: {
|
|
@@ -12606,7 +12746,7 @@ ${requestParamsVar}` : ""})${unwrap ? `.then(res => res.body)` : ""}
|
|
|
12606
12746
|
}
|
|
12607
12747
|
});
|
|
12608
12748
|
|
|
12609
|
-
var httpClientObservableTypesSource = "import { Observable } from 'rxjs'\nimport type {
|
|
12749
|
+
var httpClientObservableTypesSource = "import { Observable } from 'rxjs'\nimport type { HttpRequest, HttpResponse } from './common-types'\n\nexport type HttpClient<RequestParams = never> = {\n request: <Data>(\n req: HttpRequest,\n params?: RequestParams\n ) => Observable<HttpResponse<Data>>\n}\n";
|
|
12610
12750
|
|
|
12611
12751
|
const rxJsHttpClientRenderSpec = () => ({
|
|
12612
12752
|
typeName: {
|
|
@@ -12779,7 +12919,7 @@ const runtimeImportKey = (runtimeImport) => [
|
|
|
12779
12919
|
runtimeImport.typeOnly === true ? "type" : "value"
|
|
12780
12920
|
].join("|");
|
|
12781
12921
|
|
|
12782
|
-
var httpClientCommonTypesSource = "export type KnownRequestContentType =\n | 'application/json'\n | 'multipart/form-data'\n | 'application/x-www-form-urlencoded'\n\nexport type RequestContentType = KnownRequestContentType | string\n\nexport type QueryValue =\n | string\n | number\n | boolean\n | null\n | undefined\n | QueryValue[]\n | Record<string, any>\n // Empty schema support\n | unknown\n\nexport type QueryParams = Record<string, QueryValue>\n\nexport type
|
|
12922
|
+
var httpClientCommonTypesSource = "export type KnownRequestContentType =\n | 'application/json'\n | 'multipart/form-data'\n | 'application/x-www-form-urlencoded'\n\nexport type RequestContentType = KnownRequestContentType | string\n\nexport type QueryValue =\n | string\n | number\n | boolean\n | null\n | undefined\n | QueryValue[]\n | Record<string, any>\n // Empty schema support\n | unknown\n\nexport type QueryParams = Record<string, QueryValue>\n\nexport type HttpRequest = {\n path: string\n method: 'GET' | 'POST' | 'PUT' | 'DELETE'\n responseFormat?: 'json' | 'document'\n headers?: Record<string, string>\n query?: QueryParams\n body?: any\n contentType?: RequestContentType\n}\n\nexport type HttpResponse<Data> = {\n body: Data\n headers: Record<string, string | string[]>\n status: number\n}\n\nexport type QuerySerializer = (params: QueryParams) => string\n";
|
|
12783
12923
|
|
|
12784
12924
|
const commonTypesCode = httpClientCommonTypesSource;
|
|
12785
12925
|
const stripImports = (code) => code.replace(/^import[\s\S]*?from\s+['"][^'"]+['"]\s*;?\n?/gm, "").trim();
|
|
@@ -12801,13 +12941,13 @@ const provideHttpClientCode = (gen, opts) => {
|
|
|
12801
12941
|
);
|
|
12802
12942
|
};
|
|
12803
12943
|
|
|
12804
|
-
var __defProp$
|
|
12805
|
-
var __defNormalProp$
|
|
12806
|
-
var __publicField$
|
|
12944
|
+
var __defProp$3 = Object.defineProperty;
|
|
12945
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12946
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
12807
12947
|
class TsDocRenderer {
|
|
12808
12948
|
constructor(options) {
|
|
12809
12949
|
this.options = options;
|
|
12810
|
-
__publicField$
|
|
12950
|
+
__publicField$3(this, "render", (doc, options = {}) => {
|
|
12811
12951
|
if (!this.options.enabled) return "";
|
|
12812
12952
|
const lines = [];
|
|
12813
12953
|
this.appendNodes(lines, doc.nodes, options);
|
|
@@ -12816,7 +12956,7 @@ class TsDocRenderer {
|
|
|
12816
12956
|
}
|
|
12817
12957
|
return this.renderComment(lines);
|
|
12818
12958
|
});
|
|
12819
|
-
__publicField$
|
|
12959
|
+
__publicField$3(this, "renderComment", (lines) => {
|
|
12820
12960
|
if (!this.options.enabled) return "";
|
|
12821
12961
|
if (!lines.length) return "";
|
|
12822
12962
|
if (lines.length === 1) {
|
|
@@ -12827,7 +12967,7 @@ class TsDocRenderer {
|
|
|
12827
12967
|
${body}
|
|
12828
12968
|
*/`;
|
|
12829
12969
|
});
|
|
12830
|
-
__publicField$
|
|
12970
|
+
__publicField$3(this, "appendDocText", (lines, value) => {
|
|
12831
12971
|
const normalized = this.normalizeLines(value);
|
|
12832
12972
|
if (!normalized.length) return;
|
|
12833
12973
|
if (lines.length > 0) {
|
|
@@ -12835,19 +12975,19 @@ ${body}
|
|
|
12835
12975
|
}
|
|
12836
12976
|
lines.push(...normalized);
|
|
12837
12977
|
});
|
|
12838
|
-
__publicField$
|
|
12978
|
+
__publicField$3(this, "appendField", (lines, key, value) => {
|
|
12839
12979
|
const normalized = this.normalizeLines(value);
|
|
12840
12980
|
if (!normalized.length) return;
|
|
12841
12981
|
lines.push(`@${key} ${normalized[0]}`.trimEnd());
|
|
12842
12982
|
lines.push(...normalized.slice(1));
|
|
12843
12983
|
});
|
|
12844
|
-
__publicField$
|
|
12984
|
+
__publicField$3(this, "appendDeprecated", (lines, options) => {
|
|
12845
12985
|
if (options.separate) {
|
|
12846
12986
|
lines.push("");
|
|
12847
12987
|
}
|
|
12848
12988
|
lines.push("@deprecated");
|
|
12849
12989
|
});
|
|
12850
|
-
__publicField$
|
|
12990
|
+
__publicField$3(this, "appendNodes", (lines, nodes = [], options = {}) => {
|
|
12851
12991
|
nodes.forEach((node) => {
|
|
12852
12992
|
if (typeof node === "string") {
|
|
12853
12993
|
if (options.compactText) {
|
|
@@ -12860,21 +13000,21 @@ ${body}
|
|
|
12860
13000
|
this.appendField(lines, node.key, node.value);
|
|
12861
13001
|
});
|
|
12862
13002
|
});
|
|
12863
|
-
__publicField$
|
|
13003
|
+
__publicField$3(this, "normalizeLines", (value) => {
|
|
12864
13004
|
const trimmed = value?.trim();
|
|
12865
13005
|
if (!trimmed) return [];
|
|
12866
13006
|
return trimmed.split(/\r?\n/u).map((line) => line.trimEnd().replaceAll("*/", "*\\/"));
|
|
12867
13007
|
});
|
|
12868
|
-
__publicField$
|
|
13008
|
+
__publicField$3(this, "normalizeNonEmptyLines", (value) => this.normalizeLines(value).filter((line) => line.length > 0));
|
|
12869
13009
|
}
|
|
12870
13010
|
}
|
|
12871
13011
|
|
|
12872
|
-
const
|
|
13012
|
+
const generateOpenApiClientFiles = (clientName, input, opts) => {
|
|
12873
13013
|
const docRenderer = new TsDocRenderer({
|
|
12874
13014
|
enabled: opts.comments.enabled
|
|
12875
13015
|
});
|
|
12876
13016
|
const tsCodegenFac = new TsCodegenFactory(docRenderer);
|
|
12877
|
-
const { schemaDefinitions } =
|
|
13017
|
+
const { schemaDefinitions } = input;
|
|
12878
13018
|
const types = [...schemaDefinitions].sort((a, b) => a.name.localeCompare(b.name)).map((def) => {
|
|
12879
13019
|
const cg = tsCodegenFac.forNewChunk();
|
|
12880
13020
|
const code = cg.declaration(def.name, def.declaration, {
|
|
@@ -12897,8 +13037,8 @@ const generateTsCode = (clientName, projectResult, opts) => {
|
|
|
12897
13037
|
);
|
|
12898
13038
|
const generated = clientCodegen.generate(
|
|
12899
13039
|
clientName,
|
|
12900
|
-
|
|
12901
|
-
|
|
13040
|
+
input.operations,
|
|
13041
|
+
input.api
|
|
12902
13042
|
);
|
|
12903
13043
|
const clientModuleName = `${clientName}.client`;
|
|
12904
13044
|
const typesModuleName = `${clientName}.types`;
|
|
@@ -12925,8 +13065,7 @@ const generateTsCode = (clientName, projectResult, opts) => {
|
|
|
12925
13065
|
const all = [typesChunk, httpClientChunk, clientChunk, indexChunk];
|
|
12926
13066
|
return {
|
|
12927
13067
|
all,
|
|
12928
|
-
typesName: typesChunk.name
|
|
12929
|
-
promiseWrappersNames: [httpClientChunk.name, clientChunk.name]
|
|
13068
|
+
typesName: typesChunk.name
|
|
12930
13069
|
};
|
|
12931
13070
|
};
|
|
12932
13071
|
const createIndexFile = (moduleNames) => ({
|
|
@@ -12948,55 +13087,27 @@ const createIndexFile = (moduleNames) => ({
|
|
|
12948
13087
|
}
|
|
12949
13088
|
]
|
|
12950
13089
|
});
|
|
12951
|
-
const groupsOpsByTag = (operations) => {
|
|
12952
|
-
const groupedOps = {};
|
|
12953
|
-
const rawTagsByNormalizedName = /* @__PURE__ */ new Map();
|
|
12954
|
-
operations.forEach((operation) => {
|
|
12955
|
-
const rawTag = operation.tags.find((tag) => tag.trim())?.trim() || "root";
|
|
12956
|
-
let groupName;
|
|
12957
|
-
try {
|
|
12958
|
-
groupName = toTsCamelIdentifier(rawTag, {
|
|
12959
|
-
leadingDigitPrefix: "tag"
|
|
12960
|
-
});
|
|
12961
|
-
} catch {
|
|
12962
|
-
throw new Error(
|
|
12963
|
-
`Invalid OpenAPI tag "${rawTag}": could not derive a client group name.`
|
|
12964
|
-
);
|
|
12965
|
-
}
|
|
12966
|
-
const existingRawTag = rawTagsByNormalizedName.get(groupName);
|
|
12967
|
-
if (existingRawTag && existingRawTag !== rawTag) {
|
|
12968
|
-
throw new Error(
|
|
12969
|
-
`Tag naming collision: "${existingRawTag}" and "${rawTag}" both normalize to "${groupName}". Rename one of these OpenAPI tags to continue.`
|
|
12970
|
-
);
|
|
12971
|
-
}
|
|
12972
|
-
rawTagsByNormalizedName.set(groupName, rawTag);
|
|
12973
|
-
const bucket = groupedOps[groupName] ?? [];
|
|
12974
|
-
bucket.push(operation.op);
|
|
12975
|
-
groupedOps[groupName] = bucket;
|
|
12976
|
-
});
|
|
12977
|
-
return groupedOps;
|
|
12978
|
-
};
|
|
12979
13090
|
|
|
12980
|
-
var __defProp$
|
|
12981
|
-
var __defNormalProp$
|
|
12982
|
-
var __publicField$
|
|
13091
|
+
var __defProp$2 = Object.defineProperty;
|
|
13092
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13093
|
+
var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
12983
13094
|
const TS_IDENTIFIER_PATTERN = /^[$A-Z_][0-9A-Z_$]*$/i;
|
|
12984
13095
|
class ToTypeExprConverter {
|
|
12985
13096
|
constructor(schemas = {}, options) {
|
|
12986
13097
|
this.schemas = schemas;
|
|
12987
13098
|
this.options = options;
|
|
12988
|
-
__publicField$
|
|
12989
|
-
__publicField$
|
|
12990
|
-
__publicField$
|
|
12991
|
-
__publicField$
|
|
12992
|
-
__publicField$
|
|
12993
|
-
__publicField$
|
|
12994
|
-
__publicField$
|
|
13099
|
+
__publicField$2(this, "schemaCache", /* @__PURE__ */ new WeakMap());
|
|
13100
|
+
__publicField$2(this, "refCache", /* @__PURE__ */ new Map());
|
|
13101
|
+
__publicField$2(this, "schemaDefinitions", []);
|
|
13102
|
+
__publicField$2(this, "schemaDefinitionsById", /* @__PURE__ */ new Map());
|
|
13103
|
+
__publicField$2(this, "schemaDefinitionsInProgress", /* @__PURE__ */ new Set());
|
|
13104
|
+
__publicField$2(this, "getSchemaDefinitions", () => this.schemaDefinitions);
|
|
13105
|
+
__publicField$2(this, "registerAllSchemaDefinitions", () => {
|
|
12995
13106
|
Object.keys(this.schemas).forEach((schemaName) => {
|
|
12996
13107
|
this.ensureSchemaDefinition(`#/components/schemas/${schemaName}`);
|
|
12997
13108
|
});
|
|
12998
13109
|
});
|
|
12999
|
-
__publicField$
|
|
13110
|
+
__publicField$2(this, "fromTypeExpr", (schema) => {
|
|
13000
13111
|
if (!schema) {
|
|
13001
13112
|
return this.scalar("unknown");
|
|
13002
13113
|
}
|
|
@@ -13019,14 +13130,14 @@ class ToTypeExprConverter {
|
|
|
13019
13130
|
}
|
|
13020
13131
|
return result;
|
|
13021
13132
|
});
|
|
13022
|
-
__publicField$
|
|
13133
|
+
__publicField$2(this, "scalar", (name) => ({
|
|
13023
13134
|
kind: "inline",
|
|
13024
13135
|
expr: {
|
|
13025
13136
|
node: "scalar",
|
|
13026
13137
|
name
|
|
13027
13138
|
}
|
|
13028
13139
|
}));
|
|
13029
|
-
__publicField$
|
|
13140
|
+
__publicField$2(this, "union", (members) => {
|
|
13030
13141
|
const flatMembers = [];
|
|
13031
13142
|
for (const member of members) {
|
|
13032
13143
|
if (member.kind === "inline" && member.expr.node === "union") {
|
|
@@ -13046,14 +13157,14 @@ class ToTypeExprConverter {
|
|
|
13046
13157
|
}
|
|
13047
13158
|
};
|
|
13048
13159
|
});
|
|
13049
|
-
__publicField$
|
|
13160
|
+
__publicField$2(this, "literal", (value) => ({
|
|
13050
13161
|
kind: "inline",
|
|
13051
13162
|
expr: {
|
|
13052
13163
|
node: "literal",
|
|
13053
13164
|
value
|
|
13054
13165
|
}
|
|
13055
13166
|
}));
|
|
13056
|
-
__publicField$
|
|
13167
|
+
__publicField$2(this, "ref", (id) => {
|
|
13057
13168
|
const name = this.refNameFromPath(id);
|
|
13058
13169
|
return {
|
|
13059
13170
|
kind: "reference",
|
|
@@ -13063,14 +13174,14 @@ class ToTypeExprConverter {
|
|
|
13063
13174
|
}
|
|
13064
13175
|
};
|
|
13065
13176
|
});
|
|
13066
|
-
__publicField$
|
|
13177
|
+
__publicField$2(this, "builtinRef", (name) => ({
|
|
13067
13178
|
kind: "reference",
|
|
13068
13179
|
ref: {
|
|
13069
13180
|
kind: "builtin",
|
|
13070
13181
|
name
|
|
13071
13182
|
}
|
|
13072
13183
|
}));
|
|
13073
|
-
__publicField$
|
|
13184
|
+
__publicField$2(this, "refNameFromPath", (ref) => {
|
|
13074
13185
|
const parts = ref.split("/");
|
|
13075
13186
|
const name = parts[parts.length - 1];
|
|
13076
13187
|
if (!name) {
|
|
@@ -13078,16 +13189,16 @@ class ToTypeExprConverter {
|
|
|
13078
13189
|
}
|
|
13079
13190
|
return name;
|
|
13080
13191
|
});
|
|
13081
|
-
__publicField$
|
|
13192
|
+
__publicField$2(this, "refCacheKey", (schema) => {
|
|
13082
13193
|
return `${schema.$ref}|nullable:${schema.nullable === true}`;
|
|
13083
13194
|
});
|
|
13084
|
-
__publicField$
|
|
13195
|
+
__publicField$2(this, "isUnconstrainedSchema", (schema) => {
|
|
13085
13196
|
const meaningfulKeys = Object.keys(schema).filter(
|
|
13086
13197
|
(key) => key !== "nullable"
|
|
13087
13198
|
);
|
|
13088
13199
|
return meaningfulKeys.length === 0;
|
|
13089
13200
|
});
|
|
13090
|
-
__publicField$
|
|
13201
|
+
__publicField$2(this, "ensureSchemaDefinition", (refId) => {
|
|
13091
13202
|
if (this.schemaDefinitionsById.has(refId) || this.schemaDefinitionsInProgress.has(refId)) {
|
|
13092
13203
|
return;
|
|
13093
13204
|
}
|
|
@@ -13108,18 +13219,18 @@ class ToTypeExprConverter {
|
|
|
13108
13219
|
this.schemaDefinitionsInProgress.delete(refId);
|
|
13109
13220
|
}
|
|
13110
13221
|
});
|
|
13111
|
-
__publicField$
|
|
13222
|
+
__publicField$2(this, "isSchemaNode", (value) => {
|
|
13112
13223
|
return Boolean(
|
|
13113
13224
|
value && typeof value === "object" && !Array.isArray(value)
|
|
13114
13225
|
);
|
|
13115
13226
|
});
|
|
13116
|
-
__publicField$
|
|
13227
|
+
__publicField$2(this, "toLiteralValue", (value) => {
|
|
13117
13228
|
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
13118
13229
|
return value;
|
|
13119
13230
|
}
|
|
13120
13231
|
throw new Error(`Unsupported literal value: ${String(value)}`);
|
|
13121
13232
|
});
|
|
13122
|
-
__publicField$
|
|
13233
|
+
__publicField$2(this, "toDeclaration", (schema) => {
|
|
13123
13234
|
const enumDeclaration = this.toEnumDeclaration(schema);
|
|
13124
13235
|
if (enumDeclaration) {
|
|
13125
13236
|
return enumDeclaration;
|
|
@@ -13130,7 +13241,7 @@ class ToTypeExprConverter {
|
|
|
13130
13241
|
typeExpr: this.fromTypeExpr(schema)
|
|
13131
13242
|
};
|
|
13132
13243
|
});
|
|
13133
|
-
__publicField$
|
|
13244
|
+
__publicField$2(this, "toEnumDeclaration", (schema) => {
|
|
13134
13245
|
if (this.options.enumStyle !== "enum" || !Array.isArray(schema.enum)) {
|
|
13135
13246
|
return void 0;
|
|
13136
13247
|
}
|
|
@@ -13145,7 +13256,7 @@ class ToTypeExprConverter {
|
|
|
13145
13256
|
members: this.toEnumMembers(schema.enum)
|
|
13146
13257
|
};
|
|
13147
13258
|
});
|
|
13148
|
-
__publicField$
|
|
13259
|
+
__publicField$2(this, "getEnumValueType", (values) => {
|
|
13149
13260
|
if (!values.length) {
|
|
13150
13261
|
return void 0;
|
|
13151
13262
|
}
|
|
@@ -13157,7 +13268,7 @@ class ToTypeExprConverter {
|
|
|
13157
13268
|
}
|
|
13158
13269
|
return void 0;
|
|
13159
13270
|
});
|
|
13160
|
-
__publicField$
|
|
13271
|
+
__publicField$2(this, "toEnumMembers", (values) => {
|
|
13161
13272
|
const usedNames = /* @__PURE__ */ new Map();
|
|
13162
13273
|
return values.map((value, index) => {
|
|
13163
13274
|
const enumValue = value;
|
|
@@ -13170,7 +13281,7 @@ class ToTypeExprConverter {
|
|
|
13170
13281
|
};
|
|
13171
13282
|
});
|
|
13172
13283
|
});
|
|
13173
|
-
__publicField$
|
|
13284
|
+
__publicField$2(this, "toEnumMemberBaseName", (value, index) => {
|
|
13174
13285
|
if (typeof value === "string" && this.options.uppercaseEnumKeys) {
|
|
13175
13286
|
const compatName = this.toCompatEnumMemberName(value);
|
|
13176
13287
|
if (compatName) {
|
|
@@ -13186,14 +13297,14 @@ class ToTypeExprConverter {
|
|
|
13186
13297
|
const pascalName = toPascalCaseIdentifier(String(value));
|
|
13187
13298
|
return pascalName === "Api" ? `Value${index + 1}` : pascalName;
|
|
13188
13299
|
});
|
|
13189
|
-
__publicField$
|
|
13300
|
+
__publicField$2(this, "toCompatEnumMemberName", (value) => {
|
|
13190
13301
|
if (/^([A-Z_]{1,})$/g.test(value)) {
|
|
13191
13302
|
return value;
|
|
13192
13303
|
}
|
|
13193
13304
|
const pascalName = toPascalCaseIdentifier(value);
|
|
13194
13305
|
return pascalName === "Api" ? void 0 : pascalName;
|
|
13195
13306
|
});
|
|
13196
|
-
__publicField$
|
|
13307
|
+
__publicField$2(this, "isScalarName", (value) => {
|
|
13197
13308
|
switch (value) {
|
|
13198
13309
|
case "string":
|
|
13199
13310
|
case "number":
|
|
@@ -13209,7 +13320,7 @@ class ToTypeExprConverter {
|
|
|
13209
13320
|
return false;
|
|
13210
13321
|
}
|
|
13211
13322
|
});
|
|
13212
|
-
__publicField$
|
|
13323
|
+
__publicField$2(this, "hasNullMember", (expr) => {
|
|
13213
13324
|
if (expr.kind !== "inline") return false;
|
|
13214
13325
|
if (expr.expr.node === "scalar") {
|
|
13215
13326
|
return expr.expr.name === "null";
|
|
@@ -13219,13 +13330,13 @@ class ToTypeExprConverter {
|
|
|
13219
13330
|
}
|
|
13220
13331
|
return false;
|
|
13221
13332
|
});
|
|
13222
|
-
__publicField$
|
|
13333
|
+
__publicField$2(this, "withNullable", (expr) => {
|
|
13223
13334
|
if (this.hasNullMember(expr)) {
|
|
13224
13335
|
return expr;
|
|
13225
13336
|
}
|
|
13226
13337
|
return this.union([expr, this.scalar("null")]);
|
|
13227
13338
|
});
|
|
13228
|
-
__publicField$
|
|
13339
|
+
__publicField$2(this, "projectObjectType", (schema) => {
|
|
13229
13340
|
const requiredRaw = schema.required;
|
|
13230
13341
|
if (requiredRaw !== void 0 && !Array.isArray(requiredRaw)) {
|
|
13231
13342
|
throw new Error(
|
|
@@ -13290,7 +13401,7 @@ class ToTypeExprConverter {
|
|
|
13290
13401
|
}
|
|
13291
13402
|
};
|
|
13292
13403
|
});
|
|
13293
|
-
__publicField$
|
|
13404
|
+
__publicField$2(this, "isRequiredProperty", (name, required, propertySchema) => {
|
|
13294
13405
|
if (required.has(name)) {
|
|
13295
13406
|
return true;
|
|
13296
13407
|
}
|
|
@@ -13299,7 +13410,7 @@ class ToTypeExprConverter {
|
|
|
13299
13410
|
}
|
|
13300
13411
|
return propertySchema.required === true;
|
|
13301
13412
|
});
|
|
13302
|
-
__publicField$
|
|
13413
|
+
__publicField$2(this, "mapSchemaArrayMembers", (value, kind) => {
|
|
13303
13414
|
if (!Array.isArray(value) || !value.length) {
|
|
13304
13415
|
throw new Error(
|
|
13305
13416
|
`Unsupported schema: ${kind} must be a non-empty array`
|
|
@@ -13314,10 +13425,10 @@ class ToTypeExprConverter {
|
|
|
13314
13425
|
return this.fromTypeExpr(entry);
|
|
13315
13426
|
});
|
|
13316
13427
|
});
|
|
13317
|
-
__publicField$
|
|
13428
|
+
__publicField$2(this, "isBinaryFileSchema", (schema) => {
|
|
13318
13429
|
return schema.type === "string" && schema.format === "binary";
|
|
13319
13430
|
});
|
|
13320
|
-
__publicField$
|
|
13431
|
+
__publicField$2(this, "getSchemaDoc", (schema) => {
|
|
13321
13432
|
const summary = typeof schema.summary === "string" ? schema.summary : void 0;
|
|
13322
13433
|
const description = typeof schema.description === "string" ? schema.description : void 0;
|
|
13323
13434
|
const deprecated = typeof schema.deprecated === "boolean" ? schema.deprecated : void 0;
|
|
@@ -13338,7 +13449,7 @@ class ToTypeExprConverter {
|
|
|
13338
13449
|
nodes
|
|
13339
13450
|
};
|
|
13340
13451
|
});
|
|
13341
|
-
__publicField$
|
|
13452
|
+
__publicField$2(this, "getSchemaAnnotations", (schema) => {
|
|
13342
13453
|
if (this.options.comments?.metadata === false) return [];
|
|
13343
13454
|
return [
|
|
13344
13455
|
this.annotationNode("format", schema.format),
|
|
@@ -13365,14 +13476,14 @@ class ToTypeExprConverter {
|
|
|
13365
13476
|
(value) => value !== void 0
|
|
13366
13477
|
);
|
|
13367
13478
|
});
|
|
13368
|
-
__publicField$
|
|
13479
|
+
__publicField$2(this, "annotationNode", (name, value) => {
|
|
13369
13480
|
if (value === void 0) return void 0;
|
|
13370
13481
|
return {
|
|
13371
13482
|
key: name,
|
|
13372
13483
|
value: String(value)
|
|
13373
13484
|
};
|
|
13374
13485
|
});
|
|
13375
|
-
__publicField$
|
|
13486
|
+
__publicField$2(this, "stringifyAnnotationValue", (value) => {
|
|
13376
13487
|
if (value === void 0) return void 0;
|
|
13377
13488
|
if (value && typeof value === "object") {
|
|
13378
13489
|
return JSON.stringify(value);
|
|
@@ -13382,7 +13493,7 @@ class ToTypeExprConverter {
|
|
|
13382
13493
|
}
|
|
13383
13494
|
return String(value);
|
|
13384
13495
|
});
|
|
13385
|
-
__publicField$
|
|
13496
|
+
__publicField$2(this, "fromSchemaCore", (schema) => {
|
|
13386
13497
|
if (this.isUnconstrainedSchema(schema)) {
|
|
13387
13498
|
return this.scalar("unknown");
|
|
13388
13499
|
}
|
|
@@ -13462,9 +13573,9 @@ class ToTypeExprConverter {
|
|
|
13462
13573
|
}
|
|
13463
13574
|
}
|
|
13464
13575
|
|
|
13465
|
-
var __defProp$
|
|
13466
|
-
var __defNormalProp$
|
|
13467
|
-
var __publicField$
|
|
13576
|
+
var __defProp$1 = Object.defineProperty;
|
|
13577
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13578
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13468
13579
|
const pickPreferredMediaType = (mediaTypes) => {
|
|
13469
13580
|
if (!mediaTypes.length) return void 0;
|
|
13470
13581
|
const exactJson = mediaTypes.find((media) => media === "application/json");
|
|
@@ -13544,10 +13655,10 @@ const toHttpMethodUpper = (method) => {
|
|
|
13544
13655
|
class OperationProjector {
|
|
13545
13656
|
constructor(options) {
|
|
13546
13657
|
this.options = options;
|
|
13547
|
-
__publicField$
|
|
13548
|
-
__publicField$
|
|
13549
|
-
__publicField$
|
|
13550
|
-
this.
|
|
13658
|
+
__publicField$1(this, "rawOperationIdsByName", /* @__PURE__ */ new Map());
|
|
13659
|
+
__publicField$1(this, "typeExprConverter");
|
|
13660
|
+
__publicField$1(this, "project", (openApi) => {
|
|
13661
|
+
this.rawOperationIdsByName.clear();
|
|
13551
13662
|
this.typeExprConverter = new ToTypeExprConverter(
|
|
13552
13663
|
openApi.schemas,
|
|
13553
13664
|
this.options.typeExtraction
|
|
@@ -13556,16 +13667,32 @@ class OperationProjector {
|
|
|
13556
13667
|
this.typeExprConverter.registerAllSchemaDefinitions();
|
|
13557
13668
|
}
|
|
13558
13669
|
const operations = openApi.operations.map((operation) => {
|
|
13559
|
-
const
|
|
13560
|
-
if (!
|
|
13670
|
+
const operationId = (operation.operationId ?? syntheticOperationId(operation.method, operation.path)).trim();
|
|
13671
|
+
if (!operationId) {
|
|
13561
13672
|
throw new Error(
|
|
13562
13673
|
`Operation id is empty for ${operation.method.toUpperCase()} ${operation.path}`
|
|
13563
13674
|
);
|
|
13564
13675
|
}
|
|
13565
|
-
|
|
13566
|
-
|
|
13676
|
+
let operationName;
|
|
13677
|
+
try {
|
|
13678
|
+
operationName = toTsCamelIdentifier(operationId, {
|
|
13679
|
+
leadingDigitPrefix: "operation"
|
|
13680
|
+
});
|
|
13681
|
+
} catch {
|
|
13682
|
+
throw new Error(
|
|
13683
|
+
`Invalid operation id "${operationId}": could not derive a client method name.`
|
|
13684
|
+
);
|
|
13567
13685
|
}
|
|
13568
|
-
|
|
13686
|
+
const existingRawOperationId = this.rawOperationIdsByName.get(operationName);
|
|
13687
|
+
if (existingRawOperationId) {
|
|
13688
|
+
if (existingRawOperationId === operationId) {
|
|
13689
|
+
throw new Error(`Duplicate operation id: ${operationId}`);
|
|
13690
|
+
}
|
|
13691
|
+
throw new Error(
|
|
13692
|
+
`Operation naming collision: "${existingRawOperationId}" and "${operationId}" both normalize to "${operationName}". Rename one of these OpenAPI operation ids to continue.`
|
|
13693
|
+
);
|
|
13694
|
+
}
|
|
13695
|
+
return this.projectOne(operationId, operationName, operation);
|
|
13569
13696
|
});
|
|
13570
13697
|
return {
|
|
13571
13698
|
api: {
|
|
@@ -13577,8 +13704,8 @@ class OperationProjector {
|
|
|
13577
13704
|
schemaDefinitions: this.typeExprConverter.getSchemaDefinitions()
|
|
13578
13705
|
};
|
|
13579
13706
|
});
|
|
13580
|
-
__publicField$
|
|
13581
|
-
this.
|
|
13707
|
+
__publicField$1(this, "projectOne", (operationId, operationName, operation) => {
|
|
13708
|
+
this.rawOperationIdsByName.set(operationName, operationId);
|
|
13582
13709
|
const parameters = [];
|
|
13583
13710
|
const pathParameter = this.projectPathParameter(operation);
|
|
13584
13711
|
const queryParameter = this.projectQueryParameter(operation);
|
|
@@ -13589,7 +13716,7 @@ class OperationProjector {
|
|
|
13589
13716
|
return {
|
|
13590
13717
|
op: {
|
|
13591
13718
|
signature: {
|
|
13592
|
-
doc: this.toOperationDoc(
|
|
13719
|
+
doc: this.toOperationDoc(operationId, operation),
|
|
13593
13720
|
name: operationName,
|
|
13594
13721
|
parameters,
|
|
13595
13722
|
returnType: this.projectReturnType(operation)
|
|
@@ -13606,7 +13733,7 @@ class OperationProjector {
|
|
|
13606
13733
|
tags: [...operation.tags]
|
|
13607
13734
|
};
|
|
13608
13735
|
});
|
|
13609
|
-
__publicField$
|
|
13736
|
+
__publicField$1(this, "projectRequestContentType", (requestBody) => {
|
|
13610
13737
|
const { mediaType } = getPreferredMediaTypeEntry(
|
|
13611
13738
|
requestBody?.content ?? {}
|
|
13612
13739
|
);
|
|
@@ -13619,7 +13746,7 @@ class OperationProjector {
|
|
|
13619
13746
|
return void 0;
|
|
13620
13747
|
}
|
|
13621
13748
|
});
|
|
13622
|
-
__publicField$
|
|
13749
|
+
__publicField$1(this, "projectResponseFormat", (operation) => {
|
|
13623
13750
|
const selectedResponses = selectReturnResponses(operation.responses);
|
|
13624
13751
|
if (!selectedResponses.length) {
|
|
13625
13752
|
return void 0;
|
|
@@ -13636,7 +13763,7 @@ class OperationProjector {
|
|
|
13636
13763
|
}
|
|
13637
13764
|
return void 0;
|
|
13638
13765
|
});
|
|
13639
|
-
__publicField$
|
|
13766
|
+
__publicField$1(this, "projectParameterGroupTypeExpr", (params) => {
|
|
13640
13767
|
const properties = Object.entries(params).map(([name, parameter]) => ({
|
|
13641
13768
|
doc: this.toParameterDoc(parameter),
|
|
13642
13769
|
name,
|
|
@@ -13653,7 +13780,7 @@ class OperationProjector {
|
|
|
13653
13780
|
}
|
|
13654
13781
|
};
|
|
13655
13782
|
});
|
|
13656
|
-
__publicField$
|
|
13783
|
+
__publicField$1(this, "projectPathParameter", (operation) => {
|
|
13657
13784
|
const params = operation.parameters.path;
|
|
13658
13785
|
const entries = Object.values(params);
|
|
13659
13786
|
if (!entries.length) return null;
|
|
@@ -13666,7 +13793,7 @@ class OperationProjector {
|
|
|
13666
13793
|
typeExpr: this.projectParameterGroupTypeExpr(params)
|
|
13667
13794
|
};
|
|
13668
13795
|
});
|
|
13669
|
-
__publicField$
|
|
13796
|
+
__publicField$1(this, "projectQueryParameter", (operation) => {
|
|
13670
13797
|
const params = operation.parameters.query;
|
|
13671
13798
|
const entries = Object.values(params);
|
|
13672
13799
|
if (!entries.length) return null;
|
|
@@ -13676,7 +13803,7 @@ class OperationProjector {
|
|
|
13676
13803
|
typeExpr: this.projectParameterGroupTypeExpr(params)
|
|
13677
13804
|
};
|
|
13678
13805
|
});
|
|
13679
|
-
__publicField$
|
|
13806
|
+
__publicField$1(this, "projectBodyParameter", (operation) => {
|
|
13680
13807
|
const requestBody = operation.requestBody;
|
|
13681
13808
|
if (!requestBody) return null;
|
|
13682
13809
|
return {
|
|
@@ -13687,7 +13814,7 @@ class OperationProjector {
|
|
|
13687
13814
|
)
|
|
13688
13815
|
};
|
|
13689
13816
|
});
|
|
13690
|
-
__publicField$
|
|
13817
|
+
__publicField$1(this, "projectReturnType", (operation) => {
|
|
13691
13818
|
const selectedResponses = selectReturnResponses(operation.responses);
|
|
13692
13819
|
if (!selectedResponses.length) {
|
|
13693
13820
|
return this.typeExprConverter.scalar("void");
|
|
@@ -13701,17 +13828,17 @@ class OperationProjector {
|
|
|
13701
13828
|
});
|
|
13702
13829
|
return this.typeExprConverter.union(responseTypes);
|
|
13703
13830
|
});
|
|
13704
|
-
__publicField$
|
|
13831
|
+
__publicField$1(this, "selectParameterSchema", (parameter) => {
|
|
13705
13832
|
if (parameter.schema) return parameter.schema;
|
|
13706
13833
|
return getPreferredMediaTypeEntry(parameter.content).media?.schema;
|
|
13707
13834
|
});
|
|
13708
|
-
__publicField$
|
|
13835
|
+
__publicField$1(this, "selectRequestBodySchema", (requestBody) => {
|
|
13709
13836
|
return getPreferredMediaTypeEntry(requestBody.content).media?.schema;
|
|
13710
13837
|
});
|
|
13711
|
-
__publicField$
|
|
13838
|
+
__publicField$1(this, "selectResponseSchema", (response) => {
|
|
13712
13839
|
return getPreferredMediaTypeEntry(response.content).media?.schema;
|
|
13713
13840
|
});
|
|
13714
|
-
__publicField$
|
|
13841
|
+
__publicField$1(this, "toParameterDoc", (parameter) => {
|
|
13715
13842
|
if (!parameter.description && !parameter.deprecated) {
|
|
13716
13843
|
return void 0;
|
|
13717
13844
|
}
|
|
@@ -13720,7 +13847,7 @@ class OperationProjector {
|
|
|
13720
13847
|
nodes: parameter.description ? [parameter.description] : []
|
|
13721
13848
|
};
|
|
13722
13849
|
});
|
|
13723
|
-
__publicField$
|
|
13850
|
+
__publicField$1(this, "toOperationDoc", (operationName, operation) => {
|
|
13724
13851
|
return {
|
|
13725
13852
|
id: operationName,
|
|
13726
13853
|
request: `${toHttpMethodUpper(operation.method)}:${operation.path}`,
|
|
@@ -13780,21 +13907,21 @@ const renderImportedSymbol = (importedSymbol, importKind) => [
|
|
|
13780
13907
|
importedSymbol.alias ? `as ${importedSymbol.alias}` : void 0
|
|
13781
13908
|
].filter(Boolean).join(" ");
|
|
13782
13909
|
|
|
13783
|
-
var __defProp
|
|
13784
|
-
var __defNormalProp
|
|
13785
|
-
var __publicField
|
|
13910
|
+
var __defProp = Object.defineProperty;
|
|
13911
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13912
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13786
13913
|
class CodeWriter {
|
|
13787
13914
|
constructor(formatter, fw) {
|
|
13788
13915
|
this.formatter = formatter;
|
|
13789
13916
|
this.fw = fw;
|
|
13790
|
-
__publicField
|
|
13791
|
-
__publicField
|
|
13917
|
+
__publicField(this, "symbolChunkMap", /* @__PURE__ */ new Map());
|
|
13918
|
+
__publicField(this, "resolveModuleName", (chunkName) => {
|
|
13792
13919
|
return this.fw.resolveName({
|
|
13793
13920
|
name: chunkName,
|
|
13794
13921
|
ext: "ts"
|
|
13795
13922
|
});
|
|
13796
13923
|
});
|
|
13797
|
-
__publicField
|
|
13924
|
+
__publicField(this, "write", async (files) => {
|
|
13798
13925
|
this.symbolChunkMap = this.createSymbolChunkMap(files);
|
|
13799
13926
|
const writtenPaths = {};
|
|
13800
13927
|
for (const file of files) {
|
|
@@ -13812,7 +13939,7 @@ class CodeWriter {
|
|
|
13812
13939
|
}
|
|
13813
13940
|
return writtenPaths;
|
|
13814
13941
|
});
|
|
13815
|
-
__publicField
|
|
13942
|
+
__publicField(this, "createSymbolChunkMap", (files) => {
|
|
13816
13943
|
const map = /* @__PURE__ */ new Map();
|
|
13817
13944
|
for (const chunk of files) {
|
|
13818
13945
|
if (isTsBarrelFile(chunk)) continue;
|
|
@@ -13827,7 +13954,7 @@ class CodeWriter {
|
|
|
13827
13954
|
}
|
|
13828
13955
|
return map;
|
|
13829
13956
|
});
|
|
13830
|
-
__publicField
|
|
13957
|
+
__publicField(this, "renderCodeChunk", (chunk) => {
|
|
13831
13958
|
const imports = this.collectImports(chunk).map(
|
|
13832
13959
|
this.toImportStatementSymbol
|
|
13833
13960
|
);
|
|
@@ -13837,10 +13964,10 @@ class CodeWriter {
|
|
|
13837
13964
|
` : "";
|
|
13838
13965
|
return importCode + chunk.code;
|
|
13839
13966
|
});
|
|
13840
|
-
__publicField
|
|
13967
|
+
__publicField(this, "renderBarrelFile", (file) => file.exports.map(
|
|
13841
13968
|
(exportStatement) => this.renderBarrelExportStatement(exportStatement)
|
|
13842
13969
|
).join("\n"));
|
|
13843
|
-
__publicField
|
|
13970
|
+
__publicField(this, "renderBarrelExportStatement", (exportStatement) => {
|
|
13844
13971
|
const from = `./${this.resolveModuleName(exportStatement.from)}`;
|
|
13845
13972
|
if (exportStatement.kind === "all") {
|
|
13846
13973
|
return exportStatement.typeOnly ? `export type * from '${from}'` : `export * from '${from}'`;
|
|
@@ -13851,7 +13978,7 @@ class CodeWriter {
|
|
|
13851
13978
|
}).join(", ");
|
|
13852
13979
|
return `export { ${names} } from '${from}'`;
|
|
13853
13980
|
});
|
|
13854
|
-
__publicField
|
|
13981
|
+
__publicField(this, "collectImports", (chunk) => {
|
|
13855
13982
|
const imports = [];
|
|
13856
13983
|
for (const ref of chunk.refs) {
|
|
13857
13984
|
if (ref.kind === "builtin") continue;
|
|
@@ -13884,13 +14011,13 @@ class CodeWriter {
|
|
|
13884
14011
|
}
|
|
13885
14012
|
return imports;
|
|
13886
14013
|
});
|
|
13887
|
-
__publicField
|
|
14014
|
+
__publicField(this, "toImportStatementSymbol", (importedSymbol) => ({
|
|
13888
14015
|
name: importedSymbol.name,
|
|
13889
14016
|
alias: importedSymbol.alias,
|
|
13890
14017
|
source: this.importSourceToString(importedSymbol.source),
|
|
13891
14018
|
typeOnly: importedSymbol.typeOnly
|
|
13892
14019
|
}));
|
|
13893
|
-
__publicField
|
|
14020
|
+
__publicField(this, "importSourceToString", (src) => {
|
|
13894
14021
|
return "module" in src ? src.module : (
|
|
13895
14022
|
// TODO generalize later when we have different paths
|
|
13896
14023
|
`./${this.resolveModuleName(src.name)}`
|
|
@@ -13905,7 +14032,7 @@ const getWriteOpts = (file) => ({
|
|
|
13905
14032
|
noSuffix: isTsBarrelFile(file)
|
|
13906
14033
|
});
|
|
13907
14034
|
|
|
13908
|
-
class
|
|
14035
|
+
class OpenApiClientGenerator {
|
|
13909
14036
|
constructor(options, log) {
|
|
13910
14037
|
this.options = options;
|
|
13911
14038
|
this.log = log;
|
|
@@ -13927,17 +14054,17 @@ class VNextOasClientGenerator {
|
|
|
13927
14054
|
}).project(openApiIr);
|
|
13928
14055
|
const writer = new CodeWriter(formatter, fw);
|
|
13929
14056
|
const clientName = toPascalCaseIdentifier(apiName);
|
|
13930
|
-
const
|
|
14057
|
+
const input = {
|
|
14058
|
+
api: projectResult.api,
|
|
14059
|
+
operations: this.groupOpsByTag(projectResult.operations),
|
|
14060
|
+
schemaDefinitions: projectResult.schemaDefinitions
|
|
14061
|
+
};
|
|
14062
|
+
const chunks = generateOpenApiClientFiles(clientName, input, {
|
|
13931
14063
|
...this.options.codegen,
|
|
13932
14064
|
httpClient: this.options.httpClient
|
|
13933
14065
|
});
|
|
13934
14066
|
const writtenPaths = await writer.write(chunks.all);
|
|
13935
|
-
return
|
|
13936
|
-
promiseWrapper: chunks.promiseWrappersNames.map(
|
|
13937
|
-
(name) => writtenPaths[name]
|
|
13938
|
-
),
|
|
13939
|
-
types: writtenPaths[chunks.typesName]
|
|
13940
|
-
};
|
|
14067
|
+
return writtenPaths[chunks.typesName];
|
|
13941
14068
|
}
|
|
13942
14069
|
filterOperations(openApiIr) {
|
|
13943
14070
|
const ignoreTags = new Set(
|
|
@@ -13957,6 +14084,34 @@ class VNextOasClientGenerator {
|
|
|
13957
14084
|
})
|
|
13958
14085
|
};
|
|
13959
14086
|
}
|
|
14087
|
+
groupOpsByTag(operations) {
|
|
14088
|
+
const groupedOps = {};
|
|
14089
|
+
const rawTagsByNormalizedName = /* @__PURE__ */ new Map();
|
|
14090
|
+
operations.forEach((operation) => {
|
|
14091
|
+
const rawTag = operation.tags.find((tag) => tag.trim())?.trim() || "root";
|
|
14092
|
+
let groupName;
|
|
14093
|
+
try {
|
|
14094
|
+
groupName = toTsCamelIdentifier(rawTag, {
|
|
14095
|
+
leadingDigitPrefix: "tag"
|
|
14096
|
+
});
|
|
14097
|
+
} catch {
|
|
14098
|
+
throw new Error(
|
|
14099
|
+
`Invalid OpenAPI tag "${rawTag}": could not derive a client group name.`
|
|
14100
|
+
);
|
|
14101
|
+
}
|
|
14102
|
+
const existingRawTag = rawTagsByNormalizedName.get(groupName);
|
|
14103
|
+
if (existingRawTag && existingRawTag !== rawTag) {
|
|
14104
|
+
throw new Error(
|
|
14105
|
+
`Tag naming collision: "${existingRawTag}" and "${rawTag}" both normalize to "${groupName}". Rename one of these OpenAPI tags to continue.`
|
|
14106
|
+
);
|
|
14107
|
+
}
|
|
14108
|
+
rawTagsByNormalizedName.set(groupName, rawTag);
|
|
14109
|
+
const bucket = groupedOps[groupName] ?? [];
|
|
14110
|
+
bucket.push(operation.op);
|
|
14111
|
+
groupedOps[groupName] = bucket;
|
|
14112
|
+
});
|
|
14113
|
+
return groupedOps;
|
|
14114
|
+
}
|
|
13960
14115
|
normalizeSchema(rawSchema, inputFile) {
|
|
13961
14116
|
const { result, problems } = new OpenApiNormalizer(rawSchema).load();
|
|
13962
14117
|
problems.forEach((problem) => {
|
|
@@ -13999,11 +14154,11 @@ const toErrorMessage = (error) => {
|
|
|
13999
14154
|
return error instanceof Error ? error.message : String(error);
|
|
14000
14155
|
};
|
|
14001
14156
|
|
|
14002
|
-
const
|
|
14003
|
-
let
|
|
14157
|
+
const generateOasModel = async (spectPath, config, log, codeFormatter, fw) => {
|
|
14158
|
+
let typesFilePath;
|
|
14004
14159
|
const { openApiGenerator } = config;
|
|
14005
14160
|
if ("legacy" in openApiGenerator) {
|
|
14006
|
-
|
|
14161
|
+
typesFilePath = await generateOpenApiClient(
|
|
14007
14162
|
spectPath,
|
|
14008
14163
|
{
|
|
14009
14164
|
...openApiGenerator.legacy,
|
|
@@ -14013,7 +14168,7 @@ const generateOpenApiModel = async (spectPath, config, log, codeFormatter, fw) =
|
|
|
14013
14168
|
log
|
|
14014
14169
|
);
|
|
14015
14170
|
} else {
|
|
14016
|
-
|
|
14171
|
+
typesFilePath = await new OpenApiClientGenerator(
|
|
14017
14172
|
openApiGenerator,
|
|
14018
14173
|
log
|
|
14019
14174
|
).generate(
|
|
@@ -14026,137 +14181,9 @@ const generateOpenApiModel = async (spectPath, config, log, codeFormatter, fw) =
|
|
|
14026
14181
|
fw
|
|
14027
14182
|
);
|
|
14028
14183
|
}
|
|
14029
|
-
return { typesFilePath
|
|
14030
|
-
};
|
|
14031
|
-
|
|
14032
|
-
const removeGenericTypes = (code) => {
|
|
14033
|
-
const declarations = [];
|
|
14034
|
-
const declarationStartRegex = /^export\s+(interface|enum|type)\s+[A-Za-z0-9_]+(?:<[^>\n]+>)?/gm;
|
|
14035
|
-
let match;
|
|
14036
|
-
while ((match = declarationStartRegex.exec(code)) !== null) {
|
|
14037
|
-
const declaration = extractDeclaration(code, match);
|
|
14038
|
-
if (!declaration) continue;
|
|
14039
|
-
declarations.push(declaration);
|
|
14040
|
-
declarationStartRegex.lastIndex = match.index + declaration.length;
|
|
14041
|
-
}
|
|
14042
|
-
return declarations.join("\n\n");
|
|
14043
|
-
};
|
|
14044
|
-
const extractDeclaration = (code, match) => {
|
|
14045
|
-
const header = match[0];
|
|
14046
|
-
if (header.includes("<")) return null;
|
|
14047
|
-
const kind = match[1];
|
|
14048
|
-
let cursor = match.index + header.length;
|
|
14049
|
-
if (kind === "type") {
|
|
14050
|
-
cursor = skipWhitespace(code, cursor);
|
|
14051
|
-
if (code[cursor] !== "=") return null;
|
|
14052
|
-
cursor = skipWhitespace(code, cursor + 1);
|
|
14053
|
-
if (code[cursor] !== "{") return null;
|
|
14054
|
-
} else {
|
|
14055
|
-
cursor = code.indexOf("{", cursor);
|
|
14056
|
-
if (cursor === -1) return null;
|
|
14057
|
-
}
|
|
14058
|
-
const end = findMatchingBrace(code, cursor);
|
|
14059
|
-
if (end === -1) return null;
|
|
14060
|
-
return code.slice(match.index, end + 1);
|
|
14061
|
-
};
|
|
14062
|
-
const skipWhitespace = (code, cursor) => {
|
|
14063
|
-
while (/\s/.test(code[cursor] ?? "")) {
|
|
14064
|
-
cursor += 1;
|
|
14065
|
-
}
|
|
14066
|
-
return cursor;
|
|
14067
|
-
};
|
|
14068
|
-
const findMatchingBrace = (code, openBraceIndex) => {
|
|
14069
|
-
let depth = 0;
|
|
14070
|
-
for (let i = openBraceIndex; i < code.length; i += 1) {
|
|
14071
|
-
if (code[i] === "{") depth += 1;
|
|
14072
|
-
if (code[i] === "}") {
|
|
14073
|
-
depth -= 1;
|
|
14074
|
-
if (depth === 0) return i;
|
|
14075
|
-
}
|
|
14076
|
-
}
|
|
14077
|
-
return -1;
|
|
14184
|
+
return { typesFilePath };
|
|
14078
14185
|
};
|
|
14079
14186
|
|
|
14080
|
-
var __defProp$1 = Object.defineProperty;
|
|
14081
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14082
|
-
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, key + "" , value);
|
|
14083
|
-
class ZodSchemaGenerator {
|
|
14084
|
-
constructor(codeFormatter) {
|
|
14085
|
-
this.codeFormatter = codeFormatter;
|
|
14086
|
-
__publicField$1(this, "generate", async ({
|
|
14087
|
-
sourceText,
|
|
14088
|
-
moduleImportPath,
|
|
14089
|
-
options = {}
|
|
14090
|
-
}) => {
|
|
14091
|
-
const { getZodSchemasFile } = generate({
|
|
14092
|
-
sourceText: removeGenericTypes(sourceText)
|
|
14093
|
-
});
|
|
14094
|
-
let generated = getZodSchemasFile(moduleImportPath);
|
|
14095
|
-
generated = generated.replaceAll(".optional()", ".nullable()");
|
|
14096
|
-
generated = generated.replaceAll(".int64()", ".int()");
|
|
14097
|
-
if (options.localDateTimes) {
|
|
14098
|
-
generated = generated.replaceAll(
|
|
14099
|
-
"z.string().datetime()",
|
|
14100
|
-
"z.string().datetime({local: true})"
|
|
14101
|
-
);
|
|
14102
|
-
}
|
|
14103
|
-
return this.codeFormatter.format(generated);
|
|
14104
|
-
});
|
|
14105
|
-
}
|
|
14106
|
-
}
|
|
14107
|
-
|
|
14108
|
-
var __defProp = Object.defineProperty;
|
|
14109
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14110
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
14111
|
-
class FileWriter {
|
|
14112
|
-
constructor(outputDir, opts = {}) {
|
|
14113
|
-
this.outputDir = outputDir;
|
|
14114
|
-
this.opts = opts;
|
|
14115
|
-
__publicField(this, "resolveName", (req, opts) => {
|
|
14116
|
-
let name = opts?.preserveCase ? req.name : this.setNameCase(req.name);
|
|
14117
|
-
if (this.opts.suffix && opts?.noSuffix !== true) {
|
|
14118
|
-
name = name + "." + this.opts.suffix;
|
|
14119
|
-
}
|
|
14120
|
-
if (this.opts.mapFileName)
|
|
14121
|
-
name = this.opts.mapFileName({
|
|
14122
|
-
name,
|
|
14123
|
-
ext: req.ext
|
|
14124
|
-
});
|
|
14125
|
-
return name;
|
|
14126
|
-
});
|
|
14127
|
-
__publicField(this, "resolvePath", (req, opts) => this.getResolvedPath(req, opts));
|
|
14128
|
-
__publicField(this, "write", async ({ content, ...req }, opts) => {
|
|
14129
|
-
const resolvedPath = this.getResolvedPath(req, opts);
|
|
14130
|
-
await mkdir(Path.dirname(resolvedPath), { recursive: true });
|
|
14131
|
-
await writeFile(resolvedPath, content, "utf8");
|
|
14132
|
-
return resolvedPath;
|
|
14133
|
-
});
|
|
14134
|
-
__publicField(this, "getResolvedPath", ({ path, ext, ...req }, opts) => Path.resolve(
|
|
14135
|
-
this.outputDir,
|
|
14136
|
-
...path ?? [],
|
|
14137
|
-
`${this.resolveName(
|
|
14138
|
-
{
|
|
14139
|
-
ext,
|
|
14140
|
-
...req
|
|
14141
|
-
},
|
|
14142
|
-
opts
|
|
14143
|
-
)}.${ext}`
|
|
14144
|
-
));
|
|
14145
|
-
__publicField(this, "setNameCase", (name) => {
|
|
14146
|
-
const [first, ...rest] = name.split(".");
|
|
14147
|
-
const converted = this.transformCase(first);
|
|
14148
|
-
return [converted, ...rest].join(".");
|
|
14149
|
-
});
|
|
14150
|
-
__publicField(this, "transformCase", (value) => {
|
|
14151
|
-
const nameCase = this.opts.case ?? "pascal";
|
|
14152
|
-
if (nameCase === "kebab") {
|
|
14153
|
-
return toKebabCaseIdentifier(value);
|
|
14154
|
-
}
|
|
14155
|
-
return toPascalCaseIdentifier(value);
|
|
14156
|
-
});
|
|
14157
|
-
}
|
|
14158
|
-
}
|
|
14159
|
-
|
|
14160
14187
|
const generateApiClient = async (params, configFilePath, log = console.log) => {
|
|
14161
14188
|
const config = parseProfileConfig(params, configFilePath);
|
|
14162
14189
|
return generateApiClientFromConfig(config, log);
|
|
@@ -14190,7 +14217,7 @@ const generateApiClientFromConfig = async (config, log = console.log) => {
|
|
|
14190
14217
|
fs.mkdirSync(clientDir, {
|
|
14191
14218
|
recursive: true
|
|
14192
14219
|
});
|
|
14193
|
-
const { typesFilePath } = await
|
|
14220
|
+
const { typesFilePath } = await generateOasModel(
|
|
14194
14221
|
specPath,
|
|
14195
14222
|
{
|
|
14196
14223
|
...config,
|