Tuesday, July 26, 2022
HomeWordPress Developmentsubmit meta - The right way to correctly use oneOf and anyOf...

submit meta – The right way to correctly use oneOf and anyOf in Relaxation Schema?


I’ve requested this earlier than at Stackoverflow, now I am right here to be extra wp particular and convey extra context – as I did some advance on this.

Seeing this use of oneOf has made me change my schema to this construction under:

array(
    'kind'         => 'object',
    'show_in_rest' => array(
        'schema' => array(
            'kind'       => 'object',
            'properties' => array(
                'tipo' => array(
                    'kind'  => 'string',
                    'title'  => 'tipo',
                    'enum'  => array(
                        '...',
                    ),
                ),
                'information' => array(
                    'kind'   => 'array',
                    'objects'  => array(
                        'kind'  => 'object',
                        'oneOf' => array(
                            array(
                                'properties'           => array(
                                    'dia'         => array(
                                        'kind'        => 'string',
                                        'title'        => 'dia',
                                    ),
                                    'hora_inicio' => array(
                                        'kind'        => 'string',
                                        'title'        => 'hora_inicio',
                                    ),
                                    'hora_fim'    => array(
                                        'kind'        => 'string',
                                        'title'        => 'hora_fim',
                                    ),
                                ),
                                'title'                 => 'data_unica',
                                'title'                => 'Knowledge única',
                            ),
                            array(
                                'properties'           => array(
                                    'periodicidade' => array(
                                        'kind'        => 'string',
                                        'title'        => 'periodicidade',
                                        'enum'        => array(
                                            '...'
                                        ),
                                    ),
                                    'dia_inicial'   => array(
                                        'kind'        => 'string',
                                        'title'        => 'dia_inicial',
                                    ),
                                    'dia_final'     => array(
                                        'kind'        => 'string',
                                        'title'        => 'dia_final',
                                    ),
                                    'hora_inicial'  => array(
                                        'kind'   => 'string',
                                        'title'   => 'hora_inicial',
                                    ),
                                    'hora_final'    => array(
                                        'kind'   => 'string',
                                        'title'   => 'hora_final',
                                    ),
                                ),
                                'title'                 => 'data_corrente',
                                'title'                => 'Knowledge corrente',
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
);

The request is:

{
    "datas": {
        "tipo": "UNICA",
        "information": [{
            "dia": "2022-10-21",
            "hora_inicio": "",
            "hora_fim": ""
        }]
    }
}

And the response:

{
    "code": "rest_additional_properties_forbidden",
    "message": "dia is just not a legitimate property of Object.",
    "information": {
        "standing": 400
    }
}

What am I doing unsuitable?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments