File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -124,6 +124,10 @@ protected function attributeDefaults(): array
124
124
'allOf ' => null ,
125
125
'oneOf ' => null ,
126
126
'anyOf ' => null ,
127
+ // nullable is only relevant, when a type is specified
128
+ // return null as default when there is no type
129
+ // return false as default when there is a type
130
+ 'nullable ' => !empty ($ this ->properties ['type ' ]) ? false : null ,
127
131
];
128
132
}
129
133
Original file line number Diff line number Diff line change @@ -43,6 +43,19 @@ public function testRead()
43
43
$ this ->assertFalse ($ schema ->deprecated );
44
44
}
45
45
46
+ public function testNullable ()
47
+ {
48
+ /** @var $schema Schema */
49
+ $ schema = Reader::readFromJson ('{"type": "string"} ' , Schema::class);
50
+ $ this ->assertEquals (Type::STRING , $ schema ->type );
51
+ $ this ->assertFalse ($ schema ->nullable );
52
+
53
+ // nullable is undefined if no type is given
54
+ $ schema = Reader::readFromJson ('{"oneOf": [{"type": "string"}, {"type": "integer"}]} ' , Schema::class);
55
+ $ this ->assertNull ($ schema ->type );
56
+ $ this ->assertNull ($ schema ->nullable );
57
+ }
58
+
46
59
public function testReadObject ()
47
60
{
48
61
/** @var $schema Schema */
You can’t perform that action at this time.
0 commit comments