toolmark-monorepo / @toolmark/core/dom / synthesizeFormSchema
Function: synthesizeFormSchema()
synthesizeFormSchema(
form):JsonSchema
Defined in: packages/core/src/dom/synthesize.ts:461
Synthesizes a JSON Schema (draft 2020-12, the fromJsonSchema subset) for a DOM form (spec §10.2). Only fields count: named controls of form.elements, minus hidden, password, cc-* (and other secret autocomplete tokens), disabled, read-only and [data-tool-ignore] controls. Text controls map to strings with minLength/maxLength and an anchored pattern (a pattern that is invalid or fails the ReDoS safety check is left out); email/url add format; number/range map to integer or number from step and min, with minimum/maximum/multipleOf; dates and times get a format (or pattern) and their min/max in the description; checkboxes map to a boolean, or an array of unique values when they share a name; radios and selects to an enum whose titles are listed in the description ("Options: <value> = <label>; …"); select[multiple] to an array; files to fileFieldSchema. required attributes become required, load-time values default, and every object has additionalProperties: false. Descriptions come from toolparamdescription, the form's data-tool-param-<name>, the control's <label>, then aria-description (each capped at 500 characters, option titles at 200; labels inside [data-tool-ignore] or editable regions are ignored) — the form must be app-authored markup (spec §14).
Parameters
form
HTMLFormElement
The form to describe.
Returns
The form values' JSON Schema.