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
124124 'allOf ' => null ,
125125 'oneOf ' => null ,
126126 '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 ,
127131 ];
128132 }
129133
Original file line number Diff line number Diff line change @@ -43,6 +43,19 @@ public function testRead()
4343 $ this ->assertFalse ($ schema ->deprecated );
4444 }
4545
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+
4659 public function testReadObject ()
4760 {
4861 /** @var $schema Schema */
You can’t perform that action at this time.
0 commit comments