{"record":{"id":"526b74e7549fdddb","repo":"Budibase/budibase","slug":"empty-openapi-document","errorCode":null,"errorMessage":"Empty OpenAPI document","messagePattern":"Empty OpenAPI document","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/server/src/api/controllers/query/import/sources/base/openapi.ts","lineNumber":17,"sourceCode":"import SwaggerParser from \"@apidevtools/swagger-parser\"\nimport { load as loadYaml } from \"js-yaml\"\nimport isObject from \"lodash/isObject\"\nimport { OpenAPI } from \"openapi-types\"\nimport { ImportSource } from \".\"\n\nconst isYamlDocument = (loaded: unknown): loaded is OpenAPI.Document => {\n  if (isObject(loaded)) {\n    return true\n  }\n  return false\n}\n\nconst prepareDocument = (raw: string): string | OpenAPI.Document => {\n  const trimmed = raw.trim()\n  if (!trimmed) {\n    throw new Error(\"Empty OpenAPI document\")\n  }\n\n  try {\n    const yamlDocument = loadYaml(trimmed, {\n      // allow duplicate keys so large vendor specs (e.g. Okta) still parse\n      json: true,\n    })\n    if (isYamlDocument(yamlDocument)) {\n      return yamlDocument\n    }\n  } catch (err) {\n    // fall through to allow swagger parser to attempt parsing\n  }\n\n  return raw\n}\n\nexport abstract class OpenAPISource extends ImportSource {","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/query/import/sources/base/openapi.ts#L1-L35","documentation":"prepareDocument is the first step of OpenAPI parsing: it trims the raw input and rejects empty input with 'Empty OpenAPI document' before attempting YAML/JSON parsing. This gives a clear early error instead of a confusing parser failure downstream.","triggerScenarios":"Loading an OpenAPI source with data that is empty or whitespace-only — e.g. an empty file, a spec fetched as an empty body, or a variable that was never assigned.","commonSituations":"URL import returned 200 with an empty body (misconfigured server); reading a file with the wrong path yielding ''; a form submission where the paste box was blank but whitespace satisfied a naive check.","solutions":["Verify the input string is non-empty and contains the actual YAML/JSON spec before loading","If loading via URL, curl the URL and check the body is not empty (a 200 with empty content)","Fix file reading so the spec content is actually read and passed, not an empty string"],"exampleFix":"// before\nconst data = fs.readFileSync(path, \"utf8\") // wrong path, ''\nawait RestImporter.init(data, \"openapi3.0\")\n// after\nconst data = fs.readFileSync(correctPath, \"utf8\")\nif (!data.trim()) throw new Error(\"spec file is empty\")\nawait RestImporter.init(data, \"openapi3.0\")","handlingStrategy":"validation","validationCode":"if (!data || !data.trim()) {\n  throw new Error(\"Spec content is empty — provide the OpenAPI YAML/JSON body\")\n}","typeGuard":"const isNonEmptyString = (v: unknown): v is string =>\n  typeof v === \"string\" && v.trim().length > 0","tryCatchPattern":"null","preventionTips":["Check file reads/URL fetches actually returned content before importing","Guard paste boxes for empty/whitespace-only input client-side","When importing by URL, verify the response body is non-empty (a 200 can still carry an empty body)"],"tags":["openapi","validation","empty-input"],"backgroundTag":"empty-request-body","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}