iron-bound-designs / wp-rest-api-schema-validator

Validate WP REST API requests using a complete JSON Schema validator.
https://timothybjacobs.com/2017/05/17/json-schema-and-the-wp-rest-api/
MIT License
12 stars 2 forks source link

validation doesn't work for multilevel objects #1

Closed nurul-umbhiya closed 4 years ago

nurul-umbhiya commented 4 years ago

Hi, I was using this schema validator for one of my projects, it works as expected, except validation with 'validate_callback' => [ $this, 'custom_function' ], or 'arg_options' => [ 'validate_callback' => [ $this, 'custom_function' ] ], doesn't work.

TimothyBJacobs commented 4 years ago

Hi @nurul-umbhiya,

Could you give an example of your full schema?

If you're saying that the validate_callback does not apply in this scenario, then that is due to WordPress core behavior. See also: https://github.com/WP-API/WP-API/issues/2783

return [
    'type'       => 'object',
    'properties' => [
        'top' => [
            'type'       => 'object',
            'properties' => [
                'nested' => [
                    'type'        => 'string',
                    'arg_options' => [
                        'validate_callback' => 'my_validate_callback',
                    ]
                ]
            ]
        ]
    ]
];