@t0.labs/daxta 0.4.8 → 0.4.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -163,6 +163,8 @@ For Postman-friendly fills, export can bake the **active Try-it env + header gro
163
163
  - **Resolved values** — literals in the OpenAPI (import with parameter generation = Example)
164
164
  - **Postman `{{variables}}`** — placeholders in OpenAPI + a companion `.postman_environment.json`
165
165
 
166
+ Also download **Postman Collection** (default on): example names stay as `201 — should create…` instead of generic `Created` / `Bad Request` (Postman’s OpenAPI importer names examples from status description).
167
+
166
168
  Example label (`status-title-case`):
167
169
 
168
170
  ```text
@@ -330,16 +330,72 @@
330
330
 
331
331
  .app {
332
332
  display: grid;
333
- grid-template-columns: 320px minmax(0, 1fr);
333
+ grid-template-columns: var(--sidebar-w, 320px) 6px minmax(0, 1fr);
334
334
  height: calc(100vh - 56px);
335
335
  }
336
+ .app.sidebar-collapsed {
337
+ grid-template-columns: 0 28px minmax(0, 1fr);
338
+ }
336
339
  .sidebar, .workbench { height: 100%; overflow: auto; }
337
340
  .sidebar {
341
+ position: relative;
342
+ min-width: 0;
338
343
  padding: 16px 12px 48px;
339
344
  background: var(--sidebar);
340
- border-right: 1px solid var(--line);
345
+ border-right: 0;
341
346
  font-size: 13px;
342
347
  }
348
+ .app.sidebar-collapsed .sidebar {
349
+ overflow: hidden;
350
+ padding: 0;
351
+ pointer-events: none;
352
+ opacity: 0;
353
+ }
354
+ .sidebar-resizer {
355
+ position: relative;
356
+ z-index: 5;
357
+ width: 6px;
358
+ margin: 0;
359
+ padding: 0;
360
+ border: 0;
361
+ background: var(--line);
362
+ cursor: col-resize;
363
+ touch-action: none;
364
+ }
365
+ .sidebar-resizer::after {
366
+ content: "";
367
+ position: absolute;
368
+ inset: 0 -4px;
369
+ }
370
+ .sidebar-resizer:hover,
371
+ body.sidebar-resizing .sidebar-resizer {
372
+ background: var(--obsidian);
373
+ }
374
+ .app.sidebar-collapsed .sidebar-resizer {
375
+ width: 28px;
376
+ cursor: pointer;
377
+ background: var(--sidebar);
378
+ border-right: 1px solid var(--line);
379
+ }
380
+ .app.sidebar-collapsed .sidebar-resizer::before {
381
+ content: "";
382
+ position: absolute;
383
+ top: 50%;
384
+ left: 50%;
385
+ width: 6px;
386
+ height: 6px;
387
+ border-right: 1.5px solid var(--charcoal);
388
+ border-bottom: 1.5px solid var(--charcoal);
389
+ transform: translate(-70%, -50%) rotate(-45deg);
390
+ }
391
+ body.sidebar-resizing {
392
+ cursor: col-resize;
393
+ user-select: none;
394
+ }
395
+ body.sidebar-resizing * {
396
+ cursor: col-resize !important;
397
+ user-select: none !important;
398
+ }
343
399
  .tree-root { display: flex; flex-direction: column; gap: 2px; }
344
400
  .tree-folder { display: flex; flex-direction: column; gap: 2px; }
345
401
  .tree-folder-toggle {
@@ -459,12 +515,43 @@
459
515
  .nav-examples {
460
516
  display: none;
461
517
  flex-direction: column;
462
- gap: 1px;
518
+ gap: 6px;
463
519
  margin: 0 4px 6px 18px;
464
520
  padding-left: 10px;
465
521
  border-left: 1px solid var(--hairline);
466
522
  }
467
523
  .nav-op.examples-open > .nav-examples { display: flex; }
524
+ .nav-ex-group { display: flex; flex-direction: column; gap: 1px; }
525
+ .nav-ex-group-label {
526
+ display: flex;
527
+ align-items: center;
528
+ justify-content: space-between;
529
+ gap: 8px;
530
+ padding: 6px 8px 2px;
531
+ font: 600 10px/1.2 var(--mono);
532
+ letter-spacing: 0.06em;
533
+ text-transform: uppercase;
534
+ color: var(--stone);
535
+ }
536
+ .nav-ex-count,
537
+ .nav-ex-total,
538
+ .dd-count {
539
+ flex: none;
540
+ min-width: 16px;
541
+ padding: 1px 6px;
542
+ border-radius: 9999px;
543
+ background: var(--inset);
544
+ color: var(--charcoal);
545
+ font: 600 10px/1.4 var(--mono);
546
+ letter-spacing: 0;
547
+ text-transform: none;
548
+ text-align: center;
549
+ }
550
+ .nav-ex-total {
551
+ margin-right: 2px;
552
+ background: var(--white);
553
+ box-shadow: var(--ghost);
554
+ }
468
555
  .nav-example {
469
556
  display: block;
470
557
  width: 100%;
@@ -682,7 +769,17 @@
682
769
  font-size: 14px;
683
770
  line-height: 1.4;
684
771
  position: relative;
772
+ display: flex;
773
+ align-items: center;
774
+ gap: 8px;
685
775
  }
776
+ .dd-toggle .dd-toggle-label {
777
+ min-width: 0;
778
+ overflow: hidden;
779
+ text-overflow: ellipsis;
780
+ white-space: nowrap;
781
+ }
782
+ .dd-toggle .dd-count { margin-left: auto; margin-right: 4px; }
686
783
  .dd-toggle::after {
687
784
  content: "";
688
785
  position: absolute;
@@ -711,6 +808,10 @@
711
808
  }
712
809
  .dd.open .dd-menu { display: block; }
713
810
  .dd-group {
811
+ display: flex;
812
+ align-items: center;
813
+ justify-content: space-between;
814
+ gap: 8px;
714
815
  font-family: var(--mono);
715
816
  font-size: 11px;
716
817
  letter-spacing: 0.08em;
@@ -718,6 +819,9 @@
718
819
  color: var(--stone);
719
820
  padding: 10px 12px 6px;
720
821
  }
822
+ .dd-group .dd-count {
823
+ background: var(--paper, var(--inset));
824
+ }
721
825
  .dd-item {
722
826
  display: block;
723
827
  width: 100%;
@@ -934,20 +1038,49 @@
934
1038
  }
935
1039
  .row {
936
1040
  display: grid;
937
- grid-template-columns: 1.2fr 0.7fr 1fr;
1041
+ grid-template-columns: minmax(0, 1.5fr) minmax(72px, 0.55fr) minmax(0, 0.95fr);
938
1042
  gap: 12px;
1043
+ align-items: start;
939
1044
  padding: 8px 0;
940
1045
  font-size: 13px;
941
1046
  }
942
- .row .name { font-family: var(--mono); font-size: 12px; color: var(--obsidian); }
943
- .row .name.nested { color: var(--ink, var(--obsidian)); }
944
- .row .type { color: var(--stone); font-family: var(--mono); font-size: 12px; }
1047
+ .row .name {
1048
+ font-family: var(--mono);
1049
+ font-size: 12px;
1050
+ color: var(--obsidian);
1051
+ min-width: 0;
1052
+ overflow-wrap: anywhere;
1053
+ word-break: break-word;
1054
+ }
1055
+ .row .name.nested {
1056
+ color: var(--charcoal);
1057
+ border-left: 2px solid var(--hairline);
1058
+ padding-left: 10px;
1059
+ margin-left: 2px;
1060
+ }
1061
+ .row .name.nested[data-depth="2"] { margin-left: 14px; }
1062
+ .row .name.nested[data-depth="3"] { margin-left: 26px; }
1063
+ .row .name.nested[data-depth="4"] { margin-left: 38px; }
1064
+ .row .loc,
1065
+ .row .type {
1066
+ color: var(--stone);
1067
+ font-family: var(--mono);
1068
+ font-size: 12px;
1069
+ min-width: 0;
1070
+ }
945
1071
  .flag { margin-top: 4px; font-size: 11px; color: var(--smoke); }
946
1072
  .flag.req { color: #8a2e2e; }
947
1073
 
948
1074
  @media (max-width: 960px) {
949
- .app { grid-template-columns: 1fr; height: auto; }
950
- .sidebar { max-height: 40vh; }
1075
+ .app {
1076
+ grid-template-columns: 1fr;
1077
+ height: auto;
1078
+ }
1079
+ .app.sidebar-collapsed {
1080
+ grid-template-columns: 1fr;
1081
+ }
1082
+ .sidebar { max-height: 40vh; opacity: 1 !important; pointer-events: auto !important; padding: 16px 12px 24px !important; }
1083
+ .sidebar-resizer { display: none; }
951
1084
  .pair { grid-template-columns: 1fr; }
952
1085
  .search-wrap { width: min(280px, 70vw); }
953
1086
  }
@@ -996,7 +1129,11 @@
996
1129
  <span>Postman <code>{{variables}}</code> + download environment file</span>
997
1130
  </label>
998
1131
  </div>
999
- <p class="export-tip">In Postman Import → advanced: set parameter generation to <strong>Example</strong>. Import the environment file if you use variables mode.</p>
1132
+ <p class="export-tip">Postman names saved examples from OpenAPI <em>response description</em> (“Created”), so also download a Collection with the real scenario titles. Import → advanced → parameter generation = <strong>Example</strong>.</p>
1133
+ <label class="export-check">
1134
+ <input type="checkbox" id="export-postman-collection" checked />
1135
+ <span>Also download Postman Collection <span style="color:var(--stone)">(named examples)</span></span>
1136
+ </label>
1000
1137
  </div>
1001
1138
  <div class="export-toolbar">
1002
1139
  <button type="button" class="btn sm" id="export-all">All</button>
@@ -1010,8 +1147,9 @@
1010
1147
  </div>
1011
1148
  </div>
1012
1149
  </div>
1013
- <div class="app">
1150
+ <div class="app" id="app">
1014
1151
  <aside class="sidebar" id="nav"></aside>
1152
+ <button type="button" class="sidebar-resizer" id="sidebar-resizer" aria-label="Resize sidebar" title="Drag to resize · double-click to collapse"></button>
1015
1153
  <main class="workbench" id="main"></main>
1016
1154
  </div>
1017
1155
  <script>
@@ -1046,6 +1184,10 @@
1046
1184
  const defaultBaseUrl = locationBaseUrl || defaultBaseUrlFromSpec;
1047
1185
  const title = (spec.info && spec.info.title) || "API Docs";
1048
1186
  const STORE_KEY = "openapi-docs-env:" + (workspace || "default");
1187
+ const SIDEBAR_STORE_KEY = "openapi-docs-sidebar:" + (workspace || "default");
1188
+ const SIDEBAR_MIN = 200;
1189
+ const SIDEBAR_MAX = 560;
1190
+ const SIDEBAR_DEFAULT = 320;
1049
1191
 
1050
1192
  const docsBaseForApi = (() => {
1051
1193
  if (typeof location === "undefined") return docsPathSuffix;
@@ -1057,6 +1199,111 @@
1057
1199
  })();
1058
1200
  const ENV_STORE_URL = docsBaseForApi + "/env.json";
1059
1201
 
1202
+ const loadSidebarLayout = () => {
1203
+ try {
1204
+ const raw = localStorage.getItem(SIDEBAR_STORE_KEY);
1205
+ if (!raw) return { width: SIDEBAR_DEFAULT, collapsed: false };
1206
+ const parsed = JSON.parse(raw);
1207
+ const width = Number(parsed.width);
1208
+ return {
1209
+ width: Number.isFinite(width) ? Math.min(SIDEBAR_MAX, Math.max(SIDEBAR_MIN, width)) : SIDEBAR_DEFAULT,
1210
+ collapsed: Boolean(parsed.collapsed),
1211
+ };
1212
+ } catch {
1213
+ return { width: SIDEBAR_DEFAULT, collapsed: false };
1214
+ }
1215
+ };
1216
+
1217
+ let sidebarLayout = loadSidebarLayout();
1218
+
1219
+ const applySidebarLayout = () => {
1220
+ const app = document.getElementById("app");
1221
+ const resizer = document.getElementById("sidebar-resizer");
1222
+ if (!app) return;
1223
+ app.style.setProperty("--sidebar-w", sidebarLayout.width + "px");
1224
+ app.classList.toggle("sidebar-collapsed", sidebarLayout.collapsed);
1225
+ if (resizer) {
1226
+ resizer.title = sidebarLayout.collapsed
1227
+ ? "Click to expand sidebar"
1228
+ : "Drag to resize · double-click to collapse";
1229
+ resizer.setAttribute("aria-label", sidebarLayout.collapsed ? "Expand sidebar" : "Resize sidebar");
1230
+ }
1231
+ };
1232
+
1233
+ const persistSidebarLayout = () => {
1234
+ try {
1235
+ localStorage.setItem(SIDEBAR_STORE_KEY, JSON.stringify(sidebarLayout));
1236
+ } catch {}
1237
+ };
1238
+
1239
+ const initSidebarResize = () => {
1240
+ const resizer = document.getElementById("sidebar-resizer");
1241
+ if (!resizer) return;
1242
+ applySidebarLayout();
1243
+
1244
+ let dragging = false;
1245
+ let startX = 0;
1246
+ let startWidth = 0;
1247
+ let moved = false;
1248
+
1249
+ const onMove = (event) => {
1250
+ if (!dragging) return;
1251
+ if (event.cancelable) event.preventDefault();
1252
+ const clientX = event.touches ? event.touches[0].clientX : event.clientX;
1253
+ const delta = clientX - startX;
1254
+ if (Math.abs(delta) > 2) moved = true;
1255
+ const next = Math.min(SIDEBAR_MAX, Math.max(SIDEBAR_MIN, startWidth + delta));
1256
+ sidebarLayout.width = next;
1257
+ sidebarLayout.collapsed = false;
1258
+ applySidebarLayout();
1259
+ };
1260
+
1261
+ const onUp = () => {
1262
+ if (!dragging) return;
1263
+ dragging = false;
1264
+ document.body.classList.remove("sidebar-resizing");
1265
+ window.removeEventListener("mousemove", onMove);
1266
+ window.removeEventListener("mouseup", onUp);
1267
+ window.removeEventListener("touchmove", onMove);
1268
+ window.removeEventListener("touchend", onUp);
1269
+ persistSidebarLayout();
1270
+ };
1271
+
1272
+ const onDown = (event) => {
1273
+ if (sidebarLayout.collapsed) return;
1274
+ if (event.button != null && event.button !== 0) return;
1275
+ event.preventDefault();
1276
+ dragging = true;
1277
+ moved = false;
1278
+ startX = event.touches ? event.touches[0].clientX : event.clientX;
1279
+ startWidth = sidebarLayout.width;
1280
+ document.body.classList.add("sidebar-resizing");
1281
+ window.addEventListener("mousemove", onMove);
1282
+ window.addEventListener("mouseup", onUp);
1283
+ window.addEventListener("touchmove", onMove, { passive: false });
1284
+ window.addEventListener("touchend", onUp);
1285
+ };
1286
+
1287
+ resizer.addEventListener("mousedown", onDown);
1288
+ resizer.addEventListener("touchstart", onDown, { passive: false });
1289
+ resizer.addEventListener("dblclick", (event) => {
1290
+ event.preventDefault();
1291
+ sidebarLayout.collapsed = !sidebarLayout.collapsed;
1292
+ if (!sidebarLayout.collapsed && sidebarLayout.width < SIDEBAR_MIN) sidebarLayout.width = SIDEBAR_DEFAULT;
1293
+ applySidebarLayout();
1294
+ persistSidebarLayout();
1295
+ });
1296
+ resizer.addEventListener("click", (event) => {
1297
+ if (!sidebarLayout.collapsed || moved) return;
1298
+ event.preventDefault();
1299
+ sidebarLayout.collapsed = false;
1300
+ applySidebarLayout();
1301
+ persistSidebarLayout();
1302
+ });
1303
+ };
1304
+
1305
+ initSidebarResize();
1306
+
1060
1307
  let liveResult = null;
1061
1308
 
1062
1309
  const escapeAttr = (value) =>
@@ -1774,6 +2021,61 @@
1774
2021
  return next;
1775
2022
  };
1776
2023
 
2024
+ /** Rename example map keys to scenario titles; set summary+description (Postman-friendly). */
2025
+ const promoteExampleLabels = (examples) => {
2026
+ if (!examples || typeof examples !== "object") return examples;
2027
+ const out = {};
2028
+ for (const [key, example] of Object.entries(examples)) {
2029
+ if (!example || typeof example !== "object") continue;
2030
+ const summary = String(example.summary || example.description || key).trim() || key;
2031
+ let name = summary;
2032
+ let n = 2;
2033
+ while (Object.prototype.hasOwnProperty.call(out, name)) {
2034
+ name = summary + " (" + n + ")";
2035
+ n += 1;
2036
+ }
2037
+ out[name] = {
2038
+ summary,
2039
+ description: summary,
2040
+ value: example.value,
2041
+ };
2042
+ }
2043
+ return out;
2044
+ };
2045
+
2046
+ const promoteOperationExampleLabels = (operation) => {
2047
+ const next = { ...operation };
2048
+ if (next.requestBody?.content?.["application/json"]?.examples) {
2049
+ const media = { ...next.requestBody.content["application/json"] };
2050
+ media.examples = promoteExampleLabels(media.examples);
2051
+ next.requestBody = {
2052
+ ...next.requestBody,
2053
+ content: { ...next.requestBody.content, "application/json": media },
2054
+ };
2055
+ }
2056
+ if (next.responses) {
2057
+ const responses = {};
2058
+ for (const [status, response] of Object.entries(next.responses)) {
2059
+ const examples = response?.content?.["application/json"]?.examples;
2060
+ if (!examples) {
2061
+ responses[status] = response;
2062
+ continue;
2063
+ }
2064
+ const media = { ...response.content["application/json"] };
2065
+ media.examples = promoteExampleLabels(examples);
2066
+ const labels = Object.keys(media.examples);
2067
+ responses[status] = {
2068
+ ...response,
2069
+ // Single example: description becomes the scenario title (Postman uses this as the example name).
2070
+ description: labels.length === 1 ? labels[0] : response.description || status,
2071
+ content: { ...response.content, "application/json": media },
2072
+ };
2073
+ }
2074
+ next.responses = responses;
2075
+ }
2076
+ return next;
2077
+ };
2078
+
1777
2079
  const toExportSpec = (source, selectedByOpId) => {
1778
2080
  const pathsIn = source.paths || {};
1779
2081
  const pathsOut = {};
@@ -1806,6 +2108,7 @@
1806
2108
  if (selectedByOpId && selectedByOpId.has(opId)) {
1807
2109
  cleaned = filterOperationExamples(cleaned, selectedByOpId.get(opId));
1808
2110
  }
2111
+ cleaned = promoteOperationExampleLabels(cleaned);
1809
2112
  const tagParts = segments.filter((part) => !String(part).startsWith("{"));
1810
2113
  const tag = tagParts.length ? tagParts.join(" / ") : "API";
1811
2114
  cleaned.tags = [tag];
@@ -1924,6 +2227,138 @@
1924
2227
  };
1925
2228
  };
1926
2229
 
2230
+ const STATUS_EXPORT = {
2231
+ 200: "OK",
2232
+ 201: "Created",
2233
+ 204: "No Content",
2234
+ 400: "Bad Request",
2235
+ 401: "Unauthorized",
2236
+ 403: "Forbidden",
2237
+ 404: "Not Found",
2238
+ 409: "Conflict",
2239
+ 422: "Unprocessable Entity",
2240
+ 500: "Internal Server Error",
2241
+ };
2242
+
2243
+ const postmanUrlFromPath = (serverUrl, pathTemplate) => {
2244
+ const base = String(serverUrl || "{{baseUrl}}").replace(/\/$/, "");
2245
+ const path = String(pathTemplate || "/");
2246
+ const segments = path.split("/").filter(Boolean);
2247
+ const pathParams = [...path.matchAll(/\{([^}]+)\}/g)].map((m) => m[1]);
2248
+ return {
2249
+ raw: base + (path.startsWith("/") ? path : "/" + path),
2250
+ host: base.startsWith("{{") ? [base] : [base.replace(/^https?:\/\//, "").split("/")[0]],
2251
+ path: segments.map((seg) => (seg.startsWith("{") && seg.endsWith("}") ? ":" + seg.slice(1, -1) : seg)),
2252
+ variable: pathParams.map((key) => ({ key, value: "" })),
2253
+ };
2254
+ };
2255
+
2256
+ /**
2257
+ * Postman Collection v2.1 — example `name` = scenario title (not "Created" / "Bad Request").
2258
+ * OpenAPI→Postman import names every example after response.description; this bypasses that.
2259
+ */
2260
+ const buildPostmanCollection = (openapi) => {
2261
+ const serverUrl = (openapi.servers && openapi.servers[0] && openapi.servers[0].url) || "{{baseUrl}}";
2262
+ const folders = new Map();
2263
+
2264
+ for (const [urlPath, pathItem] of Object.entries(openapi.paths || {})) {
2265
+ if (!pathItem || typeof pathItem !== "object") continue;
2266
+ for (const method of HTTP_EXPORT) {
2267
+ const operation = pathItem[method];
2268
+ if (!operation || typeof operation !== "object") continue;
2269
+ const folderName = (operation.tags && operation.tags[0]) || "API";
2270
+ if (!folders.has(folderName)) folders.set(folderName, []);
2271
+
2272
+ const headerParams = (operation.parameters || []).filter((param) => param && param.in === "header" && param.name);
2273
+ const requestHeaders = headerParams.map((param) => ({
2274
+ key: param.name,
2275
+ value: param.example != null ? String(param.example) : "",
2276
+ type: "text",
2277
+ }));
2278
+
2279
+ const reqExamples = operation.requestBody?.content?.["application/json"]?.examples || {};
2280
+ const firstReq = Object.values(reqExamples)[0];
2281
+ const defaultBody =
2282
+ firstReq && firstReq.value !== undefined
2283
+ ? typeof firstReq.value === "string"
2284
+ ? firstReq.value
2285
+ : JSON.stringify(firstReq.value, null, 2)
2286
+ : undefined;
2287
+
2288
+ const baseRequest = {
2289
+ method: method.toUpperCase(),
2290
+ header: requestHeaders,
2291
+ url: postmanUrlFromPath(serverUrl, urlPath),
2292
+ description: operation.summary || "",
2293
+ };
2294
+ if (defaultBody !== undefined) {
2295
+ baseRequest.body = { mode: "raw", raw: defaultBody, options: { raw: { language: "json" } } };
2296
+ if (!requestHeaders.some((h) => String(h.key).toLowerCase() === "content-type")) {
2297
+ baseRequest.header = [...requestHeaders, { key: "Content-Type", value: "application/json", type: "text" }];
2298
+ }
2299
+ }
2300
+
2301
+ const responses = [];
2302
+ for (const [status, response] of Object.entries(operation.responses || {})) {
2303
+ const examples = response?.content?.["application/json"]?.examples || {};
2304
+ const entries = Object.entries(examples);
2305
+ if (!entries.length) {
2306
+ responses.push({
2307
+ name: response.description || STATUS_EXPORT[status] || status,
2308
+ originalRequest: baseRequest,
2309
+ status: STATUS_EXPORT[status] || response.description || status,
2310
+ code: Number(status) || 0,
2311
+ _postman_previewlanguage: "json",
2312
+ header: [{ key: "Content-Type", value: "application/json" }],
2313
+ body: "",
2314
+ });
2315
+ continue;
2316
+ }
2317
+ for (const [exKey, example] of entries) {
2318
+ const name = (example && (example.summary || example.description)) || exKey;
2319
+ const reqMatch = reqExamples[exKey] || reqExamples[name] || firstReq;
2320
+ const requestForExample = { ...baseRequest, header: [...(baseRequest.header || [])] };
2321
+ if (reqMatch && reqMatch.value !== undefined) {
2322
+ const raw =
2323
+ typeof reqMatch.value === "string" ? reqMatch.value : JSON.stringify(reqMatch.value, null, 2);
2324
+ requestForExample.body = { mode: "raw", raw, options: { raw: { language: "json" } } };
2325
+ }
2326
+ const bodyValue = example && example.value !== undefined ? example.value : "";
2327
+ responses.push({
2328
+ name,
2329
+ originalRequest: requestForExample,
2330
+ status: STATUS_EXPORT[status] || String(status),
2331
+ code: Number(status) || 0,
2332
+ _postman_previewlanguage: "json",
2333
+ header: [{ key: "Content-Type", value: "application/json" }],
2334
+ body: typeof bodyValue === "string" ? bodyValue : JSON.stringify(bodyValue, null, 2),
2335
+ });
2336
+ }
2337
+ }
2338
+
2339
+ folders.get(folderName).push({
2340
+ name: operation.summary || method.toUpperCase() + " " + urlPath,
2341
+ request: baseRequest,
2342
+ response: responses,
2343
+ });
2344
+ }
2345
+ }
2346
+
2347
+ const item = [...folders.entries()]
2348
+ .sort(([a], [b]) => a.localeCompare(b))
2349
+ .map(([name, children]) => ({ name, item: children }));
2350
+
2351
+ return {
2352
+ info: {
2353
+ _postman_id: typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : String(Date.now()),
2354
+ name: (openapi.info && openapi.info.title) || workspace || title || "DAxTA",
2355
+ description: (openapi.info && openapi.info.description) || "Exported from DAxTA with named examples",
2356
+ schema: "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
2357
+ },
2358
+ item,
2359
+ };
2360
+ };
2361
+
1927
2362
  const closeExportModal = () => {
1928
2363
  document.body.classList.remove("exporting");
1929
2364
  };
@@ -1998,6 +2433,7 @@
1998
2433
  const selectedByOpId = collectSelectedExamples();
1999
2434
  let exported = toExportSpec(spec, selectedByOpId);
2000
2435
  const includeTryIt = Boolean(document.getElementById("export-include-tryit")?.checked);
2436
+ const wantCollection = Boolean(document.getElementById("export-postman-collection")?.checked);
2001
2437
  const fillMode =
2002
2438
  document.querySelector('input[name="export-fill"]:checked')?.value === "variables" ? "variables" : "resolved";
2003
2439
  const base = exportSafeName();
@@ -2008,10 +2444,18 @@
2008
2444
 
2009
2445
  downloadJsonFile(base + ".openapi.json", exported);
2010
2446
 
2447
+ let delay = 120;
2448
+ if (wantCollection) {
2449
+ setTimeout(() => {
2450
+ downloadJsonFile(base + ".postman_collection.json", buildPostmanCollection(exported));
2451
+ }, delay);
2452
+ delay += 120;
2453
+ }
2454
+
2011
2455
  if (includeTryIt && fillMode === "variables") {
2012
2456
  setTimeout(() => {
2013
2457
  downloadJsonFile(base + ".postman_environment.json", buildPostmanEnvironment());
2014
- }, 150);
2458
+ }, delay);
2015
2459
  }
2016
2460
  };
2017
2461
 
@@ -2201,22 +2645,36 @@
2201
2645
  return { status: response.status, body: parsed, ok: response.ok };
2202
2646
  };
2203
2647
 
2204
- const groupedDropdown = (scenarios, selected) => {
2648
+ const groupScenarios = (scenarios) => {
2205
2649
  const groups = {};
2206
- scenarios.forEach((scenario, index) => {
2207
- (groups[scenario.group] ||= []).push({ scenario, index });
2650
+ (scenarios || []).forEach((scenario, index) => {
2651
+ const group = scenario.group || "Other";
2652
+ (groups[group] ||= []).push({ scenario, index });
2208
2653
  });
2209
- const order = GROUP_ORDER.filter((name) => groups[name]).concat(Object.keys(groups).filter((name) => !GROUP_ORDER.includes(name)));
2654
+ const order = GROUP_ORDER.filter((name) => groups[name]).concat(
2655
+ Object.keys(groups).filter((name) => !GROUP_ORDER.includes(name)),
2656
+ );
2657
+ return { groups, order };
2658
+ };
2659
+
2660
+ const groupedDropdown = (scenarios, selected) => {
2661
+ const { groups, order } = groupScenarios(scenarios);
2210
2662
  const current = scenarios[selected];
2211
- const label = current ? current.group + " · " + current.name : "Recorded call";
2663
+ const total = scenarios.length;
2664
+ const label = current
2665
+ ? current.group + " · " + current.name
2666
+ : "Recorded call";
2212
2667
  return `<div class="dd" id="scenario-dd">
