apispec icon indicating copy to clipboard operation
apispec copied to clipboard

Minor issues with field2choices

Open lafrech opened this issue 6 years ago • 0 comments

I think that in marshmallow swagger, some pathological cases are not handled the best way.

This

        field = fields.Str(validate=[
            validate.Equal('only choice'),
            validate.Equal('only choice_2')])

produces

    ['enum'] = ['only choice', 'only_choice_2']

which is wrong. Admittedly, the field declaration does not make much sense.

Also

        field = fields.Str(validate=[
            validate.Equal('only choice'),
            validate.OneOf(['freddie', 'brian', 'john'])])

produces

    ['enum'] = ['only choice']

which is wrong too. This field declaration is a big dodgy as well.

Those are corner cases that might happen, perhaps, in some complex inheritance scenarios.

apispec should at least return the correct output. Maybe raising a warning is out of scope, as if we engage in consistency validation in apispec, this could end up being a lot of work.

No time and interest to address this right now but I thought I'd leave a note here.

lafrech avatar Apr 09 '18 09:04 lafrech