next-openapi-gen 1.3.0 → 1.4.1

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.
@@ -388,7 +388,7 @@ function parseJSDocBlock(commentValue, filePath) {
388
388
  result.cookieType = extractTypeFromComment(normalizedComment, "@cookie");
389
389
  const authValue = extractLineValue(normalizedComment, "@auth");
390
390
  if (authValue) {
391
- result.auth = performAuthPresetReplacements(authValue);
391
+ result.auth = authValue;
392
392
  }
393
393
  const querystring = parseQuerystringTag(normalizedComment);
394
394
  if (querystring) {
@@ -1064,16 +1064,17 @@ var INTERNAL_OPENAPI_CONFIG_KEYS = [
1064
1064
  "next",
1065
1065
  "diagnostics",
1066
1066
  "debug",
1067
+ "authPresets",
1067
1068
  "excludeSchemas"
1068
1069
  ];
1069
- var AUTH_PRESET_REPLACEMENTS = {
1070
+ var DEFAULT_AUTH_PRESET_REPLACEMENTS = {
1070
1071
  bearer: "BearerAuth",
1071
1072
  basic: "BasicAuth",
1072
1073
  apikey: "ApiKeyAuth"
1073
1074
  };
1074
- function performAuthPresetReplacements(authValue) {
1075
+ function performAuthPresetReplacements(authValue, presets = DEFAULT_AUTH_PRESET_REPLACEMENTS) {
1075
1076
  const authParts = authValue.split(",").map((part) => part.trim());
1076
- const mappedParts = authParts.map((part) => AUTH_PRESET_REPLACEMENTS[part.toLowerCase()] || part);
1077
+ const mappedParts = authParts.map((part) => presets[part.toLowerCase()] || part);
1077
1078
  return mappedParts.join(",");
1078
1079
  }
1079
1080
  function getOperationId(routePath, method) {
@@ -1346,6 +1347,7 @@ function normalizeOpenApiConfig(template) {
1346
1347
  adapterPath: template.next?.adapterPath
1347
1348
  },
1348
1349
  diagnostics: template.diagnostics ?? { enabled: DEFAULT_DIAGNOSTICS_ENABLED },
1350
+ authPresets: { ...DEFAULT_AUTH_PRESET_REPLACEMENTS, ...template.authPresets },
1349
1351
  debug: template.debug ?? DEFAULT_DEBUG
1350
1352
  };
1351
1353
  }
@@ -1827,8 +1829,10 @@ function downgradeSchemaForOpenApi30(schema, mediaTypeName) {
1827
1829
  const nullableBranch = nextSchema.anyOf.find((item) => item.type === "null");
1828
1830
  const baseBranch = nextSchema.anyOf.find((item) => item.type !== "null");
1829
1831
  if (nullableBranch && baseBranch) {
1832
+ const { anyOf: _anyOf, ...outerMeta } = nextSchema;
1830
1833
  nextSchema = {
1831
1834
  ...structuredClone(baseBranch),
1835
+ ...outerMeta,
1832
1836
  nullable: true
1833
1837
  };
1834
1838
  }
@@ -3703,7 +3707,7 @@ function processZodLiteral(node, context) {
3703
3707
  return { type: "string", enum: [arg.value] };
3704
3708
  }
3705
3709
  if (t8.isNumericLiteral(arg)) {
3706
- return { type: "number", enum: [arg.value] };
3710
+ return { type: Number.isInteger(arg.value) ? "integer" : "number", enum: [arg.value] };
3707
3711
  }
3708
3712
  if (t8.isBooleanLiteral(arg)) {
3709
3713
  return { type: "boolean", enum: [arg.value] };
@@ -3719,7 +3723,7 @@ function processZodLiteral(node, context) {
3719
3723
  if (typeof value === "string")
3720
3724
  return { type: "string", enum: [value] };
3721
3725
  if (typeof value === "number")
3722
- return { type: "number", enum: [value] };
3726
+ return { type: Number.isInteger(value) ? "integer" : "number", enum: [value] };
3723
3727
  if (typeof value === "boolean")
3724
3728
  return { type: "boolean", enum: [value] };
3725
3729
  if (value === null)
@@ -3814,7 +3818,7 @@ function processZodTuple(node, processNode, context) {
3814
3818
  if (t8.isIdentifier(node.arguments[0]) && context?.resolveConstArrayValues) {
3815
3819
  const values = context.resolveConstArrayValues(node.arguments[0].name);
3816
3820
  if (values && values.length > 0) {
3817
- const prefixItems = values.map((value) => typeof value === "number" ? { type: "number", enum: [value] } : { type: "string", enum: [value] });
3821
+ const prefixItems = values.map((value) => typeof value === "number" ? { type: Number.isInteger(value) ? "integer" : "number", enum: [value] } : { type: "string", enum: [value] });
3818
3822
  return {
3819
3823
  type: "array",
3820
3824
  prefixItems,
@@ -3858,7 +3862,7 @@ function processZodUnion(node, processNode, context) {
3858
3862
  if (t8.isIdentifier(node.arguments[0]) && context?.resolveConstArrayValues) {
3859
3863
  const values = context.resolveConstArrayValues(node.arguments[0].name);
3860
3864
  if (values && values.length > 0) {
3861
- const type = typeof values[0] === "number" ? "number" : "string";
3865
+ const type = typeof values[0] === "number" ? Number.isInteger(values[0]) ? "integer" : "number" : "string";
3862
3866
  return { type, enum: values };
3863
3867
  }
3864
3868
  }
@@ -11305,8 +11309,17 @@ var ZodRuntimeExporter = class {
11305
11309
  return node.arguments[0] ? literal(this.buildLiteralValue(node.arguments[0])) : null;
11306
11310
  case "enum":
11307
11311
  return this.buildEnum(node);
11308
- case "array":
11309
- return node.arguments[0] && isProcessableNode(node.arguments[0]) ? array(this.buildSchema(node.arguments[0]) ?? unknown()) : array(unknown());
11312
+ case "array": {
11313
+ const arg = node.arguments[0];
11314
+ if (!arg || !isProcessableNode(arg)) {
11315
+ return array(unknown());
11316
+ }
11317
+ const itemSchema = this.buildSchema(arg);
11318
+ if (!itemSchema) {
11319
+ return null;
11320
+ }
11321
+ return array(itemSchema);
11322
+ }
11310
11323
  case "strictObject": {
11311
11324
  const base = this.buildObject(node);
11312
11325
  return base && typeof base.strict === "function" ? base.strict() : base;
@@ -11438,13 +11451,17 @@ var ZodRuntimeExporter = class {
11438
11451
  if (node.arguments.length === 0 || !t9.isArrayExpression(node.arguments[0])) {
11439
11452
  return tuple([]);
11440
11453
  }
11441
- const items = node.arguments[0].elements.flatMap((element) => {
11454
+ const items = [];
11455
+ for (const element of node.arguments[0].elements) {
11442
11456
  if (!isProcessableNode(element)) {
11443
- return [];
11457
+ return null;
11444
11458
  }
11445
11459
  const schema = this.buildSchema(element);
11446
- return schema ? [schema] : [];
11447
- });
11460
+ if (!schema) {
11461
+ return null;
11462
+ }
11463
+ items.push(schema);
11464
+ }
11448
11465
  return tuple(items);
11449
11466
  }
11450
11467
  buildTemplateLiteral(node) {
@@ -12056,7 +12073,12 @@ var ZodSchemaConverter = class {
12056
12073
  if (this.isZodSchema(path17.node.init)) {
12057
12074
  const schema = this.processZodNode(path17.node.init);
12058
12075
  if (schema) {
12059
- this.storeResolvedSchema(schemaName, schema);
12076
+ const overrideId = this.extractMetaIdFromNode(path17.node.init);
12077
+ if (overrideId) {
12078
+ this.applyMetaIdOverride(schemaName, schema, overrideId, filePath);
12079
+ } else {
12080
+ this.storeResolvedSchema(schemaName, schema);
12081
+ }
12060
12082
  }
12061
12083
  return;
12062
12084
  }
@@ -12399,8 +12421,15 @@ var ZodSchemaConverter = class {
12399
12421
  };
12400
12422
  switch (methodName) {
12401
12423
  case "optional":
12424
+ break;
12402
12425
  case "nullable":
12403
12426
  case "nullish":
12427
+ schema = {
12428
+ anyOf: [
12429
+ { $ref: `#/components/schemas/${this.getSchemaReferenceName(schemaName)}` },
12430
+ { type: "null" }
12431
+ ]
12432
+ };
12404
12433
  break;
12405
12434
  case "describe":
12406
12435
  if (node.arguments.length > 0 && t10.isStringLiteral(node.arguments[0])) {
@@ -12895,7 +12924,7 @@ var ZodSchemaConverter = class {
12895
12924
  return helperName.startsWith("coerce.") || helperName === "templateLiteral" || helperName === "stringbool";
12896
12925
  }
12897
12926
  if (t10.isMemberExpression(node.callee) && t10.isIdentifier(node.callee.property)) {
12898
- const runtimeMethods = /* @__PURE__ */ new Set(["pipe", "meta"]);
12927
+ const runtimeMethods = /* @__PURE__ */ new Set(["pipe"]);
12899
12928
  if (runtimeMethods.has(node.callee.property.name)) {
12900
12929
  return true;
12901
12930
  }
@@ -12918,12 +12947,16 @@ var ZodSchemaConverter = class {
12918
12947
  case "optional":
12919
12948
  break;
12920
12949
  case "nullable":
12921
- if (!schema.allOf) {
12950
+ if (schema.allOf) {
12951
+ schema = { anyOf: [...schema.allOf, { type: "null" }] };
12952
+ } else {
12922
12953
  schema.nullable = true;
12923
12954
  }
12924
12955
  break;
12925
12956
  case "nullish":
12926
- if (!schema.allOf) {
12957
+ if (schema.allOf) {
12958
+ schema = { anyOf: [...schema.allOf, { type: "null" }] };
12959
+ } else {
12927
12960
  schema.nullable = true;
12928
12961
  }
12929
12962
  break;
@@ -13068,15 +13101,13 @@ var ZodSchemaConverter = class {
13068
13101
  schema.type = "integer";
13069
13102
  break;
13070
13103
  case "positive":
13071
- schema.minimum = 0;
13072
- schema.exclusiveMinimum = true;
13104
+ schema.exclusiveMinimum = 0;
13073
13105
  break;
13074
13106
  case "nonnegative":
13075
13107
  schema.minimum = 0;
13076
13108
  break;
13077
13109
  case "negative":
13078
- schema.maximum = 0;
13079
- schema.exclusiveMaximum = true;
13110
+ schema.exclusiveMaximum = 0;
13080
13111
  break;
13081
13112
  case "nonpositive":
13082
13113
  schema.maximum = 0;
@@ -13438,6 +13469,9 @@ var ZodSchemaConverter = class {
13438
13469
  if (!this.getStoredSchema(schemaName)) {
13439
13470
  logger.debug(`Pre-processing Zod schema: ${schemaName}`);
13440
13471
  this.processingSchemas.add(schemaName);
13472
+ this.currentFilePath = filePath;
13473
+ this.currentAST = ast;
13474
+ this.currentImports = importedModules;
13441
13475
  const schema = this.processZodNode(declaration.init);
13442
13476
  this.processingSchemas.delete(schemaName);
13443
13477
  if (schema) {
@@ -13470,6 +13504,9 @@ var ZodSchemaConverter = class {
13470
13504
  if (!this.getStoredSchema(schemaName) && !this.processingSchemas.has(schemaName)) {
13471
13505
  logger.debug(`Pre-processing Zod schema: ${schemaName}`);
13472
13506
  this.processingSchemas.add(schemaName);
13507
+ this.currentFilePath = filePath;
13508
+ this.currentAST = ast;
13509
+ this.currentImports = importedModules;
13473
13510
  const schema = this.processZodNode(declaration.init);
13474
13511
  this.processingSchemas.delete(schemaName);
13475
13512
  if (schema) {
@@ -16340,11 +16377,16 @@ var ResponseProcessor = class {
16340
16377
  var OperationProcessor = class {
16341
16378
  schemaProcessor;
16342
16379
  responseProcessor;
16380
+ authPresets;
16343
16381
  performanceProfile;
16344
- constructor(schemaProcessor, responseProcessor, performanceProfile) {
16382
+ constructor(schemaProcessor, responseProcessor, options = {}) {
16345
16383
  this.schemaProcessor = schemaProcessor;
16346
16384
  this.responseProcessor = responseProcessor;
16347
- this.performanceProfile = performanceProfile;
16385
+ this.authPresets = {
16386
+ ...DEFAULT_AUTH_PRESET_REPLACEMENTS,
16387
+ ...options.authPresets
16388
+ };
16389
+ this.performanceProfile = options.performanceProfile;
16348
16390
  }
16349
16391
  processOperation(varName, routePath, dataTypes, pathParamNames = []) {
16350
16392
  const method = varName.toLowerCase();
@@ -16369,9 +16411,10 @@ var OperationProcessor = class {
16369
16411
  definition.deprecated = true;
16370
16412
  }
16371
16413
  if (explicitSecurity && explicitSecurity.length > 0) {
16372
- definition.security = explicitSecurity;
16414
+ definition.security = explicitSecurity.map((req) => Object.fromEntries(Object.entries(req).map(([scheme, scopes]) => [this.applyPreset(scheme), scopes])));
16373
16415
  } else if (auth) {
16374
- const authItems = auth.split(",").map((item) => item.trim());
16416
+ const mapped = performAuthPresetReplacements(auth, this.authPresets);
16417
+ const authItems = mapped.split(",").map((item) => item.trim());
16375
16418
  definition.security = authItems.map((authItem) => ({
16376
16419
  [authItem]: []
16377
16420
  }));
@@ -16584,6 +16627,9 @@ ${suffix}`;
16584
16627
  response.links[link.name] = linkObject;
16585
16628
  }
16586
16629
  }
16630
+ applyPreset(scheme) {
16631
+ return this.authPresets[scheme.toLowerCase()] ?? scheme;
16632
+ }
16587
16633
  createQuerystringParameter(dataTypes) {
16588
16634
  if (!dataTypes.querystringType) {
16589
16635
  return void 0;
@@ -16672,7 +16718,10 @@ var RouteProcessor = class {
16672
16718
  return new RegExp(`^${regexPattern}$`);
16673
16719
  });
16674
16720
  this.responseProcessor = new ResponseProcessor(this.config, this.schemaProcessor);
16675
- this.operationProcessor = new OperationProcessor(this.schemaProcessor, this.responseProcessor, this.performanceProfile);
16721
+ this.operationProcessor = new OperationProcessor(this.schemaProcessor, this.responseProcessor, {
16722
+ authPresets: this.config.authPresets,
16723
+ performanceProfile: this.performanceProfile
16724
+ });
16676
16725
  }
16677
16726
  processResponsesFromConfig(dataTypes, method) {
16678
16727
  return this.responseProcessor.processResponses(dataTypes, method);
@@ -16914,6 +16963,7 @@ function applyExcludeSchemas(document, mergedSchemas, excludedSchemas) {
16914
16963
  if (excludedNames.size === 0)
16915
16964
  return;
16916
16965
  walkAndInline(document, excludedSchemas, excludedNames, /* @__PURE__ */ new Set());
16966
+ walkAndInline(mergedSchemas, excludedSchemas, excludedNames, /* @__PURE__ */ new Set());
16917
16967
  for (const name of excludedNames) {
16918
16968
  delete mergedSchemas[name];
16919
16969
  }
@@ -388,7 +388,7 @@ function parseJSDocBlock(commentValue, filePath) {
388
388
  result.cookieType = extractTypeFromComment(normalizedComment, "@cookie");
389
389
  const authValue = extractLineValue(normalizedComment, "@auth");
390
390
  if (authValue) {
391
- result.auth = performAuthPresetReplacements(authValue);
391
+ result.auth = authValue;
392
392
  }
393
393
  const querystring = parseQuerystringTag(normalizedComment);
394
394
  if (querystring) {
@@ -1064,16 +1064,17 @@ var INTERNAL_OPENAPI_CONFIG_KEYS = [
1064
1064
  "next",
1065
1065
  "diagnostics",
1066
1066
  "debug",
1067
+ "authPresets",
1067
1068
  "excludeSchemas"
1068
1069
  ];
1069
- var AUTH_PRESET_REPLACEMENTS = {
1070
+ var DEFAULT_AUTH_PRESET_REPLACEMENTS = {
1070
1071
  bearer: "BearerAuth",
1071
1072
  basic: "BasicAuth",
1072
1073
  apikey: "ApiKeyAuth"
1073
1074
  };
1074
- function performAuthPresetReplacements(authValue) {
1075
+ function performAuthPresetReplacements(authValue, presets = DEFAULT_AUTH_PRESET_REPLACEMENTS) {
1075
1076
  const authParts = authValue.split(",").map((part) => part.trim());
1076
- const mappedParts = authParts.map((part) => AUTH_PRESET_REPLACEMENTS[part.toLowerCase()] || part);
1077
+ const mappedParts = authParts.map((part) => presets[part.toLowerCase()] || part);
1077
1078
  return mappedParts.join(",");
1078
1079
  }
1079
1080
  function getOperationId(routePath, method) {
@@ -1346,6 +1347,7 @@ function normalizeOpenApiConfig(template) {
1346
1347
  adapterPath: template.next?.adapterPath
1347
1348
  },
1348
1349
  diagnostics: template.diagnostics ?? { enabled: DEFAULT_DIAGNOSTICS_ENABLED },
1350
+ authPresets: { ...DEFAULT_AUTH_PRESET_REPLACEMENTS, ...template.authPresets },
1349
1351
  debug: template.debug ?? DEFAULT_DEBUG
1350
1352
  };
1351
1353
  }
@@ -1827,8 +1829,10 @@ function downgradeSchemaForOpenApi30(schema, mediaTypeName) {
1827
1829
  const nullableBranch = nextSchema.anyOf.find((item) => item.type === "null");
1828
1830
  const baseBranch = nextSchema.anyOf.find((item) => item.type !== "null");
1829
1831
  if (nullableBranch && baseBranch) {
1832
+ const { anyOf: _anyOf, ...outerMeta } = nextSchema;
1830
1833
  nextSchema = {
1831
1834
  ...structuredClone(baseBranch),
1835
+ ...outerMeta,
1832
1836
  nullable: true
1833
1837
  };
1834
1838
  }
@@ -3703,7 +3707,7 @@ function processZodLiteral(node, context) {
3703
3707
  return { type: "string", enum: [arg.value] };
3704
3708
  }
3705
3709
  if (t8.isNumericLiteral(arg)) {
3706
- return { type: "number", enum: [arg.value] };
3710
+ return { type: Number.isInteger(arg.value) ? "integer" : "number", enum: [arg.value] };
3707
3711
  }
3708
3712
  if (t8.isBooleanLiteral(arg)) {
3709
3713
  return { type: "boolean", enum: [arg.value] };
@@ -3719,7 +3723,7 @@ function processZodLiteral(node, context) {
3719
3723
  if (typeof value === "string")
3720
3724
  return { type: "string", enum: [value] };
3721
3725
  if (typeof value === "number")
3722
- return { type: "number", enum: [value] };
3726
+ return { type: Number.isInteger(value) ? "integer" : "number", enum: [value] };
3723
3727
  if (typeof value === "boolean")
3724
3728
  return { type: "boolean", enum: [value] };
3725
3729
  if (value === null)
@@ -3814,7 +3818,7 @@ function processZodTuple(node, processNode, context) {
3814
3818
  if (t8.isIdentifier(node.arguments[0]) && context?.resolveConstArrayValues) {
3815
3819
  const values = context.resolveConstArrayValues(node.arguments[0].name);
3816
3820
  if (values && values.length > 0) {
3817
- const prefixItems = values.map((value) => typeof value === "number" ? { type: "number", enum: [value] } : { type: "string", enum: [value] });
3821
+ const prefixItems = values.map((value) => typeof value === "number" ? { type: Number.isInteger(value) ? "integer" : "number", enum: [value] } : { type: "string", enum: [value] });
3818
3822
  return {
3819
3823
  type: "array",
3820
3824
  prefixItems,
@@ -3858,7 +3862,7 @@ function processZodUnion(node, processNode, context) {
3858
3862
  if (t8.isIdentifier(node.arguments[0]) && context?.resolveConstArrayValues) {
3859
3863
  const values = context.resolveConstArrayValues(node.arguments[0].name);
3860
3864
  if (values && values.length > 0) {
3861
- const type = typeof values[0] === "number" ? "number" : "string";
3865
+ const type = typeof values[0] === "number" ? Number.isInteger(values[0]) ? "integer" : "number" : "string";
3862
3866
  return { type, enum: values };
3863
3867
  }
3864
3868
  }
@@ -11305,8 +11309,17 @@ var ZodRuntimeExporter = class {
11305
11309
  return node.arguments[0] ? literal(this.buildLiteralValue(node.arguments[0])) : null;
11306
11310
  case "enum":
11307
11311
  return this.buildEnum(node);
11308
- case "array":
11309
- return node.arguments[0] && isProcessableNode(node.arguments[0]) ? array(this.buildSchema(node.arguments[0]) ?? unknown()) : array(unknown());
11312
+ case "array": {
11313
+ const arg = node.arguments[0];
11314
+ if (!arg || !isProcessableNode(arg)) {
11315
+ return array(unknown());
11316
+ }
11317
+ const itemSchema = this.buildSchema(arg);
11318
+ if (!itemSchema) {
11319
+ return null;
11320
+ }
11321
+ return array(itemSchema);
11322
+ }
11310
11323
  case "strictObject": {
11311
11324
  const base = this.buildObject(node);
11312
11325
  return base && typeof base.strict === "function" ? base.strict() : base;
@@ -11438,13 +11451,17 @@ var ZodRuntimeExporter = class {
11438
11451
  if (node.arguments.length === 0 || !t9.isArrayExpression(node.arguments[0])) {
11439
11452
  return tuple([]);
11440
11453
  }
11441
- const items = node.arguments[0].elements.flatMap((element) => {
11454
+ const items = [];
11455
+ for (const element of node.arguments[0].elements) {
11442
11456
  if (!isProcessableNode(element)) {
11443
- return [];
11457
+ return null;
11444
11458
  }
11445
11459
  const schema = this.buildSchema(element);
11446
- return schema ? [schema] : [];
11447
- });
11460
+ if (!schema) {
11461
+ return null;
11462
+ }
11463
+ items.push(schema);
11464
+ }
11448
11465
  return tuple(items);
11449
11466
  }
11450
11467
  buildTemplateLiteral(node) {
@@ -12056,7 +12073,12 @@ var ZodSchemaConverter = class {
12056
12073
  if (this.isZodSchema(path17.node.init)) {
12057
12074
  const schema = this.processZodNode(path17.node.init);
12058
12075
  if (schema) {
12059
- this.storeResolvedSchema(schemaName, schema);
12076
+ const overrideId = this.extractMetaIdFromNode(path17.node.init);
12077
+ if (overrideId) {
12078
+ this.applyMetaIdOverride(schemaName, schema, overrideId, filePath);
12079
+ } else {
12080
+ this.storeResolvedSchema(schemaName, schema);
12081
+ }
12060
12082
  }
12061
12083
  return;
12062
12084
  }
@@ -12399,8 +12421,15 @@ var ZodSchemaConverter = class {
12399
12421
  };
12400
12422
  switch (methodName) {
12401
12423
  case "optional":
12424
+ break;
12402
12425
  case "nullable":
12403
12426
  case "nullish":
12427
+ schema = {
12428
+ anyOf: [
12429
+ { $ref: `#/components/schemas/${this.getSchemaReferenceName(schemaName)}` },
12430
+ { type: "null" }
12431
+ ]
12432
+ };
12404
12433
  break;
12405
12434
  case "describe":
12406
12435
  if (node.arguments.length > 0 && t10.isStringLiteral(node.arguments[0])) {
@@ -12895,7 +12924,7 @@ var ZodSchemaConverter = class {
12895
12924
  return helperName.startsWith("coerce.") || helperName === "templateLiteral" || helperName === "stringbool";
12896
12925
  }
12897
12926
  if (t10.isMemberExpression(node.callee) && t10.isIdentifier(node.callee.property)) {
12898
- const runtimeMethods = /* @__PURE__ */ new Set(["pipe", "meta"]);
12927
+ const runtimeMethods = /* @__PURE__ */ new Set(["pipe"]);
12899
12928
  if (runtimeMethods.has(node.callee.property.name)) {
12900
12929
  return true;
12901
12930
  }
@@ -12918,12 +12947,16 @@ var ZodSchemaConverter = class {
12918
12947
  case "optional":
12919
12948
  break;
12920
12949
  case "nullable":
12921
- if (!schema.allOf) {
12950
+ if (schema.allOf) {
12951
+ schema = { anyOf: [...schema.allOf, { type: "null" }] };
12952
+ } else {
12922
12953
  schema.nullable = true;
12923
12954
  }
12924
12955
  break;
12925
12956
  case "nullish":
12926
- if (!schema.allOf) {
12957
+ if (schema.allOf) {
12958
+ schema = { anyOf: [...schema.allOf, { type: "null" }] };
12959
+ } else {
12927
12960
  schema.nullable = true;
12928
12961
  }
12929
12962
  break;
@@ -13068,15 +13101,13 @@ var ZodSchemaConverter = class {
13068
13101
  schema.type = "integer";
13069
13102
  break;
13070
13103
  case "positive":
13071
- schema.minimum = 0;
13072
- schema.exclusiveMinimum = true;
13104
+ schema.exclusiveMinimum = 0;
13073
13105
  break;
13074
13106
  case "nonnegative":
13075
13107
  schema.minimum = 0;
13076
13108
  break;
13077
13109
  case "negative":
13078
- schema.maximum = 0;
13079
- schema.exclusiveMaximum = true;
13110
+ schema.exclusiveMaximum = 0;
13080
13111
  break;
13081
13112
  case "nonpositive":
13082
13113
  schema.maximum = 0;
@@ -13438,6 +13469,9 @@ var ZodSchemaConverter = class {
13438
13469
  if (!this.getStoredSchema(schemaName)) {
13439
13470
  logger.debug(`Pre-processing Zod schema: ${schemaName}`);
13440
13471
  this.processingSchemas.add(schemaName);
13472
+ this.currentFilePath = filePath;
13473
+ this.currentAST = ast;
13474
+ this.currentImports = importedModules;
13441
13475
  const schema = this.processZodNode(declaration.init);
13442
13476
  this.processingSchemas.delete(schemaName);
13443
13477
  if (schema) {
@@ -13470,6 +13504,9 @@ var ZodSchemaConverter = class {
13470
13504
  if (!this.getStoredSchema(schemaName) && !this.processingSchemas.has(schemaName)) {
13471
13505
  logger.debug(`Pre-processing Zod schema: ${schemaName}`);
13472
13506
  this.processingSchemas.add(schemaName);
13507
+ this.currentFilePath = filePath;
13508
+ this.currentAST = ast;
13509
+ this.currentImports = importedModules;
13473
13510
  const schema = this.processZodNode(declaration.init);
13474
13511
  this.processingSchemas.delete(schemaName);
13475
13512
  if (schema) {
@@ -16340,11 +16377,16 @@ var ResponseProcessor = class {
16340
16377
  var OperationProcessor = class {
16341
16378
  schemaProcessor;
16342
16379
  responseProcessor;
16380
+ authPresets;
16343
16381
  performanceProfile;
16344
- constructor(schemaProcessor, responseProcessor, performanceProfile) {
16382
+ constructor(schemaProcessor, responseProcessor, options = {}) {
16345
16383
  this.schemaProcessor = schemaProcessor;
16346
16384
  this.responseProcessor = responseProcessor;
16347
- this.performanceProfile = performanceProfile;
16385
+ this.authPresets = {
16386
+ ...DEFAULT_AUTH_PRESET_REPLACEMENTS,
16387
+ ...options.authPresets
16388
+ };
16389
+ this.performanceProfile = options.performanceProfile;
16348
16390
  }
16349
16391
  processOperation(varName, routePath, dataTypes, pathParamNames = []) {
16350
16392
  const method = varName.toLowerCase();
@@ -16369,9 +16411,10 @@ var OperationProcessor = class {
16369
16411
  definition.deprecated = true;
16370
16412
  }
16371
16413
  if (explicitSecurity && explicitSecurity.length > 0) {
16372
- definition.security = explicitSecurity;
16414
+ definition.security = explicitSecurity.map((req) => Object.fromEntries(Object.entries(req).map(([scheme, scopes]) => [this.applyPreset(scheme), scopes])));
16373
16415
  } else if (auth) {
16374
- const authItems = auth.split(",").map((item) => item.trim());
16416
+ const mapped = performAuthPresetReplacements(auth, this.authPresets);
16417
+ const authItems = mapped.split(",").map((item) => item.trim());
16375
16418
  definition.security = authItems.map((authItem) => ({
16376
16419
  [authItem]: []
16377
16420
  }));
@@ -16584,6 +16627,9 @@ ${suffix}`;
16584
16627
  response.links[link.name] = linkObject;
16585
16628
  }
16586
16629
  }
16630
+ applyPreset(scheme) {
16631
+ return this.authPresets[scheme.toLowerCase()] ?? scheme;
16632
+ }
16587
16633
  createQuerystringParameter(dataTypes) {
16588
16634
  if (!dataTypes.querystringType) {
16589
16635
  return void 0;
@@ -16672,7 +16718,10 @@ var RouteProcessor = class {
16672
16718
  return new RegExp(`^${regexPattern}$`);
16673
16719
  });
16674
16720
  this.responseProcessor = new ResponseProcessor(this.config, this.schemaProcessor);
16675
- this.operationProcessor = new OperationProcessor(this.schemaProcessor, this.responseProcessor, this.performanceProfile);
16721
+ this.operationProcessor = new OperationProcessor(this.schemaProcessor, this.responseProcessor, {
16722
+ authPresets: this.config.authPresets,
16723
+ performanceProfile: this.performanceProfile
16724
+ });
16676
16725
  }
16677
16726
  processResponsesFromConfig(dataTypes, method) {
16678
16727
  return this.responseProcessor.processResponses(dataTypes, method);
@@ -16914,6 +16963,7 @@ function applyExcludeSchemas(document, mergedSchemas, excludedSchemas) {
16914
16963
  if (excludedNames.size === 0)
16915
16964
  return;
16916
16965
  walkAndInline(document, excludedSchemas, excludedNames, /* @__PURE__ */ new Set());
16966
+ walkAndInline(mergedSchemas, excludedSchemas, excludedNames, /* @__PURE__ */ new Set());
16917
16967
  for (const name of excludedNames) {
16918
16968
  delete mergedSchemas[name];
16919
16969
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-openapi-gen",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
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",