2213
- <button type="button" class="dd-toggle" id="scenario-toggle">${label}</button>
2668
+ <button type="button" class="dd-toggle" id="scenario-toggle"><span class="dd-toggle-label">${escapeHtml(label)}</span><span class="dd-count" title="Total examples">${total}</span></button>
2214
2669
  <div class="dd-menu">${order
2215
2670
  .map(
2216
2671
  (group) =>
2217
- `<div class="dd-group">${group}</div>` +
2672
+ `<div class="dd-group"><span>${escapeHtml(group)}</span><span class="dd-count">${groups[group].length}</span></div>` +
2218
2673
  groups[group]
2219
- .map(({ scenario, index }) => `<button type="button" class="dd-item ${index === selected ? "on" : ""}" data-index="${index}">${scenario.status} — ${scenario.name}</button>`)
2674
+ .map(
2675
+ ({ scenario, index }) =>
2676
+ `<button type="button" class="dd-item ${index === selected ? "on" : ""}" data-index="${index}">${escapeHtml(String(scenario.status))} — ${escapeHtml(scenario.name)}</button>`,
2677
+ )
2220
2678
  .join(""),
2221
2679
  )
2222
2680
  .join("")}</div>
@@ -2237,6 +2695,23 @@
2237
2695
  return status ? status + " — " + name : name;
