@contractkit/plugin-bruno 1.5.1 → 1.5.3

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.
@@ -23,16 +23,16 @@
23
23
  <div class='clearfix'>
24
24
 
25
25
  <div class='fl pad1y space-right2'>
26
- <span class="strong">80.27% </span>
26
+ <span class="strong">80.82% </span>
27
27
  <span class="quiet">Statements</span>
28
- <span class='fraction'>346/431</span>
28
+ <span class='fraction'>354/438</span>
29
29
  </div>
30
30
 
31
31
 
32
32
  <div class='fl pad1y space-right2'>
33
- <span class="strong">74.19% </span>
33
+ <span class="strong">75.07% </span>
34
34
  <span class="quiet">Branches</span>
35
- <span class='fraction'>253/341</span>
35
+ <span class='fraction'>259/345</span>
36
36
  </div>
37
37
 
38
38
 
@@ -44,9 +44,9 @@
44
44
 
45
45
 
46
46
  <div class='fl pad1y space-right2'>
47
- <span class="strong">80.68% </span>
47
+ <span class="strong">81.34% </span>
48
48
  <span class="quiet">Lines</span>
49
- <span class='fraction'>305/378</span>
49
+ <span class='fraction'>314/386</span>
50
50
  </div>
51
51
 
52
52
 
@@ -80,17 +80,17 @@
80
80
  </thead>
81
81
  <tbody><tr>
82
82
  <td class="file high" data-value="codegen-bruno.ts"><a href="codegen-bruno.ts.html">codegen-bruno.ts</a></td>
83
- <td data-value="88.26" class="pic high">
83
+ <td data-value="88.74" class="pic high">
84
84
  <div class="chart"><div class="cover-fill" style="width: 88%"></div><div class="cover-empty" style="width: 12%"></div></div>
85
85
  </td>
86
- <td data-value="88.26" class="pct high">88.26%</td>
87
- <td data-value="375" class="abs high">331/375</td>
88
- <td data-value="78.1" class="pct medium">78.1%</td>
89
- <td data-value="306" class="abs medium">239/306</td>
86
+ <td data-value="88.74" class="pct high">88.74%</td>
87
+ <td data-value="382" class="abs high">339/382</td>
88
+ <td data-value="79.03" class="pct medium">79.03%</td>
89
+ <td data-value="310" class="abs medium">245/310</td>
90
90
  <td data-value="93.22" class="pct high">93.22%</td>
91
91
  <td data-value="59" class="abs high">55/59</td>
92
- <td data-value="89.29" class="pct high">89.29%</td>
93
- <td data-value="327" class="abs high">292/327</td>
92
+ <td data-value="89.85" class="pct high">89.85%</td>
93
+ <td data-value="335" class="abs high">301/335</td>
94
94
  </tr>
95
95
 
96
96
  <tr>
@@ -116,7 +116,7 @@
116
116
  <div class='footer quiet pad2 space-top1 center small'>
117
117
  Code coverage generated by
118
118
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
119
- at 2026-05-08T13:02:59.392Z
119
+ at 2026-05-13T17:08:51.342Z
120
120
  </div>
121
121
  <script src="../prettify.js"></script>
122
122
  <script>
