next-openapi-gen 1.4.1 → 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.
@@ -2455,23 +2455,58 @@ var SymbolResolver = class {
2455
2455
  }
2456
2456
  /**
2457
2457
  * Returns a simple literal value (string/number/boolean/null) for a `const` declarator,
2458
- * or `null` if no such declarator exists.
2458
+ * following imports and re-exports when the name is not declared locally.
2459
2459
  */
2460
2460
  resolveLiteral(filePath, name) {
2461
+ const visited = /* @__PURE__ */ new Set();
2462
+ return this.resolveLiteralInternal(filePath, name, visited);
2463
+ }
2464
+ resolveLiteralInternal(filePath, name, visited) {
2465
+ if (visited.has(filePath))
2466
+ return void 0;
2467
+ visited.add(filePath);
2461
2468
  const index = this.getIndex(filePath);
2462
2469
  if (!index)
2463
2470
  return void 0;
2464
2471
  const literal2 = index.constLiterals.get(name);
2465
- if (!literal2)
2466
- return void 0;
2467
- if (t3.isStringLiteral(literal2))
2468
- return literal2.value;
2469
- if (t3.isNumericLiteral(literal2))
2470
- return literal2.value;
2471
- if (t3.isBooleanLiteral(literal2))
2472
- return literal2.value;
2473
- if (t3.isNullLiteral(literal2))
2474
- return null;
2472
+ if (literal2) {
2473
+ if (t3.isStringLiteral(literal2))
2474
+ return literal2.value;
2475
+ if (t3.isNumericLiteral(literal2))
2476
+ return literal2.value;
2477
+ if (t3.isBooleanLiteral(literal2))
2478
+ return literal2.value;
2479
+ if (t3.isNullLiteral(literal2))
2480
+ return null;
2481
+ }
2482
+ const imports = this.getImports(filePath);
2483
+ const importInfo = imports?.get(name);
2484
+ if (importInfo) {
2485
+ const resolved = this.resolveImportPath(filePath, importInfo.source);
2486
+ if (resolved) {
2487
+ const targetName = importInfo.importedName === "default" ? name : importInfo.importedName;
2488
+ const result = this.resolveLiteralInternal(resolved, targetName, visited);
2489
+ if (result !== void 0)
2490
+ return result;
2491
+ }
2492
+ }
2493
+ const reExport = index.namedReExports.get(name);
2494
+ if (reExport) {
2495
+ const resolved = this.resolveImportPath(filePath, reExport.source);
2496
+ if (resolved) {
2497
+ const result = this.resolveLiteralInternal(resolved, reExport.importedName, visited);
2498
+ if (result !== void 0)
2499
+ return result;
2500
+ }
2501
+ }
2502
+ for (const starSrc of index.exportsStar) {
2503
+ const resolved = this.resolveImportPath(filePath, starSrc);
2504
+ if (!resolved)
2505
+ continue;
2506
+ const result = this.resolveLiteralInternal(resolved, name, visited);
2507
+ if (result !== void 0)
2508
+ return result;
2509
+ }
2475
2510
  return void 0;
2476
2511
  }
