next-openapi-gen 1.2.3 → 1.4.0

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 CHANGED
@@ -588,121 +588,6 @@ import fse2 from "fs-extra";
588
588
  import path16 from "path";
589
589
  import fs12 from "fs";
590
590
 
591
- // ../openapi-core/dist/config/normalize.js
592
- function normalizeRouterType(routerType) {
593
- return routerType ?? DEFAULT_ROUTER_TYPE;
594
- }
595
- function normalizeSchemaTypes(schemaType) {
596
- const schemaBackends = Array.isArray(schemaType) ? schemaType : [schemaType ?? DEFAULT_RUNTIME_SCHEMA_TYPE];
597
- return [...new Set(schemaBackends)];
598
- }
599
- function normalizeOpenApiVersion(template) {
600
- if (template.openapi.startsWith("3.2")) {
601
- return "3.2";
602
- }
603
- if (template.openapi.startsWith("3.1")) {
604
- return "3.1";
605
- }
606
- if (template.openapi.startsWith("4.")) {
607
- return "4.0";
608
- }
609
- return DEFAULT_OPENAPI_VERSION;
610
- }
611
- function normalizeFrameworkKind(kind) {
612
- switch (kind) {
613
- case FrameworkKind.Nextjs:
614
- case "next":
615
- return FrameworkKind.Nextjs;
616
- case FrameworkKind.Tanstack:
617
- case "tanstack":
618
- return FrameworkKind.Tanstack;
619
- case FrameworkKind.ReactRouter:
620
- case "react-router":
621
- return FrameworkKind.ReactRouter;
622
- default:
623
- return FrameworkKind.Nextjs;
624
- }
625
- }
626
- function normalizeFramework(config2, routerType) {
627
- if (config2.framework) {
628
- const frameworkKind = normalizeFrameworkKind(config2.framework.kind);
629
- switch (frameworkKind) {
630
- case FrameworkKind.Nextjs:
631
- return {
632
- ...config2.framework,
633
- kind: frameworkKind,
634
- router: config2.framework.router || routerType,
635
- modulePath: config2.framework.modulePath || config2.framework.adapterPath || config2.next?.adapterPath,
636
- adapterPath: config2.framework.adapterPath || config2.next?.adapterPath
637
- };
638
- case FrameworkKind.Tanstack:
639
- case FrameworkKind.ReactRouter:
640
- return {
641
- ...config2.framework,
642
- kind: frameworkKind,
643
- modulePath: config2.framework.modulePath || config2.framework.adapterPath
644
- };
645
- }
646
- }
647
- return {
648
- kind: FrameworkKind.Nextjs,
649
- router: routerType,
650
- modulePath: config2.next?.adapterPath,
651
- adapterPath: config2.next?.adapterPath
652
- };
653
- }
654
- function normalizeOpenApiConfig(template) {
655
- const routerType = normalizeRouterType(template.routerType);
656
- const schemaBackends = normalizeSchemaTypes(template.schemaType);
657
- const openapiVersion = normalizeOpenApiVersion({
658
- openapi: "openapi" in template ? template.openapi || "3.0.0" : "3.0.0"
659
- });
660
- return {
661
- apiDir: template.apiDir ?? DEFAULT_API_DIR,
662
- routerType,
663
- schemaDir: template.schemaDir ?? DEFAULT_SCHEMA_DIR,
664
- docsUrl: template.docsUrl ?? DEFAULT_DOCS_URL,
665
- ui: template.ui ?? DEFAULT_UI,
666
- outputFile: template.outputFile ?? DEFAULT_GENERATED_OPENAPI_FILENAME,
667
- outputDir: template.outputDir ?? DEFAULT_OUTPUT_DIR,
668
- includeOpenApiRoutes: template.includeOpenApiRoutes ?? DEFAULT_INCLUDE_OPENAPI_ROUTES,
669
- ignoreRoutes: template.ignoreRoutes ?? [],
670
- schemaType: template.schemaType ?? DEFAULT_RUNTIME_SCHEMA_TYPE,
671
- schemaBackends,
672
- schemaFiles: template.schemaFiles ?? [],
673
- defaultResponseSet: template.defaultResponseSet,
674
- responseSets: template.responseSets,
675
- errorConfig: template.errorConfig,
676
- errorDefinitions: template.errorDefinitions,
677
- openapiVersion,
678
- framework: normalizeFramework(template, routerType),
679
- next: {
680
- adapterPath: template.next?.adapterPath
681
- },
682
- diagnostics: template.diagnostics ?? { enabled: DEFAULT_DIAGNOSTICS_ENABLED },
683
- debug: template.debug ?? DEFAULT_DEBUG
684
- };
685
- }
686
-
687
- // ../openapi-core/dist/diagnostics/collector.js
688
- var DiagnosticsCollector = class {
689
- diagnostics = [];
690
- add(diagnostic) {
691
- this.diagnostics.push(diagnostic);
692
- }
693
- getAll() {
694
- return [...this.diagnostics];
695
- }
696
- hasAny() {
697
- return this.diagnostics.length > 0;
698
- }
699
- };
700
-
701
- // ../openapi-core/dist/openapi/document.js
702
- function createDocumentFromTemplate(template) {
703
- return structuredClone(template);
704
- }
705
-
706
591
  // ../openapi-core/dist/shared/utils.js
