Skip to content

fix: oas should import requests where possible#9632

Open
jackkav wants to merge 3 commits intoKong:developfrom
jackkav:fix/oas-with-requests
Open

fix: oas should import requests where possible#9632
jackkav wants to merge 3 commits intoKong:developfrom
jackkav:fix/oas-with-requests

Conversation

@jackkav
Copy link
Contributor

@jackkav jackkav commented Feb 3, 2026

This appears to have worked previously. Just had to fix the api spec detection

image

@jackkav jackkav requested a review from a team February 3, 2026 11:32
@jackkav jackkav force-pushed the fix/oas-with-requests branch 2 times, most recently from 7621ab2 to 2570ca5 Compare February 3, 2026 13:44
Comment on lines +176 to +181
let insomnia5Import: ExportedModel[] = [];
if (contentStr.startsWith('type: ')) {
const { data, error } = tryImportV5Data(contentStr);
insomnia5Import = data as ExportedModel[];
v5Error = error;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this because the error spam was killing my debugging experience

Comment on lines 240 to 258
@@ -251,6 +255,7 @@ export async function scanResources(importEntries: ImportEntry[]): Promise<ScanR
unitTests,
unitTestSuites,
requests: [...requests, ...websocketRequests, ...grpcRequests, ...socketIoRequests],
requestGroups,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was most of what was broken about imports before, if im not mistaken

// in order to support import from api spec yaml
if (resourceCacheItem?.importer?.id && isApiSpecImport(resourceCacheItem.importer)) {
// support import from both insomnia export and api spec yaml
if (resources.find(isApiSpec) || isApiSpecImport(resourceCacheItem.importer)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes the next code support both v5 and oas

Comment on lines +695 to +699
if (isGitProject(project)) {
await models.workspaceMeta.update(workspaceMeta, {
gitFilePath: `${newWorkspace.name}-${newWorkspace._id}.yaml`,
});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved this down since it was duplicated

Copilot AI review requested due to automatic review settings February 6, 2026 14:40
@gatzjames gatzjames force-pushed the fix/oas-with-requests branch from 2570ca5 to 0157b67 Compare February 6, 2026 14:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts import scanning and workspace creation to better detect API spec vs Insomnia exports, aiming to ensure OpenAPI/Swagger imports can include generated requests (and related group structure) where possible.

Changes:

  • Tightened Insomnia v5 detection during scanning to avoid mis-detecting non-v5 content.
  • Exposed requestGroups in scan results alongside requests.
  • Updated new-workspace import flow to create design workspaces when API specs are involved, and adjusted git workspace metadata handling.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
packages/insomnia/src/routes/import.scan.tsx Removes commented-out import parsing snippet from the cURL scan path.
packages/insomnia/src/common/import.ts Updates scan heuristics, includes request groups in scan output, and changes new-workspace import behavior for API specs and git projects.
packages/insomnia-smoke-test/tests/smoke/command-palette.test.ts Adds an extra navigation step in the command palette smoke test.
Comments suppressed due to low confidence (2)

packages/insomnia/src/common/import.ts:618

  • The condition resources.find(isApiSpec) || isApiSpecImport(resourceCacheItem.importer) treats any import that contains an ApiSpec model as a raw API-spec-YAML import. For Insomnia exports that include an ApiSpec resource (e.g. v5 spec workspace export / workspace duplication), this will incorrectly write apiSpec.contents from resourceCacheItem.content (which can be the entire export payload/JSON) and force contentType: 'yaml'. Split the cases: for OAS importers, use the raw content string; for Insomnia exports containing an ApiSpec resource, use that resource's contents/contentType and preserve the workspace scope/name from the exported workspace.
  // support import from both insomnia export and api spec yaml
  if (resources.find(isApiSpec) || isApiSpecImport(resourceCacheItem.importer)) {
    newWorkspace = await models.workspace.create({
      name: workspaceToImport?.name,
      scope: 'design',
      parentId: projectId,
    });

    await models.apiSpec.updateOrCreateForParentId(newWorkspace._id, {
      contents: resourceCacheItem.content as string | undefined,
      contentType: 'yaml',
      fileName: workspaceToImport?.name,
    });

packages/insomnia/src/common/import.ts:618

  • The updated import path for API spec vs Insomnia export (the resources.find(isApiSpec) branch) changes workspace creation and apiSpec persistence logic, but there are no unit tests covering this regression-prone behavior (e.g. importing an Insomnia v5 export that contains an ApiSpec should persist apiSpec.contents from the model, not the raw file, and should still import generated requests/groups). Add tests in packages/insomnia/src/common/__tests__/import.test.ts that exercise importResourcesToProject() for an import file containing an ApiSpec resource.
  // support import from both insomnia export and api spec yaml
  if (resources.find(isApiSpec) || isApiSpecImport(resourceCacheItem.importer)) {
    newWorkspace = await models.workspace.create({
      name: workspaceToImport?.name,
      scope: 'design',
      parentId: projectId,
    });

    await models.apiSpec.updateOrCreateForParentId(newWorkspace._id, {
      contents: resourceCacheItem.content as string | undefined,
      contentType: 'yaml',
      fileName: workspaceToImport?.name,
    });

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


if (isGitProject(project)) {
await models.workspaceMeta.update(workspaceMeta, {
gitFilePath: `${newWorkspace.name}-${newWorkspace._id}.yaml`,
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gitFilePath is derived from newWorkspace.name without sanitization. Workspace names can contain path separators or other unsafe characters, which can create invalid paths or unintended directories in git-backed projects. Use the existing safeToUseInsomniaFileNameWithExt() helper (and path.join if needed) to generate a safe .yaml file name.

Suggested change
gitFilePath: `${newWorkspace.name}-${newWorkspace._id}.yaml`,
gitFilePath: safeToUseInsomniaFileNameWithExt(`${newWorkspace.name}-${newWorkspace._id}`, 'yaml'),

Copilot uses AI. Check for mistakes.
Comment on lines +176 to +181
let insomnia5Import: ExportedModel[] = [];
if (contentStr.startsWith('type: ')) {
const { data, error } = tryImportV5Data(contentStr);
insomnia5Import = data as ExportedModel[];
v5Error = error;
}
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scanResources only attempts Insomnia v5 import when contentStr.startsWith('type: '). Valid v5 YAML may include a BOM, leading whitespace, --- document start, or comments before type:, which would skip v5 parsing and change behavior/error reporting. Consider using contentStr.trimStart() and/or a regex that tolerates YAML preambles (and ideally verifies the value matches *.insomnia.rest/5.0) rather than a strict prefix match.

Copilot uses AI. Check for mistakes.
Comment on lines 239 to 259
@@ -251,6 +255,7 @@ export async function scanResources(importEntries: ImportEntry[]): Promise<ScanR
unitTests,
unitTestSuites,
requests: [...requests, ...websocketRequests, ...grpcRequests, ...socketIoRequests],
requestGroups,
workspaces,
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requestGroups is added to the returned scan result, but ScanResult interface does not declare this property. This makes the new data invisible to typed consumers and encourages any usage. Add requestGroups?: RequestGroup[] (and necessary import/type) to ScanResult to keep the contract accurate.

Copilot uses AI. Check for mistakes.
const { data: insomnia5Import, error } = tryImportV5Data(contentStr);
v5Error = error;
let insomnia5Import: ExportedModel[] = [];
if (contentStr.startsWith('type: ')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this will be true for all yaml imports.
Maybe we can improve the error logging instead?

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.

2 participants