Skip to content

Design and implement x-visibility directive for ObjectValidators #19

@nohponex

Description

@nohponex

This directive is required to enable properties based on specific values of other fields.

This feature could be implemented using JSON schema v4 oneOf directive but it's difficult to describe this schema to clients in order to create the visual components.

Definition in JSON

{
        "type": "object",
        "title": "Object Title",
        "description": "Object Description",
        "properties": {
            "field1": {
                "type": "enum",
                "order": 1,
                "title": "field1 title",
                "description": "field1 description",
                "enum": [
                    "1",
                    "2",
                    "3",
                    "4",
                    "5"
                ]
            },
            "field2": {
                "type": "number",
                "order": 1,
                "title": "field2 title",
                "description": "field2 description",
                "minimum": 0,
                "maximum": 100
            }
        },
        "required": [
            "field1"
        ],
        "x-visibility": {
            "field2": [
                "member",
                "field1",
                [
                    "1",
                    "2",
                    "3"
                ]
            ]
        }
    }

Definition in PHP

$validator = new ObjectValidator(
            (object) [
                'field1' => new EnumValidator(
                    ['yes', 'no']
                ),
                'field2' => new StringValidator(),
            ],
            ['field1', 'field2'],
            false,
            0,
            null,
            null,
            (object) [
                'field2' => [
                    'member',
                    'field1',
                    ['yes']
                ]
            ]
        );

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions