Budibase/budibase · error · Error
Empty OpenAPI document
Error message
Empty OpenAPI document
What it means
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.
Source
Thrown at packages/server/src/api/controllers/query/import/sources/base/openapi.ts:17
import SwaggerParser from "@apidevtools/swagger-parser"
import { load as loadYaml } from "js-yaml"
import isObject from "lodash/isObject"
import { OpenAPI } from "openapi-types"
import { ImportSource } from "."
const isYamlDocument = (loaded: unknown): loaded is OpenAPI.Document => {
if (isObject(loaded)) {
return true
}
return false
}
const prepareDocument = (raw: string): string | OpenAPI.Document => {
const trimmed = raw.trim()
if (!trimmed) {
throw new Error("Empty OpenAPI document")
}
try {
const yamlDocument = loadYaml(trimmed, {
// allow duplicate keys so large vendor specs (e.g. Okta) still parse
json: true,
})
if (isYamlDocument(yamlDocument)) {
return yamlDocument
}
} catch (err) {
// fall through to allow swagger parser to attempt parsing
}
return raw
}
export abstract class OpenAPISource extends ImportSource {View on GitHub (pinned to a81a902e9a)
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
Example fix
// before
const data = fs.readFileSync(path, "utf8") // wrong path, ''
await RestImporter.init(data, "openapi3.0")
// after
const data = fs.readFileSync(correctPath, "utf8")
if (!data.trim()) throw new Error("spec file is empty")
await RestImporter.init(data, "openapi3.0") Defensive patterns
Strategy: validation
Validate before calling
if (!data || !data.trim()) {
throw new Error("Spec content is empty — provide the OpenAPI YAML/JSON body")
} Type guard
const isNonEmptyString = (v: unknown): v is string => typeof v === "string" && v.trim().length > 0
Try / catch
null
Prevention
- 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)
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unsupported import data
- Selected endpoint could not be imported
- Unsupported method: ${method}
- Failed to load OpenAPI 2 document
- Failed to load OpenAPI 3 document
AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29).
Data as JSON: /api/errors/526b74e7549fdddb.
Report an issue: GitHub.