@@ -694,7 +694,7 @@ function <span class="fstat-no" title="function not covered" >deleteStalePaths(o
694
694
  <div class='footer quiet pad2 space-top1 center small'>
695
695
  Code coverage generated by
696
696
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
697
- at 2026-05-08T13:02:59.392Z
697
+ at 2026-05-13T17:08:51.342Z
698
698
  </div>
699
699
  <script src="../prettify.js"></script>
700
700
  <script>
@@ -266,7 +266,7 @@
266
266
  <span class="cline-any cline-neutral">&nbsp;</span>
267
267
  <span class="cline-any cline-neutral">&nbsp;</span>
268
268
  <span class="cline-any cline-neutral">&nbsp;</span>
269
- <span class="cline-any cline-yes">288x</span>
269
+ <span class="cline-any cline-yes">300x</span>
270
270
  <span class="cline-any cline-neutral">&nbsp;</span>
271
271
  <span class="cline-any cline-neutral">&nbsp;</span>
272
272
  <span class="cline-any cline-neutral">&nbsp;</span>
@@ -384,10 +384,10 @@
384
384
  <span class="cline-any cline-neutral">&nbsp;</span>
385
385
  <span class="cline-any cline-neutral">&nbsp;</span>
386
386
  <span class="cline-any cline-neutral">&nbsp;</span>
387
- <span class="cline-any cline-yes">115x</span>
388
- <span class="cline-any cline-yes">115x</span>
389
- <span class="cline-any cline-yes">115x</span>
390
- <span class="cline-any cline-yes">115x</span>
387
+ <span class="cline-any cline-yes">121x</span>
388
+ <span class="cline-any cline-yes">121x</span>
389
+ <span class="cline-any cline-yes">121x</span>
390
+ <span class="cline-any cline-yes">121x</span>
391
391
  <span class="cline-any cline-neutral">&nbsp;</span>
392
392
  <span class="cline-any cline-neutral">&nbsp;</span>
393
393
  <span class="cline-any cline-neutral">&nbsp;</span>
@@ -402,12 +402,12 @@
402
402
  <span class="cline-any cline-neutral">&nbsp;</span>
403
403
  <span class="cline-any cline-neutral">&nbsp;</span>
404
404
  <span class="cline-any cline-neutral">&nbsp;</span>
405
- <span class="cline-any cline-yes">104x</span>
406
- <span class="cline-any cline-yes">104x</span>
405
+ <span class="cline-any cline-yes">110x</span>
406
+ <span class="cline-any cline-yes">110x</span>
407
407
  <span class="cline-any cline-neutral">&nbsp;</span>
408
408
  <span class="cline-any cline-neutral">&nbsp;</span>
409
409
  <span class="cline-any cline-neutral">&nbsp;</span>
410
- <span class="cline-any cline-yes">101x</span>
410
+ <span class="cline-any cline-yes">107x</span>
411
411
  <span class="cline-any cline-neutral">&nbsp;</span>
412
412
  <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">import type {
413
413
  ContractRootNode,
@@ -589,7 +589,7 @@ export function opRoot(routes: OpRouteNode[], file = 'users.op', meta: Record&lt
589
589
  <div class='footer quiet pad2 space-top1 center small'>
590
590
  Code coverage generated by
591
591
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
592
- at 2026-05-08T13:02:59.392Z
592
+ at 2026-05-13T17:08:51.342Z
593
593
  </div>
594
594
  <script src="../prettify.js"></script>
595
595
  <script>
@@ -101,7 +101,7 @@
101
101
  <div class='footer quiet pad2 space-top1 center small'>
102
102
  Code coverage generated by
103
103
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
104
- at 2026-05-08T13:02:59.392Z
104
+ at 2026-05-13T17:08:51.342Z
105
105
  </div>
106
106
  <script src="../prettify.js"></script>
107
107
  <script>
@@ -1 +1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EAC9B,YAAY,EAAE,mBAAmB,EACjC,UAAU,GAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAoB,GAC3D,iBAAiB,CA8EnB;AAkHD,uGAAuG;AACvG,wBAAgB,aAAa,IAAI,mBAAmB,CAEnD;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,mBAAmB,CAmBlE;AAsBD;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,MAAM,CAOxF;AA2cD,wEAAwE;AACxE,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMhD;AAED,uEAAuE;AACvE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CASjD"}
package/dist/index.js CHANGED
@@ -34,23 +34,33 @@ function generateOpenCollectionIncremental(roots, options, prevManifest, fileExi
34
34
  return (a.meta["subarea"] ?? "").localeCompare(b.meta["subarea"] ?? "");
35
35
  });
36
36
  const units = [];
37
- for (let rootIdx = 0; rootIdx < sortedRoots.length; rootIdx++) {
38
- const root = sortedRoots[rootIdx];
37
+ const emittedFolders = /* @__PURE__ */ new Set();
38
+ let areaSeq = 0;
39
+ for (const root of sortedRoots) {
39
40
  const folder = root.meta["area"] ? slugifyName(root.meta["area"]) : deriveFolderName(root.file);
40
- const displayName = (root.meta["area"] ?? folder).charAt(0).toUpperCase() + (root.meta["area"] ?? folder).slice(1);
41
- globalFiles.push({
42
- relativePath: `${folder}/folder.yml`,
43
- content: generateFolderFile(displayName, rootIdx + 1)
44
- });
41
+ const folderRel = `${folder}/folder.yml`;
42
+ if (!emittedFolders.has(folderRel)) {
43
+ const displayName = (root.meta["area"] ?? folder).charAt(0).toUpperCase() + (root.meta["area"] ?? folder).slice(1);
44
+ areaSeq++;
45
+ globalFiles.push({
46
+ relativePath: folderRel,
47
+ content: generateFolderFile(displayName, areaSeq)
48
+ });
49
+ emittedFolders.add(folderRel);
50
+ }
45
51
  const subarea = root.meta["subarea"];
46
52
  const subareaSlug = subarea ? slugifyName(subarea) : void 0;
47
53
  const requestDir = subareaSlug ? `${folder}/${subareaSlug}` : folder;
48
54
  if (subareaSlug) {
49
- const subareaDisplayName = subarea.charAt(0).toUpperCase() + subarea.slice(1);
50
- globalFiles.push({
51
- relativePath: `${requestDir}/folder.yml`,
52
- content: generateFolderFile(subareaDisplayName, 1)
53
- });
55
+ const subareaRel = `${requestDir}/folder.yml`;
56
+ if (!emittedFolders.has(subareaRel)) {
57
+ const subareaDisplayName = subarea.charAt(0).toUpperCase() + subarea.slice(1);
58
+ globalFiles.push({
59
+ relativePath: subareaRel,
60
+ content: generateFolderFile(subareaDisplayName, 1)
61
+ });
62
+ emittedFolders.add(subareaRel);
63
+ }
54
64
  }
55
65
  for (const entry of buildOpEntries(root, requestDir, includeInternal)) {
56
66
  units.push({
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/codegen-bruno.ts"],"sourcesContent":["import { resolve, basename, dirname } from 'node:path';\nimport { existsSync, readFileSync, writeFileSync, mkdirSync, rmSync, readdirSync, rmdirSync } from 'node:fs';\nimport { generateOpenCollectionIncremental, parseManifest, emptyManifest } from './codegen-bruno.js';\nimport type { BrunoSecurityScheme } from './codegen-bruno.js';\nimport { serializeIncrementalManifest } from '@contractkit/core';\nimport type { ContractKitPlugin, PluginContext, PluginValue, OpRootNode, ContractRootNode, IncrementalManifest } from '@contractkit/core';\n\n/** Filename for the persisted Bruno manifest under the CLI cache directory. */\nconst CACHE_MANIFEST_FILENAME = 'bruno-manifest.json';\n\n/** Configuration accepted by the Bruno plugin, both via `contractkit.config.json` and `createBrunoPlugin`. */\nexport interface BrunoPluginConfig {\n baseDir?: string;\n output?: string;\n collectionName?: string;\n /**\n * When true (default), example values use Bruno's faker templates\n * (`{{$randomUUID}}`, `{{$randomEmail}}`, etc.) so each send produces\n * fresh data. Set to false for deterministic placeholders.\n */\n randomExamples?: boolean;\n /**\n * Whether to generate request files for operations marked `internal`. Defaults to\n * `true` — Bruno collections are typically used by the team that owns the API and\n * benefit from full coverage. Set to `false` to omit internal ops.\n */\n includeInternal?: boolean;\n /**\n * Map of environment name → variables. Each entry produces a\n * `environments/<name>.yml` file. When omitted, a default `local.yml` is\n * emitted with `baseUrl=http://localhost:3000` and any auth env-var\n * placeholders. When provided, the default is replaced entirely; include\n * auth variables (e.g. `token`) explicitly if you need them.\n */\n environments?: Record<string, Record<string, unknown>>;\n}\n\n/** Full plugin options shape read from `ctx.options` — extends {@link BrunoPluginConfig} with the `auth` block. */\nexport interface BrunoPluginOptions extends BrunoPluginConfig {\n auth?: { defaultScheme: string; schemes?: Record<string, BrunoSecurityScheme> };\n}\n\n// ─── Default export: loaded via plugins array, reads config from ctx.options ─\n\n/**\n * Validates a `plugins.bruno` extension entry on an operation. The expected shape is\n * `{ template?: string }`, where `template` is a YAML fragment to deep-merge into the\n * generated request file (typically a `file://...` URL whose contents have already\n * been loaded by the CLI resolver).\n */\nexport function validateBrunoExtension(value: PluginValue): { errors?: string[] } | void {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return { errors: [`expected an object, got ${describe(value)}`] };\n }\n const errors: string[] = [];\n for (const [key, val] of Object.entries(value)) {\n if (key === 'template') {\n if (typeof val !== 'string') errors.push(`'template' must be a string, got ${describe(val)}`);\n } else {\n errors.push(`unknown field '${key}' (allowed: template)`);\n }\n }\n return errors.length ? { errors } : undefined;\n}\n\nfunction describe(value: PluginValue): string {\n if (value === null) return 'null';\n if (Array.isArray(value)) return 'array';\n return typeof value;\n}\n\nconst plugin: ContractKitPlugin = {\n name: 'bruno',\n validateExtension: validateBrunoExtension,\n async generateTargets({ opRoots, contractRoots }, ctx) {\n const { auth, ...config } = ctx.options as BrunoPluginOptions;\n await runBrunoCodegen(opRoots, contractRoots, ctx, config, auth);\n },\n};\n\nexport default plugin;\n\n// ─── Factory: for programmatic use with explicit config ────────────────────\n\n/**\n * Creates a Bruno plugin instance with explicit configuration, for programmatic use.\n *\n * Prefer the default export when loading via `contractkit.config.json`. Use this\n * factory when constructing the plugin in code (e.g. in tests or custom build scripts).\n *\n * @param config - Plugin configuration (output paths and feature flags).\n * @param rootDir - Absolute path used to resolve relative paths in `config`.\n * @param auth - Optional auth scheme configuration mirroring the `auth` key in plugin options.\n */\nexport function createBrunoPlugin(\n config: BrunoPluginConfig,\n rootDir: string,\n auth?: { defaultScheme: string; schemes?: Record<string, BrunoSecurityScheme> },\n): ContractKitPlugin {\n return {\n name: 'bruno',\n validateExtension: validateBrunoExtension,\n async generateTargets({ opRoots, contractRoots }, ctx) {\n // The factory captures rootDir at creation time; ctx.rootDir may differ when the\n // plugin is loaded via a config file, so respect the explicit one passed in here.\n await runBrunoCodegen(opRoots, contractRoots, { ...ctx, rootDir }, config, auth);\n },\n };\n}\n\n/**\n * Shared orchestration used by both the default export and {@link createBrunoPlugin}.\n *\n * Reads the prior manifest, runs the cache-aware codegen, deletes any files that\n * are no longer produced, and emits the changed files plus the new manifest. When\n * `ctx.cacheEnabled` is `false` (e.g. `--force`) the prior manifest is ignored so\n * every op regenerates.\n */\nasync function runBrunoCodegen(\n opRoots: OpRootNode[],\n contractRoots: ContractRootNode[],\n ctx: PluginContext,\n config: BrunoPluginConfig,\n auth: BrunoPluginOptions['auth'],\n): Promise<void> {\n const base = config.baseDir ? resolve(ctx.rootDir, config.baseDir) : ctx.rootDir;\n const outDir = resolve(base, config.output ?? 'bruno-collection');\n const collectionName = config.collectionName ?? basename(ctx.rootDir);\n const manifestPath = resolve(ctx.cacheDir, CACHE_MANIFEST_FILENAME);\n\n const prevManifest: IncrementalManifest = ctx.cacheEnabled ? readManifest(manifestPath) : emptyManifest();\n\n const result = generateOpenCollectionIncremental(\n opRoots,\n {\n collectionName,\n contractRoots,\n auth,\n randomExamples: config.randomExamples ?? true,\n includeInternal: config.includeInternal,\n environments: config.environments,\n },\n prevManifest,\n relPath => existsSync(resolve(outDir, relPath)),\n );\n\n deleteStalePaths(outDir, result.deletedPaths);\n\n for (const { relativePath, content } of result.filesToWrite) {\n ctx.emitFile(resolve(outDir, relativePath), content);\n }\n\n // Persist the manifest under the CLI cache dir, separate from the bruno output.\n writeManifest(manifestPath, result.manifest);\n}\n\n/** Read the previous run's manifest from `manifestPath`. Returns an empty manifest when missing or unreadable. */\nfunction readManifest(manifestPath: string): IncrementalManifest {\n if (!existsSync(manifestPath)) return emptyManifest();\n try {\n return parseManifest(readFileSync(manifestPath, 'utf-8'));\n } catch {\n return emptyManifest();\n }\n}\n\n/** Write the manifest to `manifestPath`. Creates parent dirs as needed. Errors are swallowed so a broken cache never blocks the build. */\nfunction writeManifest(manifestPath: string, manifest: IncrementalManifest): void {\n try {\n mkdirSync(dirname(manifestPath), { recursive: true });\n writeFileSync(manifestPath, serializeIncrementalManifest(manifest), 'utf-8');\n } catch {\n // best-effort\n }\n}\n\n/**\n * Delete files that the previous run tracked but the current run doesn't produce, then\n * walk back up each affected directory and remove it if it's now empty (stopping at outDir).\n * Anything user-added survives because the manifest only ever lists plugin-generated paths.\n */\nfunction deleteStalePaths(outDir: string, relPaths: string[]): void {\n if (relPaths.length === 0) return;\n const removedDirs = new Set<string>();\n for (const rel of relPaths) {\n const abs = resolve(outDir, rel);\n if (existsSync(abs)) {\n rmSync(abs, { force: true });\n removedDirs.add(dirname(abs));\n }\n }\n for (const dir of removedDirs) {\n let current = dir;\n while (current.startsWith(outDir) && current !== outDir) {\n try {\n if (readdirSync(current).length === 0) {\n rmdirSync(current);\n current = dirname(current);\n } else {\n break;\n }\n } catch {\n break;\n }\n }\n }\n}\n\n","import type {\n OpRootNode,\n OpRouteNode,\n OpOperationNode,\n OpResponseNode,\n ParamSource,\n ContractTypeNode,\n ContractRootNode,\n ModelNode,\n FieldNode,\n IncrementalManifest,\n IncrementalUnit,\n IncrementalResult as IncrementalResultBase,\n} from '@contractkit/core';\nimport {\n resolveSecurity,\n resolveModifiers,\n SECURITY_NONE,\n collectTransitiveModelRefs,\n runIncrementalCodegen,\n parseIncrementalManifest,\n emptyIncrementalManifest,\n serializeIncrementalManifest,\n hashFingerprint,\n INCREMENTAL_MANIFEST_VERSION,\n} from '@contractkit/core';\nimport { basename } from 'path';\nimport { parse as parseYaml, stringify as stringifyYaml } from 'yaml';\n\n/** A single file produced by the Bruno codegen — a relative output path and its YAML content. */\nexport interface OpenCollectionFile {\n relativePath: string;\n content: string;\n}\n\n/** Manifest filename — tracks which files this plugin previously generated so subsequent runs can clean up only those, leaving any user-added files alone. */\nexport const MANIFEST_FILENAME = '.contractkit-bruno-manifest.json';\n\n/**\n * Bumped whenever the codegen output shape changes in a way that should bust\n * every per-op fingerprint. Mixed into the per-op fingerprint so a plugin\n * upgrade forces full regeneration even when source `.ck` files are unchanged.\n */\nexport const BRUNO_CODEGEN_VERSION = '1';\n\n/** Subset of a security scheme sufficient for Bruno auth generation (non-HMAC). */\nexport interface BrunoSecurityScheme {\n type: string; // \"http\" | \"apiKey\" | \"oauth2\" | \"openIdConnect\"\n scheme?: string; // \"bearer\" | \"basic\" (when type === \"http\")\n name?: string; // header/query param name (when type === \"apiKey\")\n in?: string; // \"header\" | \"query\" (when type === \"apiKey\")\n}\n\n/** Auth configuration passed to the Bruno codegen; drives collection-level auth and per-operation auth blocks. */\nexport interface BrunoAuthOptions {\n /** Name of the default scheme (from config.security.default) */\n defaultScheme?: string;\n /** Scheme definitions keyed by name (non-HMAC only) */\n schemes?: Record<string, BrunoSecurityScheme>;\n}\n\n/** Options controlling what {@link generateOpenCollection} emits. */\nexport interface OpenCollectionOptions {\n collectionName: string;\n contractRoots?: ContractRootNode[];\n auth?: BrunoAuthOptions;\n /**\n * When true, emit Bruno faker template strings (e.g. `{{$randomUUID}}`,\n * `{{$randomEmail}}`) for compatible scalar types so each send produces\n * fresh data. When false (default), use deterministic placeholders.\n */\n randomExamples?: boolean;\n /**\n * Whether to generate request files for operations marked `internal`. Defaults to\n * `true` — Bruno collections are typically used by the team that owns the API and\n * benefit from full coverage. Set to `false` to omit internal ops.\n */\n includeInternal?: boolean;\n /**\n * Map of environment name → variables. Each entry produces a\n * `environments/<name>.yml` file with the variables in declaration order.\n * Values are coerced to strings.\n *\n * When omitted, a default `environments/local.yml` is emitted with\n * `baseUrl=http://localhost:3000` plus any auth env-var placeholders the\n * default scheme requires. When provided, the default is replaced entirely\n * — auth vars are not auto-injected, so include them explicitly if needed.\n */\n environments?: Record<string, Record<string, unknown>>;\n}\n\n/** Per-operation bookkeeping computed up front: where the file lives, what to call it, and the YAML inputs needed to render or fingerprint it. */\ninterface OpEntry {\n /** Stable identifier across runs — `<file>::<METHOD> <path>`. */\n opKey: string;\n /** Output path relative to the collection root (e.g. `users/get-user.yml`). */\n relativePath: string;\n /** Display name used inside the YAML `info:` block (alphabetized within its folder). */\n requestName: string;\n /** 1-based sequence within the request's containing folder, drives Bruno's UI ordering. */\n seq: number;\n route: OpRouteNode;\n op: OpOperationNode;\n root: OpRootNode;\n}\n\n/**\n * @deprecated Use {@link IncrementalManifest} from `@contractkit/core`. Re-exported here for backwards compatibility.\n */\nexport type BrunoManifest = IncrementalManifest;\n\n/** Result of {@link generateOpenCollectionIncremental}. Renamed `skippedOpCount` for Bruno-specific clarity but otherwise the shared {@link IncrementalResultBase}. */\nexport interface IncrementalResult extends Omit<IncrementalResultBase, 'skippedUnitCount'> {\n /** Number of ops whose codegen was skipped because their fingerprint matched. */\n skippedOpCount: number;\n}\n\n/**\n * Generates an OpenCollection (https://spec.opencollection.com/) API collection\n * from a set of operation roots. Produces opencollection.yml, an environment\n * file, one .yml request file per operation, and the tracking manifest.\n *\n * This is the full-regeneration entry point — every file is rebuilt from scratch.\n * For cache-aware incremental builds, use {@link generateOpenCollectionIncremental}.\n *\n * The manifest appears in the returned list (under {@link MANIFEST_FILENAME}) for\n * convenience — single-shot callers can write the entire array as-is. The plugin's\n * incremental path persists the manifest separately (under the CLI cache dir), so\n * its `filesToWrite` does not include the manifest.\n */\nexport function generateOpenCollection(roots: OpRootNode[], options: OpenCollectionOptions): OpenCollectionFile[] {\n const result = generateOpenCollectionIncremental(roots, options, emptyManifest());\n return [...result.filesToWrite, { relativePath: MANIFEST_FILENAME, content: serializeIncrementalManifest(result.manifest) }];\n}\n\n/**\n * Cache-aware variant of {@link generateOpenCollection}. Skips re-rendering YAML\n * for any op whose fingerprint matches the entry in `prevManifest`. The caller is\n * responsible for emitting `filesToWrite`, deleting `deletedPaths`, and persisting\n * `manifest` so the next run can match against it.\n *\n * Global files (collection root, env files, folder.yml) are always regenerated —\n * they're cheap and depend on options the manifest doesn't fingerprint.\n */\nexport function generateOpenCollectionIncremental(\n roots: OpRootNode[],\n options: OpenCollectionOptions,\n prevManifest: IncrementalManifest,\n fileExists: (relativePath: string) => boolean = () => true,\n): IncrementalResult {\n const modelMap = buildModelMap(options.contractRoots ?? []);\n const authOpts = options.auth;\n const defaultScheme = authOpts?.defaultScheme ? authOpts.schemes?.[authOpts.defaultScheme] : undefined;\n const randomExamples = options.randomExamples ?? false;\n const includeInternal = options.includeInternal ?? true;\n\n // ── Global files (collection root + env files + folder.yml per area/subarea) ──\n const globalFiles: OpenCollectionFile[] = [];\n globalFiles.push({\n relativePath: 'opencollection.yml',\n content: generateCollectionRoot(options.collectionName, defaultScheme),\n });\n for (const envFile of generateEnvFiles(options.environments, defaultScheme)) {\n globalFiles.push(envFile);\n }\n\n const sortedRoots = [...roots].sort((a, b) => {\n const aArea = a.meta['area'] ?? deriveFolderName(a.file);\n const bArea = b.meta['area'] ?? deriveFolderName(b.file);\n const cmp = aArea.localeCompare(bArea);\n if (cmp !== 0) return cmp;\n return (a.meta['subarea'] ?? '').localeCompare(b.meta['subarea'] ?? '');\n });\n\n const units: IncrementalUnit[] = [];\n for (let rootIdx = 0; rootIdx < sortedRoots.length; rootIdx++) {\n const root = sortedRoots[rootIdx]!;\n const folder = root.meta['area'] ? slugifyName(root.meta['area']) : deriveFolderName(root.file);\n const displayName = (root.meta['area'] ?? folder).charAt(0).toUpperCase() + (root.meta['area'] ?? folder).slice(1);\n globalFiles.push({ relativePath: `${folder}/folder.yml`, content: generateFolderFile(displayName, rootIdx + 1) });\n\n const subarea = root.meta['subarea'];\n const subareaSlug = subarea ? slugifyName(subarea) : undefined;\n const requestDir = subareaSlug ? `${folder}/${subareaSlug}` : folder;\n\n if (subareaSlug) {\n const subareaDisplayName = subarea!.charAt(0).toUpperCase() + subarea!.slice(1);\n globalFiles.push({ relativePath: `${requestDir}/folder.yml`, content: generateFolderFile(subareaDisplayName, 1) });\n }\n\n for (const entry of buildOpEntries(root, requestDir, includeInternal)) {\n units.push({\n key: entry.opKey,\n fingerprint: computeOpFingerprint(entry, modelMap, defaultScheme, randomExamples),\n render: () => [renderOpFile(entry, modelMap, defaultScheme, randomExamples)],\n });\n }\n }\n\n const result = runIncrementalCodegen({\n codegenVersion: BRUNO_CODEGEN_VERSION,\n prevManifest,\n globalFiles,\n units,\n fileExists,\n });\n\n return {\n filesToWrite: result.filesToWrite,\n manifest: result.manifest,\n deletedPaths: result.deletedPaths,\n skippedOpCount: result.skippedUnitCount,\n };\n}\n\n/** Build the ordered, alphabetized op entries for a single root. seq numbers are assigned in alphabetical order so the Bruno UI shows requests sorted by display name. */\nfunction buildOpEntries(root: OpRootNode, requestDir: string, includeInternal: boolean): OpEntry[] {\n const requests: Array<{ route: OpRouteNode; op: OpOperationNode; requestName: string }> = [];\n for (const route of root.routes) {\n for (const op of route.operations) {\n if (!includeInternal && resolveModifiers(route, op).includes('internal')) continue;\n requests.push({ route, op, requestName: op.name ?? route.path });\n }\n }\n requests.sort((a, b) => a.requestName.localeCompare(b.requestName));\n\n const entries: OpEntry[] = [];\n let seq = 1;\n for (const { route, op, requestName } of requests) {\n const fileName = op.name ? `${slugifyName(op.name)}.yml` : `${op.method}-${sanitizePath(route.path)}.yml`;\n entries.push({\n opKey: `${root.file}::${op.method.toUpperCase()} ${route.path}`,\n relativePath: `${requestDir}/${fileName}`,\n requestName,\n seq,\n route,\n op,\n root,\n });\n seq++;\n }\n return entries;\n}\n\n/** Render a single op's request file (including any plugin-extension YAML override). */\nfunction renderOpFile(\n entry: OpEntry,\n modelMap: Map<string, ModelNode>,\n defaultScheme: BrunoSecurityScheme | undefined,\n randomExamples: boolean,\n): OpenCollectionFile {\n let content = generateRequestFile(entry.route, entry.op, entry.requestName, entry.seq, modelMap, entry.root, defaultScheme, randomExamples);\n const brunoExt = entry.op.pluginExtensions?.['bruno'];\n const pluginOverride = brunoExt && typeof brunoExt === 'object' && !Array.isArray(brunoExt) ? brunoExt['template'] : undefined;\n if (typeof pluginOverride === 'string') {\n content = mergePluginFile(content, pluginOverride);\n }\n return { relativePath: entry.relativePath, content };\n}\n\n/** Compute a fingerprint covering every input that affects this op's rendered file. Stable across runs given identical inputs. */\nfunction computeOpFingerprint(\n entry: OpEntry,\n modelMap: Map<string, ModelNode>,\n defaultScheme: BrunoSecurityScheme | undefined,\n randomExamples: boolean,\n): string {\n const referencedModels = collectTransitiveModelRefs(collectOpTypeNodes(entry.route, entry.op), modelMap);\n const modelSnapshot: Record<string, unknown> = {};\n for (const name of [...referencedModels].sort()) {\n const m = modelMap.get(name);\n if (m) modelSnapshot[name] = m;\n }\n // Only include the route fields this op actually depends on. We deliberately exclude\n // `route.operations` so a change to a sibling op doesn't invalidate this op's cache.\n const routeShape = {\n path: entry.route.path,\n params: entry.route.params ?? null,\n modifiers: entry.route.modifiers ?? null,\n security: entry.route.security ?? null,\n description: entry.route.description ?? null,\n };\n return hashFingerprint({\n v: BRUNO_CODEGEN_VERSION,\n opKey: entry.opKey,\n relativePath: entry.relativePath,\n requestName: entry.requestName,\n seq: entry.seq,\n route: routeShape,\n op: entry.op,\n rootMeta: entry.root.meta,\n rootFile: entry.root.file,\n defaultScheme: defaultScheme ?? null,\n randomExamples,\n models: modelSnapshot,\n });\n}\n\n/** Collect every ContractTypeNode that contributes to this op's rendered output. Used as the seed set for transitive model collection in {@link computeOpFingerprint}. */\nfunction collectOpTypeNodes(route: OpRouteNode, op: OpOperationNode): ContractTypeNode[] {\n const out: ContractTypeNode[] = [];\n pushFromParamSource(route.params, out);\n pushFromParamSource(op.query, out);\n pushFromParamSource(op.headers, out);\n if (op.request) {\n for (const body of op.request.bodies) out.push(body.bodyType);\n }\n for (const resp of op.responses) {\n if (resp.bodyType) out.push(resp.bodyType);\n if (resp.headers) {\n for (const h of resp.headers) out.push(h.type);\n }\n }\n return out;\n}\n\nfunction pushFromParamSource(src: ParamSource | undefined, out: ContractTypeNode[]): void {\n if (!src) return;\n if (src.kind === 'params') {\n for (const n of src.nodes) out.push(n.type);\n } else if (src.kind === 'ref') {\n out.push({ kind: 'ref', name: src.name } as ContractTypeNode);\n } else if (src.kind === 'type') {\n out.push(src.node);\n }\n}\n\n/** Empty-state manifest, used when none has been written yet (or when the cache is being bypassed). */\nexport function emptyManifest(): IncrementalManifest {\n return emptyIncrementalManifest(BRUNO_CODEGEN_VERSION);\n}\n\n/**\n * Parse a previously-written manifest. Accepts both v1 (`{ files: string[] }`) and v2\n * (full {@link IncrementalManifest}) shapes. v1 manifests are returned with an empty\n * `units` map so the next run treats every op as a cache miss while still cleaning up\n * the tracked file list.\n *\n * Returns an empty manifest on any parse error so a stale/garbled file never blocks\n * regeneration.\n */\nexport function parseManifest(content: string): IncrementalManifest {\n const parsed = parseIncrementalManifest(content);\n // The shared parser handles v2. If v2 parsing produced an empty manifest, fall\n // through to a v1 shape ({ files: [...] }) and migrate it for cleanup purposes.\n if (parsed.files.length > 0 || Object.keys(parsed.units).length > 0) return parsed;\n try {\n const raw = JSON.parse(content);\n if (Array.isArray(raw?.files) && raw.files.every((f: unknown) => typeof f === 'string')) {\n return {\n version: INCREMENTAL_MANIFEST_VERSION,\n codegenVersion: '',\n files: raw.files as string[],\n units: {},\n };\n }\n } catch {\n // fall through\n }\n return emptyManifest();\n}\n\n// ─── Plugin file merge ─────────────────────────────────────────────────────\n\nfunction deepMerge(base: unknown, override: unknown): unknown {\n if (\n override !== null &&\n typeof override === 'object' &&\n !Array.isArray(override) &&\n base !== null &&\n typeof base === 'object' &&\n !Array.isArray(base)\n ) {\n const result: Record<string, unknown> = { ...(base as Record<string, unknown>) };\n for (const [key, val] of Object.entries(override as Record<string, unknown>)) {\n result[key] = deepMerge(result[key], val);\n }\n return result;\n }\n return override;\n}\n\n/**\n * Deep-merges a YAML override string into a generated YAML string.\n *\n * Objects are merged recursively; arrays and scalars in the override replace the\n * generated value entirely. If `pluginFileContent` is not a YAML mapping (e.g. it\n * is a scalar or a list), the generated content is returned unchanged.\n *\n * @param generatedYaml - The YAML string produced by the Bruno codegen.\n * @param pluginFileContent - The YAML override string to merge in.\n * @returns The merged YAML string, or `generatedYaml` if the override is not a mapping.\n */\nexport function mergePluginFile(generatedYaml: string, pluginFileContent: string): string {\n const overrideParsed = parseYaml(pluginFileContent);\n if (overrideParsed === null || typeof overrideParsed !== 'object' || Array.isArray(overrideParsed)) {\n return generatedYaml;\n }\n const merged = deepMerge(parseYaml(generatedYaml), overrideParsed);\n return stringifyYaml(merged, { lineWidth: 0 });\n}\n\n// ─── File generators ───────────────────────────────────────────────────────\n\nfunction generateCollectionRoot(name: string, scheme?: BrunoSecurityScheme): string {\n const lines = [`opencollection: \"1.0.0\"`, `info:`, ` name: ${yamlString(name)}`];\n if (scheme) {\n lines.push(``);\n lines.push(`request:`);\n lines.push(...renderAuthBlock(scheme, ' '));\n }\n lines.push(``);\n return lines.join('\\n');\n}\n\nfunction generateEnvFiles(\n environments: Record<string, Record<string, unknown>> | undefined,\n scheme: BrunoSecurityScheme | undefined,\n): OpenCollectionFile[] {\n if (environments && Object.keys(environments).length > 0) {\n return Object.entries(environments).map(([name, variables]) => ({\n relativePath: `environments/${name}.yml`,\n content: renderEnvFile(displayNameFor(name), variables),\n }));\n }\n const defaultVars: Record<string, string> = { baseUrl: 'http://localhost:3000' };\n if (scheme) {\n for (const varName of authEnvVarNames(scheme)) defaultVars[varName] = '';\n }\n return [{ relativePath: 'environments/local.yml', content: renderEnvFile('Local', defaultVars) }];\n}\n\nfunction renderEnvFile(name: string, variables: Record<string, unknown>): string {\n const lines = [`name: ${name}`, `variables:`];\n for (const [key, value] of Object.entries(variables)) {\n const escaped = String(value).replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"');\n lines.push(` - name: ${key}`);\n lines.push(` value: \"${escaped}\"`);\n }\n lines.push(``);\n return lines.join('\\n');\n}\n\nfunction displayNameFor(envKey: string): string {\n return envKey.charAt(0).toUpperCase() + envKey.slice(1);\n}\n\nfunction generateFolderFile(name: string, seq: number): string {\n return [`info:`, ` name: ${yamlString(name)}`, ` type: folder`, ` seq: ${seq}`, ``].join('\\n');\n}\n\nfunction generateRequestFile(\n route: OpRouteNode,\n op: OpOperationNode,\n name: string,\n seq: number,\n modelMap: Map<string, ModelNode>,\n root?: OpRootNode,\n defaultScheme?: BrunoSecurityScheme,\n randomExamples = false,\n): string {\n const lines: string[] = [];\n\n lines.push(`info:`);\n lines.push(` name: ${yamlString(name)}`);\n lines.push(` type: http`);\n lines.push(` seq: ${seq}`);\n lines.push(``);\n lines.push(`http:`);\n lines.push(` method: ${op.method.toUpperCase()}`);\n lines.push(` url: ${yamlString(`{{baseUrl}}${openCollectionPath(route.path)}`)}`);\n\n // Params — flat array with type: \"path\" | \"query\". Optional query params are\n // emitted with disabled: true so users opt in before sending.\n const pathParams: Array<ParamEntry & { kind: 'path' | 'query' }> = extractPathParamNames(route.path).map(n => ({\n name: n,\n type: findParamType(route.params, n, modelMap),\n optional: false,\n kind: 'path' as const,\n }));\n const queryParams: Array<ParamEntry & { kind: 'path' | 'query' }> = op.query\n ? expandParamSource(op.query, modelMap).map(e => ({ ...e, kind: 'query' as const }))\n : [];\n const allParams = [...pathParams, ...queryParams];\n\n if (allParams.length > 0) {\n lines.push(` params:`);\n for (const p of allParams) {\n lines.push(` - name: ${p.name}`);\n lines.push(` value: ${paramExampleValue(p.type, p.default, randomExamples)}`);\n lines.push(` type: ${p.kind}`);\n if (p.optional && p.kind === 'query') lines.push(` disabled: true`);\n }\n }\n\n // Headers\n if (op.headers) {\n const headerEntries = expandParamSource(op.headers, modelMap);\n if (headerEntries.length > 0) {\n lines.push(` headers:`);\n for (const h of headerEntries) {\n lines.push(` - name: ${h.name}`);\n lines.push(` value: ${paramExampleValue(h.type, h.default, randomExamples)}`);\n if (h.optional) lines.push(` disabled: true`);\n }\n }\n }\n\n // Auth — inside http block; inherit collection default unless this op is explicitly public\n if (defaultScheme) {\n const security = root ? resolveSecurity(route, op, root) : (op.security ?? route.security);\n if (security === SECURITY_NONE) {\n lines.push(` auth:`);\n lines.push(` type: none`);\n } else {\n lines.push(` auth: inherit`);\n }\n }\n\n // Body — Bruno supports a single body per request, so prefer JSON, then form-urlencoded, then multipart.\n if (op.request && op.request.bodies.length > 0) {\n const preferredOrder: Array<(typeof op.request.bodies)[number]['contentType']> = [\n 'application/json',\n 'application/x-www-form-urlencoded',\n 'multipart/form-data',\n ];\n const primary =\n preferredOrder.map(ct => op.request!.bodies.find(b => b.contentType === ct)).find(b => b !== undefined) ?? op.request.bodies[0]!;\n\n lines.push(` body:`);\n if (primary.contentType === 'multipart/form-data') {\n lines.push(` type: multipart-form`);\n lines.push(` data: []`);\n } else if (primary.contentType === 'application/x-www-form-urlencoded') {\n lines.push(` type: form-urlencoded`);\n lines.push(` data: []`);\n } else {\n const json = JSON.stringify(typeToExampleValue(primary.bodyType, modelMap, randomExamples), null, 2);\n lines.push(` type: json`);\n lines.push(` data: |`);\n for (const jsonLine of json.split('\\n')) {\n lines.push(` ${jsonLine}`);\n }\n }\n }\n\n // runtime.assertions — auto-generate a status-code check and presence checks for required response headers.\n const expectedStatus = pickAssertionStatus(op.responses);\n const assertedResponse = op.responses.find(r => r.statusCode === expectedStatus);\n const requiredHeaders = (assertedResponse?.headers ?? []).filter(h => !h.optional);\n if (expectedStatus !== undefined) {\n lines.push(``);\n lines.push(`runtime:`);\n lines.push(` assertions:`);\n lines.push(` - expression: res.status`);\n lines.push(` operator: eq`);\n // Always quote — the OpenCollection schema types `value` as a string,\n // so we must keep \"200\" from being parsed as YAML number 200.\n lines.push(` value: \"${expectedStatus}\"`);\n for (const h of requiredHeaders) {\n lines.push(` - expression: res.headers[\"${h.name.toLowerCase()}\"]`);\n lines.push(` operator: isDefined`);\n lines.push(` value: \"\"`);\n }\n }\n\n // docs — combine route- and operation-level descriptions plus the declared response-header summary.\n const docs = buildRequestDocs(route, op, assertedResponse);\n if (docs) {\n lines.push(``);\n lines.push(`docs: |-`);\n for (const docLine of docs.split('\\n')) {\n lines.push(` ${docLine}`);\n }\n }\n\n lines.push(``);\n return lines.join('\\n');\n}\n\n/** Pick the response whose status code we'll assert against. Prefers the first declared 2xx; otherwise falls back to the first declared response. Returns undefined if no responses are declared. */\nfunction pickAssertionStatus(responses: OpResponseNode[]): number | undefined {\n const success = responses.find(r => r.statusCode >= 200 && r.statusCode < 300);\n return success?.statusCode ?? responses[0]?.statusCode;\n}\n\n/** Build a markdown docs block from route- and operation-level descriptions, plus declared response-header summary. */\nfunction buildRequestDocs(route: OpRouteNode, op: OpOperationNode, assertedResponse?: OpResponseNode): string | undefined {\n const parts: string[] = [];\n if (route.description) parts.push(route.description.trim());\n if (op.description) parts.push(op.description.trim());\n const headers = assertedResponse?.headers ?? [];\n if (headers.length > 0) {\n const lines = ['**Response headers**', ''];\n for (const h of headers) {\n const tag = h.optional ? 'optional' : 'required';\n const desc = h.description ? ` — ${h.description}` : '';\n lines.push(`- \\`${h.name}\\` (${tag})${desc}`);\n }\n parts.push(lines.join('\\n'));\n }\n return parts.length > 0 ? parts.join('\\n\\n') : undefined;\n}\n\n// ─── Auth helpers ──────────────────────────────────────────────────────────\n\n/** Generate the YAML lines for an auth block (flat, per spec), indented by `indent`. */\nfunction renderAuthBlock(scheme: BrunoSecurityScheme, indent: string): string[] {\n const i = indent;\n if (scheme.type === 'http' && scheme.scheme === 'bearer') {\n return [`${i}auth:`, `${i} type: bearer`, `${i} token: \"{{token}}\"`];\n }\n if (scheme.type === 'http' && scheme.scheme === 'basic') {\n return [`${i}auth:`, `${i} type: basic`, `${i} username: \"{{username}}\"`, `${i} password: \"{{password}}\"`];\n }\n if (scheme.type === 'apiKey' && scheme.in === 'header') {\n const headerName = scheme.name ?? 'X-Api-Key';\n return [`${i}auth:`, `${i} type: apikey`, `${i} key: ${headerName}`, `${i} value: \"{{apiKey}}\"`, `${i} placement: header`];\n }\n return [];\n}\n\n/** Return the environment variable names needed for a given auth scheme. */\nfunction authEnvVarNames(scheme: BrunoSecurityScheme): string[] {\n if (scheme.type === 'http' && scheme.scheme === 'bearer') return ['token'];\n if (scheme.type === 'http' && scheme.scheme === 'basic') return ['username', 'password'];\n if (scheme.type === 'apiKey') return ['apiKey'];\n return [];\n}\n\n// ─── Model registry ────────────────────────────────────────────────────────\n\nfunction buildModelMap(contractRoots: ContractRootNode[]): Map<string, ModelNode> {\n const map = new Map<string, ModelNode>();\n for (const root of contractRoots) {\n for (const model of root.models) {\n map.set(model.name, model);\n }\n }\n return map;\n}\n\n/** Resolve all fields for a model, including inherited base fields (bases first, in declaration order). */\nfunction resolveModelFields(model: ModelNode, modelMap: Map<string, ModelNode>): FieldNode[] {\n const collected: FieldNode[] = [];\n if (model.bases) {\n for (const base of model.bases) {\n const baseModel = modelMap.get(base);\n if (baseModel) collected.push(...resolveModelFields(baseModel, modelMap));\n }\n }\n return [...collected, ...model.fields];\n}\n\n// ─── Param helpers ─────────────────────────────────────────────────────────\n\ninterface ParamEntry {\n name: string;\n type: ContractTypeNode | undefined;\n default?: string | number | boolean;\n optional: boolean;\n}\n\n/** Expand a ParamSource into a flat list of named entries with their types. */\nfunction expandParamSource(source: ParamSource, modelMap: Map<string, ModelNode>): ParamEntry[] {\n if (source.kind === 'params') {\n return source.nodes.map(n => ({ name: n.name, type: n.type, default: n.default, optional: n.optional }));\n }\n if (source.kind === 'ref') {\n const model = modelMap.get(source.name);\n if (model) {\n return resolveModelFields(model, modelMap)\n .filter(f => f.visibility !== 'readonly')\n .map(f => ({ name: f.name, type: f.type, default: f.default, optional: f.optional }));\n }\n // Fallback: single placeholder entry\n const name = source.name.charAt(0).toLowerCase() + source.name.slice(1);\n return [{ name, type: undefined, optional: false }];\n }\n // kind === 'type': if it's an inline object, expand its fields\n if (source.node.kind === 'inlineObject') {\n return source.node.fields.map(f => ({ name: f.name, type: f.type, default: f.default, optional: f.optional }));\n }\n return [];\n}\n\n/** Look up a named path param's type from route.params. */\nfunction findParamType(source: ParamSource | undefined, name: string, modelMap: Map<string, ModelNode>): ContractTypeNode | undefined {\n if (!source) return undefined;\n if (source.kind === 'params') return source.nodes.find(n => n.name === name)?.type;\n if (source.kind === 'ref') {\n const model = modelMap.get(source.name);\n if (model) return resolveModelFields(model, modelMap).find(f => f.name === name)?.type;\n }\n if (source.kind === 'type' && source.node.kind === 'inlineObject') {\n return source.node.fields.find(f => f.name === name)?.type;\n }\n return undefined;\n}\n\n/** Return a YAML-quoted example value string for a param, preferring a default value when provided. */\nfunction paramExampleValue(type: ContractTypeNode | undefined, defaultValue?: string | number | boolean, randomExamples = false): string {\n if (defaultValue !== undefined) return `\"${defaultValue}\"`;\n if (!type) return '\"\"';\n if (type.kind === 'enum') return type.values.length > 0 ? `\"${type.values[0]}\"` : '\"\"';\n if (type.kind === 'literal') return `\"${type.value}\"`;\n if (type.kind !== 'scalar') return '\"\"';\n if (randomExamples) {\n const random = randomScalarTemplate(type.name);\n if (random !== undefined) return `\"${random}\"`;\n }\n switch (type.name) {\n case 'uuid':\n return '\"00000000-0000-0000-0000-000000000000\"';\n case 'email':\n return '\"user@example.com\"';\n case 'url':\n return '\"https://example.com\"';\n case 'number':\n case 'int':\n case 'bigint':\n return '\"0\"';\n case 'boolean':\n return '\"true\"';\n case 'date':\n return '\"2024-01-01\"';\n case 'time':\n return '\"00:00:00\"';\n case 'datetime':\n return '\"2024-01-01T00:00:00Z\"';\n case 'duration':\n return '\"PT1H\"';\n default:\n return '\"\"';\n }\n}\n\n/** Bruno faker template for a scalar type, or undefined when no clean equivalent exists (date, time, duration, raw string). */\nfunction randomScalarTemplate(name: string): string | undefined {\n switch (name) {\n case 'uuid':\n return '{{$randomUUID}}';\n case 'email':\n return '{{$randomEmail}}';\n case 'url':\n return '{{$randomUrl}}';\n case 'number':\n case 'int':\n case 'bigint':\n return '{{$randomInt}}';\n case 'boolean':\n return '{{$randomBoolean}}';\n case 'datetime':\n return '{{$isoTimestamp}}';\n default:\n return undefined;\n }\n}\n\n// ─── Body helpers ──────────────────────────────────────────────────────────\n\n/**\n * Recursively build an example JSON value from a ContractTypeNode.\n *\n * When `randomExamples` is true we substitute Bruno faker templates only for\n * scalars whose JSON representation is a string (uuid/email/url/datetime).\n * Numbers and booleans stay deterministic — embedding `{{$randomInt}}` as a\n * bare JSON number would require sentinel-stripping the surrounding quotes,\n * and the body skeleton is meant as a starting point users edit anyway.\n */\nfunction typeToExampleValue(type: ContractTypeNode, modelMap: Map<string, ModelNode>, randomExamples = false): unknown {\n switch (type.kind) {\n case 'scalar':\n switch (type.name) {\n case 'string':\n return '';\n case 'email':\n return randomExamples ? '{{$randomEmail}}' : 'user@example.com';\n case 'url':\n return randomExamples ? '{{$randomUrl}}' : 'https://example.com';\n case 'uuid':\n return randomExamples ? '{{$randomUUID}}' : '00000000-0000-0000-0000-000000000000';\n case 'number':\n case 'int':\n case 'bigint':\n return 0;\n case 'boolean':\n return true;\n case 'date':\n return '2024-01-01';\n case 'time':\n return '00:00:00';\n case 'datetime':\n return randomExamples ? '{{$isoTimestamp}}' : '2024-01-01T00:00:00Z';\n case 'duration':\n return 'PT1H';\n case 'null':\n return null;\n default:\n return null;\n }\n case 'enum':\n return type.values[0] ?? '';\n case 'literal':\n return type.value;\n case 'array':\n return [typeToExampleValue(type.item, modelMap, randomExamples)];\n case 'tuple':\n return type.items.map(t => typeToExampleValue(t, modelMap, randomExamples));\n case 'record':\n return {};\n case 'union':\n return type.members.length > 0 ? typeToExampleValue(type.members[0]!, modelMap, randomExamples) : null;\n case 'discriminatedUnion':\n return type.members.length > 0 ? typeToExampleValue(type.members[0]!, modelMap, randomExamples) : null;\n case 'intersection':\n return {};\n case 'ref': {\n const model = modelMap.get(type.name);\n if (!model) return {};\n // Type alias — recurse into the aliased type\n if (model.type) return typeToExampleValue(model.type, modelMap, randomExamples);\n return modelToExampleObject(model, modelMap, randomExamples);\n }\n case 'lazy':\n return typeToExampleValue(type.inner, modelMap, randomExamples);\n case 'inlineObject':\n return fieldsToExampleObject(type.fields, modelMap, randomExamples);\n default:\n return null;\n }\n}\n\n/** Build an example object from a ModelNode's fields (including inherited base fields). */\nfunction modelToExampleObject(model: ModelNode, modelMap: Map<string, ModelNode>, randomExamples = false): Record<string, unknown> {\n return fieldsToExampleObject(resolveModelFields(model, modelMap), modelMap, randomExamples);\n}\n\n/** Build an example object from a list of FieldNodes. Excludes readonly fields; uses defaults when available; omits optional fields that have no default so they don't appear in the JSON output. */\nfunction fieldsToExampleObject(fields: FieldNode[], modelMap: Map<string, ModelNode>, randomExamples = false): Record<string, unknown> {\n const obj: Record<string, unknown> = {};\n for (const field of fields) {\n if (field.visibility === 'readonly') continue;\n if (field.default !== undefined) {\n obj[field.name] = field.default;\n } else if (!field.optional) {\n obj[field.name] = typeToExampleValue(field.type, modelMap, randomExamples);\n }\n }\n return obj;\n}\n\n// ─── Path helpers ──────────────────────────────────────────────────────────\n\n/** Convert /users/{id}/posts → /users/:id/posts (Bruno path parameter syntax) */\nfunction openCollectionPath(path: string): string {\n return path.replace(/\\{([a-zA-Z_][a-zA-Z0-9_]*)\\}/g, ':$1');\n}\n\n/** Convert \"Create an Offer\" → create-an-offer (for .yml file names) */\nexport function slugifyName(name: string): string {\n const result = name\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-|-$/g, '');\n return result || 'request';\n}\n\n/** Convert /users/{id}/posts → users-id-posts (for .yml file names) */\nexport function sanitizePath(path: string): string {\n const result = path\n .replace(/^\\//, '')\n .replace(/\\{([a-zA-Z_][a-zA-Z0-9_]*)\\}/g, '$1')\n .replace(/\\//g, '-')\n .replace(/[^a-zA-Z0-9-]/g, '')\n .replace(/-+/g, '-')\n .replace(/^-|-$/g, '');\n return result || 'root';\n}\n\n/** Extract param names from a URL template, e.g. /users/{id} → ['id'] */\nfunction extractPathParamNames(path: string): string[] {\n return [...path.matchAll(/\\{([a-zA-Z_][a-zA-Z0-9_]*)\\}/g)].map(m => m[1]!);\n}\n\n/** Derive folder name from op file path, e.g. src/users.op → users */\nfunction deriveFolderName(file: string): string {\n return basename(file).replace(/\\.(op|ck)$/, '');\n}\n\n/**\n * Wrap a string in YAML double quotes if it contains characters that require quoting\n * (flow indicators, colons, braces, etc.).\n */\nfunction yamlString(value: string): string {\n if (/[:{}[\\],&*#?|<>=!%@`\"']/.test(value) || /^\\s|\\s$/.test(value)) {\n return `\"${value.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"')}\"`;\n }\n return value;\n}\n"],"mappings":";;;;AAAA,SAASA,SAASC,YAAAA,WAAUC,eAAe;AAC3C,SAASC,YAAYC,cAAcC,eAAeC,WAAWC,QAAQC,aAAaC,iBAAiB;;;ACanG,SACIC,iBACAC,kBACAC,eACAC,4BACAC,uBACAC,0BACAC,0BACAC,8BACAC,iBACAC,oCACG;AACP,SAASC,gBAAgB;AACzB,SAASC,SAASC,WAAWC,aAAaC,qBAAqB;AAgBxD,IAAMC,wBAAwB;AAqG9B,SAASC,kCACZC,OACAC,SACAC,cACAC,aAAgD,MAAM,MAAI;AAE1D,QAAMC,WAAWC,cAAcJ,QAAQK,iBAAiB,CAAA,CAAE;AAC1D,QAAMC,WAAWN,QAAQO;AACzB,QAAMC,gBAAgBF,UAAUE,gBAAgBF,SAASG,UAAUH,SAASE,aAAa,IAAIE;AAC7F,QAAMC,iBAAiBX,QAAQW,kBAAkB;AACjD,QAAMC,kBAAkBZ,QAAQY,mBAAmB;AAGnD,QAAMC,cAAoC,CAAA;AAC1CA,cAAYC,KAAK;IACbC,cAAc;IACdC,SAASC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rD,UAAI;AACA,YAAI2C,YAAYF,OAAAA,EAAS3D,WAAW,GAAG;AACnC8D,oBAAUH,OAAAA;AACVA,oBAAUb,QAAQa,OAAAA;QACtB,OAAO;AACH;QACJ;MACJ,QAAQ;AACJ;MACJ;IACJ;EACJ;AACJ;AAzBSxB;","names":["resolve","basename","dirname","existsSync","readFileSync","writeFileSync","mkdirSync","rmSync","readdirSync","rmdirSync","resolveSecurity","resolveModifiers","SECURITY_NONE","collectTransitiveModelRefs","runIncrementalCodegen","parseIncrementalManifest","emptyIncrementalManifest","serializeIncrementalManifest","hashFingerprint","INCREMENTAL_MANIFEST_VERSION","basename","parse","parseYaml","stringify","stringifyYaml","BRUNO_CODEGEN_VERSION","generateOpenCollectionIncremental","roots","options","prevManifest","fileExists","modelMap","buildModelMap","contractRoots","authOpts","auth","defaultScheme","schemes","undefined","randomExamples","includeInternal","globalFiles","push","relativePath","content","generateCollectionRoot","collectionName","envFile","generateEnvFiles","environments","sortedRoots","sort","a","b","aArea","meta","deriveFolderName","file","bArea","cmp","localeCompare","units","rootIdx","length","root","folder","slugifyName","displayName","charAt","toUpperCase","slice","generateFolderFile","subarea","subareaSlug","requestDir","subareaDisplayName","entry","buildOpEntries","key","opKey","fingerprint","computeOpFingerprint","render","renderOpFile","result","runIncrementalCodegen","codegenVersion","BRUNO_CODEGEN_VERSION","filesToWrite","manifest","deletedPaths","skippedOpCount","skippedUnitCount","requests","route","routes","op","operations","resolveModifiers","includes","requestName","name","path","entries","seq","fileName","method","sanitizePath","generateRequestFile","brunoExt","pluginExtensions","pluginOverride","Array","isArray","mergePluginFile","referencedModels","collectTransitiveModelRefs","collectOpTypeNodes","modelSnapshot","m","get","routeShape","params","modifiers","security","description","hashFingerprint","v","rootMeta","rootFile","models","out","pushFromParamSource","query","headers","request","body","bodies","bodyType","resp","responses","h","type","src","kind","n","nodes","node","emptyManifest","emptyIncrementalManifest","parseManifest","parsed","parseIncrementalManifest","files","Object","keys","raw","JSON","parse","every","f","version","INCREMENTAL_MANIFEST_VERSION","deepMerge","base","override","val","generatedYaml","pluginFileContent","overrideParsed","parseYaml","merged","stringifyYaml","lineWidth","scheme","lines","yamlString","renderAuthBlock","join","map","variables","renderEnvFile","displayNameFor","defaultVars","baseUrl","varName","authEnvVarNames","value","escaped","String","replace","envKey","openCollectionPath","pathParams","extractPathParamNames","findParamType","optional","queryParams","expandParamSource","e","allParams","p","paramExampleValue","default","headerEntries","resolveSecurity","SECURITY_NONE","preferredOrder","primary","ct","find","contentType","json","stringify","typeToExampleValue","jsonLine","split","expectedStatus","pickAssertionStatus","assertedResponse","r","statusCode","requiredHeaders","filter","toLowerCase","docs","buildRequestDocs","docLine","success","parts","trim","tag","desc","indent","i","in","headerName","Map","model","set","resolveModelFields","collected","bases","baseModel","fields","source","visibility","defaultValue","values","random","randomScalarTemplate","item","items","t","members","modelToExampleObject","inner","fieldsToExampleObject","obj","field","matchAll","basename","test","serializeIncrementalManifest","CACHE_MANIFEST_FILENAME","validateBrunoExtension","value","Array","isArray","errors","describe","key","val","Object","entries","push","length","undefined","plugin","name","validateExtension","generateTargets","opRoots","contractRoots","ctx","auth","config","options","runBrunoCodegen","createBrunoPlugin","rootDir","base","baseDir","resolve","outDir","output","collectionName","basename","manifestPath","cacheDir","prevManifest","cacheEnabled","readManifest","emptyManifest","result","generateOpenCollectionIncremental","randomExamples","includeInternal","environments","relPath","existsSync","deleteStalePaths","deletedPaths","relativePath","content","filesToWrite","emitFile","writeManifest","manifest","parseManifest","readFileSync","mkdirSync","dirname","recursive","writeFileSync","serializeIncrementalManifest","relPaths","removedDirs","Set","rel","abs","rmSync","force","add","dir","current","startsWith","readdirSync","rmdirSync"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/codegen-bruno.ts"],"sourcesContent":["import { resolve, basename, dirname } from 'node:path';\nimport { existsSync, readFileSync, writeFileSync, mkdirSync, rmSync, readdirSync, rmdirSync } from 'node:fs';\nimport { generateOpenCollectionIncremental, parseManifest, emptyManifest } from './codegen-bruno.js';\nimport type { BrunoSecurityScheme } from './codegen-bruno.js';\nimport { serializeIncrementalManifest } from '@contractkit/core';\nimport type { ContractKitPlugin, PluginContext, PluginValue, OpRootNode, ContractRootNode, IncrementalManifest } from '@contractkit/core';\n\n/** Filename for the persisted Bruno manifest under the CLI cache directory. */\nconst CACHE_MANIFEST_FILENAME = 'bruno-manifest.json';\n\n/** Configuration accepted by the Bruno plugin, both via `contractkit.config.json` and `createBrunoPlugin`. */\nexport interface BrunoPluginConfig {\n baseDir?: string;\n output?: string;\n collectionName?: string;\n /**\n * When true (default), example values use Bruno's faker templates\n * (`{{$randomUUID}}`, `{{$randomEmail}}`, etc.) so each send produces\n * fresh data. Set to false for deterministic placeholders.\n */\n randomExamples?: boolean;\n /**\n * Whether to generate request files for operations marked `internal`. Defaults to\n * `true` — Bruno collections are typically used by the team that owns the API and\n * benefit from full coverage. Set to `false` to omit internal ops.\n */\n includeInternal?: boolean;\n /**\n * Map of environment name → variables. Each entry produces a\n * `environments/<name>.yml` file. When omitted, a default `local.yml` is\n * emitted with `baseUrl=http://localhost:3000` and any auth env-var\n * placeholders. When provided, the default is replaced entirely; include\n * auth variables (e.g. `token`) explicitly if you need them.\n */\n environments?: Record<string, Record<string, unknown>>;\n}\n\n/** Full plugin options shape read from `ctx.options` — extends {@link BrunoPluginConfig} with the `auth` block. */\nexport interface BrunoPluginOptions extends BrunoPluginConfig {\n auth?: { defaultScheme: string; schemes?: Record<string, BrunoSecurityScheme> };\n}\n\n// ─── Default export: loaded via plugins array, reads config from ctx.options ─\n\n/**\n * Validates a `plugins.bruno` extension entry on an operation. The expected shape is\n * `{ template?: string }`, where `template` is a YAML fragment to deep-merge into the\n * generated request file (typically a `file://...` URL whose contents have already\n * been loaded by the CLI resolver).\n */\nexport function validateBrunoExtension(value: PluginValue): { errors?: string[] } | void {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return { errors: [`expected an object, got ${describe(value)}`] };\n }\n const errors: string[] = [];\n for (const [key, val] of Object.entries(value)) {\n if (key === 'template') {\n if (typeof val !== 'string') errors.push(`'template' must be a string, got ${describe(val)}`);\n } else {\n errors.push(`unknown field '${key}' (allowed: template)`);\n }\n }\n return errors.length ? { errors } : undefined;\n}\n\nfunction describe(value: PluginValue): string {\n if (value === null) return 'null';\n if (Array.isArray(value)) return 'array';\n return typeof value;\n}\n\nconst plugin: ContractKitPlugin = {\n name: 'bruno',\n validateExtension: validateBrunoExtension,\n async generateTargets({ opRoots, contractRoots }, ctx) {\n const { auth, ...config } = ctx.options as BrunoPluginOptions;\n await runBrunoCodegen(opRoots, contractRoots, ctx, config, auth);\n },\n};\n\nexport default plugin;\n\n// ─── Factory: for programmatic use with explicit config ────────────────────\n\n/**\n * Creates a Bruno plugin instance with explicit configuration, for programmatic use.\n *\n * Prefer the default export when loading via `contractkit.config.json`. Use this\n * factory when constructing the plugin in code (e.g. in tests or custom build scripts).\n *\n * @param config - Plugin configuration (output paths and feature flags).\n * @param rootDir - Absolute path used to resolve relative paths in `config`.\n * @param auth - Optional auth scheme configuration mirroring the `auth` key in plugin options.\n */\nexport function createBrunoPlugin(\n config: BrunoPluginConfig,\n rootDir: string,\n auth?: { defaultScheme: string; schemes?: Record<string, BrunoSecurityScheme> },\n): ContractKitPlugin {\n return {\n name: 'bruno',\n validateExtension: validateBrunoExtension,\n async generateTargets({ opRoots, contractRoots }, ctx) {\n // The factory captures rootDir at creation time; ctx.rootDir may differ when the\n // plugin is loaded via a config file, so respect the explicit one passed in here.\n await runBrunoCodegen(opRoots, contractRoots, { ...ctx, rootDir }, config, auth);\n },\n };\n}\n\n/**\n * Shared orchestration used by both the default export and {@link createBrunoPlugin}.\n *\n * Reads the prior manifest, runs the cache-aware codegen, deletes any files that\n * are no longer produced, and emits the changed files plus the new manifest. When\n * `ctx.cacheEnabled` is `false` (e.g. `--force`) the prior manifest is ignored so\n * every op regenerates.\n */\nasync function runBrunoCodegen(\n opRoots: OpRootNode[],\n contractRoots: ContractRootNode[],\n ctx: PluginContext,\n config: BrunoPluginConfig,\n auth: BrunoPluginOptions['auth'],\n): Promise<void> {\n const base = config.baseDir ? resolve(ctx.rootDir, config.baseDir) : ctx.rootDir;\n const outDir = resolve(base, config.output ?? 'bruno-collection');\n const collectionName = config.collectionName ?? basename(ctx.rootDir);\n const manifestPath = resolve(ctx.cacheDir, CACHE_MANIFEST_FILENAME);\n\n const prevManifest: IncrementalManifest = ctx.cacheEnabled ? readManifest(manifestPath) : emptyManifest();\n\n const result = generateOpenCollectionIncremental(\n opRoots,\n {\n collectionName,\n contractRoots,\n auth,\n randomExamples: config.randomExamples ?? true,\n includeInternal: config.includeInternal,\n environments: config.environments,\n },\n prevManifest,\n relPath => existsSync(resolve(outDir, relPath)),\n );\n\n deleteStalePaths(outDir, result.deletedPaths);\n\n for (const { relativePath, content } of result.filesToWrite) {\n ctx.emitFile(resolve(outDir, relativePath), content);\n }\n\n // Persist the manifest under the CLI cache dir, separate from the bruno output.\n writeManifest(manifestPath, result.manifest);\n}\n\n/** Read the previous run's manifest from `manifestPath`. Returns an empty manifest when missing or unreadable. */\nfunction readManifest(manifestPath: string): IncrementalManifest {\n if (!existsSync(manifestPath)) return emptyManifest();\n try {\n return parseManifest(readFileSync(manifestPath, 'utf-8'));\n } catch {\n return emptyManifest();\n }\n}\n\n/** Write the manifest to `manifestPath`. Creates parent dirs as needed. Errors are swallowed so a broken cache never blocks the build. */\nfunction writeManifest(manifestPath: string, manifest: IncrementalManifest): void {\n try {\n mkdirSync(dirname(manifestPath), { recursive: true });\n writeFileSync(manifestPath, serializeIncrementalManifest(manifest), 'utf-8');\n } catch {\n // best-effort\n }\n}\n\n/**\n * Delete files that the previous run tracked but the current run doesn't produce, then\n * walk back up each affected directory and remove it if it's now empty (stopping at outDir).\n * Anything user-added survives because the manifest only ever lists plugin-generated paths.\n */\nfunction deleteStalePaths(outDir: string, relPaths: string[]): void {\n if (relPaths.length === 0) return;\n const removedDirs = new Set<string>();\n for (const rel of relPaths) {\n const abs = resolve(outDir, rel);\n if (existsSync(abs)) {\n rmSync(abs, { force: true });\n removedDirs.add(dirname(abs));\n }\n }\n for (const dir of removedDirs) {\n let current = dir;\n while (current.startsWith(outDir) && current !== outDir) {\n try {\n if (readdirSync(current).length === 0) {\n rmdirSync(current);\n current = dirname(current);\n } else {\n break;\n }\n } catch {\n break;\n }\n }\n }\n}\n\n","import type {\n OpRootNode,\n OpRouteNode,\n OpOperationNode,\n OpResponseNode,\n ParamSource,\n ContractTypeNode,\n ContractRootNode,\n ModelNode,\n FieldNode,\n IncrementalManifest,\n IncrementalUnit,\n IncrementalResult as IncrementalResultBase,\n} from '@contractkit/core';\nimport {\n resolveSecurity,\n resolveModifiers,\n SECURITY_NONE,\n collectTransitiveModelRefs,\n runIncrementalCodegen,\n parseIncrementalManifest,\n emptyIncrementalManifest,\n serializeIncrementalManifest,\n hashFingerprint,\n INCREMENTAL_MANIFEST_VERSION,\n} from '@contractkit/core';\nimport { basename } from 'path';\nimport { parse as parseYaml, stringify as stringifyYaml } from 'yaml';\n\n/** A single file produced by the Bruno codegen — a relative output path and its YAML content. */\nexport interface OpenCollectionFile {\n relativePath: string;\n content: string;\n}\n\n/** Manifest filename — tracks which files this plugin previously generated so subsequent runs can clean up only those, leaving any user-added files alone. */\nexport const MANIFEST_FILENAME = '.contractkit-bruno-manifest.json';\n\n/**\n * Bumped whenever the codegen output shape changes in a way that should bust\n * every per-op fingerprint. Mixed into the per-op fingerprint so a plugin\n * upgrade forces full regeneration even when source `.ck` files are unchanged.\n */\nexport const BRUNO_CODEGEN_VERSION = '1';\n\n/** Subset of a security scheme sufficient for Bruno auth generation (non-HMAC). */\nexport interface BrunoSecurityScheme {\n type: string; // \"http\" | \"apiKey\" | \"oauth2\" | \"openIdConnect\"\n scheme?: string; // \"bearer\" | \"basic\" (when type === \"http\")\n name?: string; // header/query param name (when type === \"apiKey\")\n in?: string; // \"header\" | \"query\" (when type === \"apiKey\")\n}\n\n/** Auth configuration passed to the Bruno codegen; drives collection-level auth and per-operation auth blocks. */\nexport interface BrunoAuthOptions {\n /** Name of the default scheme (from config.security.default) */\n defaultScheme?: string;\n /** Scheme definitions keyed by name (non-HMAC only) */\n schemes?: Record<string, BrunoSecurityScheme>;\n}\n\n/** Options controlling what {@link generateOpenCollection} emits. */\nexport interface OpenCollectionOptions {\n collectionName: string;\n contractRoots?: ContractRootNode[];\n auth?: BrunoAuthOptions;\n /**\n * When true, emit Bruno faker template strings (e.g. `{{$randomUUID}}`,\n * `{{$randomEmail}}`) for compatible scalar types so each send produces\n * fresh data. When false (default), use deterministic placeholders.\n */\n randomExamples?: boolean;\n /**\n * Whether to generate request files for operations marked `internal`. Defaults to\n * `true` — Bruno collections are typically used by the team that owns the API and\n * benefit from full coverage. Set to `false` to omit internal ops.\n */\n includeInternal?: boolean;\n /**\n * Map of environment name → variables. Each entry produces a\n * `environments/<name>.yml` file with the variables in declaration order.\n * Values are coerced to strings.\n *\n * When omitted, a default `environments/local.yml` is emitted with\n * `baseUrl=http://localhost:3000` plus any auth env-var placeholders the\n * default scheme requires. When provided, the default is replaced entirely\n * — auth vars are not auto-injected, so include them explicitly if needed.\n */\n environments?: Record<string, Record<string, unknown>>;\n}\n\n/** Per-operation bookkeeping computed up front: where the file lives, what to call it, and the YAML inputs needed to render or fingerprint it. */\ninterface OpEntry {\n /** Stable identifier across runs — `<file>::<METHOD> <path>`. */\n opKey: string;\n /** Output path relative to the collection root (e.g. `users/get-user.yml`). */\n relativePath: string;\n /** Display name used inside the YAML `info:` block (alphabetized within its folder). */\n requestName: string;\n /** 1-based sequence within the request's containing folder, drives Bruno's UI ordering. */\n seq: number;\n route: OpRouteNode;\n op: OpOperationNode;\n root: OpRootNode;\n}\n\n/**\n * @deprecated Use {@link IncrementalManifest} from `@contractkit/core`. Re-exported here for backwards compatibility.\n */\nexport type BrunoManifest = IncrementalManifest;\n\n/** Result of {@link generateOpenCollectionIncremental}. Renamed `skippedOpCount` for Bruno-specific clarity but otherwise the shared {@link IncrementalResultBase}. */\nexport interface IncrementalResult extends Omit<IncrementalResultBase, 'skippedUnitCount'> {\n /** Number of ops whose codegen was skipped because their fingerprint matched. */\n skippedOpCount: number;\n}\n\n/**\n * Generates an OpenCollection (https://spec.opencollection.com/) API collection\n * from a set of operation roots. Produces opencollection.yml, an environment\n * file, one .yml request file per operation, and the tracking manifest.\n *\n * This is the full-regeneration entry point — every file is rebuilt from scratch.\n * For cache-aware incremental builds, use {@link generateOpenCollectionIncremental}.\n *\n * The manifest appears in the returned list (under {@link MANIFEST_FILENAME}) for\n * convenience — single-shot callers can write the entire array as-is. The plugin's\n * incremental path persists the manifest separately (under the CLI cache dir), so\n * its `filesToWrite` does not include the manifest.\n */\nexport function generateOpenCollection(roots: OpRootNode[], options: OpenCollectionOptions): OpenCollectionFile[] {\n const result = generateOpenCollectionIncremental(roots, options, emptyManifest());\n return [...result.filesToWrite, { relativePath: MANIFEST_FILENAME, content: serializeIncrementalManifest(result.manifest) }];\n}\n\n/**\n * Cache-aware variant of {@link generateOpenCollection}. Skips re-rendering YAML\n * for any op whose fingerprint matches the entry in `prevManifest`. The caller is\n * responsible for emitting `filesToWrite`, deleting `deletedPaths`, and persisting\n * `manifest` so the next run can match against it.\n *\n * Global files (collection root, env files, folder.yml) are always regenerated —\n * they're cheap and depend on options the manifest doesn't fingerprint.\n */\nexport function generateOpenCollectionIncremental(\n roots: OpRootNode[],\n options: OpenCollectionOptions,\n prevManifest: IncrementalManifest,\n fileExists: (relativePath: string) => boolean = () => true,\n): IncrementalResult {\n const modelMap = buildModelMap(options.contractRoots ?? []);\n const authOpts = options.auth;\n const defaultScheme = authOpts?.defaultScheme ? authOpts.schemes?.[authOpts.defaultScheme] : undefined;\n const randomExamples = options.randomExamples ?? false;\n const includeInternal = options.includeInternal ?? true;\n\n // ── Global files (collection root + env files + folder.yml per area/subarea) ──\n const globalFiles: OpenCollectionFile[] = [];\n globalFiles.push({\n relativePath: 'opencollection.yml',\n content: generateCollectionRoot(options.collectionName, defaultScheme),\n });\n for (const envFile of generateEnvFiles(options.environments, defaultScheme)) {\n globalFiles.push(envFile);\n }\n\n const sortedRoots = [...roots].sort((a, b) => {\n const aArea = a.meta['area'] ?? deriveFolderName(a.file);\n const bArea = b.meta['area'] ?? deriveFolderName(b.file);\n const cmp = aArea.localeCompare(bArea);\n if (cmp !== 0) return cmp;\n return (a.meta['subarea'] ?? '').localeCompare(b.meta['subarea'] ?? '');\n });\n\n const units: IncrementalUnit[] = [];\n // Track which folder.yml paths we've already emitted so multiple roots sharing\n // an area (the area's own root + its subarea roots) don't each push the\n // area-level folder.yml — that produced N near-duplicate emits per area, only\n // the last of which survived on disk.\n const emittedFolders = new Set<string>();\n let areaSeq = 0;\n for (const root of sortedRoots) {\n const folder = root.meta['area'] ? slugifyName(root.meta['area']) : deriveFolderName(root.file);\n const folderRel = `${folder}/folder.yml`;\n if (!emittedFolders.has(folderRel)) {\n const displayName = (root.meta['area'] ?? folder).charAt(0).toUpperCase() + (root.meta['area'] ?? folder).slice(1);\n areaSeq++;\n globalFiles.push({ relativePath: folderRel, content: generateFolderFile(displayName, areaSeq) });\n emittedFolders.add(folderRel);\n }\n\n const subarea = root.meta['subarea'];\n const subareaSlug = subarea ? slugifyName(subarea) : undefined;\n const requestDir = subareaSlug ? `${folder}/${subareaSlug}` : folder;\n\n if (subareaSlug) {\n const subareaRel = `${requestDir}/folder.yml`;\n if (!emittedFolders.has(subareaRel)) {\n const subareaDisplayName = subarea!.charAt(0).toUpperCase() + subarea!.slice(1);\n globalFiles.push({ relativePath: subareaRel, content: generateFolderFile(subareaDisplayName, 1) });\n emittedFolders.add(subareaRel);\n }\n }\n\n for (const entry of buildOpEntries(root, requestDir, includeInternal)) {\n units.push({\n key: entry.opKey,\n fingerprint: computeOpFingerprint(entry, modelMap, defaultScheme, randomExamples),\n render: () => [renderOpFile(entry, modelMap, defaultScheme, randomExamples)],\n });\n }\n }\n\n const result = runIncrementalCodegen({\n codegenVersion: BRUNO_CODEGEN_VERSION,\n prevManifest,\n globalFiles,\n units,\n fileExists,\n });\n\n return {\n filesToWrite: result.filesToWrite,\n manifest: result.manifest,\n deletedPaths: result.deletedPaths,\n skippedOpCount: result.skippedUnitCount,\n };\n}\n\n/** Build the ordered, alphabetized op entries for a single root. seq numbers are assigned in alphabetical order so the Bruno UI shows requests sorted by display name. */\nfunction buildOpEntries(root: OpRootNode, requestDir: string, includeInternal: boolean): OpEntry[] {\n const requests: Array<{ route: OpRouteNode; op: OpOperationNode; requestName: string }> = [];\n for (const route of root.routes) {\n for (const op of route.operations) {\n if (!includeInternal && resolveModifiers(route, op).includes('internal')) continue;\n requests.push({ route, op, requestName: op.name ?? route.path });\n }\n }\n requests.sort((a, b) => a.requestName.localeCompare(b.requestName));\n\n const entries: OpEntry[] = [];\n let seq = 1;\n for (const { route, op, requestName } of requests) {\n const fileName = op.name ? `${slugifyName(op.name)}.yml` : `${op.method}-${sanitizePath(route.path)}.yml`;\n entries.push({\n opKey: `${root.file}::${op.method.toUpperCase()} ${route.path}`,\n relativePath: `${requestDir}/${fileName}`,\n requestName,\n seq,\n route,\n op,\n root,\n });\n seq++;\n }\n return entries;\n}\n\n/** Render a single op's request file (including any plugin-extension YAML override). */\nfunction renderOpFile(\n entry: OpEntry,\n modelMap: Map<string, ModelNode>,\n defaultScheme: BrunoSecurityScheme | undefined,\n randomExamples: boolean,\n): OpenCollectionFile {\n let content = generateRequestFile(entry.route, entry.op, entry.requestName, entry.seq, modelMap, entry.root, defaultScheme, randomExamples);\n const brunoExt = entry.op.pluginExtensions?.['bruno'];\n const pluginOverride = brunoExt && typeof brunoExt === 'object' && !Array.isArray(brunoExt) ? brunoExt['template'] : undefined;\n if (typeof pluginOverride === 'string') {\n content = mergePluginFile(content, pluginOverride);\n }\n return { relativePath: entry.relativePath, content };\n}\n\n/** Compute a fingerprint covering every input that affects this op's rendered file. Stable across runs given identical inputs. */\nfunction computeOpFingerprint(\n entry: OpEntry,\n modelMap: Map<string, ModelNode>,\n defaultScheme: BrunoSecurityScheme | undefined,\n randomExamples: boolean,\n): string {\n const referencedModels = collectTransitiveModelRefs(collectOpTypeNodes(entry.route, entry.op), modelMap);\n const modelSnapshot: Record<string, unknown> = {};\n for (const name of [...referencedModels].sort()) {\n const m = modelMap.get(name);\n if (m) modelSnapshot[name] = m;\n }\n // Only include the route fields this op actually depends on. We deliberately exclude\n // `route.operations` so a change to a sibling op doesn't invalidate this op's cache.\n const routeShape = {\n path: entry.route.path,\n params: entry.route.params ?? null,\n modifiers: entry.route.modifiers ?? null,\n security: entry.route.security ?? null,\n description: entry.route.description ?? null,\n };\n return hashFingerprint({\n v: BRUNO_CODEGEN_VERSION,\n opKey: entry.opKey,\n relativePath: entry.relativePath,\n requestName: entry.requestName,\n seq: entry.seq,\n route: routeShape,\n op: entry.op,\n rootMeta: entry.root.meta,\n rootFile: entry.root.file,\n defaultScheme: defaultScheme ?? null,\n randomExamples,\n models: modelSnapshot,\n });\n}\n\n/** Collect every ContractTypeNode that contributes to this op's rendered output. Used as the seed set for transitive model collection in {@link computeOpFingerprint}. */\nfunction collectOpTypeNodes(route: OpRouteNode, op: OpOperationNode): ContractTypeNode[] {\n const out: ContractTypeNode[] = [];\n pushFromParamSource(route.params, out);\n pushFromParamSource(op.query, out);\n pushFromParamSource(op.headers, out);\n if (op.request) {\n for (const body of op.request.bodies) out.push(body.bodyType);\n }\n for (const resp of op.responses) {\n if (resp.bodyType) out.push(resp.bodyType);\n if (resp.headers) {\n for (const h of resp.headers) out.push(h.type);\n }\n }\n return out;\n}\n\nfunction pushFromParamSource(src: ParamSource | undefined, out: ContractTypeNode[]): void {\n if (!src) return;\n if (src.kind === 'params') {\n for (const n of src.nodes) out.push(n.type);\n } else if (src.kind === 'ref') {\n out.push({ kind: 'ref', name: src.name } as ContractTypeNode);\n } else if (src.kind === 'type') {\n out.push(src.node);\n }\n}\n\n/** Empty-state manifest, used when none has been written yet (or when the cache is being bypassed). */\nexport function emptyManifest(): IncrementalManifest {\n return emptyIncrementalManifest(BRUNO_CODEGEN_VERSION);\n}\n\n/**\n * Parse a previously-written manifest. Accepts both v1 (`{ files: string[] }`) and v2\n * (full {@link IncrementalManifest}) shapes. v1 manifests are returned with an empty\n * `units` map so the next run treats every op as a cache miss while still cleaning up\n * the tracked file list.\n *\n * Returns an empty manifest on any parse error so a stale/garbled file never blocks\n * regeneration.\n */\nexport function parseManifest(content: string): IncrementalManifest {\n const parsed = parseIncrementalManifest(content);\n // The shared parser handles v2. If v2 parsing produced an empty manifest, fall\n // through to a v1 shape ({ files: [...] }) and migrate it for cleanup purposes.\n if (parsed.files.length > 0 || Object.keys(parsed.units).length > 0) return parsed;\n try {\n const raw = JSON.parse(content);\n if (Array.isArray(raw?.files) && raw.files.every((f: unknown) => typeof f === 'string')) {\n return {\n version: INCREMENTAL_MANIFEST_VERSION,\n codegenVersion: '',\n files: raw.files as string[],\n units: {},\n };\n }\n } catch {\n // fall through\n }\n return emptyManifest();\n}\n\n// ─── Plugin file merge ─────────────────────────────────────────────────────\n\nfunction deepMerge(base: unknown, override: unknown): unknown {\n if (\n override !== null &&\n typeof override === 'object' &&\n !Array.isArray(override) &&\n base !== null &&\n typeof base === 'object' &&\n !Array.isArray(base)\n ) {\n const result: Record<string, unknown> = { ...(base as Record<string, unknown>) };\n for (const [key, val] of Object.entries(override as Record<string, unknown>)) {\n result[key] = deepMerge(result[key], val);\n }\n return result;\n }\n return override;\n}\n\n/**\n * Deep-merges a YAML override string into a generated YAML string.\n *\n * Objects are merged recursively; arrays and scalars in the override replace the\n * generated value entirely. If `pluginFileContent` is not a YAML mapping (e.g. it\n * is a scalar or a list), the generated content is returned unchanged.\n *\n * @param generatedYaml - The YAML string produced by the Bruno codegen.\n * @param pluginFileContent - The YAML override string to merge in.\n * @returns The merged YAML string, or `generatedYaml` if the override is not a mapping.\n */\nexport function mergePluginFile(generatedYaml: string, pluginFileContent: string): string {\n const overrideParsed = parseYaml(pluginFileContent);\n if (overrideParsed === null || typeof overrideParsed !== 'object' || Array.isArray(overrideParsed)) {\n return generatedYaml;\n }\n const merged = deepMerge(parseYaml(generatedYaml), overrideParsed);\n return stringifyYaml(merged, { lineWidth: 0 });\n}\n\n// ─── File generators ───────────────────────────────────────────────────────\n\nfunction generateCollectionRoot(name: string, scheme?: BrunoSecurityScheme): string {\n const lines = [`opencollection: \"1.0.0\"`, `info:`, ` name: ${yamlString(name)}`];\n if (scheme) {\n lines.push(``);\n lines.push(`request:`);\n lines.push(...renderAuthBlock(scheme, ' '));\n }\n lines.push(``);\n return lines.join('\\n');\n}\n\nfunction generateEnvFiles(\n environments: Record<string, Record<string, unknown>> | undefined,\n scheme: BrunoSecurityScheme | undefined,\n): OpenCollectionFile[] {\n if (environments && Object.keys(environments).length > 0) {\n return Object.entries(environments).map(([name, variables]) => ({\n relativePath: `environments/${name}.yml`,\n content: renderEnvFile(displayNameFor(name), variables),\n }));\n }\n const defaultVars: Record<string, string> = { baseUrl: 'http://localhost:3000' };\n if (scheme) {\n for (const varName of authEnvVarNames(scheme)) defaultVars[varName] = '';\n }\n return [{ relativePath: 'environments/local.yml', content: renderEnvFile('Local', defaultVars) }];\n}\n\nfunction renderEnvFile(name: string, variables: Record<string, unknown>): string {\n const lines = [`name: ${name}`, `variables:`];\n for (const [key, value] of Object.entries(variables)) {\n const escaped = String(value).replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"');\n lines.push(` - name: ${key}`);\n lines.push(` value: \"${escaped}\"`);\n }\n lines.push(``);\n return lines.join('\\n');\n}\n\nfunction displayNameFor(envKey: string): string {\n return envKey.charAt(0).toUpperCase() + envKey.slice(1);\n}\n\nfunction generateFolderFile(name: string, seq: number): string {\n return [`info:`, ` name: ${yamlString(name)}`, ` type: folder`, ` seq: ${seq}`, ``].join('\\n');\n}\n\nfunction generateRequestFile(\n route: OpRouteNode,\n op: OpOperationNode,\n name: string,\n seq: number,\n modelMap: Map<string, ModelNode>,\n root?: OpRootNode,\n defaultScheme?: BrunoSecurityScheme,\n randomExamples = false,\n): string {\n const lines: string[] = [];\n\n lines.push(`info:`);\n lines.push(` name: ${yamlString(name)}`);\n lines.push(` type: http`);\n lines.push(` seq: ${seq}`);\n lines.push(``);\n lines.push(`http:`);\n lines.push(` method: ${op.method.toUpperCase()}`);\n lines.push(` url: ${yamlString(`{{baseUrl}}${openCollectionPath(route.path)}`)}`);\n\n // Params — flat array with type: \"path\" | \"query\". Optional query params are\n // emitted with disabled: true so users opt in before sending.\n const pathParams: Array<ParamEntry & { kind: 'path' | 'query' }> = extractPathParamNames(route.path).map(n => ({\n name: n,\n type: findParamType(route.params, n, modelMap),\n optional: false,\n kind: 'path' as const,\n }));\n const queryParams: Array<ParamEntry & { kind: 'path' | 'query' }> = op.query\n ? expandParamSource(op.query, modelMap).map(e => ({ ...e, kind: 'query' as const }))\n : [];\n const allParams = [...pathParams, ...queryParams];\n\n if (allParams.length > 0) {\n lines.push(` params:`);\n for (const p of allParams) {\n lines.push(` - name: ${p.name}`);\n lines.push(` value: ${paramExampleValue(p.type, p.default, randomExamples)}`);\n lines.push(` type: ${p.kind}`);\n if (p.optional && p.kind === 'query') lines.push(` disabled: true`);\n }\n }\n\n // Headers\n if (op.headers) {\n const headerEntries = expandParamSource(op.headers, modelMap);\n if (headerEntries.length > 0) {\n lines.push(` headers:`);\n for (const h of headerEntries) {\n lines.push(` - name: ${h.name}`);\n lines.push(` value: ${paramExampleValue(h.type, h.default, randomExamples)}`);\n if (h.optional) lines.push(` disabled: true`);\n }\n }\n }\n\n // Auth — inside http block; inherit collection default unless this op is explicitly public\n if (defaultScheme) {\n const security = root ? resolveSecurity(route, op, root) : (op.security ?? route.security);\n if (security === SECURITY_NONE) {\n lines.push(` auth:`);\n lines.push(` type: none`);\n } else {\n lines.push(` auth: inherit`);\n }\n }\n\n // Body — Bruno supports a single body per request, so prefer JSON, then form-urlencoded, then multipart.\n if (op.request && op.request.bodies.length > 0) {\n const preferredOrder: Array<(typeof op.request.bodies)[number]['contentType']> = [\n 'application/json',\n 'application/x-www-form-urlencoded',\n 'multipart/form-data',\n ];\n const primary =\n preferredOrder.map(ct => op.request!.bodies.find(b => b.contentType === ct)).find(b => b !== undefined) ?? op.request.bodies[0]!;\n\n lines.push(` body:`);\n if (primary.contentType === 'multipart/form-data') {\n lines.push(` type: multipart-form`);\n lines.push(` data: []`);\n } else if (primary.contentType === 'application/x-www-form-urlencoded') {\n lines.push(` type: form-urlencoded`);\n lines.push(` data: []`);\n } else {\n const json = JSON.stringify(typeToExampleValue(primary.bodyType, modelMap, randomExamples), null, 2);\n lines.push(` type: json`);\n lines.push(` data: |`);\n for (const jsonLine of json.split('\\n')) {\n lines.push(` ${jsonLine}`);\n }\n }\n }\n\n // runtime.assertions — auto-generate a status-code check and presence checks for required response headers.\n const expectedStatus = pickAssertionStatus(op.responses);\n const assertedResponse = op.responses.find(r => r.statusCode === expectedStatus);\n const requiredHeaders = (assertedResponse?.headers ?? []).filter(h => !h.optional);\n if (expectedStatus !== undefined) {\n lines.push(``);\n lines.push(`runtime:`);\n lines.push(` assertions:`);\n lines.push(` - expression: res.status`);\n lines.push(` operator: eq`);\n // Always quote — the OpenCollection schema types `value` as a string,\n // so we must keep \"200\" from being parsed as YAML number 200.\n lines.push(` value: \"${expectedStatus}\"`);\n for (const h of requiredHeaders) {\n lines.push(` - expression: res.headers[\"${h.name.toLowerCase()}\"]`);\n lines.push(` operator: isDefined`);\n lines.push(` value: \"\"`);\n }\n }\n\n // docs — combine route- and operation-level descriptions plus the declared response-header summary.\n const docs = buildRequestDocs(route, op, assertedResponse);\n if (docs) {\n lines.push(``);\n lines.push(`docs: |-`);\n for (const docLine of docs.split('\\n')) {\n lines.push(` ${docLine}`);\n }\n }\n\n lines.push(``);\n return lines.join('\\n');\n}\n\n/** Pick the response whose status code we'll assert against. Prefers the first declared 2xx; otherwise falls back to the first declared response. Returns undefined if no responses are declared. */\nfunction pickAssertionStatus(responses: OpResponseNode[]): number | undefined {\n const success = responses.find(r => r.statusCode >= 200 && r.statusCode < 300);\n return success?.statusCode ?? responses[0]?.statusCode;\n}\n\n/** Build a markdown docs block from route- and operation-level descriptions, plus declared response-header summary. */\nfunction buildRequestDocs(route: OpRouteNode, op: OpOperationNode, assertedResponse?: OpResponseNode): string | undefined {\n const parts: string[] = [];\n if (route.description) parts.push(route.description.trim());\n if (op.description) parts.push(op.description.trim());\n const headers = assertedResponse?.headers ?? [];\n if (headers.length > 0) {\n const lines = ['**Response headers**', ''];\n for (const h of headers) {\n const tag = h.optional ? 'optional' : 'required';\n const desc = h.description ? ` — ${h.description}` : '';\n lines.push(`- \\`${h.name}\\` (${tag})${desc}`);\n }\n parts.push(lines.join('\\n'));\n }\n return parts.length > 0 ? parts.join('\\n\\n') : undefined;\n}\n\n// ─── Auth helpers ──────────────────────────────────────────────────────────\n\n/** Generate the YAML lines for an auth block (flat, per spec), indented by `indent`. */\nfunction renderAuthBlock(scheme: BrunoSecurityScheme, indent: string): string[] {\n const i = indent;\n if (scheme.type === 'http' && scheme.scheme === 'bearer') {\n return [`${i}auth:`, `${i} type: bearer`, `${i} token: \"{{token}}\"`];\n }\n if (scheme.type === 'http' && scheme.scheme === 'basic') {\n return [`${i}auth:`, `${i} type: basic`, `${i} username: \"{{username}}\"`, `${i} password: \"{{password}}\"`];\n }\n if (scheme.type === 'apiKey' && scheme.in === 'header') {\n const headerName = scheme.name ?? 'X-Api-Key';\n return [`${i}auth:`, `${i} type: apikey`, `${i} key: ${headerName}`, `${i} value: \"{{apiKey}}\"`, `${i} placement: header`];\n }\n return [];\n}\n\n/** Return the environment variable names needed for a given auth scheme. */\nfunction authEnvVarNames(scheme: BrunoSecurityScheme): string[] {\n if (scheme.type === 'http' && scheme.scheme === 'bearer') return ['token'];\n if (scheme.type === 'http' && scheme.scheme === 'basic') return ['username', 'password'];\n if (scheme.type === 'apiKey') return ['apiKey'];\n return [];\n}\n\n// ─── Model registry ────────────────────────────────────────────────────────\n\nfunction buildModelMap(contractRoots: ContractRootNode[]): Map<string, ModelNode> {\n const map = new Map<string, ModelNode>();\n for (const root of contractRoots) {\n for (const model of root.models) {\n map.set(model.name, model);\n }\n }\n return map;\n}\n\n/** Resolve all fields for a model, including inherited base fields (bases first, in declaration order). */\nfunction resolveModelFields(model: ModelNode, modelMap: Map<string, ModelNode>): FieldNode[] {\n const collected: FieldNode[] = [];\n if (model.bases) {\n for (const base of model.bases) {\n const baseModel = modelMap.get(base);\n if (baseModel) collected.push(...resolveModelFields(baseModel, modelMap));\n }\n }\n return [...collected, ...model.fields];\n}\n\n// ─── Param helpers ─────────────────────────────────────────────────────────\n\ninterface ParamEntry {\n name: string;\n type: ContractTypeNode | undefined;\n default?: string | number | boolean;\n optional: boolean;\n}\n\n/** Expand a ParamSource into a flat list of named entries with their types. */\nfunction expandParamSource(source: ParamSource, modelMap: Map<string, ModelNode>): ParamEntry[] {\n if (source.kind === 'params') {\n return source.nodes.map(n => ({ name: n.name, type: n.type, default: n.default, optional: n.optional }));\n }\n if (source.kind === 'ref') {\n const model = modelMap.get(source.name);\n if (model) {\n return resolveModelFields(model, modelMap)\n .filter(f => f.visibility !== 'readonly')\n .map(f => ({ name: f.name, type: f.type, default: f.default, optional: f.optional }));\n }\n // Fallback: single placeholder entry\n const name = source.name.charAt(0).toLowerCase() + source.name.slice(1);\n return [{ name, type: undefined, optional: false }];\n }\n // kind === 'type': if it's an inline object, expand its fields\n if (source.node.kind === 'inlineObject') {\n return source.node.fields.map(f => ({ name: f.name, type: f.type, default: f.default, optional: f.optional }));\n }\n return [];\n}\n\n/** Look up a named path param's type from route.params. */\nfunction findParamType(source: ParamSource | undefined, name: string, modelMap: Map<string, ModelNode>): ContractTypeNode | undefined {\n if (!source) return undefined;\n if (source.kind === 'params') return source.nodes.find(n => n.name === name)?.type;\n if (source.kind === 'ref') {\n const model = modelMap.get(source.name);\n if (model) return resolveModelFields(model, modelMap).find(f => f.name === name)?.type;\n }\n if (source.kind === 'type' && source.node.kind === 'inlineObject') {\n return source.node.fields.find(f => f.name === name)?.type;\n }\n return undefined;\n}\n\n/** Return a YAML-quoted example value string for a param, preferring a default value when provided. */\nfunction paramExampleValue(type: ContractTypeNode | undefined, defaultValue?: string | number | boolean, randomExamples = false): string {\n if (defaultValue !== undefined) return `\"${defaultValue}\"`;\n if (!type) return '\"\"';\n if (type.kind === 'enum') return type.values.length > 0 ? `\"${type.values[0]}\"` : '\"\"';\n if (type.kind === 'literal') return `\"${type.value}\"`;\n if (type.kind !== 'scalar') return '\"\"';\n if (randomExamples) {\n const random = randomScalarTemplate(type.name);\n if (random !== undefined) return `\"${random}\"`;\n }\n switch (type.name) {\n case 'uuid':\n return '\"00000000-0000-0000-0000-000000000000\"';\n case 'email':\n return '\"user@example.com\"';\n case 'url':\n return '\"https://example.com\"';\n case 'number':\n case 'int':\n case 'bigint':\n return '\"0\"';\n case 'boolean':\n return '\"true\"';\n case 'date':\n return '\"2024-01-01\"';\n case 'time':\n return '\"00:00:00\"';\n case 'datetime':\n return '\"2024-01-01T00:00:00Z\"';\n case 'duration':\n return '\"PT1H\"';\n default:\n return '\"\"';\n }\n}\n\n/** Bruno faker template for a scalar type, or undefined when no clean equivalent exists (date, time, duration, raw string). */\nfunction randomScalarTemplate(name: string): string | undefined {\n switch (name) {\n case 'uuid':\n return '{{$randomUUID}}';\n case 'email':\n return '{{$randomEmail}}';\n case 'url':\n return '{{$randomUrl}}';\n case 'number':\n case 'int':\n case 'bigint':\n return '{{$randomInt}}';\n case 'boolean':\n return '{{$randomBoolean}}';\n case 'datetime':\n return '{{$isoTimestamp}}';\n default:\n return undefined;\n }\n}\n\n// ─── Body helpers ──────────────────────────────────────────────────────────\n\n/**\n * Recursively build an example JSON value from a ContractTypeNode.\n *\n * When `randomExamples` is true we substitute Bruno faker templates only for\n * scalars whose JSON representation is a string (uuid/email/url/datetime).\n * Numbers and booleans stay deterministic — embedding `{{$randomInt}}` as a\n * bare JSON number would require sentinel-stripping the surrounding quotes,\n * and the body skeleton is meant as a starting point users edit anyway.\n */\nfunction typeToExampleValue(type: ContractTypeNode, modelMap: Map<string, ModelNode>, randomExamples = false): unknown {\n switch (type.kind) {\n case 'scalar':\n switch (type.name) {\n case 'string':\n return '';\n case 'email':\n return randomExamples ? '{{$randomEmail}}' : 'user@example.com';\n case 'url':\n return randomExamples ? '{{$randomUrl}}' : 'https://example.com';\n case 'uuid':\n return randomExamples ? '{{$randomUUID}}' : '00000000-0000-0000-0000-000000000000';\n case 'number':\n case 'int':\n case 'bigint':\n return 0;\n case 'boolean':\n return true;\n case 'date':\n return '2024-01-01';\n case 'time':\n return '00:00:00';\n case 'datetime':\n return randomExamples ? '{{$isoTimestamp}}' : '2024-01-01T00:00:00Z';\n case 'duration':\n return 'PT1H';\n case 'null':\n return null;\n default:\n return null;\n }\n case 'enum':\n return type.values[0] ?? '';\n case 'literal':\n return type.value;\n case 'array':\n return [typeToExampleValue(type.item, modelMap, randomExamples)];\n case 'tuple':\n return type.items.map(t => typeToExampleValue(t, modelMap, randomExamples));\n case 'record':\n return {};\n case 'union':\n return type.members.length > 0 ? typeToExampleValue(type.members[0]!, modelMap, randomExamples) : null;\n case 'discriminatedUnion':\n return type.members.length > 0 ? typeToExampleValue(type.members[0]!, modelMap, randomExamples) : null;\n case 'intersection':\n return {};\n case 'ref': {\n const model = modelMap.get(type.name);\n if (!model) return {};\n // Type alias — recurse into the aliased type\n if (model.type) return typeToExampleValue(model.type, modelMap, randomExamples);\n return modelToExampleObject(model, modelMap, randomExamples);\n }\n case 'lazy':\n return typeToExampleValue(type.inner, modelMap, randomExamples);\n case 'inlineObject':\n return fieldsToExampleObject(type.fields, modelMap, randomExamples);\n default:\n return null;\n }\n}\n\n/** Build an example object from a ModelNode's fields (including inherited base fields). */\nfunction modelToExampleObject(model: ModelNode, modelMap: Map<string, ModelNode>, randomExamples = false): Record<string, unknown> {\n return fieldsToExampleObject(resolveModelFields(model, modelMap), modelMap, randomExamples);\n}\n\n/** Build an example object from a list of FieldNodes. Excludes readonly fields; uses defaults when available; omits optional fields that have no default so they don't appear in the JSON output. */\nfunction fieldsToExampleObject(fields: FieldNode[], modelMap: Map<string, ModelNode>, randomExamples = false): Record<string, unknown> {\n const obj: Record<string, unknown> = {};\n for (const field of fields) {\n if (field.visibility === 'readonly') continue;\n if (field.default !== undefined) {\n obj[field.name] = field.default;\n } else if (!field.optional) {\n obj[field.name] = typeToExampleValue(field.type, modelMap, randomExamples);\n }\n }\n return obj;\n}\n\n// ─── Path helpers ──────────────────────────────────────────────────────────\n\n/** Convert /users/{id}/posts → /users/:id/posts (Bruno path parameter syntax) */\nfunction openCollectionPath(path: string): string {\n return path.replace(/\\{([a-zA-Z_][a-zA-Z0-9_]*)\\}/g, ':$1');\n}\n\n/** Convert \"Create an Offer\" → create-an-offer (for .yml file names) */\nexport function slugifyName(name: string): string {\n const result = name\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-|-$/g, '');\n return result || 'request';\n}\n\n/** Convert /users/{id}/posts → users-id-posts (for .yml file names) */\nexport function sanitizePath(path: string): string {\n const result = path\n .replace(/^\\//, '')\n .replace(/\\{([a-zA-Z_][a-zA-Z0-9_]*)\\}/g, '$1')\n .replace(/\\//g, '-')\n .replace(/[^a-zA-Z0-9-]/g, '')\n .replace(/-+/g, '-')\n .replace(/^-|-$/g, '');\n return result || 'root';\n}\n\n/** Extract param names from a URL template, e.g. /users/{id} → ['id'] */\nfunction extractPathParamNames(path: string): string[] {\n return [...path.matchAll(/\\{([a-zA-Z_][a-zA-Z0-9_]*)\\}/g)].map(m => m[1]!);\n}\n\n/** Derive folder name from op file path, e.g. src/users.op → users */\nfunction deriveFolderName(file: string): string {\n return basename(file).replace(/\\.(op|ck)$/, '');\n}\n\n/**\n * Wrap a string in YAML double quotes if it contains characters that require quoting\n * (flow indicators, colons, braces, etc.).\n */\nfunction yamlString(value: string): string {\n if (/[:{}[\\],&*#?|<>=!%@`\"']/.test(value) || /^\\s|\\s$/.test(value)) {\n return `\"${value.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"')}\"`;\n }\n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ChD;AAGAG,gBAAcnB,cAAcM,OAAOc,QAAQ;AAC/C;AApCe9B;AAuCf,SAASc,aAAaJ,cAAoB;AACtC,MAAI,CAACY,WAAWZ,YAAAA,EAAe,QAAOK,cAAAA;AACtC,MAAI;AACA,WAAOgB,cAAcC,aAAatB,cAAc,OAAA,CAAA;EACpD,QAAQ;AACJ,WAAOK,cAAAA;EACX;AACJ;AAPSD;AAUT,SAASe,cAAcnB,cAAsBoB,UAA6B;AACtE,MAAI;AACAG,cAAUC,QAAQxB,YAAAA,GAAe;MAAEyB,WAAW;IAAK,CAAA;AACnDC,kBAAc1B,cAAc2B,8BAA6BP,QAAAA,GAAW,OAAA;EACxE,QAAQ;EAER;AACJ;AAPSD;AAcT,SAASN,iBAAiBjB,QAAgBgC,UAAkB;AACxD,MAAIA,SAASlD,WAAW,EAAG;AAC3B,QAAMmD,cAAc,oBAAIC,IAAAA;AACxB,aAAWC,OAAOH,UAAU;AACxB,UAAMI,MAAMrC,QAAQC,QAAQmC,GAAAA;AAC5B,QAAInB,WAAWoB,GAAAA,GAAM;AACjBC,aAAOD,KAAK;QAAEE,OAAO;MAAK,CAAA;AAC1BL,kBAAYM,IAAIX,QAAQQ,GAAAA,CAAAA;IAC5B;EACJ;AACA,aAAWI,OAAOP,aAAa;AAC3B,QAAIQ,UAAUD;AACd,WAAOC,QAAQC,WAAW1C,MAAAA,KAAWyC,YAAYzC,QAAQ;AACrD,UAAI;AACA,YAAI2C,YAAYF,OAAAA,EAAS3D,WAAW,GAAG;AACnC8D,oBAAUH,OAAAA;AACVA,oBAAUb,QAAQa,OAAAA;QACtB,OAAO;AACH;QACJ;MACJ,QAAQ;AACJ;MACJ;IACJ;EACJ;AACJ;AAzBSxB;","names":["resolve","basename","dirname","existsSync","readFileSync","writeFileSync","mkdirSync","rmSync","readdirSync","rmdirSync","resolveSecurity","resolveModifiers","SECURITY_NONE","collectTransitiveModelRefs","runIncrementalCodegen","parseIncrementalManifest","emptyIncrementalManifest","serializeIncrementalManifest","hashFingerprint","INCREMENTAL_MANIFEST_VERSION","basename","parse","parseYaml","stringify","stringifyYaml","BRUNO_CODEGEN_VERSION","generateOpenCollectionIncremental","roots","options","prevManifest","fileExists","modelMap","buildModelMap","contractRoots","authOpts","auth","defaultScheme","schemes","undefined","randomExamples","includeInternal","globalFiles","push","relativePath","content","generateCollectionRoot","collectionName","envFile","generateEnvFiles","environments","sortedRoots","sort","a","b","aArea","meta","deriveFolderName","file","bArea","cmp","localeCompare","units","emittedFolders","Set","areaSeq","root","folder","slugifyName","folderRel","has","displayName","charAt","toUpperCase","slice","generateFolderFile","add","subarea","subareaSlug","requestDir","subareaRel","subareaDisplayName","entry","buildOpEntries","key","opKey","fingerprint","computeOpFingerprint","render","renderOpFile","result","runIncrementalCodegen","codegenVersion","BRUNO_CODEGEN_VERSION","filesToWrite","manifest","deletedPaths","skippedOpCount","skippedUnitCount","requests","route","routes","op","operations","resolveModifiers","includes","requestName","name","path","entries","seq","fileName","method","sanitizePath","generateRequestFile","brunoExt","pluginExtensions","pluginOverride","Array","isArray","mergePluginFile","referencedModels","collectTransitiveModelRefs","collectOpTypeNodes","modelSnapshot","m","get","routeShape","params","modifiers","security","description","hashFingerprint","v","rootMeta","rootFile","models","out","pushFromParamSource","query","headers","request","body","bodies","bodyType","resp","responses","h","type","src","kind","n","nodes","node","emptyManifest","emptyIncrementalManifest","parseManifest","parsed","parseIncrementalManifest","files","length","Object","keys","raw","JSON","parse","every","f","version","INCREMENTAL_MANIFEST_VERSION","deepMerge","base","override","val","generatedYaml","pluginFileContent","overrideParsed","parseYaml","merged","stringifyYaml","lineWidth","scheme","lines","yamlString","renderAuthBlock","join","map","variables","renderEnvFile","displayNameFor","defaultVars","baseUrl","varName","authEnvVarNames","value","escaped","String","replace","envKey","openCollectionPath","pathParams","extractPathParamNames","findParamType","optional","queryParams","expandParamSource","e","allParams","p","paramExampleValue","default","headerEntries","resolveSecurity","SECURITY_NONE","preferredOrder","primary","ct","find","contentType","json","stringify","typeToExampleValue","jsonLine","split","expectedStatus","pickAssertionStatus","assertedResponse","r","statusCode","requiredHeaders","filter","toLowerCase","docs","buildRequestDocs","docLine","success","parts","trim","tag","desc","indent","i","in","headerName","Map","model","set","resolveModelFields","collected","bases","baseModel","fields","source","visibility","defaultValue","values","random","randomScalarTemplate","item","items","t","members","modelToExampleObject","inner","fieldsToExampleObject","obj","field","matchAll","basename","test","serializeIncrementalManifest","CACHE_MANIFEST_FILENAME","validateBrunoExtension","value","Array","isArray","errors","describe","key","val","Object","entries","push","length","undefined","plugin","name","validateExtension","generateTargets","opRoots","contractRoots","ctx","auth","config","options","runBrunoCodegen","createBrunoPlugin","rootDir","base","baseDir","resolve","outDir","output","collectionName","basename","manifestPath","cacheDir","prevManifest","cacheEnabled","readManifest","emptyManifest","result","generateOpenCollectionIncremental","randomExamples","includeInternal","environments","relPath","existsSync","deleteStalePaths","deletedPaths","relativePath","content","filesToWrite","emitFile","writeManifest","manifest","parseManifest","readFileSync","mkdirSync","dirname","recursive","writeFileSync","serializeIncrementalManifest","relPaths","removedDirs","Set","rel","abs","rmSync","force","add","dir","current","startsWith","readdirSync","rmdirSync"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contractkit/plugin-bruno",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "description": "ContractKit built-in plugin: Bruno REST collection generation",
5
5
  "author": {
6
6
  "name": "Marooned Software",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "yaml": "^2.8.3",
30
- "@contractkit/core": "0.17.0"
30
+ "@contractkit/core": "0.18.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@repo/config-eslint": "0.3.1",