@t0.labs/daxta 0.4.8 → 0.4.9
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 +2 -0
- package/assets/viewer.html +411 -15
- package/dist/build/build-spec.js +7 -6
- package/dist/serve/spec-utils.js +53 -1
- package/package.json +1 -1
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
|
package/assets/viewer.html
CHANGED
|
@@ -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:
|
|
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 {
|
|
@@ -934,20 +990,49 @@
|
|
|
934
990
|
}
|
|
935
991
|
.row {
|
|
936
992
|
display: grid;
|
|
937
|
-
grid-template-columns: 1.
|
|
993
|
+
grid-template-columns: minmax(0, 1.5fr) minmax(72px, 0.55fr) minmax(0, 0.95fr);
|
|
938
994
|
gap: 12px;
|
|
995
|
+
align-items: start;
|
|
939
996
|
padding: 8px 0;
|
|
940
997
|
font-size: 13px;
|
|
941
998
|
}
|
|
942
|
-
.row .name {
|
|
943
|
-
|
|
944
|
-
|
|
999
|
+
.row .name {
|
|
1000
|
+
font-family: var(--mono);
|
|
1001
|
+
font-size: 12px;
|
|
1002
|
+
color: var(--obsidian);
|
|
1003
|
+
min-width: 0;
|
|
1004
|
+
overflow-wrap: anywhere;
|
|
1005
|
+
word-break: break-word;
|
|
1006
|
+
}
|
|
1007
|
+
.row .name.nested {
|
|
1008
|
+
color: var(--charcoal);
|
|
1009
|
+
border-left: 2px solid var(--hairline);
|
|
1010
|
+
padding-left: 10px;
|
|
1011
|
+
margin-left: 2px;
|
|
1012
|
+
}
|
|
1013
|
+
.row .name.nested[data-depth="2"] { margin-left: 14px; }
|
|
1014
|
+
.row .name.nested[data-depth="3"] { margin-left: 26px; }
|
|
1015
|
+
.row .name.nested[data-depth="4"] { margin-left: 38px; }
|
|
1016
|
+
.row .loc,
|
|
1017
|
+
.row .type {
|
|
1018
|
+
color: var(--stone);
|
|
1019
|
+
font-family: var(--mono);
|
|
1020
|
+
font-size: 12px;
|
|
1021
|
+
min-width: 0;
|
|
1022
|
+
}
|
|
945
1023
|
.flag { margin-top: 4px; font-size: 11px; color: var(--smoke); }
|
|
946
1024
|
.flag.req { color: #8a2e2e; }
|
|
947
1025
|
|
|
948
1026
|
@media (max-width: 960px) {
|
|
949
|
-
.app {
|
|
950
|
-
|
|
1027
|
+
.app {
|
|
1028
|
+
grid-template-columns: 1fr;
|
|
1029
|
+
height: auto;
|
|
1030
|
+
}
|
|
1031
|
+
.app.sidebar-collapsed {
|
|
1032
|
+
grid-template-columns: 1fr;
|
|
1033
|
+
}
|
|
1034
|
+
.sidebar { max-height: 40vh; opacity: 1 !important; pointer-events: auto !important; padding: 16px 12px 24px !important; }
|
|
1035
|
+
.sidebar-resizer { display: none; }
|
|
951
1036
|
.pair { grid-template-columns: 1fr; }
|
|
952
1037
|
.search-wrap { width: min(280px, 70vw); }
|
|
953
1038
|
}
|
|
@@ -996,7 +1081,11 @@
|
|
|
996
1081
|
<span>Postman <code>{{variables}}</code> + download environment file</span>
|
|
997
1082
|
</label>
|
|
998
1083
|
</div>
|
|
999
|
-
<p class="export-tip">
|
|
1084
|
+
<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>
|
|
1085
|
+
<label class="export-check">
|
|
1086
|
+
<input type="checkbox" id="export-postman-collection" checked />
|
|
1087
|
+
<span>Also download Postman Collection <span style="color:var(--stone)">(named examples)</span></span>
|
|
1088
|
+
</label>
|
|
1000
1089
|
</div>
|
|
1001
1090
|
<div class="export-toolbar">
|
|
1002
1091
|
<button type="button" class="btn sm" id="export-all">All</button>
|
|
@@ -1010,8 +1099,9 @@
|
|
|
1010
1099
|
</div>
|
|
1011
1100
|
</div>
|
|
1012
1101
|
</div>
|
|
1013
|
-
<div class="app">
|
|
1102
|
+
<div class="app" id="app">
|
|
1014
1103
|
<aside class="sidebar" id="nav"></aside>
|
|
1104
|
+
<button type="button" class="sidebar-resizer" id="sidebar-resizer" aria-label="Resize sidebar" title="Drag to resize · double-click to collapse"></button>
|
|
1015
1105
|
<main class="workbench" id="main"></main>
|
|
1016
1106
|
</div>
|
|
1017
1107
|
<script>
|
|
@@ -1046,6 +1136,10 @@
|
|
|
1046
1136
|
const defaultBaseUrl = locationBaseUrl || defaultBaseUrlFromSpec;
|
|
1047
1137
|
const title = (spec.info && spec.info.title) || "API Docs";
|
|
1048
1138
|
const STORE_KEY = "openapi-docs-env:" + (workspace || "default");
|
|
1139
|
+
const SIDEBAR_STORE_KEY = "openapi-docs-sidebar:" + (workspace || "default");
|
|
1140
|
+
const SIDEBAR_MIN = 200;
|
|
1141
|
+
const SIDEBAR_MAX = 560;
|
|
1142
|
+
const SIDEBAR_DEFAULT = 320;
|
|
1049
1143
|
|
|
1050
1144
|
const docsBaseForApi = (() => {
|
|
1051
1145
|
if (typeof location === "undefined") return docsPathSuffix;
|
|
@@ -1057,6 +1151,111 @@
|
|
|
1057
1151
|
})();
|
|
1058
1152
|
const ENV_STORE_URL = docsBaseForApi + "/env.json";
|
|
1059
1153
|
|
|
1154
|
+
const loadSidebarLayout = () => {
|
|
1155
|
+
try {
|
|
1156
|
+
const raw = localStorage.getItem(SIDEBAR_STORE_KEY);
|
|
1157
|
+
if (!raw) return { width: SIDEBAR_DEFAULT, collapsed: false };
|
|
1158
|
+
const parsed = JSON.parse(raw);
|
|
1159
|
+
const width = Number(parsed.width);
|
|
1160
|
+
return {
|
|
1161
|
+
width: Number.isFinite(width) ? Math.min(SIDEBAR_MAX, Math.max(SIDEBAR_MIN, width)) : SIDEBAR_DEFAULT,
|
|
1162
|
+
collapsed: Boolean(parsed.collapsed),
|
|
1163
|
+
};
|
|
1164
|
+
} catch {
|
|
1165
|
+
return { width: SIDEBAR_DEFAULT, collapsed: false };
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1168
|
+
|
|
1169
|
+
let sidebarLayout = loadSidebarLayout();
|
|
1170
|
+
|
|
1171
|
+
const applySidebarLayout = () => {
|
|
1172
|
+
const app = document.getElementById("app");
|
|
1173
|
+
const resizer = document.getElementById("sidebar-resizer");
|
|
1174
|
+
if (!app) return;
|
|
1175
|
+
app.style.setProperty("--sidebar-w", sidebarLayout.width + "px");
|
|
1176
|
+
app.classList.toggle("sidebar-collapsed", sidebarLayout.collapsed);
|
|
1177
|
+
if (resizer) {
|
|
1178
|
+
resizer.title = sidebarLayout.collapsed
|
|
1179
|
+
? "Click to expand sidebar"
|
|
1180
|
+
: "Drag to resize · double-click to collapse";
|
|
1181
|
+
resizer.setAttribute("aria-label", sidebarLayout.collapsed ? "Expand sidebar" : "Resize sidebar");
|
|
1182
|
+
}
|
|
1183
|
+
};
|
|
1184
|
+
|
|
1185
|
+
const persistSidebarLayout = () => {
|
|
1186
|
+
try {
|
|
1187
|
+
localStorage.setItem(SIDEBAR_STORE_KEY, JSON.stringify(sidebarLayout));
|
|
1188
|
+
} catch {}
|
|
1189
|
+
};
|
|
1190
|
+
|
|
1191
|
+
const initSidebarResize = () => {
|
|
1192
|
+
const resizer = document.getElementById("sidebar-resizer");
|
|
1193
|
+
if (!resizer) return;
|
|
1194
|
+
applySidebarLayout();
|
|
1195
|
+
|
|
1196
|
+
let dragging = false;
|
|
1197
|
+
let startX = 0;
|
|
1198
|
+
let startWidth = 0;
|
|
1199
|
+
let moved = false;
|
|
1200
|
+
|
|
1201
|
+
const onMove = (event) => {
|
|
1202
|
+
if (!dragging) return;
|
|
1203
|
+
if (event.cancelable) event.preventDefault();
|
|
1204
|
+
const clientX = event.touches ? event.touches[0].clientX : event.clientX;
|
|
1205
|
+
const delta = clientX - startX;
|
|
1206
|
+
if (Math.abs(delta) > 2) moved = true;
|
|
1207
|
+
const next = Math.min(SIDEBAR_MAX, Math.max(SIDEBAR_MIN, startWidth + delta));
|
|
1208
|
+
sidebarLayout.width = next;
|
|
1209
|
+
sidebarLayout.collapsed = false;
|
|
1210
|
+
applySidebarLayout();
|
|
1211
|
+
};
|
|
1212
|
+
|
|
1213
|
+
const onUp = () => {
|
|
1214
|
+
if (!dragging) return;
|
|
1215
|
+
dragging = false;
|
|
1216
|
+
document.body.classList.remove("sidebar-resizing");
|
|
1217
|
+
window.removeEventListener("mousemove", onMove);
|
|
1218
|
+
window.removeEventListener("mouseup", onUp);
|
|
1219
|
+
window.removeEventListener("touchmove", onMove);
|
|
1220
|
+
window.removeEventListener("touchend", onUp);
|
|
1221
|
+
persistSidebarLayout();
|
|
1222
|
+
};
|
|
1223
|
+
|
|
1224
|
+
const onDown = (event) => {
|
|
1225
|
+
if (sidebarLayout.collapsed) return;
|
|
1226
|
+
if (event.button != null && event.button !== 0) return;
|
|
1227
|
+
event.preventDefault();
|
|
1228
|
+
dragging = true;
|
|
1229
|
+
moved = false;
|
|
1230
|
+
startX = event.touches ? event.touches[0].clientX : event.clientX;
|
|
1231
|
+
startWidth = sidebarLayout.width;
|
|
1232
|
+
document.body.classList.add("sidebar-resizing");
|
|
1233
|
+
window.addEventListener("mousemove", onMove);
|
|
1234
|
+
window.addEventListener("mouseup", onUp);
|
|
1235
|
+
window.addEventListener("touchmove", onMove, { passive: false });
|
|
1236
|
+
window.addEventListener("touchend", onUp);
|
|
1237
|
+
};
|
|
1238
|
+
|
|
1239
|
+
resizer.addEventListener("mousedown", onDown);
|
|
1240
|
+
resizer.addEventListener("touchstart", onDown, { passive: false });
|
|
1241
|
+
resizer.addEventListener("dblclick", (event) => {
|
|
1242
|
+
event.preventDefault();
|
|
1243
|
+
sidebarLayout.collapsed = !sidebarLayout.collapsed;
|
|
1244
|
+
if (!sidebarLayout.collapsed && sidebarLayout.width < SIDEBAR_MIN) sidebarLayout.width = SIDEBAR_DEFAULT;
|
|
1245
|
+
applySidebarLayout();
|
|
1246
|
+
persistSidebarLayout();
|
|
1247
|
+
});
|
|
1248
|
+
resizer.addEventListener("click", (event) => {
|
|
1249
|
+
if (!sidebarLayout.collapsed || moved) return;
|
|
1250
|
+
event.preventDefault();
|
|
1251
|
+
sidebarLayout.collapsed = false;
|
|
1252
|
+
applySidebarLayout();
|
|
1253
|
+
persistSidebarLayout();
|
|
1254
|
+
});
|
|
1255
|
+
};
|
|
1256
|
+
|
|
1257
|
+
initSidebarResize();
|
|
1258
|
+
|
|
1060
1259
|
let liveResult = null;
|
|
1061
1260
|
|
|
1062
1261
|
const escapeAttr = (value) =>
|
|
@@ -1774,6 +1973,61 @@
|
|
|
1774
1973
|
return next;
|
|
1775
1974
|
};
|
|
1776
1975
|
|
|
1976
|
+
/** Rename example map keys to scenario titles; set summary+description (Postman-friendly). */
|
|
1977
|
+
const promoteExampleLabels = (examples) => {
|
|
1978
|
+
if (!examples || typeof examples !== "object") return examples;
|
|
1979
|
+
const out = {};
|
|
1980
|
+
for (const [key, example] of Object.entries(examples)) {
|
|
1981
|
+
if (!example || typeof example !== "object") continue;
|
|
1982
|
+
const summary = String(example.summary || example.description || key).trim() || key;
|
|
1983
|
+
let name = summary;
|
|
1984
|
+
let n = 2;
|
|
1985
|
+
while (Object.prototype.hasOwnProperty.call(out, name)) {
|
|
1986
|
+
name = summary + " (" + n + ")";
|
|
1987
|
+
n += 1;
|
|
1988
|
+
}
|
|
1989
|
+
out[name] = {
|
|
1990
|
+
summary,
|
|
1991
|
+
description: summary,
|
|
1992
|
+
value: example.value,
|
|
1993
|
+
};
|
|
1994
|
+
}
|
|
1995
|
+
return out;
|
|
1996
|
+
};
|
|
1997
|
+
|
|
1998
|
+
const promoteOperationExampleLabels = (operation) => {
|
|
1999
|
+
const next = { ...operation };
|
|
2000
|
+
if (next.requestBody?.content?.["application/json"]?.examples) {
|
|
2001
|
+
const media = { ...next.requestBody.content["application/json"] };
|
|
2002
|
+
media.examples = promoteExampleLabels(media.examples);
|
|
2003
|
+
next.requestBody = {
|
|
2004
|
+
...next.requestBody,
|
|
2005
|
+
content: { ...next.requestBody.content, "application/json": media },
|
|
2006
|
+
};
|
|
2007
|
+
}
|
|
2008
|
+
if (next.responses) {
|
|
2009
|
+
const responses = {};
|
|
2010
|
+
for (const [status, response] of Object.entries(next.responses)) {
|
|
2011
|
+
const examples = response?.content?.["application/json"]?.examples;
|
|
2012
|
+
if (!examples) {
|
|
2013
|
+
responses[status] = response;
|
|
2014
|
+
continue;
|
|
2015
|
+
}
|
|
2016
|
+
const media = { ...response.content["application/json"] };
|
|
2017
|
+
media.examples = promoteExampleLabels(examples);
|
|
2018
|
+
const labels = Object.keys(media.examples);
|
|
2019
|
+
responses[status] = {
|
|
2020
|
+
...response,
|
|
2021
|
+
// Single example: description becomes the scenario title (Postman uses this as the example name).
|
|
2022
|
+
description: labels.length === 1 ? labels[0] : response.description || status,
|
|
2023
|
+
content: { ...response.content, "application/json": media },
|
|
2024
|
+
};
|
|
2025
|
+
}
|
|
2026
|
+
next.responses = responses;
|
|
2027
|
+
}
|
|
2028
|
+
return next;
|
|
2029
|
+
};
|
|
2030
|
+
|
|
1777
2031
|
const toExportSpec = (source, selectedByOpId) => {
|
|
1778
2032
|
const pathsIn = source.paths || {};
|
|
1779
2033
|
const pathsOut = {};
|
|
@@ -1806,6 +2060,7 @@
|
|
|
1806
2060
|
if (selectedByOpId && selectedByOpId.has(opId)) {
|
|
1807
2061
|
cleaned = filterOperationExamples(cleaned, selectedByOpId.get(opId));
|
|
1808
2062
|
}
|
|
2063
|
+
cleaned = promoteOperationExampleLabels(cleaned);
|
|
1809
2064
|
const tagParts = segments.filter((part) => !String(part).startsWith("{"));
|
|
1810
2065
|
const tag = tagParts.length ? tagParts.join(" / ") : "API";
|
|
1811
2066
|
cleaned.tags = [tag];
|
|
@@ -1924,6 +2179,138 @@
|
|
|
1924
2179
|
};
|
|
1925
2180
|
};
|
|
1926
2181
|
|
|
2182
|
+
const STATUS_EXPORT = {
|
|
2183
|
+
200: "OK",
|
|
2184
|
+
201: "Created",
|
|
2185
|
+
204: "No Content",
|
|
2186
|
+
400: "Bad Request",
|
|
2187
|
+
401: "Unauthorized",
|
|
2188
|
+
403: "Forbidden",
|
|
2189
|
+
404: "Not Found",
|
|
2190
|
+
409: "Conflict",
|
|
2191
|
+
422: "Unprocessable Entity",
|
|
2192
|
+
500: "Internal Server Error",
|
|
2193
|
+
};
|
|
2194
|
+
|
|
2195
|
+
const postmanUrlFromPath = (serverUrl, pathTemplate) => {
|
|
2196
|
+
const base = String(serverUrl || "{{baseUrl}}").replace(/\/$/, "");
|
|
2197
|
+
const path = String(pathTemplate || "/");
|
|
2198
|
+
const segments = path.split("/").filter(Boolean);
|
|
2199
|
+
const pathParams = [...path.matchAll(/\{([^}]+)\}/g)].map((m) => m[1]);
|
|
2200
|
+
return {
|
|
2201
|
+
raw: base + (path.startsWith("/") ? path : "/" + path),
|
|
2202
|
+
host: base.startsWith("{{") ? [base] : [base.replace(/^https?:\/\//, "").split("/")[0]],
|
|
2203
|
+
path: segments.map((seg) => (seg.startsWith("{") && seg.endsWith("}") ? ":" + seg.slice(1, -1) : seg)),
|
|
2204
|
+
variable: pathParams.map((key) => ({ key, value: "" })),
|
|
2205
|
+
};
|
|
2206
|
+
};
|
|
2207
|
+
|
|
2208
|
+
/**
|
|
2209
|
+
* Postman Collection v2.1 — example `name` = scenario title (not "Created" / "Bad Request").
|
|
2210
|
+
* OpenAPI→Postman import names every example after response.description; this bypasses that.
|
|
2211
|
+
*/
|
|
2212
|
+
const buildPostmanCollection = (openapi) => {
|
|
2213
|
+
const serverUrl = (openapi.servers && openapi.servers[0] && openapi.servers[0].url) || "{{baseUrl}}";
|
|
2214
|
+
const folders = new Map();
|
|
2215
|
+
|
|
2216
|
+
for (const [urlPath, pathItem] of Object.entries(openapi.paths || {})) {
|
|
2217
|
+
if (!pathItem || typeof pathItem !== "object") continue;
|
|
2218
|
+
for (const method of HTTP_EXPORT) {
|
|
2219
|
+
const operation = pathItem[method];
|
|
2220
|
+
if (!operation || typeof operation !== "object") continue;
|
|
2221
|
+
const folderName = (operation.tags && operation.tags[0]) || "API";
|
|
2222
|
+
if (!folders.has(folderName)) folders.set(folderName, []);
|
|
2223
|
+
|
|
2224
|
+
const headerParams = (operation.parameters || []).filter((param) => param && param.in === "header" && param.name);
|
|
2225
|
+
const requestHeaders = headerParams.map((param) => ({
|
|
2226
|
+
key: param.name,
|
|
2227
|
+
value: param.example != null ? String(param.example) : "",
|
|
2228
|
+
type: "text",
|
|
2229
|
+
}));
|
|
2230
|
+
|
|
2231
|
+
const reqExamples = operation.requestBody?.content?.["application/json"]?.examples || {};
|
|
2232
|
+
const firstReq = Object.values(reqExamples)[0];
|
|
2233
|
+
const defaultBody =
|
|
2234
|
+
firstReq && firstReq.value !== undefined
|
|
2235
|
+
? typeof firstReq.value === "string"
|
|
2236
|
+
? firstReq.value
|
|
2237
|
+
: JSON.stringify(firstReq.value, null, 2)
|
|
2238
|
+
: undefined;
|
|
2239
|
+
|
|
2240
|
+
const baseRequest = {
|
|
2241
|
+
method: method.toUpperCase(),
|
|
2242
|
+
header: requestHeaders,
|
|
2243
|
+
url: postmanUrlFromPath(serverUrl, urlPath),
|
|
2244
|
+
description: operation.summary || "",
|
|
2245
|
+
};
|
|
2246
|
+
if (defaultBody !== undefined) {
|
|
2247
|
+
baseRequest.body = { mode: "raw", raw: defaultBody, options: { raw: { language: "json" } } };
|
|
2248
|
+
if (!requestHeaders.some((h) => String(h.key).toLowerCase() === "content-type")) {
|
|
2249
|
+
baseRequest.header = [...requestHeaders, { key: "Content-Type", value: "application/json", type: "text" }];
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
|
|
2253
|
+
const responses = [];
|
|
2254
|
+
for (const [status, response] of Object.entries(operation.responses || {})) {
|
|
2255
|
+
const examples = response?.content?.["application/json"]?.examples || {};
|
|
2256
|
+
const entries = Object.entries(examples);
|
|
2257
|
+
if (!entries.length) {
|
|
2258
|
+
responses.push({
|
|
2259
|
+
name: response.description || STATUS_EXPORT[status] || status,
|
|
2260
|
+
originalRequest: baseRequest,
|
|
2261
|
+
status: STATUS_EXPORT[status] || response.description || status,
|
|
2262
|
+
code: Number(status) || 0,
|
|
2263
|
+
_postman_previewlanguage: "json",
|
|
2264
|
+
header: [{ key: "Content-Type", value: "application/json" }],
|
|
2265
|
+
body: "",
|
|
2266
|
+
});
|
|
2267
|
+
continue;
|
|
2268
|
+
}
|
|
2269
|
+
for (const [exKey, example] of entries) {
|
|
2270
|
+
const name = (example && (example.summary || example.description)) || exKey;
|
|
2271
|
+
const reqMatch = reqExamples[exKey] || reqExamples[name] || firstReq;
|
|
2272
|
+
const requestForExample = { ...baseRequest, header: [...(baseRequest.header || [])] };
|
|
2273
|
+
if (reqMatch && reqMatch.value !== undefined) {
|
|
2274
|
+
const raw =
|
|
2275
|
+
typeof reqMatch.value === "string" ? reqMatch.value : JSON.stringify(reqMatch.value, null, 2);
|
|
2276
|
+
requestForExample.body = { mode: "raw", raw, options: { raw: { language: "json" } } };
|
|
2277
|
+
}
|
|
2278
|
+
const bodyValue = example && example.value !== undefined ? example.value : "";
|
|
2279
|
+
responses.push({
|
|
2280
|
+
name,
|
|
2281
|
+
originalRequest: requestForExample,
|
|
2282
|
+
status: STATUS_EXPORT[status] || String(status),
|
|
2283
|
+
code: Number(status) || 0,
|
|
2284
|
+
_postman_previewlanguage: "json",
|
|
2285
|
+
header: [{ key: "Content-Type", value: "application/json" }],
|
|
2286
|
+
body: typeof bodyValue === "string" ? bodyValue : JSON.stringify(bodyValue, null, 2),
|
|
2287
|
+
});
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
folders.get(folderName).push({
|
|
2292
|
+
name: operation.summary || method.toUpperCase() + " " + urlPath,
|
|
2293
|
+
request: baseRequest,
|
|
2294
|
+
response: responses,
|
|
2295
|
+
});
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2299
|
+
const item = [...folders.entries()]
|
|
2300
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
2301
|
+
.map(([name, children]) => ({ name, item: children }));
|
|
2302
|
+
|
|
2303
|
+
return {
|
|
2304
|
+
info: {
|
|
2305
|
+
_postman_id: typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : String(Date.now()),
|
|
2306
|
+
name: (openapi.info && openapi.info.title) || workspace || title || "DAxTA",
|
|
2307
|
+
description: (openapi.info && openapi.info.description) || "Exported from DAxTA with named examples",
|
|
2308
|
+
schema: "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
|
|
2309
|
+
},
|
|
2310
|
+
item,
|
|
2311
|
+
};
|
|
2312
|
+
};
|
|
2313
|
+
|
|
1927
2314
|
const closeExportModal = () => {
|
|
1928
2315
|
document.body.classList.remove("exporting");
|
|
1929
2316
|
};
|
|
@@ -1998,6 +2385,7 @@
|
|
|
1998
2385
|
const selectedByOpId = collectSelectedExamples();
|
|
1999
2386
|
let exported = toExportSpec(spec, selectedByOpId);
|
|
2000
2387
|
const includeTryIt = Boolean(document.getElementById("export-include-tryit")?.checked);
|
|
2388
|
+
const wantCollection = Boolean(document.getElementById("export-postman-collection")?.checked);
|
|
2001
2389
|
const fillMode =
|
|
2002
2390
|
document.querySelector('input[name="export-fill"]:checked')?.value === "variables" ? "variables" : "resolved";
|
|
2003
2391
|
const base = exportSafeName();
|
|
@@ -2008,10 +2396,18 @@
|
|
|
2008
2396
|
|
|
2009
2397
|
downloadJsonFile(base + ".openapi.json", exported);
|
|
2010
2398
|
|
|
2399
|
+
let delay = 120;
|
|
2400
|
+
if (wantCollection) {
|
|
2401
|
+
setTimeout(() => {
|
|
2402
|
+
downloadJsonFile(base + ".postman_collection.json", buildPostmanCollection(exported));
|
|
2403
|
+
}, delay);
|
|
2404
|
+
delay += 120;
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2011
2407
|
if (includeTryIt && fillMode === "variables") {
|
|
2012
2408
|
setTimeout(() => {
|
|
2013
2409
|
downloadJsonFile(base + ".postman_environment.json", buildPostmanEnvironment());
|
|
2014
|
-
},
|
|
2410
|
+
}, delay);
|
|
2015
2411
|
}
|
|
2016
2412
|
};
|
|
2017
2413
|
|
|
@@ -2477,13 +2873,13 @@
|
|
|
2477
2873
|
return fields
|
|
2478
2874
|
.map((field) => {
|
|
2479
2875
|
const depth = field.in === "body" ? fieldDepth(field.name) : 0;
|
|
2480
|
-
const pad = depth ? ` style="padding-left:${depth * 14}px"` : "";
|
|
2481
2876
|
const nestClass = depth ? " nested" : "";
|
|
2877
|
+
const depthAttr = depth ? ` data-depth="${Math.min(depth, 4)}"` : "";
|
|
2482
2878
|
return `<div class="row">
|
|
2483
|
-
<div class="name${nestClass}"${
|
|
2484
|
-
<div class="
|
|
2879
|
+
<div class="name${nestClass}"${depthAttr}>${escapeHtml(field.name)}</div>
|
|
2880
|
+
<div class="loc">${escapeHtml(field.in)}</div>
|
|
2485
2881
|
<div>
|
|
2486
|
-
<div class="type">${field.type}</div>
|
|
2882
|
+
<div class="type">${escapeHtml(field.type)}</div>
|
|
2487
2883
|
${field.required === true ? `<div class="flag req">Required</div>` : field.required === false ? `<div class="flag">Optional</div>` : ""}
|
|
2488
2884
|
</div>
|
|
2489
2885
|
</div>`;
|
package/dist/build/build-spec.js
CHANGED
|
@@ -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)
|
package/dist/serve/spec-utils.js
CHANGED
|
@@ -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
|
-
|
|
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];
|