mirror of
https://github.com/justinrainbow/json-schema.git
synced 2025-05-02 20:42:13 +02:00
replace "optional" attribute with "required" (optional is deprecated since draft 03)
This commit is contained in:
parent
3bfb7c2bca
commit
341e7bccb5
@ -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
|
||||
|
@ -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"}
|
||||
}
|
||||
}'
|
||||
)
|
||||
|
@ -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}
|
||||
}
|
||||
}'
|
||||
)
|
@ -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
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -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}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user