An extend() method would be nice for Structure so you could define a base schema and then define variants with additional fields. Right now you can kind of do this like:
This has a downside in that you need to expose the array and pass around the array rather than passing around Structure objects. When composing schemas it would be really nice to have the following API:
$base = Expect::structure([
'foo' => Expect::string(),
'bar' => Expect::string(),
]);
// make a new structure with additional or overridden fields
$variant = $base->extend([
'baz' => Expect::string(),
]);
An
extend()
method would be nice forStructure
so you could define a base schema and then define variants with additional fields. Right now you can kind of do this like:This has a downside in that you need to expose the array and pass around the array rather than passing around Structure objects. When composing schemas it would be really nice to have the following API:
This would be similar to a feature present in Zod https://zod.dev/?id=extend