From 2d56f154d5ddf1631385eee1fe1577428aaad5bf Mon Sep 17 00:00:00 2001 From: Bingbing Date: Wed, 23 Sep 2026 12:00:08 +0800 Subject: [PATCH] feat(INS-3641): add Export OpenAPI Spec to the document context menu (#10538) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Adds an **Export OpenAPI Spec** item right under the existing **Export** option in the sidebar workspace dropdown — the context menu for an API collection (opened via the ellipsis trigger button or by right-clicking the workspace row). Selecting it prompts for **YAML or JSON**, then a save location, and writes the spec file — the same flow as the existing Insomnia/HAR exporters (format modal → native save dialog → `writeFile`), reusing `showSaveExportedFileDialog` / `writeExportedFileToFileSystem` so the last export path is remembered. Closes INS-3641 ## Behavior details - The item shows for collection/design scope workspaces. If the spec is empty or missing, clicking it shows a `Cannot export` alert explaining there is nothing to export, rather than writing an empty file. - Same serialization as inso: matching format passes the contents through untouched; cross-format converts via `YAML.parse` + `JSON.stringify(…, 2)` / `YAML.stringify`, with an error modal if the spec is invalid. - Records `dataExport` telemetry like every sibling exporter in the file. - Spec format detection/conversion are shared with the Spec editor toolbar via new `detectApiSpecSyntax` / `convertApiSpecSyntax` helpers in `common/api-specs` (the toolbar previously inlined the same JSON-parse probe). --- packages/insomnia-smoke-test/.gitignore | 3 + .../pages/components/export-modal.ts | 2 +- .../pages/components/navigation-sidebar.ts | 2 +- .../playwright/pages/project/index.ts | 2 +- .../tests/smoke/app.test.ts | 2 +- .../tests/smoke/export-openapi-spec.test.ts | 120 ++++++++++++++ .../smoke/pre-request-script-window.test.ts | 2 +- packages/insomnia/src/common/api-specs.ts | 23 +++ .../dropdowns/sidebar-workspace-dropdown.tsx | 11 ++ .../__tests__/export-specification.test.ts | 146 ++++++++++++++++++ .../ui/components/settings/import-export.tsx | 78 +++++++++- .../insomnia/src/ui/components/spec-view.tsx | 15 +- 12 files changed, 389 insertions(+), 17 deletions(-) create mode 100644 packages/insomnia-smoke-test/tests/smoke/export-openapi-spec.test.ts create mode 100644 packages/insomnia/src/ui/components/settings/__tests__/export-specification.test.ts diff --git a/packages/insomnia-smoke-test/.gitignore b/packages/insomnia-smoke-test/.gitignore index dc0a9c6e15..06f03d4b8d 100644 --- a/packages/insomnia-smoke-test/.gitignore +++ b/packages/insomnia-smoke-test/.gitignore @@ -20,3 +20,6 @@ fixtures/inso-nedb/insomnia.OAuth2Token.db fixtures/inso-nedb/insomnia.PluginData.db fixtures/inso-nedb/insomnia.CaCertificate.db fixtures/inso-nedb/insomnia.CloudCredential.db + +# Playwright junit/xml run artifacts +test-results.xml diff --git a/packages/insomnia-smoke-test/playwright/pages/components/export-modal.ts b/packages/insomnia-smoke-test/playwright/pages/components/export-modal.ts index 961368cf5c..629b0a248f 100644 --- a/packages/insomnia-smoke-test/playwright/pages/components/export-modal.ts +++ b/packages/insomnia-smoke-test/playwright/pages/components/export-modal.ts @@ -11,7 +11,7 @@ export class ExportModal { * Handles the export type selection modal (Insomnia v5 or HAR). * @param format - The format to select ('yaml' for Insomnia v5, 'har' for HAR) */ - async selectExportFormat(format: 'yaml' | 'har'): Promise { + async selectExportFormat(format: 'yaml' | 'har' | 'json'): Promise { await this.page.getByText('Which format would you like to export as?').waitFor({ state: 'visible' }); // The modal uses a