707
592
  import { parse } from "@babel/parser";
708
593
  import * as t from "@babel/types";
@@ -1038,7 +923,7 @@ function parseJSDocBlock(commentValue, filePath) {
1038
923
  result.cookieType = extractTypeFromComment(normalizedComment, "@cookie");
1039
924
  const authValue = extractLineValue(normalizedComment, "@auth");
1040
925
  if (authValue) {
1041
- result.auth = performAuthPresetReplacements(authValue);
926
+ result.auth = authValue;
1042
927
  }
1043
928
  const querystring = parseQuerystringTag(normalizedComment);
1044
929
  if (querystring) {
@@ -1406,6 +1291,17 @@ function mergeJSDocData(target, source) {
1406
1291
  function cleanComment(commentValue) {
1407
1292
  return commentValue.replace(/\*\s*/g, "").trim();
1408
1293
  }
1294
+ function extractInternalFlagFromComments(comments) {
1295
+ if (!comments)
1296
+ return false;
1297
+ for (const comment of comments) {
1298
+ const cleaned = cleanComment(comment.value);
1299
+ if (/@internal\b/.test(cleaned) || /@schema\s+false\b/.test(cleaned)) {
1300
+ return true;
1301
+ }
1302
+ }
1303
+ return false;
1304
+ }
1409
1305
  function extractSchemaIdFromComments(comments) {
1410
1306
  if (!comments)
1411
1307
  return null;
@@ -1702,16 +1598,18 @@ var INTERNAL_OPENAPI_CONFIG_KEYS = [
1702
1598
  "framework",
1703
1599
  "next",
1704
1600
  "diagnostics",
1705
- "debug"
1601
+ "debug",
1602
+ "authPresets",
1603
+ "excludeSchemas"
1706
1604
  ];
1707
- var AUTH_PRESET_REPLACEMENTS = {
1605
+ var DEFAULT_AUTH_PRESET_REPLACEMENTS = {
1708
1606
  bearer: "BearerAuth",
1709
1607
  basic: "BasicAuth",
1710
1608
  apikey: "ApiKeyAuth"
1711
1609
  };
1712
- function performAuthPresetReplacements(authValue) {
1610
+ function performAuthPresetReplacements(authValue, presets = DEFAULT_AUTH_PRESET_REPLACEMENTS) {
1713
1611
  const authParts = authValue.split(",").map((part) => part.trim());
1714
- const mappedParts = authParts.map((part) => AUTH_PRESET_REPLACEMENTS[part.toLowerCase()] || part);
1612
+ const mappedParts = authParts.map((part) => presets[part.toLowerCase()] || part);
1715
1613
  return mappedParts.join(",");
1716
1614
  }
1717
1615
  function getOperationId(routePath, method) {
@@ -1729,6 +1627,123 @@ function parseTypeScriptFile(content, options) {
1729
1627
  });
1730
1628
  }
1731
1629
 
1630
+ // ../openapi-core/dist/config/normalize.js
1631
+ function normalizeRouterType(routerType) {
1632
+ return routerType ?? DEFAULT_ROUTER_TYPE;
1633
+ }
1634
+ function normalizeSchemaTypes(schemaType) {
1635
+ const schemaBackends = Array.isArray(schemaType) ? schemaType : [schemaType ?? DEFAULT_RUNTIME_SCHEMA_TYPE];
1636
+ return [...new Set(schemaBackends)];
1637
+ }
1638
+ function normalizeOpenApiVersion(template) {
1639
+ if (template.openapi.startsWith("3.2")) {
1640
+ return "3.2";
1641
+ }
1642
+ if (template.openapi.startsWith("3.1")) {
1643
+ return "3.1";
1644
+ }
1645
+ if (template.openapi.startsWith("4.")) {
1646
+ return "4.0";
1647
+ }
1648
+ return DEFAULT_OPENAPI_VERSION;
1649
+ }
1650
+ function normalizeFrameworkKind(kind) {
1651
+ switch (kind) {
1652
+ case FrameworkKind.Nextjs:
1653
+ case "next":
1654
+ return FrameworkKind.Nextjs;
1655
+ case FrameworkKind.Tanstack:
1656
+ case "tanstack":
1657
+ return FrameworkKind.Tanstack;
1658
+ case FrameworkKind.ReactRouter:
1659
+ case "react-router":
1660
+ return FrameworkKind.ReactRouter;
1661
+ default:
1662
+ return FrameworkKind.Nextjs;
1663
+ }
1664
+ }
1665
+ function normalizeFramework(config2, routerType) {
1666
+ if (config2.framework) {
1667
+ const frameworkKind = normalizeFrameworkKind(config2.framework.kind);
1668
+ switch (frameworkKind) {
1669
+ case FrameworkKind.Nextjs:
1670
+ return {
1671
+ ...config2.framework,
1672
+ kind: frameworkKind,
1673
+ router: config2.framework.router || routerType,
1674
+ modulePath: config2.framework.modulePath || config2.framework.adapterPath || config2.next?.adapterPath,
1675
+ adapterPath: config2.framework.adapterPath || config2.next?.adapterPath
1676
+ };
1677
+ case FrameworkKind.Tanstack:
1678
+ case FrameworkKind.ReactRouter:
1679
+ return {
1680
+ ...config2.framework,
1681
+ kind: frameworkKind,
1682
+ modulePath: config2.framework.modulePath || config2.framework.adapterPath
1683
+ };
1684
+ }
1685
+ }
1686
+ return {
1687
+ kind: FrameworkKind.Nextjs,
1688
+ router: routerType,
1689
+ modulePath: config2.next?.adapterPath,
1690
+ adapterPath: config2.next?.adapterPath
1691
+ };
1692
+ }
1693
+ function normalizeOpenApiConfig(template) {
1694
+ const routerType = normalizeRouterType(template.routerType);
1695
+ const schemaBackends = normalizeSchemaTypes(template.schemaType);
1696
+ const openapiVersion = normalizeOpenApiVersion({
1697
+ openapi: "openapi" in template ? template.openapi || "3.0.0" : "3.0.0"
1698
+ });
1699
+ return {
1700
+ apiDir: template.apiDir ?? DEFAULT_API_DIR,
1701
+ routerType,
1702
+ schemaDir: template.schemaDir ?? DEFAULT_SCHEMA_DIR,
1703
+ docsUrl: template.docsUrl ?? DEFAULT_DOCS_URL,
1704
+ ui: template.ui ?? DEFAULT_UI,
1705
+ outputFile: template.outputFile ?? DEFAULT_GENERATED_OPENAPI_FILENAME,
1706
+ outputDir: template.outputDir ?? DEFAULT_OUTPUT_DIR,
1707
+ includeOpenApiRoutes: template.includeOpenApiRoutes ?? DEFAULT_INCLUDE_OPENAPI_ROUTES,
1708
+ ignoreRoutes: template.ignoreRoutes ?? [],
1709
+ excludeSchemas: template.excludeSchemas ?? [],
1710
+ schemaType: template.schemaType ?? DEFAULT_RUNTIME_SCHEMA_TYPE,
1711
+ schemaBackends,
1712
+ schemaFiles: template.schemaFiles ?? [],
1713
+ defaultResponseSet: template.defaultResponseSet,
1714
+ responseSets: template.responseSets,
1715
+ errorConfig: template.errorConfig,
1716
+ errorDefinitions: template.errorDefinitions,
1717
+ openapiVersion,
1718
+ framework: normalizeFramework(template, routerType),
1719
+ next: {
1720
+ adapterPath: template.next?.adapterPath
1721
+ },
1722
+ diagnostics: template.diagnostics ?? { enabled: DEFAULT_DIAGNOSTICS_ENABLED },
1723
+ authPresets: { ...DEFAULT_AUTH_PRESET_REPLACEMENTS, ...template.authPresets },
1724
+ debug: template.debug ?? DEFAULT_DEBUG
1725
+ };
1726
+ }
1727
+
1728
+ // ../openapi-core/dist/diagnostics/collector.js
1729
+ var DiagnosticsCollector = class {
1730
+ diagnostics = [];
1731
+ add(diagnostic) {
1732
+ this.diagnostics.push(diagnostic);
1733
+ }
1734
+ getAll() {
1735
+ return [...this.diagnostics];
1736
+ }
1737
+ hasAny() {
1738
+ return this.diagnostics.length > 0;
1739
+ }
1740
+ };
1741
+
1742
+ // ../openapi-core/dist/openapi/document.js
1743
+ function createDocumentFromTemplate(template) {
1744
+ return structuredClone(template);
1745
+ }
1746
+
1732
1747
  // ../openapi-core/dist/openapi/version-processor.js
1733
1748
  var DefaultOpenApiVersionProcessor = class {
1734
1749
  id;
@@ -2187,8 +2202,10 @@ function downgradeSchemaForOpenApi30(schema, mediaTypeName) {
2187
2202
  const nullableBranch = nextSchema.anyOf.find((item) => item.type === "null");
2188
2203
  const baseBranch = nextSchema.anyOf.find((item) => item.type !== "null");
2189
2204
  if (nullableBranch && baseBranch) {
2205
+ const { anyOf: _anyOf, ...outerMeta } = nextSchema;
2190
2206
  nextSchema = {
2191
2207
  ...structuredClone(baseBranch),
2208
+ ...outerMeta,
2192
2209
  nullable: true
2193
2210
  };
2194
2211
  }
@@ -4103,7 +4120,7 @@ function processZodLiteral(node, context) {
4103
4120
  return { type: "string", enum: [arg.value] };
4104
4121
  }
4105
4122
  if (t8.isNumericLiteral(arg)) {
4106
- return { type: "number", enum: [arg.value] };
4123
+ return { type: Number.isInteger(arg.value) ? "integer" : "number", enum: [arg.value] };
4107
4124
  }
4108
4125
  if (t8.isBooleanLiteral(arg)) {
4109
4126
  return { type: "boolean", enum: [arg.value] };
@@ -4119,7 +4136,7 @@ function processZodLiteral(node, context) {
4119
4136
  if (typeof value === "string")
4120
4137
  return { type: "string", enum: [value] };
4121
4138
  if (typeof value === "number")
4122
- return { type: "number", enum: [value] };
4139
+ return { type: Number.isInteger(value) ? "integer" : "number", enum: [value] };
4123
4140
  if (typeof value === "boolean")
4124
4141
  return { type: "boolean", enum: [value] };
4125
4142
  if (value === null)
@@ -4214,7 +4231,7 @@ function processZodTuple(node, processNode, context) {
4214
4231
  if (t8.isIdentifier(node.arguments[0]) && context?.resolveConstArrayValues) {
4215
4232
  const values = context.resolveConstArrayValues(node.arguments[0].name);
4216
4233
  if (values && values.length > 0) {
4217
- const prefixItems = values.map((value) => typeof value === "number" ? { type: "number", enum: [value] } : { type: "string", enum: [value] });
4234
+ const prefixItems = values.map((value) => typeof value === "number" ? { type: Number.isInteger(value) ? "integer" : "number", enum: [value] } : { type: "string", enum: [value] });
4218
4235
  return {
4219
4236
  type: "array",
4220
4237
  prefixItems,
@@ -4258,7 +4275,7 @@ function processZodUnion(node, processNode, context) {
4258
4275
  if (t8.isIdentifier(node.arguments[0]) && context?.resolveConstArrayValues) {
4259
4276
  const values = context.resolveConstArrayValues(node.arguments[0].name);
4260
4277
  if (values && values.length > 0) {
4261
- const type = typeof values[0] === "number" ? "number" : "string";
4278
+ const type = typeof values[0] === "number" ? Number.isInteger(values[0]) ? "integer" : "number" : "string";
4262
4279
  return { type, enum: values };
4263
4280
  }
4264
4281
  }
@@ -11705,8 +11722,17 @@ var ZodRuntimeExporter = class {
11705
11722
  return node.arguments[0] ? literal(this.buildLiteralValue(node.arguments[0])) : null;
11706
11723
  case "enum":
11707
11724
  return this.buildEnum(node);
11708
- case "array":
11709
- return node.arguments[0] && isProcessableNode(node.arguments[0]) ? array(this.buildSchema(node.arguments[0]) ?? unknown()) : array(unknown());
11725
+ case "array": {
11726
+ const arg = node.arguments[0];
11727
+ if (!arg || !isProcessableNode(arg)) {
11728
+ return array(unknown());
11729
+ }
11730
+ const itemSchema = this.buildSchema(arg);
11731
+ if (!itemSchema) {
11732
+ return null;
11733
+ }
11734
+ return array(itemSchema);
11735
+ }
11710
11736
  case "strictObject": {
11711
11737
  const base = this.buildObject(node);
11712
11738
  return base && typeof base.strict === "function" ? base.strict() : base;
@@ -11838,13 +11864,17 @@ var ZodRuntimeExporter = class {
11838
11864
  if (node.arguments.length === 0 || !t9.isArrayExpression(node.arguments[0])) {
11839
11865
  return tuple([]);
11840
11866
  }
11841
- const items = node.arguments[0].elements.flatMap((element) => {
11867
+ const items = [];
11868
+ for (const element of node.arguments[0].elements) {
11842
11869
  if (!isProcessableNode(element)) {
11843
- return [];
11870
+ return null;
11844
11871
  }
11845
11872
  const schema = this.buildSchema(element);
11846
- return schema ? [schema] : [];
11847
- });
11873
+ if (!schema) {
11874
+ return null;
11875
+ }
11876
+ items.push(schema);
11877
+ }
11848
11878
  return tuple(items);
11849
11879
  }
11850
11880
  buildTemplateLiteral(node) {
@@ -12145,6 +12175,8 @@ var ZodSchemaConverter = class {
12145
12175
  /** Schema variable names whose component name was overridden via .meta({ id }). These must
12146
12176
  * NOT be copied back under the original variable name in the OpenAPI components object. */
12147
12177
  metaIdSchemaNames = /* @__PURE__ */ new Set();
12178
+ /** Schema variable names marked @internal — excluded from components/schemas output. */
12179
+ internalSchemaNames = /* @__PURE__ */ new Set();
12148
12180
  // Current processing context (set during file processing)
12149
12181
  currentFilePath;
12150
12182
  currentAST;
@@ -12454,7 +12486,12 @@ var ZodSchemaConverter = class {
12454
12486
  if (this.isZodSchema(path25.node.init)) {
12455
12487
  const schema = this.processZodNode(path25.node.init);
12456
12488
  if (schema) {
12457
- this.storeResolvedSchema(schemaName, schema);
12489
+ const overrideId = this.extractMetaIdFromNode(path25.node.init);
12490
+ if (overrideId) {
12491
+ this.applyMetaIdOverride(schemaName, schema, overrideId, filePath);
12492
+ } else {
12493
+ this.storeResolvedSchema(schemaName, schema);
12494
+ }
12458
12495
  }
12459
12496
  return;
12460
12497
  }
@@ -12797,8 +12834,15 @@ var ZodSchemaConverter = class {
12797
12834
  };
12798
12835
  switch (methodName) {
12799
12836
  case "optional":
12837
+ break;
12800
12838
  case "nullable":
12801
12839
  case "nullish":
12840
+ schema = {
12841
+ anyOf: [
12842
+ { $ref: `#/components/schemas/${this.getSchemaReferenceName(schemaName)}` },
12843
+ { type: "null" }
12844
+ ]
12845
+ };
12802
12846
  break;
12803
12847
  case "describe":
12804
12848
  if (node.arguments.length > 0 && t10.isStringLiteral(node.arguments[0])) {
@@ -13316,12 +13360,16 @@ var ZodSchemaConverter = class {
13316
13360
  case "optional":
13317
13361
  break;
13318
13362
  case "nullable":
13319
- if (!schema.allOf) {
13363
+ if (schema.allOf) {
13364
+ schema = { anyOf: [...schema.allOf, { type: "null" }] };
13365
+ } else {
13320
13366
  schema.nullable = true;
13321
13367
  }
13322
13368
  break;
13323
13369
  case "nullish":
13324
- if (!schema.allOf) {
13370
+ if (schema.allOf) {
13371
+ schema = { anyOf: [...schema.allOf, { type: "null" }] };
13372
+ } else {
13325
13373
  schema.nullable = true;
13326
13374
  }
13327
13375
  break;
@@ -13766,7 +13814,13 @@ var ZodSchemaConverter = class {
13766
13814
  * Get all processed Zod schemas
13767
13815
  */
13768
13816
  getProcessedSchemas() {
13769
- return this.zodSchemas;
13817
+ const result = {};
13818
+ for (const [name, schema] of Object.entries(this.zodSchemas)) {
13819
+ if (!this.internalSchemaNames.has(name)) {
13820
+ result[name] = schema;
13821
+ }
13822
+ }
13823
+ return result;
13770
13824
  }
13771
13825
  /**
13772
13826
  * Pre-scan all files to build type mappings
@@ -13818,9 +13872,21 @@ var ZodSchemaConverter = class {
13818
13872
  if (t10.isIdentifier(declaration.id) && declaration.init) {
13819
13873
  const schemaName = declaration.id.name;
13820
13874
  if (this.isZodSchema(declaration.init)) {
13875
+ const decl = path25.node.declaration;
13876
+ const allComments = [
13877
+ ...path25.node.leadingComments ?? [],
13878
+ ...decl?.leadingComments ?? [],
13879
+ ...declaration.leadingComments ?? []
13880
+ ];
13881
+ if (extractInternalFlagFromComments(allComments)) {
13882
+ this.internalSchemaNames.add(schemaName);
13883
+ }
13821
13884
  if (!this.getStoredSchema(schemaName)) {
13822
13885
  logger.debug(`Pre-processing Zod schema: ${schemaName}`);
13823
13886
  this.processingSchemas.add(schemaName);
13887
+ this.currentFilePath = filePath;
13888
+ this.currentAST = ast;
13889
+ this.currentImports = importedModules;
13824
13890
  const schema = this.processZodNode(declaration.init);
13825
13891
  this.processingSchemas.delete(schemaName);
13826
13892
  if (schema) {
@@ -13843,9 +13909,19 @@ var ZodSchemaConverter = class {
13843
13909
  if (t10.isIdentifier(declaration.id) && declaration.init) {
13844
13910
  const schemaName = declaration.id.name;
13845
13911
  if (this.isZodSchema(declaration.init)) {
13912
+ const allComments = [
13913
+ ...path25.node.leadingComments ?? [],
13914
+ ...declaration.leadingComments ?? []
13915
+ ];
13916
+ if (extractInternalFlagFromComments(allComments)) {
13917
+ this.internalSchemaNames.add(schemaName);
13918
+ }
13846
13919
  if (!this.getStoredSchema(schemaName) && !this.processingSchemas.has(schemaName)) {
13847
13920
  logger.debug(`Pre-processing Zod schema: ${schemaName}`);
13848
13921
  this.processingSchemas.add(schemaName);
13922
+ this.currentFilePath = filePath;
13923
+ this.currentAST = ast;
13924
+ this.currentImports = importedModules;
13849
13925
  const schema = this.processZodNode(declaration.init);
13850
13926
  this.processingSchemas.delete(schemaName);
13851
13927
  if (schema) {
@@ -14577,7 +14653,7 @@ function collectFirstMemberLeadingComments(interfaceDecl) {
14577
14653
  const firstMember = body.body?.[0];
14578
14654
  return firstMember?.leadingComments ?? [];
14579
14655
  }
14580
- function collectAllExportedDefinitions(ast, typeDefinitions, currentFile, schemaIdAliases) {
14656
+ function collectAllExportedDefinitions(ast, typeDefinitions, currentFile, schemaIdAliases, internalSchemaNames) {
14581
14657
  function registerDefinition(name, entry, allComments) {
14582
14658
  if (!typeDefinitions[name]) {
14583
14659
  typeDefinitions[name] = entry;
@@ -14589,6 +14665,9 @@ function collectAllExportedDefinitions(ast, typeDefinitions, currentFile, schema
14589
14665
  typeDefinitions[overrideId] = entry;
14590
14666
  }
14591
14667
  }
14668
+ if (internalSchemaNames && extractInternalFlagFromComments(allComments)) {
14669
+ internalSchemaNames.add(name);
14670
+ }
14592
14671
  }
14593
14672
  resolvedTraverse(ast, {
14594
14673
  TSTypeAliasDeclaration: (path25) => {
@@ -15068,6 +15147,7 @@ var SchemaProcessor = class {
15068
15147
  schemaTypes;
15069
15148
  isResolvingPickOmitBase = false;
15070
15149
  schemaIdAliases = {};
15150
+ internalSchemaNames = /* @__PURE__ */ new Set();
15071
15151
  fileAccess;
15072
15152
  symbolResolver;
15073
15153
  // Track imports per file for resolving ReturnType<typeof func>
@@ -15108,7 +15188,7 @@ var SchemaProcessor = class {
15108
15188
  getDefinedSchemas() {
15109
15189
  const filteredSchemas = {};
15110
15190
  Object.entries(this.openapiDefinitions).forEach(([key, value]) => {
15111
- if (!this.schemaIdAliases[key] && !this.isGenericTypeParameter(key) && !this.isInvalidSchemaName(key) && !this.isBuiltInUtilityType(key) && !this.isFunctionSchema(key)) {
15191
+ if (!this.schemaIdAliases[key] && !this.isGenericTypeParameter(key) && !this.isInvalidSchemaName(key) && !this.isBuiltInUtilityType(key) && !this.isFunctionSchema(key) && !this.internalSchemaNames.has(key)) {
15112
15192
  filteredSchemas[key] = value;
15113
15193
  }
15114
15194
  });
@@ -15118,6 +15198,22 @@ var SchemaProcessor = class {
15118
15198
  this.customSchemaProcessor.getDefinedSchemas()
15119
15199
  ]);
15120
15200
  }
15201
+ getInternalSchemas() {
15202
+ const result = {};
15203
+ for (const name of this.internalSchemaNames) {
15204
+ const def = this.openapiDefinitions[name];
15205
+ if (def)
15206
+ result[name] = def;
15207
+ }
15208
+ if (this.zodSchemaConverter) {
15209
+ for (const name of this.zodSchemaConverter.internalSchemaNames) {
15210
+ const schema = this.zodSchemaConverter.zodSchemas[name];
15211
+ if (schema)
15212
+ result[name] = schema;
15213
+ }
15214
+ }
15215
+ return result;
15216
+ }
15121
15217
  findSchemaDefinition(schemaName, contentType) {
15122
15218
  this.contentType = contentType;
15123
15219
  if (schemaName.includes("<") && schemaName.includes(">")) {
@@ -15268,7 +15364,7 @@ var SchemaProcessor = class {
15268
15364
  * Used when processing imported files to ensure all referenced types are available
15269
15365
  */
15270
15366
  collectAllExportedDefinitions(ast, filePath) {
15271
- collectAllExportedDefinitions(ast, this.typeDefinitions, filePath || this.currentFilePath, this.schemaIdAliases);
15367
+ collectAllExportedDefinitions(ast, this.typeDefinitions, filePath || this.currentFilePath, this.schemaIdAliases, this.internalSchemaNames);
15272
15368
  }
15273
15369
  collectTypeDefinitions(ast, schemaName, filePath) {
15274
15370
  collectTypeDefinitions(ast, schemaName, this.typeDefinitions, filePath || this.currentFilePath);
@@ -16696,11 +16792,16 @@ var ResponseProcessor = class {
16696
16792
  var OperationProcessor = class {
16697
16793
  schemaProcessor;
16698
16794
  responseProcessor;
16795
+ authPresets;
16699
16796
  performanceProfile;
16700
- constructor(schemaProcessor, responseProcessor, performanceProfile) {
16797
+ constructor(schemaProcessor, responseProcessor, options = {}) {
16701
16798
  this.schemaProcessor = schemaProcessor;
16702
16799
  this.responseProcessor = responseProcessor;
16703
- this.performanceProfile = performanceProfile;
16800
+ this.authPresets = {
16801
+ ...DEFAULT_AUTH_PRESET_REPLACEMENTS,
16802
+ ...options.authPresets
16803
+ };
16804
+ this.performanceProfile = options.performanceProfile;
16704
16805
  }
16705
16806
  processOperation(varName, routePath, dataTypes, pathParamNames = []) {
16706
16807
  const method = varName.toLowerCase();
@@ -16725,9 +16826,10 @@ var OperationProcessor = class {
16725
16826
  definition.deprecated = true;
16726
16827
  }
16727
16828
  if (explicitSecurity && explicitSecurity.length > 0) {
16728
- definition.security = explicitSecurity;
16829
+ definition.security = explicitSecurity.map((req) => Object.fromEntries(Object.entries(req).map(([scheme, scopes]) => [this.applyPreset(scheme), scopes])));
16729
16830
  } else if (auth) {
16730
- const authItems = auth.split(",").map((item) => item.trim());
16831
+ const mapped = performAuthPresetReplacements(auth, this.authPresets);
16832
+ const authItems = mapped.split(",").map((item) => item.trim());
16731
16833
  definition.security = authItems.map((authItem) => ({
16732
16834
  [authItem]: []
16733
16835
  }));
@@ -16940,6 +17042,9 @@ ${suffix}`;
16940
17042
  response.links[link.name] = linkObject;
16941
17043
  }
16942
17044
  }
17045
+ applyPreset(scheme) {
17046
+ return this.authPresets[scheme.toLowerCase()] ?? scheme;
17047
+ }
16943
17048
  createQuerystringParameter(dataTypes) {
16944
17049
  if (!dataTypes.querystringType) {
16945
17050
  return void 0;
@@ -17028,7 +17133,10 @@ var RouteProcessor = class {
17028
17133
  return new RegExp(`^${regexPattern}$`);
17029
17134
  });
17030
17135
  this.responseProcessor = new ResponseProcessor(this.config, this.schemaProcessor);
17031
- this.operationProcessor = new OperationProcessor(this.schemaProcessor, this.responseProcessor, this.performanceProfile);
17136
+ this.operationProcessor = new OperationProcessor(this.schemaProcessor, this.responseProcessor, {
17137
+ authPresets: this.config.authPresets,
17138
+ performanceProfile: this.performanceProfile
17139
+ });
17032
17140
  }
17033
17141
  processResponsesFromConfig(dataTypes, method) {
17034
17142
  return this.responseProcessor.processResponses(dataTypes, method);
@@ -17254,6 +17362,64 @@ function generateErrorResponsesFromConfig(document, errorConfig) {
17254
17362
  });
17255
17363
  }
17256
17364
 
17365
+ // ../openapi-core/dist/core/exclude-schemas.js
17366
+ function patternToRegExp(pattern) {
17367
+ const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
17368
+ return new RegExp(`^${escaped.replace(/\*/g, ".*")}$`);
17369
+ }
17370
+ function matchExcludePatterns(names, patterns) {
17371
+ if (patterns.length === 0)
17372
+ return [];
17373
+ const regexes = patterns.map(patternToRegExp);
17374
+ return names.filter((name) => regexes.some((re) => re.test(name)));
17375
+ }
17376
+ function applyExcludeSchemas(document, mergedSchemas, excludedSchemas) {
17377
+ const excludedNames = new Set(Object.keys(excludedSchemas));
17378
+ if (excludedNames.size === 0)
17379
+ return;
17380
+ walkAndInline(document, excludedSchemas, excludedNames, /* @__PURE__ */ new Set());
17381
+ for (const name of excludedNames) {
17382
+ delete mergedSchemas[name];
17383
+ }
17384
+ }
17385
+ function walkAndInline(obj, excluded, excludedNames, visiting) {
17386
+ if (!obj || typeof obj !== "object")
17387
+ return;
17388
+ if (Array.isArray(obj)) {
17389
+ for (const item of obj) {
17390
+ walkAndInline(item, excluded, excludedNames, visiting);
17391
+ }
17392
+ return;
17393
+ }
17394
+ const rec = obj;
17395
+ const ref = rec["$ref"];
17396
+ if (typeof ref === "string") {
17397
+ const match = ref.match(/^#\/components\/schemas\/(.+)$/);
17398
+ const name = match?.[1];
17399
+ if (name && excludedNames.has(name)) {
17400
+ if (visiting.has(name)) {
17401
+ logger.warn(`Circular reference to internal schema "${name}", keeping $ref`);
17402
+ return;
17403
+ }
17404
+ const schemaDef = excluded[name];
17405
+ if (schemaDef) {
17406
+ const cloned = JSON.parse(JSON.stringify(schemaDef));
17407
+ delete rec["$ref"];
17408
+ Object.assign(rec, cloned);
17409
+ const newVisiting = new Set(visiting);
17410
+ newVisiting.add(name);
17411
+ for (const key of Object.keys(rec)) {
17412
+ walkAndInline(rec[key], excluded, excludedNames, newVisiting);
17413
+ }
17414
+ return;
17415
+ }
17416
+ }
17417
+ }
17418
+ for (const key of Object.keys(rec)) {
17419
+ walkAndInline(rec[key], excluded, excludedNames, visiting);
17420
+ }
17421
+ }
17422
+
17257
17423
  // ../openapi-core/dist/core/orchestrator.js
17258
17424
  function runGenerationOrchestrator({ config: config2, template, hooks, runtime, createFrameworkSource }) {
17259
17425
  const diagnostics = new DiagnosticsCollector();
@@ -17324,11 +17490,21 @@ function runGenerationOrchestrator({ config: config2, template, hooks, runtime,
17324
17490
  }
17325
17491
  profile.defaultComponentsAndErrorsMs = performance.now() - phaseStartedAt;
17326
17492
  phaseStartedAt = performance.now();
17327
- const definedSchemas = routeProcessor.getSchemaProcessor().getDefinedSchemas();
17493
+ const schemaProcessor = routeProcessor.getSchemaProcessor();
17494
+ const definedSchemas = schemaProcessor.getDefinedSchemas();
17328
17495
  const mergedSchemas = {
17329
17496
  ...document.components.schemas,
17330
17497
  ...definedSchemas
17331
17498
  };
17499
+ const internalSchemas = schemaProcessor.getInternalSchemas();
17500
+ const patternExcludedNames = matchExcludePatterns(Object.keys(mergedSchemas), config2.excludeSchemas ?? []);
17501
+ const allExcludedSchemas = {
17502
+ ...internalSchemas,
17503
+ ...Object.fromEntries(patternExcludedNames.map((name) => [name, mergedSchemas[name]]))
17504
+ };
17505
+ if (Object.keys(allExcludedSchemas).length > 0) {
17506
+ applyExcludeSchemas(document, mergedSchemas, allExcludedSchemas);
17507
+ }
17332
17508
  if (Object.keys(mergedSchemas).length > 0) {
17333
17509
  document.components.schemas = Object.fromEntries(Object.entries(mergedSchemas).sort(([a], [b]) => a.localeCompare(b, "en", { sensitivity: "base" })));
17334
17510
  }