{"record":{"id":"3d5be6358f12d014","repo":"windmill-labs/windmill","slug":"errormessage","errorCode":null,"errorMessage":"${errorMessage}","messagePattern":"\\$\\{errorMessage\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/src/lib/utils.ts","lineNumber":68,"sourceCode":"\t/**\n\t * Parses and validates an OpenAPI specification provided as a string in either JSON or YAML format.\n\t *\n\t * @param api - A string containing a valid OpenAPI specification in JSON or YAML format.\n\t * @returns A promise that resolves to a tuple:\n\t *   - The first element is the validated OpenAPI document.\n\t *   - The second element is the detected OpenAPI version (2, 3.0, or 3.1).\n\t *\n\t * @throws Will throw an error if the specification is invalid or cannot be parsed.\n\t */\n\texport async function parse(api: string): Promise<[OpenAPI.Document, OpenApiVersion]> {\n\t\tconst { validate, dereference } = await import('@scalar/openapi-parser')\n\t\tconst { valid, errors } = await validate(api)\n\n\t\tif (!valid) {\n\t\t\tconst errorMessage = errors\n\t\t\t\t? errors.map((error) => error.message).join('\\n')\n\t\t\t\t: 'Invalid OpenAPI document'\n\t\t\tthrow new Error(errorMessage)\n\t\t}\n\n\t\tconst document = await dereference(api)\n\n\t\tconst version = getOpenApiVersion(document.version!)\n\n\t\treturn [document.schema, version]\n\t}\n}\n\nexport function isJobCancelable(j: Job): boolean {\n\treturn j.type === 'QueuedJob' && !j.schedule_path && !j.canceled\n}\n\nexport function isJobReRunnable(j: Job): boolean {\n\treturn (j.job_kind === 'script' || j.job_kind === 'flow') && j.parent_job === undefined\n}\n","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/frontend/src/lib/utils.ts#L50-L86","documentation":"utils/OpenApi.parse validates an OpenAPI document (JSON or YAML string) with @scalar/openapi-parser before dereferencing. If validate() reports valid=false, it throws an Error whose message is all validation error messages joined by newlines, or 'Invalid OpenAPI document' when no detailed errors are returned.","triggerScenarios":"Calling parse() with a spec that fails schema validation: missing required 'openapi'/'info'/'paths' fields, wrong types, invalid references, or unparseable YAML/JSON; also OpenAPI 2.0/Swagger docs that violate 3.x rules the parser enforces.","commonSituations":"Pasting a Swagger 2.0 spec into an OpenAPI 3 importer; hand-edited specs with broken $refs; truncated or YAML-indentation-broken documents; specs served with wrong content generating invalid JSON.","solutions":["Read the thrown message — it lists each validation error from @scalar/openapi-parser; fix the referenced paths/fields","Validate the spec locally with a linter (e.g. Redocly CLI or swagger-editor) to pinpoint issues","Ensure required fields (openapi, info.title, info.version, paths) exist and $refs resolve","Convert Swagger 2.0 documents to OpenAPI 3 before importing"],"exampleFix":"// before\nconst [doc, version] = await OpenApi.parse(userSpec) // throws joined validation errors\n// after\nlet doc, version\ntry {\n  ;[doc, version] = await OpenApi.parse(userSpec)\n} catch (e) {\n  console.error('OpenAPI validation failed:', e.message) // per-line validation errors\n  showSpecError(e.message)\n}","handlingStrategy":"validation","validationCode":"// lightweight pre-checks before OpenApi.parse\nfunction looksLikeOpenApiSpec(api: string): boolean {\n  return /\"openapi\"\\s*:|^openapi:\\s*['\"]?3/im.test(api)\n}\nif (!api.trim() || !looksLikeOpenApiSpec(api)) {\n  throw new Error('Not an OpenAPI 3.x document (got Swagger 2.0 or invalid input?)')\n}","typeGuard":"function isOpenApiValidationMessage(err: unknown): err is Error & { message: string } {\n  return err instanceof Error && (err.message.includes('Invalid OpenAPI') || /invalid|must|required/i.test(err.message))\n}","tryCatchPattern":"try {\n  const [doc, version] = await OpenApi.parse(api)\n} catch (err) {\n  if (err instanceof Error) {\n    // message contains one validation error per line — show all to the user\n    showValidationErrors(err.message.split('\\n'))\n    return\n  }\n  throw err\n}","preventionTips":["Lint specs with Redocly CLI/swagger-editor before importing","Ensure required root fields: openapi, info.title, info.version, paths","Convert Swagger 2.0 specs to OpenAPI 3 first","Check that all $ref targets exist and JSON/YAML parses cleanly"],"tags":["openapi","validation","schema","api"],"backgroundTag":"schema-validation-failed","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}