Form schema checking is disabled. Set LINT_DEFINITIONS=true in settings.env and restart the app.
Load a sample schema
JSON definition · shared/definitions/creator-load-save.jsonView on GitHub
{
"title": "Support request",
"elements": [
{
"type": "dropdown",
"name": "product",
"title": "Product",
"choices": [
"Form Library",
"Survey Creator",
"Dashboard",
"PDF Generator"
]
},
{
"type": "comment",
"name": "issue",
"title": "Describe the issue",
"isRequired": true
},
{
"type": "radiogroup",
"name": "urgency",
"title": "How urgent is it?",
"choices": [
"Low",
"Normal",
"Blocking"
]
},
{
"type": "boolean",
"name": "callback",
"title": "Call me back"
}
]
}Client · src/app/examples/lint-definition/client.tsx · sjs:lint-definition.clientView on GitHub
// Display the server's errors and warnings and return the actual save result to Creator
async function saveDefinition(definition: unknown) {
const response = await fetch(`/api/forms/${formId}`, {
method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify(definition)
});
const report: LintReport = response.status === 204 ? {} : await response.json();
reportFindings(report);
if (response.status === 422 && Array.isArray(report.errors) && report.errors.length) {
note("Form schema not saved. Fix the reported errors and retry.", "error");
return false;
}
if (!response.ok) throw new Error(report.error || "Couldn't save the form schema. Please try again.");
const count = report.warnings?.length ?? 0;
note(count ? `Schema saved with ${count} warning${count === 1 ? "" : "s"}. Review the findings above.` : "Form schema saved successfully.", "ok");
return true;
}
creator.saveSurveyFunc = async (saveNo: number, callback: (saveNo: number, success: boolean) => void) => callback(saveNo, await checkAndSave(creator.JSON));Server · src/server/routes/lint-definition.ts · sjs:lint-definition.serverView on GitHub
// PUT /api/forms/:id — lint the definition from Creator before storing it
export async function lintAndSaveForm(req: Request, { id }: { id: string }) {
const denied = can(currentUser(req), "edit-forms");
if (denied) throw httpError(403, denied);
const definition = await readJson(req); // the parsed raw body: {} stays {} (see Load and Save Form JSON Schemas)
if (definition === null || typeof definition !== "object" || Array.isArray(definition)) {
throw httpError(400, "Expected a form definition");
}
const { findings } = lintSurvey(definition, lintOptions);
const errors = findings.filter((finding) => finding.severity === "error");
const warnings = findings.filter((finding) => finding.severity !== "error");
if (errors.length > 0) return Response.json({ errors, warnings }, { status: 422 }); // refuse: the previous version stays
db(req).prepare("INSERT INTO forms (key, json) VALUES (?, ?) ON CONFLICT (key) DO UPDATE SET json = excluded.json")
.run(id, JSON.stringify(definition)); // stored as it arrived, never a copy
if (warnings.length > 0) return Response.json({ warnings }); // warnings don't block the save
return new Response(null, { status: 204 });
}