Skip to content

How It Works

weili edited this page Feb 2, 2023 · 1 revision

Note: This page explains the inner workings of the library and is meant for engineers who want to contribute to the library.

JSON to schema

Validation schema generation
  1. The jsonToSchema() function is the main function to convert a JSON object to the validation schema.
  2. It will first run through generateFieldConfigs() which iterates through each field and call the corresponding field config generator based on the fieldType. Each field config generator will return the formatted yup schema and validation config of the field.
  3. Then it runs through parseWhenKeys() which looks for conditional validation rules (when condition) and generate a yup schema based on the source field. This yup schema will be used in mapRules() to generate the actual conditional validation schema.
  4. Next it runs through mapRules() which parses each validation config and generates the Yup schema rules accordingly. This function also assigns custom validation to the field.
  5. Once this is done, a Yup validation schema is returned.

Clone this wiki locally