@ps-aux/api-client-gen 0.7.0-rc.3 → 0.7.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -5
- package/dist/bin.cjs +74 -9
- package/dist/bin.mjs +56 -10
- package/dist/generateApiClient.cjs +560 -78
- package/dist/generateApiClient.mjs +564 -85
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +80 -5
- package/dist/index.d.mts +80 -5
- package/dist/index.d.ts +80 -5
- package/dist/index.mjs +1 -1
- package/package.json +6 -4
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import Path from 'path';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
|
-
import fs__default from 'fs';
|
|
3
|
+
import fs__default$1 from 'fs';
|
|
4
4
|
import fs$1 from 'fs/promises';
|
|
5
5
|
import { generateApi } from 'swagger-typescript-api';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { readFile } from 'node:fs/promises';
|
|
8
8
|
import Path$1 from 'node:path';
|
|
9
|
-
import
|
|
9
|
+
import fs__default from 'node:fs';
|
|
10
10
|
import { generate } from 'ts-to-zod';
|
|
11
11
|
|
|
12
12
|
/** A special constant with type `never` */
|
|
@@ -701,6 +701,7 @@ const string$1 = (params) => {
|
|
|
701
701
|
const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
|
|
702
702
|
return new RegExp(`^${regex}$`);
|
|
703
703
|
};
|
|
704
|
+
const number = /^-?\d+(?:\.\d+)?$/;
|
|
704
705
|
const boolean$1 = /^(?:true|false)$/i;
|
|
705
706
|
// regex for string with no uppercase letters
|
|
706
707
|
const lowercase = /^[^A-Z]*$/;
|
|
@@ -1897,6 +1898,122 @@ function handleIntersectionResults(result, left, right) {
|
|
|
1897
1898
|
result.value = merged.data;
|
|
1898
1899
|
return result;
|
|
1899
1900
|
}
|
|
1901
|
+
const $ZodRecord = /*@__PURE__*/ $constructor("$ZodRecord", (inst, def) => {
|
|
1902
|
+
$ZodType.init(inst, def);
|
|
1903
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1904
|
+
const input = payload.value;
|
|
1905
|
+
if (!isPlainObject(input)) {
|
|
1906
|
+
payload.issues.push({
|
|
1907
|
+
expected: "record",
|
|
1908
|
+
code: "invalid_type",
|
|
1909
|
+
input,
|
|
1910
|
+
inst,
|
|
1911
|
+
});
|
|
1912
|
+
return payload;
|
|
1913
|
+
}
|
|
1914
|
+
const proms = [];
|
|
1915
|
+
const values = def.keyType._zod.values;
|
|
1916
|
+
if (values) {
|
|
1917
|
+
payload.value = {};
|
|
1918
|
+
const recordKeys = new Set();
|
|
1919
|
+
for (const key of values) {
|
|
1920
|
+
if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
|
|
1921
|
+
recordKeys.add(typeof key === "number" ? key.toString() : key);
|
|
1922
|
+
const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
|
|
1923
|
+
if (result instanceof Promise) {
|
|
1924
|
+
proms.push(result.then((result) => {
|
|
1925
|
+
if (result.issues.length) {
|
|
1926
|
+
payload.issues.push(...prefixIssues(key, result.issues));
|
|
1927
|
+
}
|
|
1928
|
+
payload.value[key] = result.value;
|
|
1929
|
+
}));
|
|
1930
|
+
}
|
|
1931
|
+
else {
|
|
1932
|
+
if (result.issues.length) {
|
|
1933
|
+
payload.issues.push(...prefixIssues(key, result.issues));
|
|
1934
|
+
}
|
|
1935
|
+
payload.value[key] = result.value;
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
let unrecognized;
|
|
1940
|
+
for (const key in input) {
|
|
1941
|
+
if (!recordKeys.has(key)) {
|
|
1942
|
+
unrecognized = unrecognized ?? [];
|
|
1943
|
+
unrecognized.push(key);
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
if (unrecognized && unrecognized.length > 0) {
|
|
1947
|
+
payload.issues.push({
|
|
1948
|
+
code: "unrecognized_keys",
|
|
1949
|
+
input,
|
|
1950
|
+
inst,
|
|
1951
|
+
keys: unrecognized,
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
else {
|
|
1956
|
+
payload.value = {};
|
|
1957
|
+
for (const key of Reflect.ownKeys(input)) {
|
|
1958
|
+
if (key === "__proto__")
|
|
1959
|
+
continue;
|
|
1960
|
+
let keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
|
|
1961
|
+
if (keyResult instanceof Promise) {
|
|
1962
|
+
throw new Error("Async schemas not supported in object keys currently");
|
|
1963
|
+
}
|
|
1964
|
+
// Numeric string fallback: if key is a numeric string and failed, retry with Number(key)
|
|
1965
|
+
// This handles z.number(), z.literal([1, 2, 3]), and unions containing numeric literals
|
|
1966
|
+
const checkNumericKey = typeof key === "string" && number.test(key) && keyResult.issues.length;
|
|
1967
|
+
if (checkNumericKey) {
|
|
1968
|
+
const retryResult = def.keyType._zod.run({ value: Number(key), issues: [] }, ctx);
|
|
1969
|
+
if (retryResult instanceof Promise) {
|
|
1970
|
+
throw new Error("Async schemas not supported in object keys currently");
|
|
1971
|
+
}
|
|
1972
|
+
if (retryResult.issues.length === 0) {
|
|
1973
|
+
keyResult = retryResult;
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
if (keyResult.issues.length) {
|
|
1977
|
+
if (def.mode === "loose") {
|
|
1978
|
+
// Pass through unchanged
|
|
1979
|
+
payload.value[key] = input[key];
|
|
1980
|
+
}
|
|
1981
|
+
else {
|
|
1982
|
+
// Default "strict" behavior: error on invalid key
|
|
1983
|
+
payload.issues.push({
|
|
1984
|
+
code: "invalid_key",
|
|
1985
|
+
origin: "record",
|
|
1986
|
+
issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
|
|
1987
|
+
input: key,
|
|
1988
|
+
path: [key],
|
|
1989
|
+
inst,
|
|
1990
|
+
});
|
|
1991
|
+
}
|
|
1992
|
+
continue;
|
|
1993
|
+
}
|
|
1994
|
+
const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
|
|
1995
|
+
if (result instanceof Promise) {
|
|
1996
|
+
proms.push(result.then((result) => {
|
|
1997
|
+
if (result.issues.length) {
|
|
1998
|
+
payload.issues.push(...prefixIssues(key, result.issues));
|
|
1999
|
+
}
|
|
2000
|
+
payload.value[keyResult.value] = result.value;
|
|
2001
|
+
}));
|
|
2002
|
+
}
|
|
2003
|
+
else {
|
|
2004
|
+
if (result.issues.length) {
|
|
2005
|
+
payload.issues.push(...prefixIssues(key, result.issues));
|
|
2006
|
+
}
|
|
2007
|
+
payload.value[keyResult.value] = result.value;
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
if (proms.length) {
|
|
2012
|
+
return Promise.all(proms).then(() => payload);
|
|
2013
|
+
}
|
|
2014
|
+
return payload;
|
|
2015
|
+
};
|
|
2016
|
+
});
|
|
1900
2017
|
const $ZodEnum = /*@__PURE__*/ $constructor("$ZodEnum", (inst, def) => {
|
|
1901
2018
|
$ZodType.init(inst, def);
|
|
1902
2019
|
const values = getEnumValues(def.entries);
|
|
@@ -3293,6 +3410,49 @@ const intersectionProcessor = (schema, ctx, json, params) => {
|
|
|
3293
3410
|
];
|
|
3294
3411
|
json.allOf = allOf;
|
|
3295
3412
|
};
|
|
3413
|
+
const recordProcessor = (schema, ctx, _json, params) => {
|
|
3414
|
+
const json = _json;
|
|
3415
|
+
const def = schema._zod.def;
|
|
3416
|
+
json.type = "object";
|
|
3417
|
+
// For looseRecord with regex patterns, use patternProperties
|
|
3418
|
+
// This correctly represents "only validate keys matching the pattern" semantics
|
|
3419
|
+
// and composes well with allOf (intersections)
|
|
3420
|
+
const keyType = def.keyType;
|
|
3421
|
+
const keyBag = keyType._zod.bag;
|
|
3422
|
+
const patterns = keyBag?.patterns;
|
|
3423
|
+
if (def.mode === "loose" && patterns && patterns.size > 0) {
|
|
3424
|
+
// Use patternProperties for looseRecord with regex patterns
|
|
3425
|
+
const valueSchema = process(def.valueType, ctx, {
|
|
3426
|
+
...params,
|
|
3427
|
+
path: [...params.path, "patternProperties", "*"],
|
|
3428
|
+
});
|
|
3429
|
+
json.patternProperties = {};
|
|
3430
|
+
for (const pattern of patterns) {
|
|
3431
|
+
json.patternProperties[pattern.source] = valueSchema;
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
else {
|
|
3435
|
+
// Default behavior: use propertyNames + additionalProperties
|
|
3436
|
+
if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
|
|
3437
|
+
json.propertyNames = process(def.keyType, ctx, {
|
|
3438
|
+
...params,
|
|
3439
|
+
path: [...params.path, "propertyNames"],
|
|
3440
|
+
});
|
|
3441
|
+
}
|
|
3442
|
+
json.additionalProperties = process(def.valueType, ctx, {
|
|
3443
|
+
...params,
|
|
3444
|
+
path: [...params.path, "additionalProperties"],
|
|
3445
|
+
});
|
|
3446
|
+
}
|
|
3447
|
+
// Add required for keys with discrete values (enum, literal, etc.)
|
|
3448
|
+
const keyValues = keyType._zod.values;
|
|
3449
|
+
if (keyValues) {
|
|
3450
|
+
const validKeyValues = [...keyValues].filter((v) => typeof v === "string" || typeof v === "number");
|
|
3451
|
+
if (validKeyValues.length > 0) {
|
|
3452
|
+
json.required = validKeyValues;
|
|
3453
|
+
}
|
|
3454
|
+
}
|
|
3455
|
+
};
|
|
3296
3456
|
const nullableProcessor = (schema, ctx, json, params) => {
|
|
3297
3457
|
const def = schema._zod.def;
|
|
3298
3458
|
const inner = process(def.innerType, ctx, params);
|
|
@@ -3796,6 +3956,21 @@ function intersection(left, right) {
|
|
|
3796
3956
|
right: right,
|
|
3797
3957
|
});
|
|
3798
3958
|
}
|
|
3959
|
+
const ZodRecord = /*@__PURE__*/ $constructor("ZodRecord", (inst, def) => {
|
|
3960
|
+
$ZodRecord.init(inst, def);
|
|
3961
|
+
ZodType.init(inst, def);
|
|
3962
|
+
inst._zod.processJSONSchema = (ctx, json, params) => recordProcessor(inst, ctx, json, params);
|
|
3963
|
+
inst.keyType = def.keyType;
|
|
3964
|
+
inst.valueType = def.valueType;
|
|
3965
|
+
});
|
|
3966
|
+
function record(keyType, valueType, params) {
|
|
3967
|
+
return new ZodRecord({
|
|
3968
|
+
type: "record",
|
|
3969
|
+
keyType,
|
|
3970
|
+
valueType: valueType,
|
|
3971
|
+
...normalizeParams(params),
|
|
3972
|
+
});
|
|
3973
|
+
}
|
|
3799
3974
|
const ZodEnum = /*@__PURE__*/ $constructor("ZodEnum", (inst, def) => {
|
|
3800
3975
|
$ZodEnum.init(inst, def);
|
|
3801
3976
|
ZodType.init(inst, def);
|
|
@@ -4028,8 +4203,19 @@ const vNextOasGeneratorSchema = strictObject({
|
|
|
4028
4203
|
unwrap: boolean().default(true),
|
|
4029
4204
|
withRequestParams: boolean().default(false),
|
|
4030
4205
|
pathParamsStyle: _enum(["object", "positional"]).default("positional"),
|
|
4031
|
-
enumStyle: _enum(["enum", "union"]).default("enum")
|
|
4032
|
-
|
|
4206
|
+
enumStyle: _enum(["enum", "union"]).default("enum"),
|
|
4207
|
+
comments: strictObject({
|
|
4208
|
+
enabled: boolean().default(true),
|
|
4209
|
+
operation: strictObject({
|
|
4210
|
+
tags: boolean().default(true),
|
|
4211
|
+
summary: boolean().default(true),
|
|
4212
|
+
description: boolean().default(true)
|
|
4213
|
+
}).prefault({}),
|
|
4214
|
+
schema: strictObject({
|
|
4215
|
+
metadata: boolean().default(true)
|
|
4216
|
+
}).prefault({})
|
|
4217
|
+
}).prefault({})
|
|
4218
|
+
}).prefault({}),
|
|
4033
4219
|
compat: strictObject({
|
|
4034
4220
|
uppercaseEnumKeys: boolean(),
|
|
4035
4221
|
swaggerTsApiRequiredBooleans: boolean()
|
|
@@ -4040,7 +4226,7 @@ const legacyOasGeneratorSchema = strictObject({
|
|
|
4040
4226
|
ignoreOperationsWithTags: array(string()).optional()
|
|
4041
4227
|
})
|
|
4042
4228
|
});
|
|
4043
|
-
const
|
|
4229
|
+
const profileConfigSchema = strictObject({
|
|
4044
4230
|
srcSpec: string().trim().min(1),
|
|
4045
4231
|
dstDir: string().trim().min(1),
|
|
4046
4232
|
apiName: string().trim().min(1),
|
|
@@ -4058,6 +4244,8 @@ const configSchema = strictObject({
|
|
|
4058
4244
|
localDateTimes: boolean().optional()
|
|
4059
4245
|
}).optional()
|
|
4060
4246
|
});
|
|
4247
|
+
const configSchema = record(string(), profileConfigSchema);
|
|
4248
|
+
const defineConfig = (config) => config;
|
|
4061
4249
|
const parseConfig = (userConfig, filePath) => {
|
|
4062
4250
|
const parsed = configSchema.safeParse(userConfig);
|
|
4063
4251
|
if (parsed.success) return parsed.data;
|
|
@@ -4065,6 +4253,13 @@ const parseConfig = (userConfig, filePath) => {
|
|
|
4065
4253
|
cause: parsed.error
|
|
4066
4254
|
});
|
|
4067
4255
|
};
|
|
4256
|
+
const parseProfileConfig = (userConfig, filePath) => {
|
|
4257
|
+
const parsed = profileConfigSchema.safeParse(userConfig);
|
|
4258
|
+
if (parsed.success) return parsed.data;
|
|
4259
|
+
throw new Error(`Invalid config at ${filePath}: ${parsed.error.message}`, {
|
|
4260
|
+
cause: parsed.error
|
|
4261
|
+
});
|
|
4262
|
+
};
|
|
4068
4263
|
|
|
4069
4264
|
const downloadSpec = async (path, url) => {
|
|
4070
4265
|
let response;
|
|
@@ -4219,9 +4414,9 @@ const resolveLocalRef = (root, ref) => {
|
|
|
4219
4414
|
return current;
|
|
4220
4415
|
};
|
|
4221
4416
|
|
|
4222
|
-
var __defProp$
|
|
4223
|
-
var __defNormalProp$
|
|
4224
|
-
var __publicField$
|
|
4417
|
+
var __defProp$a = Object.defineProperty;
|
|
4418
|
+
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4419
|
+
var __publicField$a = (obj, key, value) => __defNormalProp$a(obj, key + "" , value);
|
|
4225
4420
|
const PARAMETER_LOCATIONS = [
|
|
4226
4421
|
"path",
|
|
4227
4422
|
"query",
|
|
@@ -4247,7 +4442,7 @@ const mergeParameters = (base, override) => {
|
|
|
4247
4442
|
class OpenApiNormalizer {
|
|
4248
4443
|
constructor(doc) {
|
|
4249
4444
|
this.doc = doc;
|
|
4250
|
-
__publicField$
|
|
4445
|
+
__publicField$a(this, "problems", []);
|
|
4251
4446
|
}
|
|
4252
4447
|
load() {
|
|
4253
4448
|
const info = readRecord(this.doc, "info");
|
|
@@ -4590,23 +4785,24 @@ const syntheticOperationId = (method, path) => {
|
|
|
4590
4785
|
return `_${compact}`;
|
|
4591
4786
|
};
|
|
4592
4787
|
|
|
4593
|
-
var __defProp$
|
|
4594
|
-
var __defNormalProp$
|
|
4595
|
-
var __publicField$
|
|
4788
|
+
var __defProp$9 = Object.defineProperty;
|
|
4789
|
+
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4790
|
+
var __publicField$9 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4596
4791
|
class TsCodegen {
|
|
4597
|
-
constructor(typeExprCodegen) {
|
|
4792
|
+
constructor(typeExprCodegen, docRenderer) {
|
|
4598
4793
|
this.typeExprCodegen = typeExprCodegen;
|
|
4599
|
-
__publicField$
|
|
4600
|
-
__publicField$
|
|
4601
|
-
__publicField$
|
|
4794
|
+
__publicField$9(this, "usedTypeRefs", []);
|
|
4795
|
+
__publicField$9(this, "usedTypeRefKeys", /* @__PURE__ */ new Set());
|
|
4796
|
+
__publicField$9(this, "docRenderer");
|
|
4797
|
+
__publicField$9(this, "typeExpr", (typeExpr) => {
|
|
4602
4798
|
this.collectTypeRefsFromExpr(typeExpr);
|
|
4603
4799
|
return this.typeExprCodegen.toCode(typeExpr).code;
|
|
4604
4800
|
});
|
|
4605
|
-
__publicField$
|
|
4801
|
+
__publicField$9(this, "declaration", (name, declaration, options = {}) => {
|
|
4606
4802
|
this.collectTypeRefsFromDeclaration(declaration);
|
|
4607
|
-
return this.toDeclarationCode(name, declaration);
|
|
4803
|
+
return this.toDeclarationCode(name, declaration, options);
|
|
4608
4804
|
});
|
|
4609
|
-
__publicField$
|
|
4805
|
+
__publicField$9(this, "toChunk", (name, code, exports$1) => {
|
|
4610
4806
|
const exportedSymbols = new Set(exports$1);
|
|
4611
4807
|
const refs = this.getTypeRefs().filter((ref) => {
|
|
4612
4808
|
return ref.kind !== "internal" || !exportedSymbols.has(ref.name);
|
|
@@ -4618,17 +4814,25 @@ class TsCodegen {
|
|
|
4618
4814
|
refs
|
|
4619
4815
|
};
|
|
4620
4816
|
});
|
|
4621
|
-
__publicField$
|
|
4817
|
+
__publicField$9(this, "getTypeRefs", () => {
|
|
4622
4818
|
return this.usedTypeRefs.map((ref) => ({ ...ref }));
|
|
4623
4819
|
});
|
|
4624
|
-
__publicField$
|
|
4820
|
+
__publicField$9(this, "toDeclarationCode", (name, d, o) => {
|
|
4821
|
+
let code = this.toDeclarationBodyCode(name, d);
|
|
4822
|
+
if (o.exported) {
|
|
4823
|
+
code = `export ${code}`;
|
|
4824
|
+
}
|
|
4825
|
+
return this.addDoc(code, d.doc);
|
|
4826
|
+
});
|
|
4827
|
+
__publicField$9(this, "toDeclarationBodyCode", (name, declaration) => {
|
|
4625
4828
|
switch (declaration.kind) {
|
|
4626
4829
|
case "typeAlias":
|
|
4627
4830
|
return `type ${name} = ${this.typeExprCodegen.toCode(declaration.typeExpr).code}`;
|
|
4628
4831
|
case "enum": {
|
|
4629
|
-
const members = declaration.members.map(
|
|
4630
|
-
|
|
4631
|
-
|
|
4832
|
+
const members = declaration.members.map((member) => {
|
|
4833
|
+
const code = `${member.name} = ${JSON.stringify(member.value)}`;
|
|
4834
|
+
return this.addDoc(code, member.doc);
|
|
4835
|
+
}).join(",\n");
|
|
4632
4836
|
return `enum ${name} {
|
|
4633
4837
|
${members}
|
|
4634
4838
|
}`;
|
|
@@ -4641,6 +4845,13 @@ ${members}
|
|
|
4641
4845
|
}
|
|
4642
4846
|
}
|
|
4643
4847
|
});
|
|
4848
|
+
__publicField$9(this, "addDoc", (code, doc) => {
|
|
4849
|
+
if (!doc) return code;
|
|
4850
|
+
const rendered = this.docRenderer.render(doc);
|
|
4851
|
+
return rendered ? `${rendered}
|
|
4852
|
+
${code}` : code;
|
|
4853
|
+
});
|
|
4854
|
+
this.docRenderer = docRenderer;
|
|
4644
4855
|
}
|
|
4645
4856
|
collectTypeRef(typeRef) {
|
|
4646
4857
|
if (typeRef.kind === "builtin") return;
|
|
@@ -4766,12 +4977,13 @@ const toTsPropertyKey = (value) => {
|
|
|
4766
4977
|
return isTsIdentifier(value) ? value : JSON.stringify(value);
|
|
4767
4978
|
};
|
|
4768
4979
|
|
|
4769
|
-
var __defProp$
|
|
4770
|
-
var __defNormalProp$
|
|
4771
|
-
var __publicField$
|
|
4980
|
+
var __defProp$8 = Object.defineProperty;
|
|
4981
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4982
|
+
var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4772
4983
|
class TypeExprCodegen {
|
|
4773
|
-
constructor() {
|
|
4774
|
-
__publicField$
|
|
4984
|
+
constructor(docRenderer) {
|
|
4985
|
+
__publicField$8(this, "docRenderer");
|
|
4986
|
+
__publicField$8(this, "toCode", (typeExpr) => {
|
|
4775
4987
|
switch (typeExpr.kind) {
|
|
4776
4988
|
case "reference":
|
|
4777
4989
|
return this.toReferenceCode(typeExpr);
|
|
@@ -4787,7 +4999,7 @@ class TypeExprCodegen {
|
|
|
4787
4999
|
}
|
|
4788
5000
|
}
|
|
4789
5001
|
});
|
|
4790
|
-
__publicField$
|
|
5002
|
+
__publicField$8(this, "toReferenceCode", (typeExpr) => {
|
|
4791
5003
|
if (!typeExpr.typeArgs?.length) {
|
|
4792
5004
|
return {
|
|
4793
5005
|
code: typeExpr.ref.name,
|
|
@@ -4800,7 +5012,7 @@ class TypeExprCodegen {
|
|
|
4800
5012
|
ref: typeExpr.ref
|
|
4801
5013
|
};
|
|
4802
5014
|
});
|
|
4803
|
-
__publicField$
|
|
5015
|
+
__publicField$8(this, "toInlineCode", (expr) => {
|
|
4804
5016
|
switch (expr.node) {
|
|
4805
5017
|
case "scalar":
|
|
4806
5018
|
return expr.name === "integer" ? "number" : expr.name;
|
|
@@ -4825,55 +5037,66 @@ class TypeExprCodegen {
|
|
|
4825
5037
|
}
|
|
4826
5038
|
}
|
|
4827
5039
|
});
|
|
4828
|
-
__publicField$
|
|
5040
|
+
__publicField$8(this, "toIntersectionMemberCode", (typeExpr) => {
|
|
4829
5041
|
const rendered = this.toCode(typeExpr).code;
|
|
4830
5042
|
return this.isUnion(typeExpr) ? `(${rendered})` : rendered;
|
|
4831
5043
|
});
|
|
4832
|
-
__publicField$
|
|
5044
|
+
__publicField$8(this, "toArrayElementCode", (typeExpr) => {
|
|
4833
5045
|
const rendered = this.toCode(typeExpr).code;
|
|
4834
5046
|
return this.needsGroupingForArrayElement(typeExpr) ? `(${rendered})` : rendered;
|
|
4835
5047
|
});
|
|
4836
|
-
__publicField$
|
|
5048
|
+
__publicField$8(this, "isUnion", (typeExpr) => {
|
|
4837
5049
|
return typeExpr.kind === "inline" && typeExpr.expr.node === "union";
|
|
4838
5050
|
});
|
|
4839
|
-
__publicField$
|
|
5051
|
+
__publicField$8(this, "needsGroupingForArrayElement", (typeExpr) => {
|
|
4840
5052
|
return typeExpr.kind === "inline" && (typeExpr.expr.node === "union" || typeExpr.expr.node === "intersection");
|
|
4841
5053
|
});
|
|
4842
|
-
__publicField$
|
|
5054
|
+
__publicField$8(this, "toLiteralCode", (value) => {
|
|
4843
5055
|
if (value === null) return "null";
|
|
4844
5056
|
return JSON.stringify(value);
|
|
4845
5057
|
});
|
|
4846
|
-
__publicField$
|
|
5058
|
+
__publicField$8(this, "toObjectCode", (properties, additionalProperties) => {
|
|
4847
5059
|
const members = properties.map(
|
|
4848
5060
|
(property) => this.toPropertyCode(property)
|
|
4849
5061
|
);
|
|
4850
5062
|
if (additionalProperties === true) {
|
|
4851
|
-
members.push("[key: string]: unknown");
|
|
5063
|
+
members.push("[key: string]: unknown;");
|
|
4852
5064
|
} else if (additionalProperties !== void 0 && additionalProperties !== false) {
|
|
4853
5065
|
members.push(
|
|
4854
|
-
`[key: string]: ${this.toCode(additionalProperties).code}
|
|
5066
|
+
`[key: string]: ${this.toCode(additionalProperties).code};`
|
|
4855
5067
|
);
|
|
4856
5068
|
}
|
|
4857
|
-
|
|
4858
|
-
|
|
5069
|
+
return `{
|
|
5070
|
+
${members.join("\n")}
|
|
5071
|
+
}`;
|
|
4859
5072
|
});
|
|
4860
|
-
__publicField$
|
|
5073
|
+
__publicField$8(this, "toPropertyCode", (property) => {
|
|
4861
5074
|
const name = toTsPropertyKey(property.name);
|
|
4862
5075
|
const optional = property.required ? "" : "?";
|
|
4863
|
-
|
|
4864
|
-
|
|
5076
|
+
const propertyCode = `${name}${optional}: ${this.toCode(property.typeExpr).code}`;
|
|
5077
|
+
const docCode = property.doc ? this.docRenderer.render(property.doc, {
|
|
5078
|
+
compactText: true
|
|
5079
|
+
}) : "";
|
|
5080
|
+
const renderedProperty = `${propertyCode};`;
|
|
5081
|
+
return docCode ? `${docCode}
|
|
5082
|
+
${renderedProperty}` : renderedProperty;
|
|
5083
|
+
});
|
|
5084
|
+
this.docRenderer = docRenderer;
|
|
4865
5085
|
}
|
|
4866
5086
|
}
|
|
4867
5087
|
|
|
4868
|
-
var __defProp$
|
|
4869
|
-
var __defNormalProp$
|
|
4870
|
-
var __publicField$
|
|
5088
|
+
var __defProp$7 = Object.defineProperty;
|
|
5089
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5090
|
+
var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4871
5091
|
class TsCodegenFactory {
|
|
4872
|
-
constructor() {
|
|
4873
|
-
__publicField$
|
|
4874
|
-
__publicField$
|
|
4875
|
-
|
|
4876
|
-
|
|
5092
|
+
constructor(docRenderer) {
|
|
5093
|
+
__publicField$7(this, "typeExprCodegen");
|
|
5094
|
+
__publicField$7(this, "docRenderer");
|
|
5095
|
+
__publicField$7(this, "forNewChunk", () => {
|
|
5096
|
+
return new TsCodegen(this.typeExprCodegen, this.docRenderer);
|
|
5097
|
+
});
|
|
5098
|
+
this.docRenderer = docRenderer;
|
|
5099
|
+
this.typeExprCodegen = new TypeExprCodegen(this.docRenderer);
|
|
4877
5100
|
}
|
|
4878
5101
|
}
|
|
4879
5102
|
|
|
@@ -4922,13 +5145,13 @@ const isReservedWord = (value) => {
|
|
|
4922
5145
|
return RESERVED_WORDS.has(value);
|
|
4923
5146
|
};
|
|
4924
5147
|
|
|
4925
|
-
var __defProp$
|
|
4926
|
-
var __defNormalProp$
|
|
4927
|
-
var __publicField$
|
|
5148
|
+
var __defProp$6 = Object.defineProperty;
|
|
5149
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5150
|
+
var __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4928
5151
|
class ParamsConstructor {
|
|
4929
5152
|
constructor(options) {
|
|
4930
5153
|
this.options = options;
|
|
4931
|
-
__publicField$
|
|
5154
|
+
__publicField$6(this, "process", (params, httpPath) => {
|
|
4932
5155
|
const pathParamSpec = validatePathParams(params, httpPath);
|
|
4933
5156
|
const pathParamBindings = pathParamSpec?.bindings;
|
|
4934
5157
|
const funParams = params.flatMap(
|
|
@@ -4948,7 +5171,7 @@ class ParamsConstructor {
|
|
|
4948
5171
|
hasQuery
|
|
4949
5172
|
};
|
|
4950
5173
|
});
|
|
4951
|
-
__publicField$
|
|
5174
|
+
__publicField$6(this, "renderOperationParams", (param, pathParamSpec) => {
|
|
4952
5175
|
if (param.kind !== "path" || !pathParamSpec) {
|
|
4953
5176
|
return [
|
|
4954
5177
|
{
|
|
@@ -4972,7 +5195,7 @@ class ParamsConstructor {
|
|
|
4972
5195
|
}
|
|
4973
5196
|
];
|
|
4974
5197
|
});
|
|
4975
|
-
__publicField$
|
|
5198
|
+
__publicField$6(this, "renderPathTemplateLiteral", (path, pathParamVarName, pathParamBindings) => {
|
|
4976
5199
|
const escapedPath = path.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
4977
5200
|
const pathWithParams = escapedPath.replace(
|
|
4978
5201
|
/\{([^}]+)\}/g,
|
|
@@ -4986,7 +5209,7 @@ class ParamsConstructor {
|
|
|
4986
5209
|
);
|
|
4987
5210
|
return `\`${pathWithParams}\``;
|
|
4988
5211
|
});
|
|
4989
|
-
__publicField$
|
|
5212
|
+
__publicField$6(this, "renderPathParamDestructuring", (pathParamBindings) => {
|
|
4990
5213
|
const members = Object.entries(pathParamBindings).map(
|
|
4991
5214
|
([paramName, binding]) => {
|
|
4992
5215
|
const key = toTsPropertyKey(paramName);
|
|
@@ -4995,7 +5218,7 @@ class ParamsConstructor {
|
|
|
4995
5218
|
);
|
|
4996
5219
|
return `{ ${members.join(", ")} }`;
|
|
4997
5220
|
});
|
|
4998
|
-
__publicField$
|
|
5221
|
+
__publicField$6(this, "paramName", (p) => {
|
|
4999
5222
|
switch (p.kind) {
|
|
5000
5223
|
case "body":
|
|
5001
5224
|
return this.options.paramNames.body;
|
|
@@ -5107,19 +5330,27 @@ const validatePathParams = (params, httpPath) => {
|
|
|
5107
5330
|
};
|
|
5108
5331
|
};
|
|
5109
5332
|
|
|
5333
|
+
const indentBlock = (value, indent) => {
|
|
5334
|
+
if (!value || !indent) {
|
|
5335
|
+
return value;
|
|
5336
|
+
}
|
|
5337
|
+
return value.split("\n").map((line) => `${indent}${line}`).join("\n");
|
|
5338
|
+
};
|
|
5339
|
+
|
|
5110
5340
|
const EMPTY_LINE_MARKER = "/*__EMPTY_LINE_MARKER__*/";
|
|
5111
5341
|
|
|
5112
|
-
var __defProp$
|
|
5113
|
-
var __defNormalProp$
|
|
5114
|
-
var __publicField$
|
|
5342
|
+
var __defProp$5 = Object.defineProperty;
|
|
5343
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5344
|
+
var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5115
5345
|
const REQUEST_PARAMS_TYPE = "RequestParams";
|
|
5116
5346
|
const REQUEST_PARAMS_DEFAULT = "never";
|
|
5117
5347
|
const REQUEST_PARAMS_ARG = "params";
|
|
5118
5348
|
class ApiClientCodegen {
|
|
5119
|
-
constructor(opts, tsCodegenFactory) {
|
|
5349
|
+
constructor(opts, tsCodegenFactory, docRenderer) {
|
|
5120
5350
|
this.opts = opts;
|
|
5121
5351
|
this.tsCodegenFactory = tsCodegenFactory;
|
|
5122
|
-
|
|
5352
|
+
this.docRenderer = docRenderer;
|
|
5353
|
+
__publicField$5(this, "generate", (apiName, operations, doc) => {
|
|
5123
5354
|
const tsCodegen = this.tsCodegenFactory.forNewChunk();
|
|
5124
5355
|
const httpClientType = tsCodegen.typeExpr(this.opts.httpClient.typeName);
|
|
5125
5356
|
let clientType = httpClientType;
|
|
@@ -5129,16 +5360,18 @@ class ApiClientCodegen {
|
|
|
5129
5360
|
classTypeParams = `<${REQUEST_PARAMS_TYPE} = ${REQUEST_PARAMS_DEFAULT}>`;
|
|
5130
5361
|
}
|
|
5131
5362
|
const methodsCode = Array.isArray(operations) ? this.opsCode(tsCodegen, operations) : this.groupsOpsCode(tsCodegen, operations);
|
|
5363
|
+
const classDocCode = this.renderApiClientDoc(doc, "");
|
|
5132
5364
|
const code = `
|
|
5133
|
-
|
|
5134
|
-
|
|
5365
|
+
${classDocCode ? `${classDocCode}
|
|
5366
|
+
` : ""}export class ${apiName}${classTypeParams} {
|
|
5367
|
+
constructor(private readonly http: ${clientType}) {}
|
|
5135
5368
|
|
|
5136
5369
|
${methodsCode}
|
|
5137
5370
|
}
|
|
5138
5371
|
`;
|
|
5139
5372
|
return tsCodegen.toChunk("api", code, [apiName]);
|
|
5140
5373
|
});
|
|
5141
|
-
__publicField$
|
|
5374
|
+
__publicField$5(this, "groupsOpsCode", (codegen, groupedOps) => Object.entries(groupedOps).map(([groupName, ops]) => {
|
|
5142
5375
|
const methodsCode = this.opsCode(codegen, ops, "object");
|
|
5143
5376
|
return `
|
|
5144
5377
|
${toTsPropertyKey(groupName)} = {
|
|
@@ -5146,14 +5379,14 @@ class ApiClientCodegen {
|
|
|
5146
5379
|
}
|
|
5147
5380
|
`;
|
|
5148
5381
|
}).join("\n\n"));
|
|
5149
|
-
__publicField$
|
|
5382
|
+
__publicField$5(this, "opsCode", (codegen, operations, target = "class") => {
|
|
5150
5383
|
const separator = target === "object" ? `,
|
|
5151
5384
|
${EMPTY_LINE_MARKER}
|
|
5152
5385
|
` : "\n\n";
|
|
5153
5386
|
const methodsCode = operations.map((op) => this.renderOp(op, codegen, target)).join(separator);
|
|
5154
5387
|
return methodsCode;
|
|
5155
5388
|
});
|
|
5156
|
-
__publicField$
|
|
5389
|
+
__publicField$5(this, "renderOp", (op, tsCodegen, target) => {
|
|
5157
5390
|
const { signature: sig, http } = op;
|
|
5158
5391
|
const invocationVars = this.opts.httpClient.invocation.vars;
|
|
5159
5392
|
const paramNames = {
|
|
@@ -5179,6 +5412,7 @@ ${EMPTY_LINE_MARKER}
|
|
|
5179
5412
|
const responseType = tsCodegen.typeExpr(sig.returnType);
|
|
5180
5413
|
const returnType = this.wrapInResponseWrapper(sig.returnType, tsCodegen);
|
|
5181
5414
|
return this.renderFunctionCode({
|
|
5415
|
+
doc: sig.doc,
|
|
5182
5416
|
funName: sig.name,
|
|
5183
5417
|
responseType,
|
|
5184
5418
|
returnType,
|
|
@@ -5194,13 +5428,14 @@ ${EMPTY_LINE_MARKER}
|
|
|
5194
5428
|
target
|
|
5195
5429
|
});
|
|
5196
5430
|
});
|
|
5197
|
-
__publicField$
|
|
5431
|
+
__publicField$5(this, "wrapInResponseWrapper", (typeExpr, tsCodegen) => {
|
|
5198
5432
|
return tsCodegen.typeExpr({
|
|
5199
5433
|
...this.opts.httpClient.responseWrapper,
|
|
5200
5434
|
typeArgs: [typeExpr]
|
|
5201
5435
|
});
|
|
5202
5436
|
});
|
|
5203
|
-
__publicField$
|
|
5437
|
+
__publicField$5(this, "renderFunctionCode", ({
|
|
5438
|
+
doc,
|
|
5204
5439
|
funName,
|
|
5205
5440
|
responseType,
|
|
5206
5441
|
returnType,
|
|
@@ -5232,9 +5467,74 @@ ${EMPTY_LINE_MARKER}
|
|
|
5232
5467
|
invocation = invocation.replaceAll("\n", "");
|
|
5233
5468
|
const operator = target === "object" ? ":" : "=";
|
|
5234
5469
|
const returnTypeCode = this.opts.httpClient.inferMethodReturnType ? "" : `:${returnType}`;
|
|
5235
|
-
|
|
5236
|
-
this.
|
|
5470
|
+
const functionCode = `${funName} ${operator} (${params})${returnTypeCode} =>
|
|
5471
|
+
this.http${invocation}
|
|
5237
5472
|
`;
|
|
5473
|
+
const docCode = this.renderOperationDoc(
|
|
5474
|
+
doc,
|
|
5475
|
+
this.opts.comments,
|
|
5476
|
+
target === "object" ? " " : " "
|
|
5477
|
+
);
|
|
5478
|
+
return docCode ? `${docCode}
|
|
5479
|
+
${functionCode}` : functionCode;
|
|
5480
|
+
});
|
|
5481
|
+
__publicField$5(this, "renderOperationDoc", (doc, comments, indent = "") => {
|
|
5482
|
+
if (!doc) return null;
|
|
5483
|
+
return indentBlock(this.docRenderer.render(this.toTsDoc(doc)), indent);
|
|
5484
|
+
});
|
|
5485
|
+
__publicField$5(this, "renderApiClientDoc", (doc, indent = "") => {
|
|
5486
|
+
if (!doc) return "";
|
|
5487
|
+
return indentBlock(
|
|
5488
|
+
this.docRenderer.render({
|
|
5489
|
+
nodes: [
|
|
5490
|
+
{
|
|
5491
|
+
key: "title",
|
|
5492
|
+
value: doc.title
|
|
5493
|
+
},
|
|
5494
|
+
{
|
|
5495
|
+
key: "version",
|
|
5496
|
+
value: doc.version
|
|
5497
|
+
},
|
|
5498
|
+
...doc.description ? [doc.description] : []
|
|
5499
|
+
]
|
|
5500
|
+
}),
|
|
5501
|
+
indent
|
|
5502
|
+
);
|
|
5503
|
+
});
|
|
5504
|
+
__publicField$5(this, "toTsDoc", (doc) => {
|
|
5505
|
+
const nodes = [
|
|
5506
|
+
{
|
|
5507
|
+
key: "id",
|
|
5508
|
+
value: doc.id
|
|
5509
|
+
}
|
|
5510
|
+
];
|
|
5511
|
+
const comms = this.opts.comments;
|
|
5512
|
+
if ((comms.summary ?? true) && doc.summary) {
|
|
5513
|
+
nodes.push({
|
|
5514
|
+
key: "summary",
|
|
5515
|
+
value: doc.summary
|
|
5516
|
+
});
|
|
5517
|
+
}
|
|
5518
|
+
if ((comms.description ?? true) && doc.description) {
|
|
5519
|
+
nodes.push({
|
|
5520
|
+
key: "description",
|
|
5521
|
+
value: doc.description
|
|
5522
|
+
});
|
|
5523
|
+
}
|
|
5524
|
+
nodes.push({
|
|
5525
|
+
key: "request",
|
|
5526
|
+
value: doc.request
|
|
5527
|
+
});
|
|
5528
|
+
if ((comms.tags ?? true) && doc.tags.length) {
|
|
5529
|
+
nodes.push({
|
|
5530
|
+
key: "tags",
|
|
5531
|
+
value: doc.tags.join(", ")
|
|
5532
|
+
});
|
|
5533
|
+
}
|
|
5534
|
+
return {
|
|
5535
|
+
deprecated: doc.deprecated,
|
|
5536
|
+
nodes
|
|
5537
|
+
};
|
|
5238
5538
|
});
|
|
5239
5539
|
}
|
|
5240
5540
|
}
|
|
@@ -5403,21 +5703,102 @@ const provideHttpClientCode = (gen, opts) => gen.toChunk(
|
|
|
5403
5703
|
["HttpRequest", "HttpResponse", "HttpClient"]
|
|
5404
5704
|
);
|
|
5405
5705
|
|
|
5706
|
+
var __defProp$4 = Object.defineProperty;
|
|
5707
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5708
|
+
var __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5709
|
+
class TsDocRenderer {
|
|
5710
|
+
constructor(options) {
|
|
5711
|
+
this.options = options;
|
|
5712
|
+
__publicField$4(this, "render", (doc, options = {}) => {
|
|
5713
|
+
if (!this.options.enabled) return "";
|
|
5714
|
+
const lines = [];
|
|
5715
|
+
this.appendNodes(lines, doc.nodes, options);
|
|
5716
|
+
if (doc.deprecated) {
|
|
5717
|
+
this.appendDeprecated(lines, { separate: lines.length > 0 });
|
|
5718
|
+
}
|
|
5719
|
+
return this.renderComment(lines);
|
|
5720
|
+
});
|
|
5721
|
+
__publicField$4(this, "renderComment", (lines) => {
|
|
5722
|
+
if (!this.options.enabled) return "";
|
|
5723
|
+
if (!lines.length) return "";
|
|
5724
|
+
if (lines.length === 1) {
|
|
5725
|
+
return `/** ${lines[0]} */`;
|
|
5726
|
+
}
|
|
5727
|
+
const body = lines.map((line) => line ? ` * ${line}` : " *").join("\n");
|
|
5728
|
+
return `/**
|
|
5729
|
+
${body}
|
|
5730
|
+
*/`;
|
|
5731
|
+
});
|
|
5732
|
+
__publicField$4(this, "appendDocText", (lines, value) => {
|
|
5733
|
+
const normalized = this.normalizeLines(value);
|
|
5734
|
+
if (!normalized.length) return;
|
|
5735
|
+
if (lines.length > 0) {
|
|
5736
|
+
lines.push("");
|
|
5737
|
+
}
|
|
5738
|
+
lines.push(...normalized);
|
|
5739
|
+
});
|
|
5740
|
+
__publicField$4(this, "appendField", (lines, key, value) => {
|
|
5741
|
+
const normalized = this.normalizeLines(value);
|
|
5742
|
+
if (!normalized.length) return;
|
|
5743
|
+
lines.push(`@${key} ${normalized[0]}`.trimEnd());
|
|
5744
|
+
lines.push(...normalized.slice(1));
|
|
5745
|
+
});
|
|
5746
|
+
__publicField$4(this, "appendDeprecated", (lines, options) => {
|
|
5747
|
+
if (options.separate) {
|
|
5748
|
+
lines.push("");
|
|
5749
|
+
}
|
|
5750
|
+
lines.push("@deprecated");
|
|
5751
|
+
});
|
|
5752
|
+
__publicField$4(this, "appendNodes", (lines, nodes = [], options = {}) => {
|
|
5753
|
+
nodes.forEach((node) => {
|
|
5754
|
+
if (typeof node === "string") {
|
|
5755
|
+
if (options.compactText) {
|
|
5756
|
+
lines.push(...this.normalizeNonEmptyLines(node));
|
|
5757
|
+
return;
|
|
5758
|
+
}
|
|
5759
|
+
this.appendDocText(lines, node);
|
|
5760
|
+
return;
|
|
5761
|
+
}
|
|
5762
|
+
this.appendField(lines, node.key, node.value);
|
|
5763
|
+
});
|
|
5764
|
+
});
|
|
5765
|
+
__publicField$4(this, "normalizeLines", (value) => {
|
|
5766
|
+
const trimmed = value?.trim();
|
|
5767
|
+
if (!trimmed) return [];
|
|
5768
|
+
return trimmed.split(/\r?\n/u).map((line) => line.trimEnd().replaceAll("*/", "*\\/"));
|
|
5769
|
+
});
|
|
5770
|
+
__publicField$4(this, "normalizeNonEmptyLines", (value) => this.normalizeLines(value).filter((line) => line.length > 0));
|
|
5771
|
+
}
|
|
5772
|
+
}
|
|
5773
|
+
|
|
5406
5774
|
const generateTsCode = (clientName, projectResult, opts) => {
|
|
5407
|
-
const
|
|
5775
|
+
const docRenderer = new TsDocRenderer({
|
|
5776
|
+
enabled: opts.comments.enabled
|
|
5777
|
+
});
|
|
5778
|
+
const tsCodegenFac = new TsCodegenFactory(docRenderer);
|
|
5408
5779
|
const { schemaDefinitions } = projectResult;
|
|
5409
5780
|
const types = [...schemaDefinitions].sort((a, b) => a.name.localeCompare(b.name)).map((def) => {
|
|
5410
5781
|
const cg = tsCodegenFac.forNewChunk();
|
|
5411
|
-
const code =
|
|
5782
|
+
const code = cg.declaration(def.name, def.declaration, {
|
|
5783
|
+
exported: true
|
|
5784
|
+
});
|
|
5412
5785
|
return cg.toChunk(def.name, code, [def.name]);
|
|
5413
5786
|
});
|
|
5414
5787
|
const clientCodegen = new ApiClientCodegen(
|
|
5415
|
-
{
|
|
5416
|
-
|
|
5788
|
+
{
|
|
5789
|
+
httpClient: promiseHttpClientCodegenSpec(),
|
|
5790
|
+
comments: opts.comments.operation,
|
|
5791
|
+
unwrap: opts.unwrap,
|
|
5792
|
+
pathParamsStyle: opts.pathParamsStyle,
|
|
5793
|
+
withRequestParams: opts.withRequestParams
|
|
5794
|
+
},
|
|
5795
|
+
tsCodegenFac,
|
|
5796
|
+
docRenderer
|
|
5417
5797
|
);
|
|
5418
5798
|
const generated = clientCodegen.generate(
|
|
5419
5799
|
clientName,
|
|
5420
|
-
groupsOpsByTag(projectResult.operations)
|
|
5800
|
+
groupsOpsByTag(projectResult.operations),
|
|
5801
|
+
projectResult.api
|
|
5421
5802
|
);
|
|
5422
5803
|
const clientChunk = {
|
|
5423
5804
|
...generated,
|
|
@@ -5627,6 +6008,7 @@ class ToTypeExprConverter {
|
|
|
5627
6008
|
}
|
|
5628
6009
|
return {
|
|
5629
6010
|
kind: "typeAlias",
|
|
6011
|
+
doc: this.getSchemaDoc(schema),
|
|
5630
6012
|
typeExpr: this.fromTypeExpr(schema)
|
|
5631
6013
|
};
|
|
5632
6014
|
});
|
|
@@ -5640,6 +6022,7 @@ class ToTypeExprConverter {
|
|
|
5640
6022
|
}
|
|
5641
6023
|
return {
|
|
5642
6024
|
kind: "enum",
|
|
6025
|
+
doc: this.getSchemaDoc(schema),
|
|
5643
6026
|
valueType,
|
|
5644
6027
|
members: this.toEnumMembers(schema.enum)
|
|
5645
6028
|
};
|
|
@@ -5755,6 +6138,7 @@ class ToTypeExprConverter {
|
|
|
5755
6138
|
);
|
|
5756
6139
|
}
|
|
5757
6140
|
return {
|
|
6141
|
+
doc: this.getSchemaDoc(propertySchema),
|
|
5758
6142
|
name,
|
|
5759
6143
|
required: this.isRequiredProperty(
|
|
5760
6144
|
name,
|
|
@@ -5815,6 +6199,71 @@ class ToTypeExprConverter {
|
|
|
5815
6199
|
__publicField$3(this, "isBinaryFileSchema", (schema) => {
|
|
5816
6200
|
return schema.type === "string" && schema.format === "binary";
|
|
5817
6201
|
});
|
|
6202
|
+
__publicField$3(this, "getSchemaDoc", (schema) => {
|
|
6203
|
+
const summary = typeof schema.summary === "string" ? schema.summary : void 0;
|
|
6204
|
+
const description = typeof schema.description === "string" ? schema.description : void 0;
|
|
6205
|
+
const deprecated = typeof schema.deprecated === "boolean" ? schema.deprecated : void 0;
|
|
6206
|
+
const annotations = this.getSchemaAnnotations(schema);
|
|
6207
|
+
if (!summary && !description && !deprecated && !annotations.length) {
|
|
6208
|
+
return void 0;
|
|
6209
|
+
}
|
|
6210
|
+
const nodes = [];
|
|
6211
|
+
if (summary) {
|
|
6212
|
+
nodes.push(summary);
|
|
6213
|
+
}
|
|
6214
|
+
if (description) {
|
|
6215
|
+
nodes.push(description);
|
|
6216
|
+
}
|
|
6217
|
+
nodes.push(...annotations);
|
|
6218
|
+
return {
|
|
6219
|
+
deprecated,
|
|
6220
|
+
nodes
|
|
6221
|
+
};
|
|
6222
|
+
});
|
|
6223
|
+
__publicField$3(this, "getSchemaAnnotations", (schema) => {
|
|
6224
|
+
if (this.options.comments?.metadata === false) return [];
|
|
6225
|
+
return [
|
|
6226
|
+
this.annotationNode("format", schema.format),
|
|
6227
|
+
this.annotationNode("min", schema.minimum),
|
|
6228
|
+
this.annotationNode("multipleOf", schema.multipleOf),
|
|
6229
|
+
this.annotationNode("exclusiveMin", schema.exclusiveMinimum),
|
|
6230
|
+
this.annotationNode("max", schema.maximum),
|
|
6231
|
+
this.annotationNode("minLength", schema.minLength),
|
|
6232
|
+
this.annotationNode("maxLength", schema.maxLength),
|
|
6233
|
+
this.annotationNode("exclusiveMax", schema.exclusiveMaximum),
|
|
6234
|
+
this.annotationNode("maxItems", schema.maxItems),
|
|
6235
|
+
this.annotationNode("minItems", schema.minItems),
|
|
6236
|
+
this.annotationNode("uniqueItems", schema.uniqueItems),
|
|
6237
|
+
this.annotationNode(
|
|
6238
|
+
"default",
|
|
6239
|
+
this.stringifyAnnotationValue(schema.default)
|
|
6240
|
+
),
|
|
6241
|
+
this.annotationNode("pattern", schema.pattern),
|
|
6242
|
+
this.annotationNode(
|
|
6243
|
+
"example",
|
|
6244
|
+
this.stringifyAnnotationValue(schema.example)
|
|
6245
|
+
)
|
|
6246
|
+
].filter(
|
|
6247
|
+
(value) => value !== void 0
|
|
6248
|
+
);
|
|
6249
|
+
});
|
|
6250
|
+
__publicField$3(this, "annotationNode", (name, value) => {
|
|
6251
|
+
if (value === void 0) return void 0;
|
|
6252
|
+
return {
|
|
6253
|
+
key: name,
|
|
6254
|
+
value: String(value)
|
|
6255
|
+
};
|
|
6256
|
+
});
|
|
6257
|
+
__publicField$3(this, "stringifyAnnotationValue", (value) => {
|
|
6258
|
+
if (value === void 0) return void 0;
|
|
6259
|
+
if (value && typeof value === "object") {
|
|
6260
|
+
return JSON.stringify(value);
|
|
6261
|
+
}
|
|
6262
|
+
if (typeof value === "string") {
|
|
6263
|
+
return JSON.stringify(value);
|
|
6264
|
+
}
|
|
6265
|
+
return String(value);
|
|
6266
|
+
});
|
|
5818
6267
|
__publicField$3(this, "fromSchemaCore", (schema) => {
|
|
5819
6268
|
if (this.isUnconstrainedSchema(schema)) {
|
|
5820
6269
|
return this.scalar("unknown");
|
|
@@ -6001,6 +6450,11 @@ class OperationProjector {
|
|
|
6001
6450
|
return this.projectOne(operationName, operation);
|
|
6002
6451
|
});
|
|
6003
6452
|
return {
|
|
6453
|
+
api: {
|
|
6454
|
+
title: openApi.info.title,
|
|
6455
|
+
version: openApi.info.version,
|
|
6456
|
+
description: openApi.info.description
|
|
6457
|
+
},
|
|
6004
6458
|
operations,
|
|
6005
6459
|
schemaDefinitions: this.typeExprConverter.getSchemaDefinitions()
|
|
6006
6460
|
};
|
|
@@ -6017,6 +6471,7 @@ class OperationProjector {
|
|
|
6017
6471
|
return {
|
|
6018
6472
|
op: {
|
|
6019
6473
|
signature: {
|
|
6474
|
+
doc: this.toOperationDoc(operationName, operation),
|
|
6020
6475
|
name: operationName,
|
|
6021
6476
|
parameters,
|
|
6022
6477
|
returnType: this.projectReturnType(operation)
|
|
@@ -6065,6 +6520,7 @@ class OperationProjector {
|
|
|
6065
6520
|
});
|
|
6066
6521
|
__publicField$2(this, "projectParameterGroupTypeExpr", (params) => {
|
|
6067
6522
|
const properties = Object.entries(params).map(([name, parameter]) => ({
|
|
6523
|
+
doc: this.toParameterDoc(parameter),
|
|
6068
6524
|
name,
|
|
6069
6525
|
required: parameter.required,
|
|
6070
6526
|
typeExpr: this.typeExprConverter.fromTypeExpr(
|
|
@@ -6137,6 +6593,25 @@ class OperationProjector {
|
|
|
6137
6593
|
__publicField$2(this, "selectResponseSchema", (response) => {
|
|
6138
6594
|
return getPreferredMediaTypeEntry(response.content).media?.schema;
|
|
6139
6595
|
});
|
|
6596
|
+
__publicField$2(this, "toParameterDoc", (parameter) => {
|
|
6597
|
+
if (!parameter.description && !parameter.deprecated) {
|
|
6598
|
+
return void 0;
|
|
6599
|
+
}
|
|
6600
|
+
return {
|
|
6601
|
+
deprecated: parameter.deprecated,
|
|
6602
|
+
nodes: parameter.description ? [parameter.description] : []
|
|
6603
|
+
};
|
|
6604
|
+
});
|
|
6605
|
+
__publicField$2(this, "toOperationDoc", (operationName, operation) => {
|
|
6606
|
+
return {
|
|
6607
|
+
id: operationName,
|
|
6608
|
+
request: `${toHttpMethodUpper(operation.method)}:${operation.path}`,
|
|
6609
|
+
summary: operation.summary,
|
|
6610
|
+
description: operation.description,
|
|
6611
|
+
deprecated: operation.deprecated,
|
|
6612
|
+
tags: operation.tags.map((tag) => tag.trim()).filter(Boolean)
|
|
6613
|
+
};
|
|
6614
|
+
});
|
|
6140
6615
|
}
|
|
6141
6616
|
}
|
|
6142
6617
|
|
|
@@ -6175,7 +6650,7 @@ class CodeWriter {
|
|
|
6175
6650
|
__publicField(this, "symbolChunkMap", /* @__PURE__ */ new Map());
|
|
6176
6651
|
__publicField(this, "write", async (dir, chunks) => {
|
|
6177
6652
|
this.symbolChunkMap = this.createSymbolChunkMap(chunks);
|
|
6178
|
-
|
|
6653
|
+
fs__default.mkdirSync(dir, { recursive: true });
|
|
6179
6654
|
for (const chunk of chunks) {
|
|
6180
6655
|
const imports = this.collectImports(chunk);
|
|
6181
6656
|
const importStatements = this.genImportStatements(imports);
|
|
@@ -6185,7 +6660,7 @@ class CodeWriter {
|
|
|
6185
6660
|
let code = importCode + chunk.code;
|
|
6186
6661
|
code = await this.formatter.format(code);
|
|
6187
6662
|
code = ensureSingleTrailingNewline(code);
|
|
6188
|
-
|
|
6663
|
+
fs__default.writeFileSync(`${dir}/${chunk.name}.ts`, code, "utf8");
|
|
6189
6664
|
}
|
|
6190
6665
|
});
|
|
6191
6666
|
__publicField(this, "createSymbolChunkMap", (chunks) => {
|
|
@@ -6262,6 +6737,7 @@ class VNextOasClientGenerator {
|
|
|
6262
6737
|
const projectResult = new OperationProjector({
|
|
6263
6738
|
includeAllSchema: this.options.selection?.allSchemas === true,
|
|
6264
6739
|
typeExtraction: {
|
|
6740
|
+
comments: this.options.codegen.comments.schema,
|
|
6265
6741
|
enumStyle: this.options.codegen.enumStyle,
|
|
6266
6742
|
uppercaseEnumKeys: this.options.compat?.uppercaseEnumKeys,
|
|
6267
6743
|
swaggerTsApiRequiredBooleans: this.options.compat?.swaggerTsApiRequiredBooleans
|
|
@@ -6455,7 +6931,7 @@ const findMatchingBrace = (code, openBraceIndex) => {
|
|
|
6455
6931
|
};
|
|
6456
6932
|
|
|
6457
6933
|
const generateSchemas = async (inputFile, outputFile, opts = {}) => {
|
|
6458
|
-
const code = fs__default.readFileSync(inputFile).toString();
|
|
6934
|
+
const code = fs__default$1.readFileSync(inputFile).toString();
|
|
6459
6935
|
const { getZodSchemasFile } = generate({
|
|
6460
6936
|
sourceText: removeGenericTypes(code)
|
|
6461
6937
|
});
|
|
@@ -6473,7 +6949,7 @@ const generateSchemas = async (inputFile, outputFile, opts = {}) => {
|
|
|
6473
6949
|
...prettierConfig,
|
|
6474
6950
|
filepath: outputFile
|
|
6475
6951
|
});
|
|
6476
|
-
fs__default.writeFileSync(outputFile, formatted);
|
|
6952
|
+
fs__default$1.writeFileSync(outputFile, formatted);
|
|
6477
6953
|
};
|
|
6478
6954
|
const getModuleImportPath = (inputFile, outputFile) => {
|
|
6479
6955
|
const sourceDir = Path.dirname(outputFile);
|
|
@@ -6484,7 +6960,10 @@ const getModuleImportPath = (inputFile, outputFile) => {
|
|
|
6484
6960
|
};
|
|
6485
6961
|
|
|
6486
6962
|
const generateApiClient = async (params, configFilePath, log = console.log) => {
|
|
6487
|
-
const config =
|
|
6963
|
+
const config = parseProfileConfig(params, configFilePath);
|
|
6964
|
+
return generateApiClientFromConfig(config, log);
|
|
6965
|
+
};
|
|
6966
|
+
const generateApiClientFromConfig = async (config, log = console.log) => {
|
|
6488
6967
|
const { dstDir, apiName, srcSpec, zodSchemas } = config;
|
|
6489
6968
|
const dir = Path.resolve(dstDir, apiName);
|
|
6490
6969
|
if (!fs.existsSync(dir)) {
|
|
@@ -6531,4 +7010,4 @@ const getSpecPath = async (urlOrPath, dir, log) => {
|
|
|
6531
7010
|
return specPath;
|
|
6532
7011
|
};
|
|
6533
7012
|
|
|
6534
|
-
export { generateApiClient as g };
|
|
7013
|
+
export { generateApiClientFromConfig as a, defineConfig as d, generateApiClient as g, parseConfig as p };
|