string()as its metadata, but there is a number in the incoming JSON, it will be coerced with
M.ajvMetadataand JSON schema
M.metadata()takes an optional
Ajvinstance parameter and returns metadata functions that take an additional parameter in the form of JSON schema for the current field. When no instance of
Ajvis passed in, it returns metadata functions with the same API but no validation is performed. This can be leveraged to only enable validation during development in favour of faster parsing in production:
M.withValidationfacilitates this use case.
stringinstead of the normal
stringto combine custom and JSON schema rules.
M.withValidationworks with any metadata, including the
Ajvvariant and can be composed, since it returns a function that takes metadata and returns metadata.
M.withValidationonly once with the result, by using
M.withValidationfor each individual function you can attach specific error messages to simplify debugging.
min <= maxin a
setare also valid, it is sometimes preferable to consider internal use of the class as trusted and only validate external JSON.
M.validate, which takes a Modélico instance, optional inner metadata for generic types, and returns an array with 2 items: the result of the validation (boolean), and an
Errorif the validation was not successful.