replace "optional" attribute with "required" (optional is deprecated since draft 03)

This commit is contained in:
Igor Wiedler 2011-10-01 21:35:12 +02:00
parent 3bfb7c2bca
commit 341e7bccb5
5 changed files with 16 additions and 17 deletions

View File

@ -159,10 +159,10 @@ class Validator {
if(isset($schema->extends)) {
$this->checkProp($value,$schema->extends,$path,$i,$_changing);
}
// verify optional values
// verify required values
if (is_object($value) && $value instanceOf Undefined) {
if ( isset($schema->optional) ? !$schema->optional : true) {
$this->adderror($path,"is missing and it is not optional");
if (isset($schema->required) && $schema->required) {
$this->adderror($path,"is missing and it is required");
}
}
// normal verifications

View File

@ -14,8 +14,8 @@ class RequireTest extends BaseTestCase
'{
"type":"object",
"properties":{
"state":{"type":"string","optional":true,"requires":"city"},
"city":{"type":"string","optional":true}
"state":{"type":"string","requires":"city"},
"city":{"type":"string"}
}
}'
)
@ -33,8 +33,8 @@ class RequireTest extends BaseTestCase
'{
"type":"object",
"properties":{
"state":{"type":"string","optional":true,"requires":"city"},
"city":{"type":"string","optional":true}
"state":{"type":"string","requires":"city"},
"city":{"type":"string"}
}
}'
)

View File

@ -2,7 +2,7 @@
namespace JsonSchema\Tests;
class OptionalPropertyTest extends BaseTestCase
class RequiredPropertyTest extends BaseTestCase
{
public function getInvalidTests()
{
@ -12,7 +12,7 @@ class OptionalPropertyTest extends BaseTestCase
'{
"type":"object",
"properties":{
"number":{"type":"string","optional":false}
"number":{"type":"string","required":true}
}
}'
)
@ -29,7 +29,7 @@ class OptionalPropertyTest extends BaseTestCase
'{
"type":"object",
"properties":{
"number":{"type":"string","optional":false}
"number":{"type":"string","required":true}
}
}'
)

View File

@ -16,8 +16,7 @@ class SelfDefinedSchemaTest extends BaseTestCase
},
"age" : {
"type": "integer",
"maximum": 25,
"optional": true
"maximum": 25
}
}
},
@ -42,8 +41,7 @@ class SelfDefinedSchemaTest extends BaseTestCase
},
"age" : {
"type": "integer",
"maximum": 125,
"optional": true
"maximum": 125
}
}
},

View File

@ -71,7 +71,8 @@ class TupleTypingTest extends BaseTestCase
"type":"array",
"items":[
{"type":"string"},
{"type":"number"}
{"type":"number"},
{"required":true}
]
}
}
@ -94,8 +95,8 @@ class TupleTypingTest extends BaseTestCase
"type":"array",
"items":[
{"type":"string"},
{"type":"number","optional":true},
{"type":"number","optional":true}
{"type":"number","required":false},
{"type":"number","required":false}
]
}
}