{"record":{"id":"fe31ce8cc1b97b05","repo":"Kong/insomnia","slug":"failed-to-parse-api-spec","errorCode":null,"errorMessage":"Failed to parse API spec","messagePattern":"Failed to parse API spec","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/insomnia/src/common/api-specs.ts","lineNumber":22,"sourceCode":"  contents: Record<string, any> | null;\n  rawContents: string;\n  format: 'openapi' | 'swagger' | null;\n  formatVersion: string | null;\n}\n\nexport function parseApiSpec(rawDocument: string) {\n  const result: ParsedApiSpec = {\n    contents: null,\n    rawContents: rawDocument,\n    format: null,\n    formatVersion: null,\n  };\n\n  // NOTE: JSON is valid YAML so we only need to parse YAML\n  try {\n    result.contents = YAML.parse(rawDocument);\n  } catch {\n    throw new Error('Failed to parse API spec');\n  }\n\n  if (result.contents) {\n    if (result.contents.openapi) {\n      // Check if it's OpenAPI\n      result.format = 'openapi';\n      result.formatVersion = result.contents.openapi;\n    } else if (result.contents.swagger) {\n      // Check if it's Swagger\n      result.format = 'swagger';\n      result.formatVersion = result.contents.swagger;\n    } else {\n      // Not sure what format it is\n    }\n  }\n\n  return result;\n}","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/Kong/insomnia/blob/d9bb2b0142600f21309832daea3317942d285984/packages/insomnia/src/common/api-specs.ts#L4-L40","documentation":"Error \"Failed to parse API spec\" thrown in Kong/insomnia.","triggerScenarios":"Thrown at packages/insomnia/src/common/api-specs.ts:22 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d9bb2b0142600f21309832daea3317942d285984","analyzedAt":"2026-08-26T18:04:05.187Z","schemaVersion":2},"datasetVersion":"2026-08-26T21:11:00.512Z"}