balena-io-modules / reql-schema

ReQL to JSON Schema translator
Apache License 2.0
3 stars 0 forks source link

Incorrect filtering when combining arrays and anyOf #1

Open LucianBuzzo opened 6 years ago

LucianBuzzo commented 6 years ago

Given a document like this:

{
    "markers": [ "a", "b", "c+d" ]
}

and a schema like this:

{
    "type": "object",
    "properties": {
        "type": "array",
        "items": {
            "type": "string",
            "anyOf": [
                {
                    "enum": [ "a", "b" ]
                },
                {
                    "pattern": "(^|\\+)c($|\\+)"
                }
            ]
        }
    }
}

I would expect the document to be returned, but it is not.

LucianBuzzo commented 6 years ago

I debugged this further and found that the reason for reqlschema not returning the value is because the markers field wasn't present on the target document that I expected to be returned. @jviotti if a field is not explicitly required, does reqlschema make that field optional? It appears not to.

LucianBuzzo commented 6 years ago

It looks like something is wrong in this else statement https://github.com/resin-io-modules/reql-schema/blob/master/lib/index.js#L140