systopia/opis-json-schema-ext

Extension for Opis JSON Schema

v0.5.0 2024-04-04 10:48 UTC

This package is auto-updated.

Last update: 2024-05-04 11:30:20 UTC


README

This is an extension for Opis JSON Schema.

Keywords

The following additional keywords are provided:

  • $calculate
  • evaluate
  • maxDate
  • minDate
  • noIntersect An array must not contain intersecting intervals.
  • $order Order arrays. (Only performed, if array has no violations.)
  • precision
  • $tag Tagged data can be fetched from a data container after validation.
  • $validations

See tests for how to use them.

The SystopiaValidator already provides those keywords. To use them in a different validator class you might want to use SystopiaSchemaParser or SystopiaVocabulary.

Empty array to object conversion

If the option convertEmptyArrays is set to true (disabled by default), empty arrays will be converted to objects if the schema type contains object, but not array. This might be necessary if the data to validate was already decoded.

Translation

This extension allows to translate ValidationErrors:

First create an instance of TranslatorInterface:

$translator = new Translator($locale, $messages);

If there is a localisation in the messages directory you can use:

$translator = TranslatorFactory::createTranslator($locale);

Then create an instance of ErrorTranslator:

$errorTranslator = new ErrorTranslator($translator);

Let the ErrorTranslator translate a validation error:

echo $errorTranslator->trans($error);