AJV custom keyword with subschema validation

I’m using AJV to validate a JSON based on some JSON Schema.

I’d like to define a custom keyword that applies validation from a subschema based on some condition of the data (basically a more flexible version of discriminator).

For example:

{
    "mykeyword": {
        "even": {
            "properties": {
                "p": {"type": "string"}
            }
        },
        "odd": {
            "properties": {
                "p": {"type": "number"}
            }
        }
    }
    "type": "object",
    "properties": {
        "n": "number"
    }
}

I’d like to figure out how to implement the following logic:

if ( data.n % 2 == 0 )
    validate(schema.even, data)
else
    validate(schema.odd, data)

Meaning selecting the right schema to validate against based on some condition.

It seems to be possible using the code custom keyword definition but their documentation only provides trivial examples.

For some context on my actual use case: the schema has its definitions in oneOf, I only want to validate the correct one but the provided discriminator is not enough to figure out which schema to validate. Not doing this causes AJV to return errors for every possible schema in oneOf which I don’t want.