Nette/Schema skipDefaults() unclarity

medhi
Generous Backer | 255
+
0
-

From documentation:

If you do not want to output properties with only a default value, use skipDefaults():

$schema = Expect::structure([
	'required' => Expect::string()->required(),
	'optional' => Expect::string(),
])->skipDefaults();

$processor->process($schema, ['required' => 'foo']);
// OK, returns {'required' => 'foo'}

But there is no default values in the example, so what is it skipping?

Also, could you please provide more complex example? How about combination required() and default()? It seems that when it is required, it throws error, because it does not fill the default value, because it is skipped? Or is also the validation skipped, so it does not return any error?

Or can I understand it like if I use skipDefaults(), it is the same as I would remove all default(...) from the structure?

Thanks!

@Felix @DavidGrudl

David Grudl
Nette Core | 8133
+
0
-

Important sentence is “By default, all properties are optional and have a default value of null”, so there are implicit default values.