2238
2696
  };
2239
2697
 
2698
+ const renderNavExamples = (item) => {
2699
+ const { groups, order } = groupScenarios(item.scenarios);
2700
+ return `<div class="nav-examples">${order
2701
+ .map(
2702
+ (group) => `<div class="nav-ex-group">
2703
+ <div class="nav-ex-group-label"><span>${escapeHtml(group)}</span><span class="nav-ex-count">${groups[group].length}</span></div>
2704
+ ${groups[group]
2705
+ .map(
2706
+ ({ scenario, index }) =>
2707
+ `<button type="button" class="nav-example ${item.id === currentId && index === scenarioIndex ? "on" : ""}" data-id="${escapeAttr(item.id)}" data-scenario="${index}" title="${escapeAttr(scenarioNavLabel(scenario))}">${escapeHtml(scenarioNavLabel(scenario))}</button>`,
2708
+ )
2709
+ .join("")}
2710
+ </div>`,
2711
+ )
2712
+ .join("")}</div>`;
2713
+ };
2714
+
2240
2715
  const kv = (label, value) => {
2241
2716
  if (value === undefined || value === "") return "";
2242
2717
  const shown = typeof value === "object" ? JSON.stringify(value) : String(value);
@@ -2290,20 +2765,15 @@
2290
2765
  .map((item) => {
2291
2766
  const hasExamples = Array.isArray(item.scenarios) && item.scenarios.length > 0;
2292
2767
  const examplesOpen = expandedExampleOps.has(item.id);
2293
- const examplesHtml = hasExamples
2294
- ? `<div class="nav-examples">${item.scenarios
2295
- .map(
2296
- (scenario, index) =>
2297
- `<button type="button" class="nav-example ${item.id === currentId && index === scenarioIndex ? "on" : ""}" data-id="${escapeAttr(item.id)}" data-scenario="${index}" title="${escapeAttr(scenarioNavLabel(scenario))}">${escapeAttr(scenarioNavLabel(scenario))}</button>`,
2298
- )
2299
- .join("")}</div>`
2300
- : "";
2768
+ const examplesHtml = hasExamples ? renderNavExamples(item) : "";
2769
+ const exampleCount = hasExamples ? item.scenarios.length : 0;
2301
2770
  return `<div class="nav-op ${item.id === currentId ? "active" : ""} ${examplesOpen ? "examples-open" : ""}" data-op-id="${escapeAttr(item.id)}">
2302
2771
  <div class="nav-op-row">
2303
2772
  <button type="button" class="nav-item" data-id="${escapeAttr(item.id)}" title="${escapeAttr(item.path)}">
2304
2773
  <span class="method ${item.method}">${item.method}</span>
2305
2774
  <span class="nav-title">${escapeAttr(item.title)}</span>
2306
2775
  </button>
2776
+ ${hasExamples ? `<span class="nav-ex-total" title="${exampleCount} examples">${exampleCount}</span>` : ""}
2307
2777
  <button type="button" class="nav-expand" data-expand-id="${escapeAttr(item.id)}" title="Examples" aria-label="Toggle examples" aria-expanded="${examplesOpen ? "true" : "false"}" ${hasExamples ? "" : "disabled"}>
2308
2778
  <span class="chev"></span>
2309
2779
  </button>
@@ -2477,13 +2947,13 @@
2477
2947
  return fields
2478
2948
  .map((field) => {
2479
2949
  const depth = field.in === "body" ? fieldDepth(field.name) : 0;
2480
- const pad = depth ? ` style="padding-left:${depth * 14}px"` : "";
2481
2950
  const nestClass = depth ? " nested" : "";
2951
+ const depthAttr = depth ? ` data-depth="${Math.min(depth, 4)}"` : "";
2482
2952
  return `<div class="row">
2483
- <div class="name${nestClass}"${pad}>${field.name}</div>
2484
- <div class="type">${field.in}</div>
2953
+ <div class="name${nestClass}"${depthAttr}>${escapeHtml(field.name)}</div>
2954
+ <div class="loc">${escapeHtml(field.in)}</div>
2485
2955
  <div>
2486
- <div class="type">${field.type}</div>
2956
+ <div class="type">${escapeHtml(field.type)}</div>
2487
2957
  ${field.required === true ? `<div class="flag req">Required</div>` : field.required === false ? `<div class="flag">Optional</div>` : ""}
2488
2958
  </div>
2489
2959
  </div>`;
@@ -161,13 +161,14 @@ function valueFingerprint(value) {
161
161
  return Object.prototype.toString.call(value);
162
162
  }
163
163
  }
164
- /** Stable shared key so request + response examples from the same hit stay paired. */
165
- function exampleKeyForHit(hit, index) {
166
- const base = slug((0, catalog_1.exampleLabel)(hit), index);
167
- return `${base}-${index}`;
168
- }
169
164
  function putExample(store, key, summary, value) {
170
- store[key] = { summary, value };
165
+ store[key] = { summary, description: summary, value };
166
+ }
167
+ /** Prefer a stable, human-readable example map key (Postman often displays the key). */
168
+ function exampleKeyForHit(hit, index) {
169
+ const label = (0, catalog_1.exampleLabel)(hit);
170
+ const base = slug(label, index);
171
+ return base ? `${base}-${index}` : `example-${index + 1}`;
171
172
  }
172
173
  function isPrimaryHit(hit) {
173
174
  if (!hit.test)
@@ -45,6 +45,57 @@ function exportPathFromTree(urlPath, treeSegments) {
45
45
  : [...treeSegments, ...tail];
46
46
  return `/${parts.join('/')}`;
47
47
  }
48
+ function promoteExampleLabels(examples) {
49
+ if (!examples || typeof examples !== 'object')
50
+ return examples;
51
+ const out = {};
52
+ for (const [key, example] of Object.entries(examples)) {
53
+ if (!example || typeof example !== 'object')
54
+ continue;
55
+ const summary = String(example.summary || example.description || key).trim() || key;
56
+ let name = summary;
57
+ let n = 2;
58
+ while (Object.prototype.hasOwnProperty.call(out, name)) {
59
+ name = `${summary} (${n})`;
60
+ n += 1;
61
+ }
62
+ out[name] = { summary, description: summary, value: example.value };
63
+ }
64
+ return out;
65
+ }
66
+ function promoteOperationExampleLabels(operation) {
67
+ const next = { ...operation };
68
+ const requestBody = next.requestBody;
69
+ if (requestBody?.content?.['application/json']?.examples) {
70
+ const media = { ...requestBody.content['application/json'] };
71
+ media.examples = promoteExampleLabels(media.examples);
72
+ next.requestBody = {
73
+ ...requestBody,
74
+ content: { ...requestBody.content, 'application/json': media },
75
+ };
76
+ }
77
+ const responses = next.responses;
78
+ if (responses) {
79
+ const out = {};
80
+ for (const [status, response] of Object.entries(responses)) {
81
+ const examples = response?.content?.['application/json']?.examples;
82
+ if (!examples) {
83
+ out[status] = response;
84
+ continue;
85
+ }
86
+ const media = { ...response.content['application/json'] };
87
+ media.examples = promoteExampleLabels(examples);
88
+ const labels = Object.keys(media.examples || {});
89
+ out[status] = {
90
+ ...response,
91
+ description: labels.length === 1 ? labels[0] : response.description || status,
92
+ content: { ...response.content, 'application/json': media },
93
+ };
94
+ }
95
+ next.responses = out;
96
+ }
97
+ return next;
98
+ }
48
99
  /**
49
100
  * Export OpenAPI with path keys ordered like the docs sidebar (`x-tree-segments`).
50
101
  * Real request URLs stay on `x-daxta-url-path` when remapped.
@@ -76,7 +127,8 @@ function toTreeOrderedOpenApi(raw) {
76
127
  }
77
128
  const operation = value;
78
129
  const segments = treeSegmentsForOperation(urlPath, operation);
79
- const cleaned = stripViewerExtensions(operation);
130
+ let cleaned = stripViewerExtensions(operation);
131
+ cleaned = promoteOperationExampleLabels(cleaned);
80
132
  const tagParts = segments.filter((part) => !part.startsWith('{'));
81
133
  const tag = tagParts.length ? tagParts.join(' / ') : 'API';
82
134
  cleaned.tags = [tag];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t0.labs/daxta",
3
- "version": "0.4.8",
3
+ "version": "0.4.10",
4
4
  "description": "DAxTA \u2014 docs from Nest integration traffic + DTO field CLI / Try-it",
5
5
  "license": "MIT",
6
6
  "repository": {