Skip to content

fix: prune unselected folders from filtered v5 exports#9863

Open
officialasishkumar wants to merge 1 commit intoKong:developfrom
officialasishkumar:fix/export-only-ancestor-folders-of-selected-requests
Open

fix: prune unselected folders from filtered v5 exports#9863
officialasishkumar wants to merge 1 commit intoKong:developfrom
officialasishkumar:fix/export-only-ancestor-folders-of-selected-requests

Conversation

@officialasishkumar
Copy link
Copy Markdown

Summary

When a user exports a subset of requests (for example, a single request from the Scratch Pad), every folder in the workspace was still embedded in the resulting YAML along with each folder's name and docs. Re-importing such a file recreated empty folder skeletons and leaked documentation from unrelated areas of the workspace.

Root cause

In getInsomniaV5DataExport (packages/insomnia/src/common/insomnia-v5.ts), the filter applied when a requestIds list is provided short-circuits for every RequestGroup, so request groups are always included regardless of whether they contain any of the selected requests.

Fix

Pre-compute the set of RequestGroup IDs that are ancestors of at least one selected request, then only emit request groups whose ID is in that set. Non-folder resources still use the existing requestIds.includes(...) filter. Behavior is unchanged when no filter is supplied.

Tests

Two new tests in packages/insomnia/src/common/__tests__/insomnia-v5.test.ts cover:

  1. A deep folder tree where only the folder chain containing the selected request is exported (unrelated folders and their docs must not appear in the YAML).
  2. A request selected at the workspace root (no ancestor folders to keep) alongside an unrelated folder that must be pruned.

Test plan

  • npm test -w packages/insomnia passes for src/common/__tests__/insomnia-v5.test.ts (21/21, including the 2 new cases).
  • npm run lint passes.
  • tsc reports no new type errors in insomnia-v5.ts.

Closes #9482
Closes #8538

When a user exports a subset of requests from the Scratch Pad or any
collection, every folder in the workspace was still embedded in the
resulting YAML (including each folder's name and docs). Importing such
a file recreated empty folder skeletons and leaked documentation from
unrelated areas.

Pre-compute the set of folder ancestors for the selected request IDs
and drop any request group that is not in that set. Requests and other
leaf resources still apply the existing ID filter, so behavior is
unchanged when no filter is provided.

Closes Kong#9482
Closes Kong#8538
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Local exports always store the whole folder structure Exporting a single request still includes unrelated “docs” content

2 participants