orisai / object-mapper

Raw data mapping to validated objects
Mozilla Public License 2.0
10 stars 1 forks source link

Array shape #24

Open mabar opened 2 years ago

mabar commented 2 years ago
final class Example extends MappedObject {

    /** @var array{foo: string, bar: string} */
    #[AllOf([
        new ArrayShape([
            'foo' => new StringValue(),
            'bar' => new MixedValue()
        ]),
        new ArrayShape([
            'bar' => new StringValue(),
        ], allowExtraProps: true),
    ])]
    public array $merged;

    /** @var array{foo: string, bar: string} */
    #[AllOf([
        new ArrayShape(FullObject::class),
        new ArrayShape(PartialObject::class, allowExtraProps: true),
    ])]
    public array $merged2;

}
$processor->process([
    'merged' => [
        'foo' => 'string',
        'bar' => 'string',
    ],
    'merged2' => [
        'foo' => 'string',
        'bar' => 'string',
    ],
], Example::class);