Skip to content

Commit c5d3203

Browse files
committed
Merge pull request #1 from digitalkaoz/composer_json
Composer json and schema fix
2 parents 5fe0224 + fe3da56 commit c5d3203

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-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+
```

composer.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "justinrainbow/json-schema",
3+
"description": "a library to validate a json schema"
4+
"keywords": ["json", "schema"],
5+
"homepage": "https://github.com/justinrainbow/json-schema",
6+
"type": "library",
7+
"license": "MIT",
8+
"version": "1.0.0",
9+
"authors": [
10+
{
11+
"name": "Justin Rainbow"
12+
}
13+
],
14+
15+
"autoload": {
16+
"psr-0": { "JsonSchema": "libs/", "JsonSchemaUndefined": "libs/"}
17+
}
18+
}
19+

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)