@t0.labs/daxta 0.4.11 → 0.4.12

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.
@@ -2112,6 +2112,7 @@
2112
2112
  const tagParts = segments.filter((part) => !String(part).startsWith("{"));
2113
2113
  const tag = tagParts.length ? tagParts.join(" / ") : "API";
2114
2114
  cleaned.tags = [tag];
2115
+ cleaned["x-tree-segments"] = segments;
2115
2116
  tagNames.add(tag);
2116
2117
  if (exportPath !== urlPath) cleaned["x-daxta-url-path"] = urlPath;
2117
2118
  itemOut[method] = cleaned;
@@ -2253,21 +2254,52 @@
2253
2254
  };
2254
2255
  };
2255
2256
 
2257
+ const collectionFolderSegments = (urlPath, operation) => {
2258
+ const fromTree = operation && operation["x-tree-segments"];
2259
+ const parts = Array.isArray(fromTree) && fromTree.length
2260
+ ? fromTree.map(String)
2261
+ : String(urlPath || "").split("/").filter(Boolean);
2262
+ const named = parts.filter((part) => part && !part.startsWith("{"));
2263
+ return named.length ? named : ["API"];
2264
+ };
2265
+
2266
+ const pushIntoFolderTree = (root, segments, requestItem) => {
2267
+ let level = root;
2268
+ for (let index = 0; index < segments.length; index += 1) {
2269
+ const name = segments[index];
2270
+ let folder = level.find((entry) => entry && entry.name === name && Array.isArray(entry.item) && !entry.request);
2271
+ if (!folder) {
2272
+ folder = { name, item: [] };
2273
+ level.push(folder);
2274
+ }
2275
+ if (index === segments.length - 1) folder.item.push(requestItem);
2276
+ else level = folder.item;
2277
+ }
2278
+ };
2279
+
2280
+ const sortCollectionTree = (items) => {
2281
+ const folders = items.filter((entry) => entry && Array.isArray(entry.item) && !entry.request);
2282
+ const requests = items.filter((entry) => entry && entry.request);
2283
+ folders.sort((left, right) => String(left.name).localeCompare(String(right.name)));
2284
+ for (const folder of folders) folder.item = sortCollectionTree(folder.item);
2285
+ requests.sort((left, right) => String(left.name).localeCompare(String(right.name)));
2286
+ return [...folders, ...requests];
2287
+ };
2288
+
2256
2289
  /**
2257
2290
  * 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.
2291
+ * Folders follow the docs tree (v1 → admin → product), not a single joined tag.
2259
2292
  */
2260
2293
  const buildPostmanCollection = (openapi) => {
2261
2294
  const serverUrl = (openapi.servers && openapi.servers[0] && openapi.servers[0].url) || "{{baseUrl}}";
2262
- const folders = new Map();
2295
+ const root = [];
2263
2296
 
2264
2297
  for (const [urlPath, pathItem] of Object.entries(openapi.paths || {})) {
2265
2298
  if (!pathItem || typeof pathItem !== "object") continue;
2266
2299
  for (const method of HTTP_EXPORT) {
2267
2300
  const operation = pathItem[method];
2268
2301
  if (!operation || typeof operation !== "object") continue;
2269
- const folderName = (operation.tags && operation.tags[0]) || "API";
2270
- if (!folders.has(folderName)) folders.set(folderName, []);
2302
+ const requestPath = operation["x-daxta-url-path"] || urlPath;
2271
2303
 
2272
2304
  const headerParams = (operation.parameters || []).filter((param) => param && param.in === "header" && param.name);
2273
2305
  const requestHeaders = headerParams.map((param) => ({
@@ -2288,7 +2320,7 @@
2288
2320
  const baseRequest = {
2289
2321
  method: method.toUpperCase(),
2290
2322
  header: requestHeaders,
2291
- url: postmanUrlFromPath(serverUrl, urlPath),
2323
+ url: postmanUrlFromPath(serverUrl, requestPath),
2292
2324
  description: operation.summary || "",
2293
2325
  };
2294
2326
  if (defaultBody !== undefined) {
@@ -2336,17 +2368,15 @@
2336
2368
  }
2337
2369
  }
2338
2370
 
2339
- folders.get(folderName).push({
2340
- name: operation.summary || method.toUpperCase() + " " + urlPath,
2371
+ pushIntoFolderTree(root, collectionFolderSegments(urlPath, operation), {
2372
+ name: operation.summary || method.toUpperCase() + " " + requestPath,
2341
2373
  request: baseRequest,
2342
2374
  response: responses,
2343
2375
  });
2344
2376
  }
2345
2377
  }
2346
2378
 
2347
- const item = [...folders.entries()]
2348
- .sort(([a], [b]) => a.localeCompare(b))
2349
- .map(([name, children]) => ({ name, item: children }));
2379
+ const item = sortCollectionTree(root);
2350
2380
 
2351
2381
  return {
2352
2382
  info: {
@@ -132,6 +132,7 @@ function toTreeOrderedOpenApi(raw) {
132
132
  const tagParts = segments.filter((part) => !part.startsWith('{'));
133
133
  const tag = tagParts.length ? tagParts.join(' / ') : 'API';
134
134
  cleaned.tags = [tag];
135
+ cleaned['x-tree-segments'] = segments;
135
136
  tagNames.add(tag);
136
137
  if (exportPath !== urlPath) {
137
138
  cleaned['x-daxta-url-path'] = urlPath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t0.labs/daxta",
3
- "version": "0.4.11",
3
+ "version": "0.4.12",
4
4
  "description": "DAxTA \u2014 docs from Nest integration traffic + DTO field CLI / Try-it",
5
5
  "license": "MIT",
6
6
  "repository": {