Skip to content

Commit fe3da56

Browse files
committed
fixed README, fixed required/optional (optional is default)
1 parent b54c0e6 commit fe3da56

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
## Usage
44

5-
$json = json_decode($input_json);
6-
$schema = json_decode($input_schema);
7-
$result = JsonSchema::validate($json, $schema);
8-
9-
if ($result->valid) {
5+
```php
6+
<?php
7+
8+
$json = json_decode($input_json);
9+
$schema = json_decode($input_schema);
10+
$result = JsonSchema::validate($json, $schema);
11+
12+
if ($result->valid) {
1013
die('success!');
11-
}
12-
else {
14+
}
15+
else {
1316
die('fail...');
14-
}
17+
}
18+
```

libs/JsonSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static function checkProp($value, $schema, $path, $i = '', $_changing = false) {
169169
}
170170
// verify optional values
171171
if (is_object($value) && $value instanceOf JsonSchemaUndefined) {
172-
if ( isset($schema->optional) ? !$schema->optional : true) {
172+
if ( isset($schema->required) ? !$schema->required : true) {
173173
self::adderror($path,"is missing and it is not optional");
174174
}
175175
}

0 commit comments

Comments
 (0)