@kubb/core 5.14.3 → 5.14.5

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.
@@ -2286,9 +2286,9 @@ type Generator<TOptions extends PluginType = PluginType, TElement = unknown> = {
2286
2286
  */
2287
2287
  declare function defineGenerator<TOptions extends PluginType = PluginType, TElement = unknown>(generator: Generator<TOptions, TElement>): Generator<TOptions, TElement>;
2288
2288
  //#endregion
2289
- //#region src/Resolver.d.ts
2289
+ //#region src/resolveOptions.d.ts
2290
2290
  /**
2291
- * Context for resolving filtered options for a given operation or schema node.
2291
+ * Filters and overrides applied to an operation or schema's options.
2292
2292
  *
2293
2293
  * @internal
2294
2294
  */
@@ -2298,6 +2298,8 @@ type ResolveOptionsContext<TOptions> = {
2298
2298
  include?: Array<Filter>;
2299
2299
  override?: Array<Override<TOptions>>;
2300
2300
  };
2301
+ //#endregion
2302
+ //#region src/Resolver.d.ts
2301
2303
  /**
2302
2304
  * The built-in resolution machinery exposed on every resolver as `resolver.default`.
2303
2305
  * Plugins delegate to it via `this.default.*` and set their own conventions through
@@ -2520,6 +2522,19 @@ type ResolverBuildOptions = {
2520
2522
  name?: (name: string) => string;
2521
2523
  file?: ResolverFile;
2522
2524
  };
2525
+ /**
2526
+ * Reuse the declaration's key when resolving its references.
2527
+ */
2528
+ type ResolveNameOptions = {
2529
+ key: string | ReadonlyArray<string | undefined>;
2530
+ name: string;
2531
+ /**
2532
+ * Compares emitted identifiers while returning raw names. Keep numeric suffixes distinct.
2533
+ * Return several names when one declaration emits more than one identifier, such as an enum's
2534
+ * value and its type alias: the raw name is only taken when all of them are free.
2535
+ */
2536
+ normalize?: (name: string) => string | ReadonlyArray<string>;
2537
+ };
2523
2538
  /**
2524
2539
  * Partial resolver fields accepted by `Resolver.merge` and `setResolver`. Parameterize with a
2525
2540
  * concrete resolver type (e.g. `ResolverPatch<ResolverTs>`) to type-check overrides and bind
@@ -2572,6 +2587,35 @@ declare class Resolver {
2572
2587
  /** Exposes the raw build options so `Resolver.merge` can read them across `@kubb/core` copies. */
2573
2588
  get [resolverOptions](): ResolverBuildOptions;
2574
2589
  name(name: string): string;
2590
+ /**
2591
+ * Reserves emitted identifiers before allocating other declarations. The driver reserves component
2592
+ * names. Reserve extra identifiers, such as enum type aliases, before calling `resolveName`.
2593
+ *
2594
+ * @example Reserve an enum's type and value names
2595
+ * ```ts
2596
+ * resolver.reserveNames(['petStatusEnum', 'PetStatusEnumKey'])
2597
+ * ```
2598
+ */
2599
+ reserveNames(names: Iterable<string>): void;
2600
+ /**
2601
+ * Returns the same name for repeated declaration keys. Adds numeric suffixes starting at `2`
2602
+ * when the preferred name is taken. Array segment order and boundaries matter. String and array
2603
+ * keys are distinct. Pass an already-cased name or use `normalize` to compare emitted identifiers
2604
+ * while returning raw names. `Resolver.merge` creates a resolver with no reservations.
2605
+ *
2606
+ * @example Resolve a request body that collides with a component
2607
+ * ```ts
2608
+ * resolver.reserveNames(['CreateContainerBody'])
2609
+ * resolver.resolveName({ key: ['operation', 'POST', '/containers', 'body'], name: 'CreateContainerBody' })
2610
+ * // 'CreateContainerBody2'
2611
+ * ```
2612
+ *
2613
+ * @example Resolve a name that has to be free as both an enum value and a type alias
2614
+ * ```ts
2615
+ * resolver.resolveName({ key: ['enum', 'Pet', 'status'], name: 'Status', normalize: (name) => [camelCase(name), `${name}Key`] })
2616
+ * ```
2617
+ */
2618
+ resolveName({ key, name, normalize }: ResolveNameOptions): string;
2575
2619
  file(options: ResolveFileOptions): FileNode;
2576
2620
  /**
2577
2621
  * Builds one `ImportNode` per unique schema referenced in the tree, in first-occurrence
@@ -3132,7 +3176,8 @@ declare function defineExtension<TFactory extends PluginType = PluginType>(defin
3132
3176
  * input shape with paths resolved to absolute.
3133
3177
  *
3134
3178
  * - `{ type: 'path' }`: single file on disk.
3135
- * - `{ type: 'data' }`: raw string or parsed object provided inline.
3179
+ * - `{ type: 'data' }`: raw string or parsed object provided inline. `root` is the folder that
3180
+ * relative external `$ref`s in it resolve from.
3136
3181
  */
3137
3182
  type AdapterSource = {
3138
3183
  type: 'path';
@@ -3140,6 +3185,7 @@ type AdapterSource = {
3140
3185
  } | {
3141
3186
  type: 'data';
3142
3187
  data: string | unknown;
3188
+ root?: string;
3143
3189
  };
3144
3190
  /**
3145
3191
  * Generic parameters used by `defineExtension` with `kind: 'adapter'` and the resulting `Adapter` type.
@@ -3192,6 +3238,11 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
3192
3238
  * Parsed source document after the first `parse()` call. `null` before parsing.
3193
3239
  */
3194
3240
  document: TOptions['document'] | null;
3241
+ /**
3242
+ * The files and URLs the last `parse()` read, such as the ones external `$ref`s point at, including
3243
+ * any that could not be read. Inline data is not listed. A watcher rebuilds when one of them changes.
3244
+ */
3245
+ sources?: Array<string>;
3195
3246
  /**
3196
3247
  * Parse the source into a universal `InputNode`.
3197
3248
  *
@@ -3253,5 +3304,5 @@ type AdapterFactory<T extends AdapterFactoryOptions = AdapterFactoryOptions> = E
3253
3304
  */
3254
3305
  declare function createAdapter<T extends AdapterFactoryOptions = AdapterFactoryOptions>(definition: AdapterDefinition<T>): AdapterFactory<T>;
3255
3306
  //#endregion
3256
- export { NodeCache as $, ReporterContext as $t, PluginFactory as A, KubbInfoContext as At, ResolveImportsOptions as B, RunHookOptions as Bt, NormalizedPlugin as C, KubbGenerationEndContext as Ct, Override as D, KubbHookLineContext as Dt, OutputOptions as E, KubbHookEndContext as Et, definePlugin as F, KubbWarnContext as Ft, ResolverFile as G, createOutputManifest as Gt, ResolvePathOptions as H, KubbDriver as Ht, BannerMeta as I, PossibleConfig as It, ResolverPatch as J, createRenderer as Jt, ResolverFileParams as K, Renderer as Kt, ResolveBannerContext as L, PostGenerateCommand as Lt, PluginType as M, KubbMessageContext as Mt, ResolvePluginOptions as N, KubbPluginsEndContext as Nt, Plugin as O, KubbHookStartContext as Ot, assertPluginOption as P, KubbSuccessContext as Pt, defineGenerator as Q, Reporter as Qt, ResolveBannerFile as R, UserConfig as Rt, KubbPluginStartContext as S, KubbFilesProcessingUpdateContext as St, OutputMode as T, KubbGenerationSummaryContext as Tt, Resolver as U, Hookable as Ut, ResolveOptionsContext as V, runHook as Vt, ResolverDefault as W, OutputManifest as Wt, Generator as X, createStorage as Xt, ResolverPathParams as Y, Storage as Yt, GeneratorContext as Z, GenerationResult as Zt, Filter as _, KubbDiagnosticContext as _t, AdapterSource as a, DiagnosticFormatOptions as an, Diagnostics as at, KubbPluginEndContext as b, KubbFilesProcessingEndContext as bt, ExtensionDependency as c, ParserDefinition as cn, ProblemDiagnostic as ct, ExtensionKind as d, CLIOptions as dt, ReporterName as en, Diagnostic as et, ExtensionMeta as f, Config as ft, Exclude$1 as g, KubbBuildStartContext as gt, resolveMeta as h, KubbBuildEndContext as ht, AdapterFactoryOptions as i, logLevel as in, DiagnosticSeverity as it, PluginName as j, KubbLifecycleStartContext as jt, PluginDefinition as k, KubbHooks as kt, ExtensionDependencyRecord as l, ParserFactory as ln, UpdateDiagnostic as lt, defineExtension as m, Input as mt, AdapterDefinition as n, UserReporter as nn, DiagnosticKind as nt, createAdapter as o, SerializedDiagnostic as on, PerformanceDiagnostic as ot, checkCompatibility as p, FilesContext as pt, ResolverFilePathParams as q, RendererFactory as qt, AdapterFactory as r, createReporter as rn, DiagnosticLocation as rt, ExtensionDependencies as s, Parser as sn, ProblemCode as st, Adapter as t, ReporterPluginFiles as tn, DiagnosticDoc as tt, ExtensionFactory as u, defineParser as un, BuildOutput as ut, Group as v, KubbErrorContext as vt, Output as w, KubbGenerationStartContext as wt, KubbPluginSetupContext as x, KubbFilesProcessingStartContext as xt, Include as y, KubbFileProcessingUpdate as yt, ResolveFileOptions as z, HookResult as zt };
3257
- //# sourceMappingURL=createAdapter-DwnjwKN0.d.ts.map
3307
+ export { defineGenerator as $, Reporter as $t, PluginFactory as A, KubbHooks as At, ResolveImportsOptions as B, HookResult as Bt, NormalizedPlugin as C, KubbFilesProcessingUpdateContext as Ct, Override as D, KubbHookEndContext as Dt, OutputOptions as E, KubbGenerationSummaryContext as Et, definePlugin as F, KubbSuccessContext as Ft, ResolverFile as G, OutputManifest as Gt, ResolvePathOptions as H, runHook as Ht, BannerMeta as I, KubbWarnContext as It, ResolverPatch as J, RendererFactory as Jt, ResolverFileParams as K, createOutputManifest as Kt, ResolveBannerContext as L, PossibleConfig as Lt, PluginType as M, KubbLifecycleStartContext as Mt, ResolvePluginOptions as N, KubbMessageContext as Nt, Plugin as O, KubbHookLineContext as Ot, assertPluginOption as P, KubbPluginsEndContext as Pt, GeneratorContext as Q, GenerationResult as Qt, ResolveBannerFile as R, PostGenerateCommand as Rt, KubbPluginStartContext as S, KubbFilesProcessingStartContext as St, OutputMode as T, KubbGenerationStartContext as Tt, Resolver as U, KubbDriver as Ut, ResolveNameOptions as V, RunHookOptions as Vt, ResolverDefault as W, Hookable as Wt, ResolveOptionsContext as X, Storage as Xt, ResolverPathParams as Y, createRenderer as Yt, Generator as Z, createStorage as Zt, Filter as _, KubbBuildStartContext as _t, AdapterSource as a, logLevel as an, DiagnosticSeverity as at, KubbPluginEndContext as b, KubbFileProcessingUpdate as bt, ExtensionDependency as c, Parser as cn, ProblemCode as ct, ExtensionKind as d, defineParser as dn, BuildOutput as dt, ReporterContext as en, NodeCache as et, ExtensionMeta as f, CLIOptions as ft, Exclude$1 as g, KubbBuildEndContext as gt, resolveMeta as h, Input as ht, AdapterFactoryOptions as i, createReporter as in, DiagnosticLocation as it, PluginName as j, KubbInfoContext as jt, PluginDefinition as k, KubbHookStartContext as kt, ExtensionDependencyRecord as l, ParserDefinition as ln, ProblemDiagnostic as lt, defineExtension as m, FilesContext as mt, AdapterDefinition as n, ReporterPluginFiles as nn, DiagnosticDoc as nt, createAdapter as o, DiagnosticFormatOptions as on, Diagnostics as ot, checkCompatibility as p, Config as pt, ResolverFilePathParams as q, Renderer as qt, AdapterFactory as r, UserReporter as rn, DiagnosticKind as rt, ExtensionDependencies as s, SerializedDiagnostic as sn, PerformanceDiagnostic as st, Adapter as t, ReporterName as tn, Diagnostic as tt, ExtensionFactory as u, ParserFactory as un, UpdateDiagnostic as ut, Group as v, KubbDiagnosticContext as vt, Output as w, KubbGenerationEndContext as wt, KubbPluginSetupContext as x, KubbFilesProcessingEndContext as xt, Include as y, KubbErrorContext as yt, ResolveFileOptions as z, UserConfig as zt };
3308
+ //# sourceMappingURL=createAdapter-BD4waEKc.d.ts.map
package/dist/index.cjs CHANGED
@@ -42,7 +42,7 @@ let node_readline = require("node:readline");
42
42
  let node_url = require("node:url");
43
43
  let node_module = require("node:module");
44
44
  //#region package.json
45
- var version = "5.14.3";
45
+ var version = "5.14.5";
46
46
  //#endregion
47
47
  //#region ../../internals/utils/src/casing.ts
48
48
  /**
@@ -1694,7 +1694,8 @@ function isLegacyInput(input) {
1694
1694
  /**
1695
1695
  * Normalizes `config.input` into an `AdapterSource` the adapter can parse.
1696
1696
  *
1697
- * A parsed object and inline content become `{ type: 'data' }`; a URL or git input is kept
1697
+ * A parsed object and inline content become `{ type: 'data' }` with `config.root` as the folder
1698
+ * their relative `$ref`s resolve from; a URL or git input is kept
1698
1699
  * verbatim and a local path is resolved against `config.root`, all as `{ type: 'path' }`. The
1699
1700
  * driver checks out a git input before the adapter parses it.
1700
1701
  */
@@ -1716,12 +1717,14 @@ function inputToAdapterSource(config) {
1716
1717
  });
1717
1718
  if (typeof input !== "string") return {
1718
1719
  type: "data",
1719
- data: input
1720
+ data: input,
1721
+ root: (0, node_path.resolve)(config.root)
1720
1722
  };
1721
1723
  const kind = getInputKind(input);
1722
1724
  if (kind === "inline") return {
1723
1725
  type: "data",
1724
- data: input
1726
+ data: input,
1727
+ root: (0, node_path.resolve)(config.root)
1725
1728
  };
1726
1729
  if (kind === "url" || kind === "git") return {
1727
1730
  type: "path",
@@ -1733,6 +1736,75 @@ function inputToAdapterSource(config) {
1733
1736
  };
1734
1737
  }
1735
1738
  //#endregion
1739
+ //#region src/resolveOptions.ts
1740
+ const patternCache = /* @__PURE__ */ new Map();
1741
+ const optionsCache = /* @__PURE__ */ new WeakMap();
1742
+ function testPattern(value, pattern) {
1743
+ if (typeof pattern === "string") {
1744
+ let regex = patternCache.get(pattern);
1745
+ regex ??= new RegExp(pattern);
1746
+ patternCache.set(pattern, regex);
1747
+ return regex.test(value);
1748
+ }
1749
+ return value.match(pattern) !== null;
1750
+ }
1751
+ function matchesOperation(node, filter) {
1752
+ if (filter.type === "extension") {
1753
+ const { extensions } = node;
1754
+ return extensions !== void 0 && Object.hasOwn(extensions, filter.key) && (filter.value === void 0 || extensions[filter.key] === filter.value);
1755
+ }
1756
+ const { type, pattern } = filter;
1757
+ if (type === "tag") return node.tags.some((tag) => testPattern(tag, pattern));
1758
+ if (type === "operationId") return testPattern(node.operationId, pattern);
1759
+ if (type === "path") return node.path !== void 0 && testPattern(node.path, pattern);
1760
+ if (type === "method") return node.method !== void 0 && testPattern(node.method.toLowerCase(), pattern);
1761
+ if (type === "contentType") return node.requestBody?.content?.some((c) => testPattern(c.contentType, pattern)) ?? false;
1762
+ return false;
1763
+ }
1764
+ function matchesSchema(node, filter) {
1765
+ if (filter.type === "schemaName") return node.name ? testPattern(node.name, filter.pattern) : false;
1766
+ return null;
1767
+ }
1768
+ function computeOptions(node, { options, exclude = [], include, override = [] }) {
1769
+ if (node.kind === _kubb_ast.ast.nodeKinds.operation) {
1770
+ if (exclude.some((filter) => matchesOperation(node, filter))) return null;
1771
+ if (include && !include.some((filter) => matchesOperation(node, filter))) return null;
1772
+ return {
1773
+ ...options,
1774
+ ...override.find((filter) => matchesOperation(node, filter))?.options
1775
+ };
1776
+ }
1777
+ if (node.kind === _kubb_ast.ast.nodeKinds.schema) {
1778
+ if (exclude.some((filter) => matchesSchema(node, filter) === true)) return null;
1779
+ if (include) {
1780
+ const applicable = include.map((filter) => matchesSchema(node, filter)).filter((result) => result !== null);
1781
+ if (applicable.length > 0 && !applicable.includes(true)) return null;
1782
+ }
1783
+ return {
1784
+ ...options,
1785
+ ...override.find((filter) => matchesSchema(node, filter) === true)?.options
1786
+ };
1787
+ }
1788
+ return options;
1789
+ }
1790
+ /**
1791
+ * Returns `null` for filtered nodes. Caches merged options per options object and node.
1792
+ */
1793
+ function resolveOptions(node, context) {
1794
+ const { options } = context;
1795
+ if (typeof options !== "object" || options === null) return computeOptions(node, context);
1796
+ let byOptions = optionsCache.get(options);
1797
+ if (!byOptions) {
1798
+ byOptions = /* @__PURE__ */ new WeakMap();
1799
+ optionsCache.set(options, byOptions);
1800
+ }
1801
+ const cached = byOptions.get(node);
1802
+ if (cached) return cached.value;
1803
+ const result = computeOptions(node, context);
1804
+ byOptions.set(node, { value: result });
1805
+ return result;
1806
+ }
1807
+ //#endregion
1736
1808
  //#region src/Resolver.ts
1737
1809
  function isNamespace(value) {
1738
1810
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -1803,12 +1875,12 @@ function toBaseName({ name, extname }) {
1803
1875
  * ```
1804
1876
  */
1805
1877
  var Resolver = class Resolver {
1806
- static #patternCache = /* @__PURE__ */ new Map();
1807
- static #optionsCache = /* @__PURE__ */ new WeakMap();
1808
1878
  pluginName;
1809
1879
  /** The built-in machinery, untouched by `name`/`file` overrides and built once since the driver reads it per node. */
1810
1880
  default;
1811
1881
  #options;
1882
+ #usedNames = /* @__PURE__ */ new Set();
1883
+ #resolvedNames = /* @__PURE__ */ new Map();
1812
1884
  #baseName;
1813
1885
  #filePath;
1814
1886
  constructor(options) {
@@ -1818,7 +1890,7 @@ var Resolver = class Resolver {
1818
1890
  this.#filePath = options.file?.path ? options.file.path.bind(this) : void 0;
1819
1891
  this.default = {
1820
1892
  name: camelCase,
1821
- options: this.#resolveOptions.bind(this),
1893
+ options: resolveOptions,
1822
1894
  path: this.#resolvePath.bind(this),
1823
1895
  file: this.#resolveFile.bind(this),
1824
1896
  banner: this.#resolveBanner.bind(this),
@@ -1833,6 +1905,50 @@ var Resolver = class Resolver {
1833
1905
  name(name) {
1834
1906
  return this.default.name(name);
1835
1907
  }
1908
+ /**
1909
+ * Reserves emitted identifiers before allocating other declarations. The driver reserves component
1910
+ * names. Reserve extra identifiers, such as enum type aliases, before calling `resolveName`.
1911
+ *
1912
+ * @example Reserve an enum's type and value names
1913
+ * ```ts
1914
+ * resolver.reserveNames(['petStatusEnum', 'PetStatusEnumKey'])
1915
+ * ```
1916
+ */
1917
+ reserveNames(names) {
1918
+ for (const name of names) this.#usedNames.add(name);
1919
+ }
1920
+ /**
1921
+ * Returns the same name for repeated declaration keys. Adds numeric suffixes starting at `2`
1922
+ * when the preferred name is taken. Array segment order and boundaries matter. String and array
1923
+ * keys are distinct. Pass an already-cased name or use `normalize` to compare emitted identifiers
1924
+ * while returning raw names. `Resolver.merge` creates a resolver with no reservations.
1925
+ *
1926
+ * @example Resolve a request body that collides with a component
1927
+ * ```ts
1928
+ * resolver.reserveNames(['CreateContainerBody'])
1929
+ * resolver.resolveName({ key: ['operation', 'POST', '/containers', 'body'], name: 'CreateContainerBody' })
1930
+ * // 'CreateContainerBody2'
1931
+ * ```
1932
+ *
1933
+ * @example Resolve a name that has to be free as both an enum value and a type alias
1934
+ * ```ts
1935
+ * resolver.resolveName({ key: ['enum', 'Pet', 'status'], name: 'Status', normalize: (name) => [camelCase(name), `${name}Key`] })
1936
+ * ```
1937
+ */
1938
+ resolveName({ key, name, normalize = (name) => name }) {
1939
+ const cacheKey = JSON.stringify(key);
1940
+ const previous = this.#resolvedNames.get(cacheKey);
1941
+ if (previous !== void 0) return previous;
1942
+ const emitted = (value) => {
1943
+ const names = normalize(value);
1944
+ return typeof names === "string" ? [names] : names;
1945
+ };
1946
+ let result = name;
1947
+ for (let suffix = 2; emitted(result).some((emittedName) => this.#usedNames.has(emittedName)); suffix++) result = `${name}${suffix}`;
1948
+ this.reserveNames(emitted(result));
1949
+ this.#resolvedNames.set(cacheKey, result);
1950
+ return result;
1951
+ }
1836
1952
  file(options) {
1837
1953
  return this.#resolveFile(options);
1838
1954
  }
@@ -1903,76 +2019,6 @@ var Resolver = class Resolver {
1903
2019
  root[key] = isNamespace(value) ? Object.fromEntries(Object.entries(value).map(([method, member]) => [method, bind(member)])) : bind(value);
1904
2020
  }
1905
2021
  }
1906
- static #testPattern(value, pattern) {
1907
- if (typeof pattern === "string") {
1908
- let regex = Resolver.#patternCache.get(pattern);
1909
- regex ??= new RegExp(pattern);
1910
- Resolver.#patternCache.set(pattern, regex);
1911
- return regex.test(value);
1912
- }
1913
- return value.match(pattern) !== null;
1914
- }
1915
- static #matchesOperation(node, filter) {
1916
- if (filter.type === "extension") {
1917
- const { extensions } = node;
1918
- return extensions !== void 0 && Object.hasOwn(extensions, filter.key) && (filter.value === void 0 || extensions[filter.key] === filter.value);
1919
- }
1920
- const { type, pattern } = filter;
1921
- if (type === "tag") return node.tags.some((tag) => Resolver.#testPattern(tag, pattern));
1922
- if (type === "operationId") return Resolver.#testPattern(node.operationId, pattern);
1923
- if (type === "path") return node.path !== void 0 && Resolver.#testPattern(node.path, pattern);
1924
- if (type === "method") return node.method !== void 0 && Resolver.#testPattern(node.method.toLowerCase(), pattern);
1925
- if (type === "contentType") return node.requestBody?.content?.some((c) => Resolver.#testPattern(c.contentType, pattern)) ?? false;
1926
- return false;
1927
- }
1928
- /**
1929
- * Returns `null` when the filter type doesn't apply to schemas, so include rules built
1930
- * from operation filters (e.g. `tag`) don't exclude every schema.
1931
- */
1932
- static #matchesSchema(node, filter) {
1933
- if (filter.type === "schemaName") return node.name ? Resolver.#testPattern(node.name, filter.pattern) : false;
1934
- return null;
1935
- }
1936
- static #computeOptions(node, { options, exclude = [], include, override = [] }) {
1937
- if (node.kind === _kubb_ast.ast.nodeKinds.operation) {
1938
- if (exclude.some((filter) => Resolver.#matchesOperation(node, filter))) return null;
1939
- if (include && !include.some((filter) => Resolver.#matchesOperation(node, filter))) return null;
1940
- return {
1941
- ...options,
1942
- ...override.find((filter) => Resolver.#matchesOperation(node, filter))?.options
1943
- };
1944
- }
1945
- if (node.kind === _kubb_ast.ast.nodeKinds.schema) {
1946
- if (exclude.some((filter) => Resolver.#matchesSchema(node, filter) === true)) return null;
1947
- if (include) {
1948
- const applicable = include.map((filter) => Resolver.#matchesSchema(node, filter)).filter((result) => result !== null);
1949
- if (applicable.length > 0 && !applicable.includes(true)) return null;
1950
- }
1951
- return {
1952
- ...options,
1953
- ...override.find((filter) => Resolver.#matchesSchema(node, filter) === true)?.options
1954
- };
1955
- }
1956
- return options;
1957
- }
1958
- /**
1959
- * Applies include/exclude filters and merges matching override options, caching the result
1960
- * per `(options, node)` pair. Returns `null` when the node is filtered out.
1961
- */
1962
- #resolveOptions(node, context) {
1963
- const { options } = context;
1964
- if (typeof options !== "object" || options === null) return Resolver.#computeOptions(node, context);
1965
- let byOptions = Resolver.#optionsCache.get(options);
1966
- if (!byOptions) {
1967
- byOptions = /* @__PURE__ */ new WeakMap();
1968
- Resolver.#optionsCache.set(options, byOptions);
1969
- }
1970
- const cached = byOptions.get(node);
1971
- if (cached) return cached.value;
1972
- const result = Resolver.#computeOptions(node, context);
1973
- byOptions.set(node, { value: result });
1974
- return result;
1975
- }
1976
2022
  /**
1977
2023
  * A custom `group.name` wins; otherwise `tag` groups use the camelCased tag and `path`
1978
2024
  * groups use the first non-traversal segment (`''` when none remain, placing the file in
@@ -3002,6 +3048,7 @@ var KubbDriver = class {
3002
3048
  optionsAreStatic: !exclude?.length && !include?.length && !override?.length,
3003
3049
  allowedSchemaNames: allowedSchemaNamesByPlugin.get(plugin.name) ?? null,
3004
3050
  schemaGenerators: generators.filter((generator) => generator.schema),
3051
+ schemas: /* @__PURE__ */ new Map(),
3005
3052
  operationGenerators: generators.filter((generator) => generator.operation),
3006
3053
  operationsGenerators: generators.filter((generator) => generator.operations),
3007
3054
  pluginOperations: [],
@@ -3027,15 +3074,29 @@ var KubbDriver = class {
3027
3074
  options
3028
3075
  };
3029
3076
  };
3077
+ for (const state of states) {
3078
+ if (!state.schemaGenerators.length) continue;
3079
+ for (const node of schemas) try {
3080
+ const resolved = resolveForPlugin(state, node);
3081
+ if (!resolved) continue;
3082
+ const name = resolved.transformedNode.name;
3083
+ if (state.allowedSchemaNames !== null && name && !state.allowedSchemaNames.has(name)) continue;
3084
+ state.schemas.set(node, resolved);
3085
+ if (name) state.generatorContext.resolver.reserveNames([state.generatorContext.resolver.name(name)]);
3086
+ } catch (caughtError) {
3087
+ state.schemas.set(node, toError(caughtError));
3088
+ break;
3089
+ }
3090
+ }
3030
3091
  for (const node of schemas) {
3031
3092
  const cache = createNodeCache();
3032
3093
  for (const state of states) {
3033
3094
  if (state.error || !state.schemaGenerators.length) continue;
3034
3095
  try {
3035
- const resolved = resolveForPlugin(state, node);
3096
+ const resolved = state.schemas.get(node);
3097
+ if (resolved instanceof Error) throw resolved;
3036
3098
  if (!resolved) continue;
3037
3099
  const { transformedNode, options } = resolved;
3038
- if (state.allowedSchemaNames !== null && transformedNode.name && !state.allowedSchemaNames.has(transformedNode.name)) continue;
3039
3100
  const ctx = {
3040
3101
  ...state.generatorContext,
3041
3102
  options,