plangrid/flask-rebar

OneOfConverter validator in array.

fcr-- opened this issue · 0 comments

fcr-- commented

Given the following schema:

class MyQuerySchema(QuerySchema):
    status = CommaSeparatedList(
        cls_or_instance=fields.Str(),
        validate=ContainsOnly(choices=["foo", "bar"]),
    )

Swagger-generator is producing the following output:

                    {
                        "collectionFormat": "csv",
                        "enum": [
                            "foo",
                            "bar"
                        ],
                        "in": "query",
                        "items": {
                            "type": "string"
                        },
                        "name": "status",
                        "required": false,
                        "type": "array"
                    },

the problem here is that the enum property should be inside items, since enum (as defined in json schema) have the following defined behaviour: https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.1.2 that is to limit the possible values to those listed in its associated value.

If we were to have the enum property at the same level as we have the type array, we would need for this example to have this infinite array (and that's why we should instead place it inside items):

{
  "type": "array",
  "enum": [
    [],
    ["foo"], ["bar"],
    ["foo", "foo"], ["foo", "bar"], ["bar","foo"], ["bar", "bar"],
    ["foo", "foo", "foo"], ...
  ]
  ...
}