next-openapi-gen 1.4.0 → 1.4.2
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/cli.js +257 -141
- package/dist/index.js +257 -141
- package/dist/next/index.js +257 -141
- package/dist/react-router/index.js +168 -56
- package/dist/vite/index.js +168 -56
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2417,23 +2417,58 @@ var SymbolResolver = class {
|
|
|
2417
2417
|
}
|
|
2418
2418
|
/**
|
|
2419
2419
|
* Returns a simple literal value (string/number/boolean/null) for a `const` declarator,
|
|
2420
|
-
*
|
|
2420
|
+
* following imports and re-exports when the name is not declared locally.
|
|
2421
2421
|
*/
|
|
2422
2422
|
resolveLiteral(filePath, name) {
|
|
2423
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2424
|
+
return this.resolveLiteralInternal(filePath, name, visited);
|
|
2425
|
+
}
|
|
2426
|
+
resolveLiteralInternal(filePath, name, visited) {
|
|
2427
|
+
if (visited.has(filePath))
|
|
2428
|
+
return void 0;
|
|
2429
|
+
visited.add(filePath);
|
|
2423
2430
|
const index = this.getIndex(filePath);
|
|
2424
2431
|
if (!index)
|
|
2425
2432
|
return void 0;
|
|
2426
2433
|
const literal2 = index.constLiterals.get(name);
|
|
2427
|
-
if (
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2434
|
+
if (literal2) {
|
|
2435
|
+
if (t3.isStringLiteral(literal2))
|
|
2436
|
+
return literal2.value;
|
|
2437
|
+
if (t3.isNumericLiteral(literal2))
|
|
2438
|
+
return literal2.value;
|
|
2439
|
+
if (t3.isBooleanLiteral(literal2))
|
|
2440
|
+
return literal2.value;
|
|
2441
|
+
if (t3.isNullLiteral(literal2))
|
|
2442
|
+
return null;
|
|
2443
|
+
}
|
|
2444
|
+
const imports = this.getImports(filePath);
|
|
2445
|
+
const importInfo = imports?.get(name);
|
|
2446
|
+
if (importInfo) {
|
|
2447
|
+
const resolved = this.resolveImportPath(filePath, importInfo.source);
|
|
2448
|
+
if (resolved) {
|
|
2449
|
+
const targetName = importInfo.importedName === "default" ? name : importInfo.importedName;
|
|
2450
|
+
const result = this.resolveLiteralInternal(resolved, targetName, visited);
|
|
2451
|
+
if (result !== void 0)
|
|
2452
|
+
return result;
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
const reExport = index.namedReExports.get(name);
|
|
2456
|
+
if (reExport) {
|
|
2457
|
+
const resolved = this.resolveImportPath(filePath, reExport.source);
|
|
2458
|
+
if (resolved) {
|
|
2459
|
+
const result = this.resolveLiteralInternal(resolved, reExport.importedName, visited);
|
|
2460
|
+
if (result !== void 0)
|
|
2461
|
+
return result;
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
for (const starSrc of index.exportsStar) {
|
|
2465
|
+
const resolved = this.resolveImportPath(filePath, starSrc);
|
|
2466
|
+
if (!resolved)
|
|
2467
|
+
continue;
|
|
2468
|
+
const result = this.resolveLiteralInternal(resolved, name, visited);
|
|
2469
|
+
if (result !== void 0)
|
|
2470
|
+
return result;
|
|
2471
|
+
}
|
|
2437
2472
|
return void 0;
|
|
2438
2473
|
}
|
|
2439
2474
|
/**
|
|
@@ -12756,6 +12791,58 @@ var ZodSchemaConverter = class {
|
|
|
12756
12791
|
this.symbolResolver.primeAST(this.currentFilePath, this.currentAST);
|
|
12757
12792
|
return this.symbolResolver.resolveLiteral(this.currentFilePath, name);
|
|
12758
12793
|
}
|
|
12794
|
+
/**
|
|
12795
|
+
* Unwrap a possible `TSAsExpression` / `TSSatisfiesExpression` to get the
|
|
12796
|
+
* underlying expression node. Returns the node itself when no wrapper is
|
|
12797
|
+
* present.
|
|
12798
|
+
*/
|
|
12799
|
+
unwrapTypeAssertion(node) {
|
|
12800
|
+
if (!node)
|
|
12801
|
+
return void 0;
|
|
12802
|
+
if (t10.isTSAsExpression(node) || t10.isTSSatisfiesExpression(node)) {
|
|
12803
|
+
return node.expression;
|
|
12804
|
+
}
|
|
12805
|
+
return node;
|
|
12806
|
+
}
|
|
12807
|
+
/**
|
|
12808
|
+
* Resolve a numeric value from a call-expression argument.
|
|
12809
|
+
* Handles: numeric literals, identifier references to const numbers,
|
|
12810
|
+
* and `x as number` / `x satisfies number` wrappers around either.
|
|
12811
|
+
*/
|
|
12812
|
+
resolveNumericArg(arg) {
|
|
12813
|
+
if (!arg)
|
|
12814
|
+
return void 0;
|
|
12815
|
+
const node = this.unwrapTypeAssertion(arg);
|
|
12816
|
+
if (t10.isNumericLiteral(node))
|
|
12817
|
+
return node.value;
|
|
12818
|
+
if (t10.isUnaryExpression(node) && node.operator === "-" && t10.isNumericLiteral(node.argument)) {
|
|
12819
|
+
return -node.argument.value;
|
|
12820
|
+
}
|
|
12821
|
+
if (t10.isIdentifier(node)) {
|
|
12822
|
+
const val = this.resolveLiteralValue(node.name);
|
|
12823
|
+
if (typeof val === "number")
|
|
12824
|
+
return val;
|
|
12825
|
+
}
|
|
12826
|
+
return void 0;
|
|
12827
|
+
}
|
|
12828
|
+
/**
|
|
12829
|
+
* Resolve a string value from a call-expression argument.
|
|
12830
|
+
* Handles: string literals, identifier references to const strings,
|
|
12831
|
+
* and `x as string` / `x satisfies string` wrappers around either.
|
|
12832
|
+
*/
|
|
12833
|
+
resolveStringArg(arg) {
|
|
12834
|
+
if (!arg)
|
|
12835
|
+
return void 0;
|
|
12836
|
+
const node = this.unwrapTypeAssertion(arg);
|
|
12837
|
+
if (t10.isStringLiteral(node))
|
|
12838
|
+
return node.value;
|
|
12839
|
+
if (t10.isIdentifier(node)) {
|
|
12840
|
+
const val = this.resolveLiteralValue(node.name);
|
|
12841
|
+
if (typeof val === "string")
|
|
12842
|
+
return val;
|
|
12843
|
+
}
|
|
12844
|
+
return void 0;
|
|
12845
|
+
}
|
|
12759
12846
|
/**
|
|
12760
12847
|
* Resolve an identifier referring to a `z.object({...})` (or similar) call expression.
|
|
12761
12848
|
* This lets callers inline the referenced object's shape.
|
|
@@ -12824,6 +12911,14 @@ var ZodSchemaConverter = class {
|
|
|
12824
12911
|
if (t10.isNullLiteral(node)) {
|
|
12825
12912
|
return null;
|
|
12826
12913
|
}
|
|
12914
|
+
if (t10.isIdentifier(node)) {
|
|
12915
|
+
const val = this.resolveLiteralValue(node.name);
|
|
12916
|
+
if (val !== void 0)
|
|
12917
|
+
return val;
|
|
12918
|
+
}
|
|
12919
|
+
if (t10.isTSAsExpression(node) || t10.isTSSatisfiesExpression(node)) {
|
|
12920
|
+
return this.extractStaticJsonValue(node.expression);
|
|
12921
|
+
}
|
|
12827
12922
|
if (t10.isArrayExpression(node)) {
|
|
12828
12923
|
const values = [];
|
|
12829
12924
|
for (const element of node.elements) {
|
|
@@ -12886,7 +12981,7 @@ var ZodSchemaConverter = class {
|
|
|
12886
12981
|
return helperName.startsWith("coerce.") || helperName === "templateLiteral" || helperName === "stringbool";
|
|
12887
12982
|
}
|
|
12888
12983
|
if (t10.isMemberExpression(node.callee) && t10.isIdentifier(node.callee.property)) {
|
|
12889
|
-
const runtimeMethods = /* @__PURE__ */ new Set(["pipe"
|
|
12984
|
+
const runtimeMethods = /* @__PURE__ */ new Set(["pipe"]);
|
|
12890
12985
|
if (runtimeMethods.has(node.callee.property.name)) {
|
|
12891
12986
|
return true;
|
|
12892
12987
|
}
|
|
@@ -12922,53 +13017,60 @@ var ZodSchemaConverter = class {
|
|
|
12922
13017
|
schema.nullable = true;
|
|
12923
13018
|
}
|
|
12924
13019
|
break;
|
|
12925
|
-
case "describe":
|
|
12926
|
-
|
|
12927
|
-
|
|
12928
|
-
if (
|
|
13020
|
+
case "describe": {
|
|
13021
|
+
const descVal = this.resolveStringArg(node.arguments[0]);
|
|
13022
|
+
if (descVal !== void 0) {
|
|
13023
|
+
if (descVal.startsWith("@deprecated")) {
|
|
12929
13024
|
schema.deprecated = true;
|
|
12930
|
-
schema.description =
|
|
13025
|
+
schema.description = descVal.replace("@deprecated", "").trim();
|
|
12931
13026
|
} else {
|
|
12932
|
-
schema.description =
|
|
13027
|
+
schema.description = descVal;
|
|
12933
13028
|
}
|
|
12934
13029
|
}
|
|
12935
13030
|
break;
|
|
13031
|
+
}
|
|
12936
13032
|
case "deprecated":
|
|
12937
13033
|
schema.deprecated = true;
|
|
12938
13034
|
break;
|
|
12939
|
-
case "min":
|
|
12940
|
-
|
|
13035
|
+
case "min": {
|
|
13036
|
+
const minVal = this.resolveNumericArg(node.arguments[0]);
|
|
13037
|
+
if (minVal !== void 0) {
|
|
12941
13038
|
if (schema.type === "string") {
|
|
12942
|
-
schema.minLength =
|
|
13039
|
+
schema.minLength = minVal;
|
|
12943
13040
|
} else if (schema.type === "number" || schema.type === "integer") {
|
|
12944
|
-
schema.minimum =
|
|
13041
|
+
schema.minimum = minVal;
|
|
12945
13042
|
} else if (schema.type === "array") {
|
|
12946
|
-
schema.minItems =
|
|
13043
|
+
schema.minItems = minVal;
|
|
12947
13044
|
}
|
|
12948
13045
|
}
|
|
12949
13046
|
break;
|
|
12950
|
-
|
|
12951
|
-
|
|
13047
|
+
}
|
|
13048
|
+
case "max": {
|
|
13049
|
+
const maxVal = this.resolveNumericArg(node.arguments[0]);
|
|
13050
|
+
if (maxVal !== void 0) {
|
|
12952
13051
|
if (schema.type === "string") {
|
|
12953
|
-
schema.maxLength =
|
|
13052
|
+
schema.maxLength = maxVal;
|
|
12954
13053
|
} else if (schema.type === "number" || schema.type === "integer") {
|
|
12955
|
-
schema.maximum =
|
|
13054
|
+
schema.maximum = maxVal;
|
|
12956
13055
|
} else if (schema.type === "array") {
|
|
12957
|
-
schema.maxItems =
|
|
13056
|
+
schema.maxItems = maxVal;
|
|
12958
13057
|
}
|
|
12959
13058
|
}
|
|
12960
13059
|
break;
|
|
12961
|
-
|
|
12962
|
-
|
|
13060
|
+
}
|
|
13061
|
+
case "length": {
|
|
13062
|
+
const lenVal = this.resolveNumericArg(node.arguments[0]);
|
|
13063
|
+
if (lenVal !== void 0) {
|
|
12963
13064
|
if (schema.type === "string") {
|
|
12964
|
-
schema.minLength =
|
|
12965
|
-
schema.maxLength =
|
|
13065
|
+
schema.minLength = lenVal;
|
|
13066
|
+
schema.maxLength = lenVal;
|
|
12966
13067
|
} else if (schema.type === "array") {
|
|
12967
|
-
schema.minItems =
|
|
12968
|
-
schema.maxItems =
|
|
13068
|
+
schema.minItems = lenVal;
|
|
13069
|
+
schema.maxItems = lenVal;
|
|
12969
13070
|
}
|
|
12970
13071
|
}
|
|
12971
13072
|
break;
|
|
13073
|
+
}
|
|
12972
13074
|
case "nonempty":
|
|
12973
13075
|
if (schema.type === "array") {
|
|
12974
13076
|
schema.minItems = Math.max(schema.minItems ?? 0, 1);
|
|
@@ -13044,34 +13146,38 @@ var ZodSchemaConverter = class {
|
|
|
13044
13146
|
schema.pattern = node.arguments[0].pattern;
|
|
13045
13147
|
}
|
|
13046
13148
|
break;
|
|
13047
|
-
case "startsWith":
|
|
13048
|
-
|
|
13049
|
-
|
|
13149
|
+
case "startsWith": {
|
|
13150
|
+
const swVal = this.resolveStringArg(node.arguments[0]);
|
|
13151
|
+
if (swVal !== void 0) {
|
|
13152
|
+
schema.pattern = `^${this.escapeRegExp(swVal)}`;
|
|
13050
13153
|
}
|
|
13051
13154
|
break;
|
|
13052
|
-
|
|
13053
|
-
|
|
13054
|
-
|
|
13155
|
+
}
|
|
13156
|
+
case "endsWith": {
|
|
13157
|
+
const ewVal = this.resolveStringArg(node.arguments[0]);
|
|
13158
|
+
if (ewVal !== void 0) {
|
|
13159
|
+
schema.pattern = `${this.escapeRegExp(ewVal)}$`;
|
|
13055
13160
|
}
|
|
13056
13161
|
break;
|
|
13057
|
-
|
|
13058
|
-
|
|
13059
|
-
|
|
13162
|
+
}
|
|
13163
|
+
case "includes": {
|
|
13164
|
+
const incVal = this.resolveStringArg(node.arguments[0]);
|
|
13165
|
+
if (incVal !== void 0) {
|
|
13166
|
+
schema.pattern = this.escapeRegExp(incVal);
|
|
13060
13167
|
}
|
|
13061
13168
|
break;
|
|
13169
|
+
}
|
|
13062
13170
|
case "int":
|
|
13063
13171
|
schema.type = "integer";
|
|
13064
13172
|
break;
|
|
13065
13173
|
case "positive":
|
|
13066
|
-
schema.
|
|
13067
|
-
schema.exclusiveMinimum = true;
|
|
13174
|
+
schema.exclusiveMinimum = 0;
|
|
13068
13175
|
break;
|
|
13069
13176
|
case "nonnegative":
|
|
13070
13177
|
schema.minimum = 0;
|
|
13071
13178
|
break;
|
|
13072
13179
|
case "negative":
|
|
13073
|
-
schema.
|
|
13074
|
-
schema.exclusiveMaximum = true;
|
|
13180
|
+
schema.exclusiveMaximum = 0;
|
|
13075
13181
|
break;
|
|
13076
13182
|
case "nonpositive":
|
|
13077
13183
|
schema.maximum = 0;
|
|
@@ -13084,17 +13190,22 @@ var ZodSchemaConverter = class {
|
|
|
13084
13190
|
break;
|
|
13085
13191
|
case "default":
|
|
13086
13192
|
if (node.arguments.length > 0) {
|
|
13087
|
-
|
|
13088
|
-
|
|
13089
|
-
|
|
13090
|
-
|
|
13091
|
-
|
|
13092
|
-
|
|
13093
|
-
|
|
13193
|
+
const defaultArg = this.unwrapTypeAssertion(node.arguments[0]);
|
|
13194
|
+
if (t10.isStringLiteral(defaultArg)) {
|
|
13195
|
+
schema.default = defaultArg.value;
|
|
13196
|
+
} else if (t10.isNumericLiteral(defaultArg)) {
|
|
13197
|
+
schema.default = defaultArg.value;
|
|
13198
|
+
} else if (t10.isBooleanLiteral(defaultArg)) {
|
|
13199
|
+
schema.default = defaultArg.value;
|
|
13200
|
+
} else if (t10.isNullLiteral(defaultArg)) {
|
|
13094
13201
|
schema.default = null;
|
|
13095
|
-
} else if (t10.
|
|
13202
|
+
} else if (t10.isIdentifier(defaultArg)) {
|
|
13203
|
+
const val = this.resolveLiteralValue(defaultArg.name);
|
|
13204
|
+
if (val !== void 0)
|
|
13205
|
+
schema.default = val;
|
|
13206
|
+
} else if (t10.isObjectExpression(defaultArg)) {
|
|
13096
13207
|
const defaultObj = {};
|
|
13097
|
-
|
|
13208
|
+
defaultArg.properties.forEach((prop) => {
|
|
13098
13209
|
if (t10.isObjectProperty(prop) && (t10.isIdentifier(prop.key) || t10.isStringLiteral(prop.key)) && (t10.isStringLiteral(prop.value) || t10.isNumericLiteral(prop.value) || t10.isBooleanLiteral(prop.value))) {
|
|
13099
13210
|
const key = t10.isIdentifier(prop.key) ? prop.key.name : prop.key.value;
|
|
13100
13211
|
const value = t10.isStringLiteral(prop.value) ? prop.value.value : t10.isNumericLiteral(prop.value) ? prop.value.value : t10.isBooleanLiteral(prop.value) ? prop.value.value : null;
|
|
@@ -16927,6 +17038,7 @@ function applyExcludeSchemas(document, mergedSchemas, excludedSchemas) {
|
|
|
16927
17038
|
if (excludedNames.size === 0)
|
|
16928
17039
|
return;
|
|
16929
17040
|
walkAndInline(document, excludedSchemas, excludedNames, /* @__PURE__ */ new Set());
|
|
17041
|
+
walkAndInline(mergedSchemas, excludedSchemas, excludedNames, /* @__PURE__ */ new Set());
|
|
16930
17042
|
for (const name of excludedNames) {
|
|
16931
17043
|
delete mergedSchemas[name];
|
|
16932
17044
|
}
|
|
@@ -17859,96 +17971,100 @@ function typeToOpenApiSchema(type, checker, seen) {
|
|
|
17859
17971
|
return { type: "object" };
|
|
17860
17972
|
}
|
|
17861
17973
|
seen.add(seenKey);
|
|
17862
|
-
|
|
17863
|
-
|
|
17864
|
-
|
|
17865
|
-
|
|
17866
|
-
|
|
17867
|
-
|
|
17868
|
-
|
|
17869
|
-
|
|
17870
|
-
type: "boolean",
|
|
17871
|
-
enum: [checker.typeToString(type) === "true"]
|
|
17872
|
-
};
|
|
17873
|
-
}
|
|
17874
|
-
if (type.flags & ts3.TypeFlags.TemplateLiteral) {
|
|
17875
|
-
return { type: "string" };
|
|
17876
|
-
}
|
|
17877
|
-
if (type.flags & ts3.TypeFlags.StringLike) {
|
|
17878
|
-
return { type: "string" };
|
|
17879
|
-
}
|
|
17880
|
-
if (type.flags & ts3.TypeFlags.NumberLike) {
|
|
17881
|
-
return { type: "number" };
|
|
17882
|
-
}
|
|
17883
|
-
if (type.flags & ts3.TypeFlags.BooleanLike) {
|
|
17884
|
-
return { type: "boolean" };
|
|
17885
|
-
}
|
|
17886
|
-
if (type.flags & ts3.TypeFlags.Null) {
|
|
17887
|
-
return { type: "null" };
|
|
17888
|
-
}
|
|
17889
|
-
if (type.isUnion()) {
|
|
17890
|
-
const nullable2 = type.types.some((member) => member.flags & ts3.TypeFlags.Null);
|
|
17891
|
-
const nonNullTypes = type.types.filter((member) => !(member.flags & ts3.TypeFlags.Null));
|
|
17892
|
-
const soleNonNullType = nonNullTypes[0];
|
|
17893
|
-
if (nullable2 && soleNonNullType && nonNullTypes.length === 1) {
|
|
17974
|
+
try {
|
|
17975
|
+
if (type.isStringLiteral()) {
|
|
17976
|
+
return { type: "string", enum: [type.value] };
|
|
17977
|
+
}
|
|
17978
|
+
if (type.isNumberLiteral()) {
|
|
17979
|
+
return { type: "number", enum: [type.value] };
|
|
17980
|
+
}
|
|
17981
|
+
if (type.flags & ts3.TypeFlags.BooleanLiteral) {
|
|
17894
17982
|
return {
|
|
17895
|
-
|
|
17896
|
-
|
|
17983
|
+
type: "boolean",
|
|
17984
|
+
enum: [checker.typeToString(type) === "true"]
|
|
17897
17985
|
};
|
|
17898
17986
|
}
|
|
17899
|
-
|
|
17900
|
-
|
|
17901
|
-
}
|
|
17902
|
-
|
|
17903
|
-
|
|
17904
|
-
|
|
17905
|
-
|
|
17906
|
-
type: "
|
|
17907
|
-
|
|
17908
|
-
|
|
17909
|
-
|
|
17910
|
-
|
|
17911
|
-
|
|
17912
|
-
|
|
17913
|
-
|
|
17914
|
-
|
|
17915
|
-
|
|
17916
|
-
type
|
|
17917
|
-
|
|
17918
|
-
|
|
17919
|
-
|
|
17920
|
-
|
|
17921
|
-
|
|
17922
|
-
|
|
17923
|
-
const required2 = [];
|
|
17924
|
-
properties.forEach((property) => {
|
|
17925
|
-
const propertyDeclaration = property.valueDeclaration || property.declarations?.[0];
|
|
17926
|
-
if (!propertyDeclaration) {
|
|
17927
|
-
return;
|
|
17928
|
-
}
|
|
17929
|
-
const propertyType = checker.getTypeOfSymbolAtLocation(property, propertyDeclaration);
|
|
17930
|
-
schemaProperties[property.getName()] = typeToOpenApiSchema(propertyType, checker, seen);
|
|
17931
|
-
if (!(property.flags & ts3.SymbolFlags.Optional)) {
|
|
17932
|
-
required2.push(property.getName());
|
|
17987
|
+
if (type.flags & ts3.TypeFlags.TemplateLiteral) {
|
|
17988
|
+
return { type: "string" };
|
|
17989
|
+
}
|
|
17990
|
+
if (type.flags & ts3.TypeFlags.StringLike) {
|
|
17991
|
+
return { type: "string" };
|
|
17992
|
+
}
|
|
17993
|
+
if (type.flags & ts3.TypeFlags.NumberLike) {
|
|
17994
|
+
return { type: "number" };
|
|
17995
|
+
}
|
|
17996
|
+
if (type.flags & ts3.TypeFlags.BooleanLike) {
|
|
17997
|
+
return { type: "boolean" };
|
|
17998
|
+
}
|
|
17999
|
+
if (type.flags & ts3.TypeFlags.Null) {
|
|
18000
|
+
return { type: "null" };
|
|
18001
|
+
}
|
|
18002
|
+
if (type.isUnion()) {
|
|
18003
|
+
const nullable2 = type.types.some((member) => member.flags & ts3.TypeFlags.Null);
|
|
18004
|
+
const nonNullTypes = type.types.filter((member) => !(member.flags & ts3.TypeFlags.Null));
|
|
18005
|
+
const soleNonNullType = nonNullTypes[0];
|
|
18006
|
+
if (nullable2 && soleNonNullType && nonNullTypes.length === 1) {
|
|
18007
|
+
return {
|
|
18008
|
+
...typeToOpenApiSchema(soleNonNullType, checker, seen),
|
|
18009
|
+
nullable: true
|
|
18010
|
+
};
|
|
17933
18011
|
}
|
|
17934
|
-
|
|
17935
|
-
|
|
17936
|
-
|
|
17937
|
-
|
|
17938
|
-
|
|
17939
|
-
|
|
17940
|
-
|
|
17941
|
-
|
|
17942
|
-
|
|
17943
|
-
|
|
17944
|
-
|
|
17945
|
-
|
|
17946
|
-
|
|
17947
|
-
|
|
17948
|
-
|
|
17949
|
-
|
|
18012
|
+
return {
|
|
18013
|
+
oneOf: nonNullTypes.map((member) => typeToOpenApiSchema(member, checker, seen))
|
|
18014
|
+
};
|
|
18015
|
+
}
|
|
18016
|
+
if (checker.isTupleType(type)) {
|
|
18017
|
+
const itemTypes = checker.getTypeArguments(type);
|
|
18018
|
+
return {
|
|
18019
|
+
type: "array",
|
|
18020
|
+
prefixItems: itemTypes.map((itemType) => typeToOpenApiSchema(itemType, checker, seen)),
|
|
18021
|
+
items: false,
|
|
18022
|
+
minItems: itemTypes.length,
|
|
18023
|
+
maxItems: itemTypes.length
|
|
18024
|
+
};
|
|
18025
|
+
}
|
|
18026
|
+
if (checker.isArrayType(type)) {
|
|
18027
|
+
const elementType = checker.getTypeArguments(type)[0];
|
|
18028
|
+
return {
|
|
18029
|
+
type: "array",
|
|
18030
|
+
items: elementType ? typeToOpenApiSchema(elementType, checker, seen) : { type: "object" }
|
|
18031
|
+
};
|
|
18032
|
+
}
|
|
18033
|
+
const properties = checker.getPropertiesOfType(type);
|
|
18034
|
+
if (properties.length > 0) {
|
|
18035
|
+
const schemaProperties = {};
|
|
18036
|
+
const required2 = [];
|
|
18037
|
+
properties.forEach((property) => {
|
|
18038
|
+
const propertyDeclaration = property.valueDeclaration || property.declarations?.[0];
|
|
18039
|
+
if (!propertyDeclaration) {
|
|
18040
|
+
return;
|
|
18041
|
+
}
|
|
18042
|
+
const propertyType = checker.getTypeOfSymbolAtLocation(property, propertyDeclaration);
|
|
18043
|
+
schemaProperties[property.getName()] = typeToOpenApiSchema(propertyType, checker, seen);
|
|
18044
|
+
if (!(property.flags & ts3.SymbolFlags.Optional)) {
|
|
18045
|
+
required2.push(property.getName());
|
|
18046
|
+
}
|
|
18047
|
+
});
|
|
18048
|
+
return required2.length > 0 ? {
|
|
18049
|
+
type: "object",
|
|
18050
|
+
properties: schemaProperties,
|
|
18051
|
+
required: required2
|
|
18052
|
+
} : {
|
|
18053
|
+
type: "object",
|
|
18054
|
+
properties: schemaProperties
|
|
18055
|
+
};
|
|
18056
|
+
}
|
|
18057
|
+
const stringIndexType = type.getStringIndexType();
|
|
18058
|
+
if (stringIndexType) {
|
|
18059
|
+
return {
|
|
18060
|
+
type: "object",
|
|
18061
|
+
additionalProperties: typeToOpenApiSchema(stringIndexType, checker, seen)
|
|
18062
|
+
};
|
|
18063
|
+
}
|
|
18064
|
+
return { type: "object" };
|
|
18065
|
+
} finally {
|
|
18066
|
+
seen.delete(seenKey);
|
|
17950
18067
|
}
|
|
17951
|
-
return { type: "object" };
|
|
17952
18068
|
}
|
|
17953
18069
|
function unwrapPromiseType(type, checker) {
|
|
17954
18070
|
const symbolName = type.getSymbol()?.getName();
|