2477
2512
  /**
@@ -12794,6 +12829,58 @@ var ZodSchemaConverter = class {
12794
12829
  this.symbolResolver.primeAST(this.currentFilePath, this.currentAST);
12795
12830
  return this.symbolResolver.resolveLiteral(this.currentFilePath, name);
12796
12831
  }
12832
+ /**
12833
+ * Unwrap a possible `TSAsExpression` / `TSSatisfiesExpression` to get the
12834
+ * underlying expression node. Returns the node itself when no wrapper is
12835
+ * present.
12836
+ */
12837
+ unwrapTypeAssertion(node) {
12838
+ if (!node)
12839
+ return void 0;
12840
+ if (t10.isTSAsExpression(node) || t10.isTSSatisfiesExpression(node)) {
12841
+ return node.expression;
12842
+ }
12843
+ return node;
12844
+ }
12845
+ /**
12846
+ * Resolve a numeric value from a call-expression argument.
12847
+ * Handles: numeric literals, identifier references to const numbers,
12848
+ * and `x as number` / `x satisfies number` wrappers around either.
12849
+ */
12850
+ resolveNumericArg(arg) {
12851
+ if (!arg)
12852
+ return void 0;
12853
+ const node = this.unwrapTypeAssertion(arg);
12854
+ if (t10.isNumericLiteral(node))
12855
+ return node.value;
12856
+ if (t10.isUnaryExpression(node) && node.operator === "-" && t10.isNumericLiteral(node.argument)) {
12857
+ return -node.argument.value;
12858
+ }
12859
+ if (t10.isIdentifier(node)) {
12860
+ const val = this.resolveLiteralValue(node.name);
12861
+ if (typeof val === "number")
12862
+ return val;
12863
+ }
12864
+ return void 0;
12865
+ }
12866
+ /**
12867
+ * Resolve a string value from a call-expression argument.
12868
+ * Handles: string literals, identifier references to const strings,
12869
+ * and `x as string` / `x satisfies string` wrappers around either.
12870
+ */
12871
+ resolveStringArg(arg) {
12872
+ if (!arg)
12873
+ return void 0;
12874
+ const node = this.unwrapTypeAssertion(arg);
12875
+ if (t10.isStringLiteral(node))
12876
+ return node.value;
12877
+ if (t10.isIdentifier(node)) {
12878
+ const val = this.resolveLiteralValue(node.name);
12879
+ if (typeof val === "string")
12880
+ return val;
12881
+ }
12882
+ return void 0;
12883
+ }
12797
12884
  /**
12798
12885
  * Resolve an identifier referring to a `z.object({...})` (or similar) call expression.
12799
12886
  * This lets callers inline the referenced object's shape.
@@ -12862,6 +12949,14 @@ var ZodSchemaConverter = class {
12862
12949
  if (t10.isNullLiteral(node)) {
12863
12950
  return null;
12864
12951
  }
12952
+ if (t10.isIdentifier(node)) {
12953
+ const val = this.resolveLiteralValue(node.name);
12954
+ if (val !== void 0)
12955
+ return val;
12956
+ }
12957
+ if (t10.isTSAsExpression(node) || t10.isTSSatisfiesExpression(node)) {
12958
+ return this.extractStaticJsonValue(node.expression);
12959
+ }
12865
12960
  if (t10.isArrayExpression(node)) {
12866
12961
  const values = [];
12867
12962
  for (const element of node.elements) {
@@ -12960,53 +13055,60 @@ var ZodSchemaConverter = class {
12960
13055
  schema.nullable = true;
12961
13056
  }
12962
13057
  break;
12963
- case "describe":
12964
- if (node.arguments.length > 0 && t10.isStringLiteral(node.arguments[0])) {
12965
- const description = node.arguments[0].value;
12966
- if (description.startsWith("@deprecated")) {
13058
+ case "describe": {
13059
+ const descVal = this.resolveStringArg(node.arguments[0]);
13060
+ if (descVal !== void 0) {
13061
+ if (descVal.startsWith("@deprecated")) {
12967
13062
  schema.deprecated = true;
12968
- schema.description = description.replace("@deprecated", "").trim();
13063
+ schema.description = descVal.replace("@deprecated", "").trim();
12969
13064
  } else {
12970
- schema.description = description;
13065
+ schema.description = descVal;
12971
13066
  }
12972
13067
  }
12973
13068
  break;
13069
+ }
12974
13070
  case "deprecated":
12975
13071
  schema.deprecated = true;
12976
13072
  break;
12977
- case "min":
12978
- if (node.arguments.length > 0 && t10.isNumericLiteral(node.arguments[0])) {
13073
+ case "min": {
13074
+ const minVal = this.resolveNumericArg(node.arguments[0]);
13075
+ if (minVal !== void 0) {
12979
13076
  if (schema.type === "string") {
12980
- schema.minLength = node.arguments[0].value;
13077
+ schema.minLength = minVal;
12981
13078
  } else if (schema.type === "number" || schema.type === "integer") {
12982
- schema.minimum = node.arguments[0].value;
13079
+ schema.minimum = minVal;
12983
13080
  } else if (schema.type === "array") {
12984
- schema.minItems = node.arguments[0].value;
13081
+ schema.minItems = minVal;
12985
13082
  }
12986
13083
  }
12987
13084
  break;
12988
- case "max":
12989
- if (node.arguments.length > 0 && t10.isNumericLiteral(node.arguments[0])) {
13085
+ }
13086
+ case "max": {
13087
+ const maxVal = this.resolveNumericArg(node.arguments[0]);
13088
+ if (maxVal !== void 0) {
12990
13089
  if (schema.type === "string") {
12991
- schema.maxLength = node.arguments[0].value;
13090
+ schema.maxLength = maxVal;
12992
13091
  } else if (schema.type === "number" || schema.type === "integer") {
12993
- schema.maximum = node.arguments[0].value;
13092
+ schema.maximum = maxVal;
12994
13093
  } else if (schema.type === "array") {
12995
- schema.maxItems = node.arguments[0].value;
13094
+ schema.maxItems = maxVal;
12996
13095
  }
12997
13096
  }
12998
13097
  break;
12999
- case "length":
13000
- if (node.arguments.length > 0 && t10.isNumericLiteral(node.arguments[0])) {
13098
+ }
13099
+ case "length": {
13100
+ const lenVal = this.resolveNumericArg(node.arguments[0]);
13101
+ if (lenVal !== void 0) {
13001
13102
  if (schema.type === "string") {
13002
- schema.minLength = node.arguments[0].value;
13003
- schema.maxLength = node.arguments[0].value;
13103
+ schema.minLength = lenVal;
13104
+ schema.maxLength = lenVal;
13004
13105
  } else if (schema.type === "array") {
13005
- schema.minItems = node.arguments[0].value;
13006
- schema.maxItems = node.arguments[0].value;
13106
+ schema.minItems = lenVal;
13107
+ schema.maxItems = lenVal;
13007
13108
  }
13008
13109
  }
13009
13110
  break;
13111
+ }
13010
13112
  case "nonempty":
13011
13113
  if (schema.type === "array") {
13012
13114
  schema.minItems = Math.max(schema.minItems ?? 0, 1);
@@ -13082,21 +13184,27 @@ var ZodSchemaConverter = class {
13082
13184
  schema.pattern = node.arguments[0].pattern;
13083
13185
  }
13084
13186
  break;
13085
- case "startsWith":
13086
- if (node.arguments.length > 0 && t10.isStringLiteral(node.arguments[0])) {
13087
- schema.pattern = `^${this.escapeRegExp(node.arguments[0].value)}`;
13187
+ case "startsWith": {
13188
+ const swVal = this.resolveStringArg(node.arguments[0]);
13189
+ if (swVal !== void 0) {
13190
+ schema.pattern = `^${this.escapeRegExp(swVal)}`;
13088
13191
  }
13089
13192
  break;
13090
- case "endsWith":
13091
- if (node.arguments.length > 0 && t10.isStringLiteral(node.arguments[0])) {
13092
- schema.pattern = `${this.escapeRegExp(node.arguments[0].value)}$`;
13193
+ }
13194
+ case "endsWith": {
13195
+ const ewVal = this.resolveStringArg(node.arguments[0]);
13196
+ if (ewVal !== void 0) {
13197
+ schema.pattern = `${this.escapeRegExp(ewVal)}$`;
13093
13198
  }
13094
13199
  break;
13095
- case "includes":
13096
- if (node.arguments.length > 0 && t10.isStringLiteral(node.arguments[0])) {
13097
- schema.pattern = this.escapeRegExp(node.arguments[0].value);
13200
+ }
13201
+ case "includes": {
13202
+ const incVal = this.resolveStringArg(node.arguments[0]);
13203
+ if (incVal !== void 0) {
13204
+ schema.pattern = this.escapeRegExp(incVal);
13098
13205
  }
13099
13206
  break;
13207
+ }
13100
13208
  case "int":
13101
13209
  schema.type = "integer";
13102
13210
  break;
@@ -13120,17 +13228,22 @@ var ZodSchemaConverter = class {
13120
13228
  break;
13121
13229
  case "default":
13122
13230
  if (node.arguments.length > 0) {
13123
- if (t10.isStringLiteral(node.arguments[0])) {
13124
- schema.default = node.arguments[0].value;
13125
- } else if (t10.isNumericLiteral(node.arguments[0])) {
13126
- schema.default = node.arguments[0].value;
13127
- } else if (t10.isBooleanLiteral(node.arguments[0])) {
13128
- schema.default = node.arguments[0].value;
13129
- } else if (t10.isNullLiteral(node.arguments[0])) {
13231
+ const defaultArg = this.unwrapTypeAssertion(node.arguments[0]);
13232
+ if (t10.isStringLiteral(defaultArg)) {
13233
+ schema.default = defaultArg.value;
13234
+ } else if (t10.isNumericLiteral(defaultArg)) {
13235
+ schema.default = defaultArg.value;
13236
+ } else if (t10.isBooleanLiteral(defaultArg)) {
13237
+ schema.default = defaultArg.value;
13238
+ } else if (t10.isNullLiteral(defaultArg)) {
13130
13239
  schema.default = null;
13131
- } else if (t10.isObjectExpression(node.arguments[0])) {
13240
+ } else if (t10.isIdentifier(defaultArg)) {
13241
+ const val = this.resolveLiteralValue(defaultArg.name);
13242
+ if (val !== void 0)
13243
+ schema.default = val;
13244
+ } else if (t10.isObjectExpression(defaultArg)) {
13132
13245
  const defaultObj = {};
13133
- node.arguments[0].properties.forEach((prop) => {
13246
+ defaultArg.properties.forEach((prop) => {
13134
13247
  if (t10.isObjectProperty(prop) && (t10.isIdentifier(prop.key) || t10.isStringLiteral(prop.key)) && (t10.isStringLiteral(prop.value) || t10.isNumericLiteral(prop.value) || t10.isBooleanLiteral(prop.value))) {
13135
13248
  const key = t10.isIdentifier(prop.key) ? prop.key.name : prop.key.value;
13136
13249
  const value = t10.isStringLiteral(prop.value) ? prop.value.value : t10.isNumericLiteral(prop.value) ? prop.value.value : t10.isBooleanLiteral(prop.value) ? prop.value.value : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-openapi-gen",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
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",