Download the PHP package foamzou/easy-json-schema without Composer
On this page you can find all versions of the php package foamzou/easy-json-schema. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package easy-json-schema
English | 简体中文
Easy Json Schema
Of course, I recommend you use protobuf.
- Use php object to define Json-Schema easily (support draft-07 and draft-06)
- Use opis/json-schema as validator
Advantage
- Easy to define,avoid complex json-schema
- More readability
- Easier to maintain
Install
Of course, I recommend you use protobuf.
composer require "foamzou/easy-json-schema"
Usage
Define Schema
Here's a comparison with json-schema. You can see that the definition of using php objects is simpler, more readable, and easier to maintain.
Easy-Json-Schema
Json-Schema
Data type
String
(new Str)->min(1)->max(23)->pattern('/regex/')->contentEncoding()->contentMediaType()
Number
Integer
Boolean
new Boolean
Null
new Nul
Array
Object
keyword
Enum
Constant
AnyOf, OneOf, AllOf
not
if.then.else
Reuse Schema
When a schema need to reuse the other schema, you can use require
Common Method
All objects have a desc
method to describes the object
The object which base Type
has default
method to set default value
Compiling EasyJsonSchema to Json Schema
Check data and get error information
If data does not match the schema, isValid
will return false, otherwise it will be true
$errMessage and $errList has value while isValid
return false
$errMessage is a semantically string, $errList is an array of items with Opis\JsonSchema\ValidationError
You can use $errList to build the error message you want when $errMessage does not you hope