{"record":{"id":"a0d57cec72407e7c","repo":"Budibase/budibase","slug":"template-name-is-required","errorCode":null,"errorMessage":"Template name is required","messagePattern":"Template name is required","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/api/controllers/restTemplate.ts","lineNumber":72,"sourceCode":"    UploadCustomRestTemplateRequest,\n    UploadCustomRestTemplateResponse\n  >\n) => {\n  const file = ctx.request.files?.file\n  if (!file || Array.isArray(file)) {\n    throw new HTTPError(\"Exactly one OpenAPI template file is required\", 400)\n  }\n\n  const uploadDetails = getUploadDetails(file)\n  if (!uploadDetails) {\n    throw new HTTPError(\"Invalid OpenAPI template upload\", 400)\n  }\n\n  try {\n    const name = ctx.request.body.name\n    const description = ctx.request.body.description\n    if (typeof name !== \"string\" || !name.trim()) {\n      throw new HTTPError(\"Template name is required\", 400)\n    }\n    if (typeof description !== \"string\") {\n      throw new HTTPError(\"Template description is required\", 400)\n    }\n\n    const fileExtension = getFileExtension(uploadDetails.filename)\n    const data = await readFile(uploadDetails.filepath, \"utf8\")\n    let importer\n    let info\n    try {\n      importer = await createImporter({ data })\n      const source = importer.getSource().getImportSource()\n      if (source !== \"openapi2.0\" && source !== \"openapi3.0\") {\n        throw new Error(\"Unsupported OpenAPI source\")\n      }\n      info = importer.getInfo()\n    } catch {\n      throw new HTTPError(\"File must contain a valid OpenAPI schema\", 400)","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/restTemplate.ts#L54-L90","documentation":"This 400 HTTPError is thrown by the REST template upload controller when the multipart request's 'name' body field is missing, not a string, or an empty/whitespace-only string. The controller validates name before parsing the uploaded OpenAPI file, since name and description are stored as the template's metadata.","triggerScenarios":"POSTing to the custom REST template upload endpoint with multipart form data containing a file but no 'name' field, a name sent as a non-string value, or a name of only whitespace (e.g. name='   ').","commonSituations":"Client scripts that only attach the file part of the multipart form; API wrappers that forget to forward text fields alongside the file; frontend forms where the name input was left blank or trimmed to empty.","solutions":["Add a non-empty 'name' text field to the multipart form body alongside the file","Ensure the field is sent as a string (not a file part or null) and trim it to confirm it is non-empty","Retry the upload with corrected form data"],"exampleFix":"// before\nformData.append(\"file\", fileBlob) // name missing\n// after\nformData.append(\"name\", \"My API Template\")\nformData.append(\"description\", \"Petstore API\")\nformData.append(\"file\", fileBlob)","handlingStrategy":"validation","validationCode":"const name = body.name\nif (typeof name !== \"string\" || !name.trim()) {\n  throw new Error(\"Template name is required before upload\")\n}","typeGuard":"const isNonEmptyString = (v: unknown): v is string =>\n  typeof v === \"string\" && v.trim().length > 0","tryCatchPattern":"try {\n  await uploadTemplate(form)\n} catch (e) {\n  if (e?.status === 400 && e?.message === \"Template name is required\") {\n    // surface name field as invalid in the UI\n  } else throw e\n}","preventionTips":["Always append both name and description text fields when building the multipart form","Trim client-side and block submission when name is empty","Add a required-field check in the upload form before submitting"],"tags":["validation","http-400","rest-template","input-validation"],"backgroundTag":"missing-required-field","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}