next-openapi-gen 1.0.5 → 1.0.7
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 +97 -2
- package/dist/index.js +97 -2
- package/dist/next/index.js +97 -2
- package/dist/react-router/index.js +94 -1
- package/dist/vite/index.js +94 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3311,6 +3311,7 @@ function processZodPrimitiveNode(node, context) {
|
|
|
3311
3311
|
schema = { type: "array", items: itemsType };
|
|
3312
3312
|
break;
|
|
3313
3313
|
}
|
|
3314
|
+
case "nativeEnum":
|
|
3314
3315
|
case "enum":
|
|
3315
3316
|
if (node.arguments.length > 0 && t6.isArrayExpression(node.arguments[0])) {
|
|
3316
3317
|
const enumValues = node.arguments[0].elements.filter((el) => t6.isStringLiteral(el) || t6.isNumericLiteral(el)).map((el) => el.value);
|
|
@@ -3331,6 +3332,14 @@ function processZodPrimitiveNode(node, context) {
|
|
|
3331
3332
|
type: "string",
|
|
3332
3333
|
enum: enumValues
|
|
3333
3334
|
} : { type: "string" };
|
|
3335
|
+
} else if (node.arguments.length > 0 && t6.isIdentifier(node.arguments[0]) && context.resolveEnumValues) {
|
|
3336
|
+
const resolved = context.resolveEnumValues(node.arguments[0].name);
|
|
3337
|
+
if (resolved && resolved.length > 0) {
|
|
3338
|
+
const valueType = typeof resolved[0] === "number" ? "number" : "string";
|
|
3339
|
+
schema = { type: valueType, enum: resolved };
|
|
3340
|
+
} else {
|
|
3341
|
+
schema = { type: "string" };
|
|
3342
|
+
}
|
|
3334
3343
|
} else {
|
|
3335
3344
|
schema = { type: "string" };
|
|
3336
3345
|
}
|
|
@@ -11622,9 +11631,93 @@ var ZodSchemaConverter = class {
|
|
|
11622
11631
|
},
|
|
11623
11632
|
getReferenceSchema: (schemaName) => ({
|
|
11624
11633
|
$ref: `#/components/schemas/${this.getSchemaReferenceName(schemaName)}`
|
|
11625
|
-
})
|
|
11634
|
+
}),
|
|
11635
|
+
resolveEnumValues: (name) => this.resolveEnumValues(name)
|
|
11626
11636
|
});
|
|
11627
11637
|
}
|
|
11638
|
+
/**
|
|
11639
|
+
* Resolve enum values from a TS enum declaration or an `as const` object by identifier name.
|
|
11640
|
+
* Searches the current file first, then follows imports.
|
|
11641
|
+
*/
|
|
11642
|
+
resolveEnumValues(name) {
|
|
11643
|
+
const extractFromAST = (ast) => {
|
|
11644
|
+
let result = null;
|
|
11645
|
+
resolvedTraverse(ast, {
|
|
11646
|
+
TSEnumDeclaration: (nodePath) => {
|
|
11647
|
+
if (result)
|
|
11648
|
+
return;
|
|
11649
|
+
if (nodePath.node.id && t8.isIdentifier(nodePath.node.id, { name })) {
|
|
11650
|
+
const values = [];
|
|
11651
|
+
for (const member of nodePath.node.members) {
|
|
11652
|
+
if (t8.isTSEnumMember(member) && member.initializer) {
|
|
11653
|
+
if (t8.isStringLiteral(member.initializer)) {
|
|
11654
|
+
values.push(member.initializer.value);
|
|
11655
|
+
} else if (t8.isNumericLiteral(member.initializer)) {
|
|
11656
|
+
values.push(member.initializer.value);
|
|
11657
|
+
}
|
|
11658
|
+
}
|
|
11659
|
+
}
|
|
11660
|
+
if (values.length > 0) {
|
|
11661
|
+
result = values;
|
|
11662
|
+
}
|
|
11663
|
+
}
|
|
11664
|
+
},
|
|
11665
|
+
VariableDeclarator: (nodePath) => {
|
|
11666
|
+
if (result)
|
|
11667
|
+
return;
|
|
11668
|
+
if (!t8.isIdentifier(nodePath.node.id, { name }) || !nodePath.node.init)
|
|
11669
|
+
return;
|
|
11670
|
+
let initNode = nodePath.node.init;
|
|
11671
|
+
if (t8.isTSAsExpression(initNode) || t8.isTSSatisfiesExpression(initNode)) {
|
|
11672
|
+
initNode = initNode.expression;
|
|
11673
|
+
}
|
|
11674
|
+
if (t8.isObjectExpression(initNode)) {
|
|
11675
|
+
const values = [];
|
|
11676
|
+
for (const prop of initNode.properties) {
|
|
11677
|
+
if (t8.isObjectProperty(prop)) {
|
|
11678
|
+
if (t8.isStringLiteral(prop.value)) {
|
|
11679
|
+
values.push(prop.value.value);
|
|
11680
|
+
} else if (t8.isNumericLiteral(prop.value)) {
|
|
11681
|
+
values.push(prop.value.value);
|
|
11682
|
+
}
|
|
11683
|
+
}
|
|
11684
|
+
}
|
|
11685
|
+
if (values.length > 0) {
|
|
11686
|
+
result = values;
|
|
11687
|
+
}
|
|
11688
|
+
} else if (t8.isArrayExpression(initNode)) {
|
|
11689
|
+
const values = [];
|
|
11690
|
+
for (const element of initNode.elements) {
|
|
11691
|
+
if (t8.isStringLiteral(element)) {
|
|
11692
|
+
values.push(element.value);
|
|
11693
|
+
} else if (t8.isNumericLiteral(element)) {
|
|
11694
|
+
values.push(element.value);
|
|
11695
|
+
}
|
|
11696
|
+
}
|
|
11697
|
+
if (values.length > 0) {
|
|
11698
|
+
result = values;
|
|
11699
|
+
}
|
|
11700
|
+
}
|
|
11701
|
+
}
|
|
11702
|
+
});
|
|
11703
|
+
return result;
|
|
11704
|
+
};
|
|
11705
|
+
if (this.currentAST) {
|
|
11706
|
+
const values = extractFromAST(this.currentAST);
|
|
11707
|
+
if (values)
|
|
11708
|
+
return values;
|
|
11709
|
+
}
|
|
11710
|
+
if (this.currentImports && this.currentFilePath && this.currentImports[name]) {
|
|
11711
|
+
const resolvedPath = this.resolveImportPath(this.currentFilePath, this.currentImports[name]);
|
|
11712
|
+
if (resolvedPath) {
|
|
11713
|
+
const importedAST = this.parseFileWithCache(resolvedPath);
|
|
11714
|
+
if (importedAST) {
|
|
11715
|
+
return extractFromAST(importedAST);
|
|
11716
|
+
}
|
|
11717
|
+
}
|
|
11718
|
+
}
|
|
11719
|
+
return null;
|
|
11720
|
+
}
|
|
11628
11721
|
/**
|
|
11629
11722
|
* Extract description from method arguments if it's a .describe() call
|
|
11630
11723
|
*/
|
|
@@ -16269,12 +16362,14 @@ var NextFrameworkSource = class {
|
|
|
16269
16362
|
}
|
|
16270
16363
|
getScanRoots() {
|
|
16271
16364
|
const roots = [this.config.apiDir];
|
|
16365
|
+
const resolvedApiDir = path22.resolve(this.config.apiDir);
|
|
16272
16366
|
const candidateRoots = [
|
|
16273
16367
|
path22.join(process.cwd(), "src", "app", "api"),
|
|
16274
16368
|
path22.join(process.cwd(), "app", "api")
|
|
16275
16369
|
];
|
|
16276
16370
|
candidateRoots.forEach((candidateRoot) => {
|
|
16277
|
-
|
|
16371
|
+
const resolvedCandidate = path22.resolve(candidateRoot);
|
|
16372
|
+
if (fs17.existsSync(candidateRoot) && resolvedCandidate !== resolvedApiDir && !resolvedApiDir.startsWith(resolvedCandidate + path22.sep) && !roots.includes(candidateRoot)) {
|
|
16278
16373
|
roots.push(candidateRoot);
|
|
16279
16374
|
}
|
|
16280
16375
|
});
|
package/dist/index.js
CHANGED
|
@@ -2860,6 +2860,7 @@ function processZodPrimitiveNode(node, context) {
|
|
|
2860
2860
|
schema = { type: "array", items: itemsType };
|
|
2861
2861
|
break;
|
|
2862
2862
|
}
|
|
2863
|
+
case "nativeEnum":
|
|
2863
2864
|
case "enum":
|
|
2864
2865
|
if (node.arguments.length > 0 && t6.isArrayExpression(node.arguments[0])) {
|
|
2865
2866
|
const enumValues = node.arguments[0].elements.filter((el) => t6.isStringLiteral(el) || t6.isNumericLiteral(el)).map((el) => el.value);
|
|
@@ -2880,6 +2881,14 @@ function processZodPrimitiveNode(node, context) {
|
|
|
2880
2881
|
type: "string",
|
|
2881
2882
|
enum: enumValues
|
|
2882
2883
|
} : { type: "string" };
|
|
2884
|
+
} else if (node.arguments.length > 0 && t6.isIdentifier(node.arguments[0]) && context.resolveEnumValues) {
|
|
2885
|
+
const resolved = context.resolveEnumValues(node.arguments[0].name);
|
|
2886
|
+
if (resolved && resolved.length > 0) {
|
|
2887
|
+
const valueType = typeof resolved[0] === "number" ? "number" : "string";
|
|
2888
|
+
schema = { type: valueType, enum: resolved };
|
|
2889
|
+
} else {
|
|
2890
|
+
schema = { type: "string" };
|
|
2891
|
+
}
|
|
2883
2892
|
} else {
|
|
2884
2893
|
schema = { type: "string" };
|
|
2885
2894
|
}
|
|
@@ -11171,9 +11180,93 @@ var ZodSchemaConverter = class {
|
|
|
11171
11180
|
},
|
|
11172
11181
|
getReferenceSchema: (schemaName) => ({
|
|
11173
11182
|
$ref: `#/components/schemas/${this.getSchemaReferenceName(schemaName)}`
|
|
11174
|
-
})
|
|
11183
|
+
}),
|
|
11184
|
+
resolveEnumValues: (name) => this.resolveEnumValues(name)
|
|
11175
11185
|
});
|
|
11176
11186
|
}
|
|
11187
|
+
/**
|
|
11188
|
+
* Resolve enum values from a TS enum declaration or an `as const` object by identifier name.
|
|
11189
|
+
* Searches the current file first, then follows imports.
|
|
11190
|
+
*/
|
|
11191
|
+
resolveEnumValues(name) {
|
|
11192
|
+
const extractFromAST = (ast) => {
|
|
11193
|
+
let result = null;
|
|
11194
|
+
resolvedTraverse(ast, {
|
|
11195
|
+
TSEnumDeclaration: (nodePath) => {
|
|
11196
|
+
if (result)
|
|
11197
|
+
return;
|
|
11198
|
+
if (nodePath.node.id && t8.isIdentifier(nodePath.node.id, { name })) {
|
|
11199
|
+
const values = [];
|
|
11200
|
+
for (const member of nodePath.node.members) {
|
|
11201
|
+
if (t8.isTSEnumMember(member) && member.initializer) {
|
|
11202
|
+
if (t8.isStringLiteral(member.initializer)) {
|
|
11203
|
+
values.push(member.initializer.value);
|
|
11204
|
+
} else if (t8.isNumericLiteral(member.initializer)) {
|
|
11205
|
+
values.push(member.initializer.value);
|
|
11206
|
+
}
|
|
11207
|
+
}
|
|
11208
|
+
}
|
|
11209
|
+
if (values.length > 0) {
|
|
11210
|
+
result = values;
|
|
11211
|
+
}
|
|
11212
|
+
}
|
|
11213
|
+
},
|
|
11214
|
+
VariableDeclarator: (nodePath) => {
|
|
11215
|
+
if (result)
|
|
11216
|
+
return;
|
|
11217
|
+
if (!t8.isIdentifier(nodePath.node.id, { name }) || !nodePath.node.init)
|
|
11218
|
+
return;
|
|
11219
|
+
let initNode = nodePath.node.init;
|
|
11220
|
+
if (t8.isTSAsExpression(initNode) || t8.isTSSatisfiesExpression(initNode)) {
|
|
11221
|
+
initNode = initNode.expression;
|
|
11222
|
+
}
|
|
11223
|
+
if (t8.isObjectExpression(initNode)) {
|
|
11224
|
+
const values = [];
|
|
11225
|
+
for (const prop of initNode.properties) {
|
|
11226
|
+
if (t8.isObjectProperty(prop)) {
|
|
11227
|
+
if (t8.isStringLiteral(prop.value)) {
|
|
11228
|
+
values.push(prop.value.value);
|
|
11229
|
+
} else if (t8.isNumericLiteral(prop.value)) {
|
|
11230
|
+
values.push(prop.value.value);
|
|
11231
|
+
}
|
|
11232
|
+
}
|
|
11233
|
+
}
|
|
11234
|
+
if (values.length > 0) {
|
|
11235
|
+
result = values;
|
|
11236
|
+
}
|
|
11237
|
+
} else if (t8.isArrayExpression(initNode)) {
|
|
11238
|
+
const values = [];
|
|
11239
|
+
for (const element of initNode.elements) {
|
|
11240
|
+
if (t8.isStringLiteral(element)) {
|
|
11241
|
+
values.push(element.value);
|
|
11242
|
+
} else if (t8.isNumericLiteral(element)) {
|
|
11243
|
+
values.push(element.value);
|
|
11244
|
+
}
|
|
11245
|
+
}
|
|
11246
|
+
if (values.length > 0) {
|
|
11247
|
+
result = values;
|
|
11248
|
+
}
|
|
11249
|
+
}
|
|
11250
|
+
}
|
|
11251
|
+
});
|
|
11252
|
+
return result;
|
|
11253
|
+
};
|
|
11254
|
+
if (this.currentAST) {
|
|
11255
|
+
const values = extractFromAST(this.currentAST);
|
|
11256
|
+
if (values)
|
|
11257
|
+
return values;
|
|
11258
|
+
}
|
|
11259
|
+
if (this.currentImports && this.currentFilePath && this.currentImports[name]) {
|
|
11260
|
+
const resolvedPath = this.resolveImportPath(this.currentFilePath, this.currentImports[name]);
|
|
11261
|
+
if (resolvedPath) {
|
|
11262
|
+
const importedAST = this.parseFileWithCache(resolvedPath);
|
|
11263
|
+
if (importedAST) {
|
|
11264
|
+
return extractFromAST(importedAST);
|
|
11265
|
+
}
|
|
11266
|
+
}
|
|
11267
|
+
}
|
|
11268
|
+
return null;
|
|
11269
|
+
}
|
|
11177
11270
|
/**
|
|
11178
11271
|
* Extract description from method arguments if it's a .describe() call
|
|
11179
11272
|
*/
|
|
@@ -15971,12 +16064,14 @@ var NextFrameworkSource = class {
|
|
|
15971
16064
|
}
|
|
15972
16065
|
getScanRoots() {
|
|
15973
16066
|
const roots = [this.config.apiDir];
|
|
16067
|
+
const resolvedApiDir = path19.resolve(this.config.apiDir);
|
|
15974
16068
|
const candidateRoots = [
|
|
15975
16069
|
path19.join(process.cwd(), "src", "app", "api"),
|
|
15976
16070
|
path19.join(process.cwd(), "app", "api")
|
|
15977
16071
|
];
|
|
15978
16072
|
candidateRoots.forEach((candidateRoot) => {
|
|
15979
|
-
|
|
16073
|
+
const resolvedCandidate = path19.resolve(candidateRoot);
|
|
16074
|
+
if (fs15.existsSync(candidateRoot) && resolvedCandidate !== resolvedApiDir && !resolvedApiDir.startsWith(resolvedCandidate + path19.sep) && !roots.includes(candidateRoot)) {
|
|
15980
16075
|
roots.push(candidateRoot);
|
|
15981
16076
|
}
|
|
15982
16077
|
});
|
package/dist/next/index.js
CHANGED
|
@@ -1938,12 +1938,14 @@ var NextFrameworkSource = class {
|
|
|
1938
1938
|
}
|
|
1939
1939
|
getScanRoots() {
|
|
1940
1940
|
const roots = [this.config.apiDir];
|
|
1941
|
+
const resolvedApiDir = path5.resolve(this.config.apiDir);
|
|
1941
1942
|
const candidateRoots = [
|
|
1942
1943
|
path5.join(process.cwd(), "src", "app", "api"),
|
|
1943
1944
|
path5.join(process.cwd(), "app", "api")
|
|
1944
1945
|
];
|
|
1945
1946
|
candidateRoots.forEach((candidateRoot) => {
|
|
1946
|
-
|
|
1947
|
+
const resolvedCandidate = path5.resolve(candidateRoot);
|
|
1948
|
+
if (fs5.existsSync(candidateRoot) && resolvedCandidate !== resolvedApiDir && !resolvedApiDir.startsWith(resolvedCandidate + path5.sep) && !roots.includes(candidateRoot)) {
|
|
1947
1949
|
roots.push(candidateRoot);
|
|
1948
1950
|
}
|
|
1949
1951
|
});
|
|
@@ -3892,6 +3894,7 @@ function processZodPrimitiveNode(node, context) {
|
|
|
3892
3894
|
schema = { type: "array", items: itemsType };
|
|
3893
3895
|
break;
|
|
3894
3896
|
}
|
|
3897
|
+
case "nativeEnum":
|
|
3895
3898
|
case "enum":
|
|
3896
3899
|
if (node.arguments.length > 0 && t7.isArrayExpression(node.arguments[0])) {
|
|
3897
3900
|
const enumValues = node.arguments[0].elements.filter((el) => t7.isStringLiteral(el) || t7.isNumericLiteral(el)).map((el) => el.value);
|
|
@@ -3912,6 +3915,14 @@ function processZodPrimitiveNode(node, context) {
|
|
|
3912
3915
|
type: "string",
|
|
3913
3916
|
enum: enumValues
|
|
3914
3917
|
} : { type: "string" };
|
|
3918
|
+
} else if (node.arguments.length > 0 && t7.isIdentifier(node.arguments[0]) && context.resolveEnumValues) {
|
|
3919
|
+
const resolved = context.resolveEnumValues(node.arguments[0].name);
|
|
3920
|
+
if (resolved && resolved.length > 0) {
|
|
3921
|
+
const valueType = typeof resolved[0] === "number" ? "number" : "string";
|
|
3922
|
+
schema = { type: valueType, enum: resolved };
|
|
3923
|
+
} else {
|
|
3924
|
+
schema = { type: "string" };
|
|
3925
|
+
}
|
|
3915
3926
|
} else {
|
|
3916
3927
|
schema = { type: "string" };
|
|
3917
3928
|
}
|
|
@@ -12203,9 +12214,93 @@ var ZodSchemaConverter = class {
|
|
|
12203
12214
|
},
|
|
12204
12215
|
getReferenceSchema: (schemaName) => ({
|
|
12205
12216
|
$ref: `#/components/schemas/${this.getSchemaReferenceName(schemaName)}`
|
|
12206
|
-
})
|
|
12217
|
+
}),
|
|
12218
|
+
resolveEnumValues: (name) => this.resolveEnumValues(name)
|
|
12207
12219
|
});
|
|
12208
12220
|
}
|
|
12221
|
+
/**
|
|
12222
|
+
* Resolve enum values from a TS enum declaration or an `as const` object by identifier name.
|
|
12223
|
+
* Searches the current file first, then follows imports.
|
|
12224
|
+
*/
|
|
12225
|
+
resolveEnumValues(name) {
|
|
12226
|
+
const extractFromAST = (ast) => {
|
|
12227
|
+
let result = null;
|
|
12228
|
+
resolvedTraverse(ast, {
|
|
12229
|
+
TSEnumDeclaration: (nodePath) => {
|
|
12230
|
+
if (result)
|
|
12231
|
+
return;
|
|
12232
|
+
if (nodePath.node.id && t9.isIdentifier(nodePath.node.id, { name })) {
|
|
12233
|
+
const values = [];
|
|
12234
|
+
for (const member of nodePath.node.members) {
|
|
12235
|
+
if (t9.isTSEnumMember(member) && member.initializer) {
|
|
12236
|
+
if (t9.isStringLiteral(member.initializer)) {
|
|
12237
|
+
values.push(member.initializer.value);
|
|
12238
|
+
} else if (t9.isNumericLiteral(member.initializer)) {
|
|
12239
|
+
values.push(member.initializer.value);
|
|
12240
|
+
}
|
|
12241
|
+
}
|
|
12242
|
+
}
|
|
12243
|
+
if (values.length > 0) {
|
|
12244
|
+
result = values;
|
|
12245
|
+
}
|
|
12246
|
+
}
|
|
12247
|
+
},
|
|
12248
|
+
VariableDeclarator: (nodePath) => {
|
|
12249
|
+
if (result)
|
|
12250
|
+
return;
|
|
12251
|
+
if (!t9.isIdentifier(nodePath.node.id, { name }) || !nodePath.node.init)
|
|
12252
|
+
return;
|
|
12253
|
+
let initNode = nodePath.node.init;
|
|
12254
|
+
if (t9.isTSAsExpression(initNode) || t9.isTSSatisfiesExpression(initNode)) {
|
|
12255
|
+
initNode = initNode.expression;
|
|
12256
|
+
}
|
|
12257
|
+
if (t9.isObjectExpression(initNode)) {
|
|
12258
|
+
const values = [];
|
|
12259
|
+
for (const prop of initNode.properties) {
|
|
12260
|
+
if (t9.isObjectProperty(prop)) {
|
|
12261
|
+
if (t9.isStringLiteral(prop.value)) {
|
|
12262
|
+
values.push(prop.value.value);
|
|
12263
|
+
} else if (t9.isNumericLiteral(prop.value)) {
|
|
12264
|
+
values.push(prop.value.value);
|
|
12265
|
+
}
|
|
12266
|
+
}
|
|
12267
|
+
}
|
|
12268
|
+
if (values.length > 0) {
|
|
12269
|
+
result = values;
|
|
12270
|
+
}
|
|
12271
|
+
} else if (t9.isArrayExpression(initNode)) {
|
|
12272
|
+
const values = [];
|
|
12273
|
+
for (const element of initNode.elements) {
|
|
12274
|
+
if (t9.isStringLiteral(element)) {
|
|
12275
|
+
values.push(element.value);
|
|
12276
|
+
} else if (t9.isNumericLiteral(element)) {
|
|
12277
|
+
values.push(element.value);
|
|
12278
|
+
}
|
|
12279
|
+
}
|
|
12280
|
+
if (values.length > 0) {
|
|
12281
|
+
result = values;
|
|
12282
|
+
}
|
|
12283
|
+
}
|
|
12284
|
+
}
|
|
12285
|
+
});
|
|
12286
|
+
return result;
|
|
12287
|
+
};
|
|
12288
|
+
if (this.currentAST) {
|
|
12289
|
+
const values = extractFromAST(this.currentAST);
|
|
12290
|
+
if (values)
|
|
12291
|
+
return values;
|
|
12292
|
+
}
|
|
12293
|
+
if (this.currentImports && this.currentFilePath && this.currentImports[name]) {
|
|
12294
|
+
const resolvedPath = this.resolveImportPath(this.currentFilePath, this.currentImports[name]);
|
|
12295
|
+
if (resolvedPath) {
|
|
12296
|
+
const importedAST = this.parseFileWithCache(resolvedPath);
|
|
12297
|
+
if (importedAST) {
|
|
12298
|
+
return extractFromAST(importedAST);
|
|
12299
|
+
}
|
|
12300
|
+
}
|
|
12301
|
+
}
|
|
12302
|
+
return null;
|
|
12303
|
+
}
|
|
12209
12304
|
/**
|
|
12210
12305
|
* Extract description from method arguments if it's a .describe() call
|
|
12211
12306
|
*/
|
|
@@ -2898,6 +2898,7 @@ function processZodPrimitiveNode(node, context) {
|
|
|
2898
2898
|
schema = { type: "array", items: itemsType };
|
|
2899
2899
|
break;
|
|
2900
2900
|
}
|
|
2901
|
+
case "nativeEnum":
|
|
2901
2902
|
case "enum":
|
|
2902
2903
|
if (node.arguments.length > 0 && t6.isArrayExpression(node.arguments[0])) {
|
|
2903
2904
|
const enumValues = node.arguments[0].elements.filter((el) => t6.isStringLiteral(el) || t6.isNumericLiteral(el)).map((el) => el.value);
|
|
@@ -2918,6 +2919,14 @@ function processZodPrimitiveNode(node, context) {
|
|
|
2918
2919
|
type: "string",
|
|
2919
2920
|
enum: enumValues
|
|
2920
2921
|
} : { type: "string" };
|
|
2922
|
+
} else if (node.arguments.length > 0 && t6.isIdentifier(node.arguments[0]) && context.resolveEnumValues) {
|
|
2923
|
+
const resolved = context.resolveEnumValues(node.arguments[0].name);
|
|
2924
|
+
if (resolved && resolved.length > 0) {
|
|
2925
|
+
const valueType = typeof resolved[0] === "number" ? "number" : "string";
|
|
2926
|
+
schema = { type: valueType, enum: resolved };
|
|
2927
|
+
} else {
|
|
2928
|
+
schema = { type: "string" };
|
|
2929
|
+
}
|
|
2921
2930
|
} else {
|
|
2922
2931
|
schema = { type: "string" };
|
|
2923
2932
|
}
|
|
@@ -11209,9 +11218,93 @@ var ZodSchemaConverter = class {
|
|
|
11209
11218
|
},
|
|
11210
11219
|
getReferenceSchema: (schemaName) => ({
|
|
11211
11220
|
$ref: `#/components/schemas/${this.getSchemaReferenceName(schemaName)}`
|
|
11212
|
-
})
|
|
11221
|
+
}),
|
|
11222
|
+
resolveEnumValues: (name) => this.resolveEnumValues(name)
|
|
11213
11223
|
});
|
|
11214
11224
|
}
|
|
11225
|
+
/**
|
|
11226
|
+
* Resolve enum values from a TS enum declaration or an `as const` object by identifier name.
|
|
11227
|
+
* Searches the current file first, then follows imports.
|
|
11228
|
+
*/
|
|
11229
|
+
resolveEnumValues(name) {
|
|
11230
|
+
const extractFromAST = (ast) => {
|
|
11231
|
+
let result = null;
|
|
11232
|
+
resolvedTraverse(ast, {
|
|
11233
|
+
TSEnumDeclaration: (nodePath) => {
|
|
11234
|
+
if (result)
|
|
11235
|
+
return;
|
|
11236
|
+
if (nodePath.node.id && t8.isIdentifier(nodePath.node.id, { name })) {
|
|
11237
|
+
const values = [];
|
|
11238
|
+
for (const member of nodePath.node.members) {
|
|
11239
|
+
if (t8.isTSEnumMember(member) && member.initializer) {
|
|
11240
|
+
if (t8.isStringLiteral(member.initializer)) {
|
|
11241
|
+
values.push(member.initializer.value);
|
|
11242
|
+
} else if (t8.isNumericLiteral(member.initializer)) {
|
|
11243
|
+
values.push(member.initializer.value);
|
|
11244
|
+
}
|
|
11245
|
+
}
|
|
11246
|
+
}
|
|
11247
|
+
if (values.length > 0) {
|
|
11248
|
+
result = values;
|
|
11249
|
+
}
|
|
11250
|
+
}
|
|
11251
|
+
},
|
|
11252
|
+
VariableDeclarator: (nodePath) => {
|
|
11253
|
+
if (result)
|
|
11254
|
+
return;
|
|
11255
|
+
if (!t8.isIdentifier(nodePath.node.id, { name }) || !nodePath.node.init)
|
|
11256
|
+
return;
|
|
11257
|
+
let initNode = nodePath.node.init;
|
|
11258
|
+
if (t8.isTSAsExpression(initNode) || t8.isTSSatisfiesExpression(initNode)) {
|
|
11259
|
+
initNode = initNode.expression;
|
|
11260
|
+
}
|
|
11261
|
+
if (t8.isObjectExpression(initNode)) {
|
|
11262
|
+
const values = [];
|
|
11263
|
+
for (const prop of initNode.properties) {
|
|
11264
|
+
if (t8.isObjectProperty(prop)) {
|
|
11265
|
+
if (t8.isStringLiteral(prop.value)) {
|
|
11266
|
+
values.push(prop.value.value);
|
|
11267
|
+
} else if (t8.isNumericLiteral(prop.value)) {
|
|
11268
|
+
values.push(prop.value.value);
|
|
11269
|
+
}
|
|
11270
|
+
}
|
|
11271
|
+
}
|
|
11272
|
+
if (values.length > 0) {
|
|
11273
|
+
result = values;
|
|
11274
|
+
}
|
|
11275
|
+
} else if (t8.isArrayExpression(initNode)) {
|
|
11276
|
+
const values = [];
|
|
11277
|
+
for (const element of initNode.elements) {
|
|
11278
|
+
if (t8.isStringLiteral(element)) {
|
|
11279
|
+
values.push(element.value);
|
|
11280
|
+
} else if (t8.isNumericLiteral(element)) {
|
|
11281
|
+
values.push(element.value);
|
|
11282
|
+
}
|
|
11283
|
+
}
|
|
11284
|
+
if (values.length > 0) {
|
|
11285
|
+
result = values;
|
|
11286
|
+
}
|
|
11287
|
+
}
|
|
11288
|
+
}
|
|
11289
|
+
});
|
|
11290
|
+
return result;
|
|
11291
|
+
};
|
|
11292
|
+
if (this.currentAST) {
|
|
11293
|
+
const values = extractFromAST(this.currentAST);
|
|
11294
|
+
if (values)
|
|
11295
|
+
return values;
|
|
11296
|
+
}
|
|
11297
|
+
if (this.currentImports && this.currentFilePath && this.currentImports[name]) {
|
|
11298
|
+
const resolvedPath = this.resolveImportPath(this.currentFilePath, this.currentImports[name]);
|
|
11299
|
+
if (resolvedPath) {
|
|
11300
|
+
const importedAST = this.parseFileWithCache(resolvedPath);
|
|
11301
|
+
if (importedAST) {
|
|
11302
|
+
return extractFromAST(importedAST);
|
|
11303
|
+
}
|
|
11304
|
+
}
|
|
11305
|
+
}
|
|
11306
|
+
return null;
|
|
11307
|
+
}
|
|
11215
11308
|
/**
|
|
11216
11309
|
* Extract description from method arguments if it's a .describe() call
|
|
11217
11310
|
*/
|
package/dist/vite/index.js
CHANGED
|
@@ -2898,6 +2898,7 @@ function processZodPrimitiveNode(node, context) {
|
|
|
2898
2898
|
schema = { type: "array", items: itemsType };
|
|
2899
2899
|
break;
|
|
2900
2900
|
}
|
|
2901
|
+
case "nativeEnum":
|
|
2901
2902
|
case "enum":
|
|
2902
2903
|
if (node.arguments.length > 0 && t6.isArrayExpression(node.arguments[0])) {
|
|
2903
2904
|
const enumValues = node.arguments[0].elements.filter((el) => t6.isStringLiteral(el) || t6.isNumericLiteral(el)).map((el) => el.value);
|
|
@@ -2918,6 +2919,14 @@ function processZodPrimitiveNode(node, context) {
|
|
|
2918
2919
|
type: "string",
|
|
2919
2920
|
enum: enumValues
|
|
2920
2921
|
} : { type: "string" };
|
|
2922
|
+
} else if (node.arguments.length > 0 && t6.isIdentifier(node.arguments[0]) && context.resolveEnumValues) {
|
|
2923
|
+
const resolved = context.resolveEnumValues(node.arguments[0].name);
|
|
2924
|
+
if (resolved && resolved.length > 0) {
|
|
2925
|
+
const valueType = typeof resolved[0] === "number" ? "number" : "string";
|
|
2926
|
+
schema = { type: valueType, enum: resolved };
|
|
2927
|
+
} else {
|
|
2928
|
+
schema = { type: "string" };
|
|
2929
|
+
}
|
|
2921
2930
|
} else {
|
|
2922
2931
|
schema = { type: "string" };
|
|
2923
2932
|
}
|
|
@@ -11209,9 +11218,93 @@ var ZodSchemaConverter = class {
|
|
|
11209
11218
|
},
|
|
11210
11219
|
getReferenceSchema: (schemaName) => ({
|
|
11211
11220
|
$ref: `#/components/schemas/${this.getSchemaReferenceName(schemaName)}`
|
|
11212
|
-
})
|
|
11221
|
+
}),
|
|
11222
|
+
resolveEnumValues: (name) => this.resolveEnumValues(name)
|
|
11213
11223
|
});
|
|
11214
11224
|
}
|
|
11225
|
+
/**
|
|
11226
|
+
* Resolve enum values from a TS enum declaration or an `as const` object by identifier name.
|
|
11227
|
+
* Searches the current file first, then follows imports.
|
|
11228
|
+
*/
|
|
11229
|
+
resolveEnumValues(name) {
|
|
11230
|
+
const extractFromAST = (ast) => {
|
|
11231
|
+
let result = null;
|
|
11232
|
+
resolvedTraverse(ast, {
|
|
11233
|
+
TSEnumDeclaration: (nodePath) => {
|
|
11234
|
+
if (result)
|
|
11235
|
+
return;
|
|
11236
|
+
if (nodePath.node.id && t8.isIdentifier(nodePath.node.id, { name })) {
|
|
11237
|
+
const values = [];
|
|
11238
|
+
for (const member of nodePath.node.members) {
|
|
11239
|
+
if (t8.isTSEnumMember(member) && member.initializer) {
|
|
11240
|
+
if (t8.isStringLiteral(member.initializer)) {
|
|
11241
|
+
values.push(member.initializer.value);
|
|
11242
|
+
} else if (t8.isNumericLiteral(member.initializer)) {
|
|
11243
|
+
values.push(member.initializer.value);
|
|
11244
|
+
}
|
|
11245
|
+
}
|
|
11246
|
+
}
|
|
11247
|
+
if (values.length > 0) {
|
|
11248
|
+
result = values;
|
|
11249
|
+
}
|
|
11250
|
+
}
|
|
11251
|
+
},
|
|
11252
|
+
VariableDeclarator: (nodePath) => {
|
|
11253
|
+
if (result)
|
|
11254
|
+
return;
|
|
11255
|
+
if (!t8.isIdentifier(nodePath.node.id, { name }) || !nodePath.node.init)
|
|
11256
|
+
return;
|
|
11257
|
+
let initNode = nodePath.node.init;
|
|
11258
|
+
if (t8.isTSAsExpression(initNode) || t8.isTSSatisfiesExpression(initNode)) {
|
|
11259
|
+
initNode = initNode.expression;
|
|
11260
|
+
}
|
|
11261
|
+
if (t8.isObjectExpression(initNode)) {
|
|
11262
|
+
const values = [];
|
|
11263
|
+
for (const prop of initNode.properties) {
|
|
11264
|
+
if (t8.isObjectProperty(prop)) {
|
|
11265
|
+
if (t8.isStringLiteral(prop.value)) {
|
|
11266
|
+
values.push(prop.value.value);
|
|
11267
|
+
} else if (t8.isNumericLiteral(prop.value)) {
|
|
11268
|
+
values.push(prop.value.value);
|
|
11269
|
+
}
|
|
11270
|
+
}
|
|
11271
|
+
}
|
|
11272
|
+
if (values.length > 0) {
|
|
11273
|
+
result = values;
|
|
11274
|
+
}
|
|
11275
|
+
} else if (t8.isArrayExpression(initNode)) {
|
|
11276
|
+
const values = [];
|
|
11277
|
+
for (const element of initNode.elements) {
|
|
11278
|
+
if (t8.isStringLiteral(element)) {
|
|
11279
|
+
values.push(element.value);
|
|
11280
|
+
} else if (t8.isNumericLiteral(element)) {
|
|
11281
|
+
values.push(element.value);
|
|
11282
|
+
}
|
|
11283
|
+
}
|
|
11284
|
+
if (values.length > 0) {
|
|
11285
|
+
result = values;
|
|
11286
|
+
}
|
|
11287
|
+
}
|
|
11288
|
+
}
|
|
11289
|
+
});
|
|
11290
|
+
return result;
|
|
11291
|
+
};
|
|
11292
|
+
if (this.currentAST) {
|
|
11293
|
+
const values = extractFromAST(this.currentAST);
|
|
11294
|
+
if (values)
|
|
11295
|
+
return values;
|
|
11296
|
+
}
|
|
11297
|
+
if (this.currentImports && this.currentFilePath && this.currentImports[name]) {
|
|
11298
|
+
const resolvedPath = this.resolveImportPath(this.currentFilePath, this.currentImports[name]);
|
|
11299
|
+
if (resolvedPath) {
|
|
11300
|
+
const importedAST = this.parseFileWithCache(resolvedPath);
|
|
11301
|
+
if (importedAST) {
|
|
11302
|
+
return extractFromAST(importedAST);
|
|
11303
|
+
}
|
|
11304
|
+
}
|
|
11305
|
+
}
|
|
11306
|
+
return null;
|
|
11307
|
+
}
|
|
11215
11308
|
/**
|
|
11216
11309
|
* Extract description from method arguments if it's a .describe() call
|
|
11217
11310
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-openapi-gen",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Automatically generate OpenAPI 3.0, 3.1, and 3.2 documentation from Next.js projects, with support for Zod schemas, TypeScript types, and reusable OpenAPI fragments.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|