Validating form definitions
You can perform a static validation of a form definition using the JSON Schema. To implement validation, you need a validator for the language or framework you are using. For example, if you use Node.js you can use Ajv or Hyperjump to validate a form definition.
📥 Download JSON Schema for IDefinition
tip
There is a list of validators on the JSON Schema website.
👩💻 Example
The following example shows how to set up validation using the JSON Schema.
- Ajv
- Hyperjump
// Make sure to install ajv first: `npm i ajv`
import Ajv from "ajv";
// Download the schema for the Tripetto form definition and make it available to your code
import tripettoFormDefinitionSchema from "tripetto.schema.json";
const ajv = new Ajv({
allowUnionTypes: true,
validateSchema: false
});
const validate = ajv.compile(tripettoFormDefinitionSchema);
// Now you can validate a form definition
if (validate(/* Supply your form definition here */)) {
// All good!
}
// Make sure to install Hyperjump first: `npm i @hyperjump/json-schema`
import JsonSchema from "@hyperjump/json-schema";
// Download the schema for the Tripetto form definition and make it available to your code
import tripettoFormDefinitionSchema from "tripetto.schema.json";
JsonSchema.add(tripettoFormDefinitionSchema);
const schema = awit JsonSchema.get("https://tripetto.com/sdk/tripetto.schema.json");
// Now you can validate a form definition
const result = await JsonSchema.validate(
schema,
/* Supply your form definition here */
);
if (result.valid) {
// All good!
}