Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OneOfConverter validator in array. #183

Open
fcr-- opened this issue Apr 23, 2020 · 0 comments
Open

OneOfConverter validator in array. #183

fcr-- opened this issue Apr 23, 2020 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers swagger-generation Concerns automatic swagger generation

Comments

@fcr--
Copy link
Contributor

fcr-- commented Apr 23, 2020

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"], ...
  ]
  ...
}
@airstandley airstandley added bug Something isn't working good first issue Good for newcomers swagger-generation Concerns automatic swagger generation labels Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers swagger-generation Concerns automatic swagger generation
Projects
None yet
Development

No branches or pull requests

2 participants