Skip to content

[Proposal]: Allow extra and optional fields in structure type #1732

@norberttech

Description

@norberttech

Describe the Proposal

Currently following code wont pass assertion due to missing tags:

$data = [
    'id' => 1,
    'name' => 'Test',
    'tags' => [1, 2, 3]
];

$data = type_structure([
    'id' => type_integer(),
    'name' => type_string(),
])->assert($data);

API Adjustments

/**
 * @template T of array
 *
 * @param T $elements
 *
 * @return StructureType<T>
 */
#[DocumentationDSL(module: Module::TYPES, type: DSLType::TYPE)]
function type_structure(array $elements, bool $allow_extra = false) : StructureType
{
    return new StructureType($elements, $allow_extra);
}

Are you intenting to also work on proposed change?

Yes

Are you interested in sponsoring this change?

None

Integration & Dependencies

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions