diff --git a/README.md b/README.md index 8e63f258..6a940044 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,17 @@ ## Usage - $json = json_decode($input_json); - $schema = json_decode($input_schema); - $result = JsonSchema::validate($json, $schema); - - if ($result->valid) { +```php +valid) { die('success!'); - } - else { +} +else { die('fail...'); - } +} +``` \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 00000000..a3040886 --- /dev/null +++ b/composer.json @@ -0,0 +1,19 @@ +{ + "name": "justinrainbow/json-schema", + "description": "a library to validate a json schema" + "keywords": ["json", "schema"], + "homepage": "https://github.com/justinrainbow/json-schema", + "type": "library", + "license": "MIT", + "version": "1.0.0", + "authors": [ + { + "name": "Justin Rainbow" + } + ], + + "autoload": { + "psr-0": { "JsonSchema": "libs/", "JsonSchemaUndefined": "libs/"} + } +} + diff --git a/libs/JsonSchema.php b/libs/JsonSchema.php index d5e06715..a324a3ef 100644 --- a/libs/JsonSchema.php +++ b/libs/JsonSchema.php @@ -169,7 +169,7 @@ static function checkProp($value, $schema, $path, $i = '', $_changing = false) { } // verify optional values if (is_object($value) && $value instanceOf JsonSchemaUndefined) { - if ( isset($schema->optional) ? !$schema->optional : true) { + if ( isset($schema->required) ? !$schema->required : true) { self::adderror($path,"is missing and it is not optional"); } }