systopia / opis-json-schema-ext
Extension for Opis JSON Schema
Installs: 3 836
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 0
Open Issues: 0
Requires
- php: ^7.4 || ^8
- beberlei/assert: ^3 || ^4
- opis/json-schema: ^2.3
Requires (Dev)
- symfony/expression-language: ^5 || ^6
Suggests
- ext-intl: For error translation
- symfony/expression-language: To use Symfony ExpressionLanguage Component for calculations and evaluations
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 ValidationError
s:
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);