Skip to content

Using 'choices' in add_argument leads to invalid swagger schema #164

Closed
@leopold-p

Description

@leopold-p

I seems the issue is inherited from flask-restplus
noirbizarre/flask-restplus#488

Code

In Argument from regparse.py:

    @property
    def __schema__(self):
        if self.location == 'cookie':
            return
        param = {
            'name': self.name,
            'in': LOCATIONS.get(self.location, 'query')
        }
        _handle_arg_type(self, param)
        if self.required:
            param['required'] = True
        if self.help:
            param['description'] = self.help
        if self.default is not None:
            param['default'] = self.default() if callable(self.default) else self.default
        if self.action == 'append':
            param['items'] = {'type': param['type']}
            param['type'] = 'array'
            param['collectionFormat'] = 'multi'
        if self.action == 'split':
            param['items'] = {'type': param['type']}
            param['type'] = 'array'
            param['collectionFormat'] = 'csv'
        if self.choices:
            param['enum'] = self.choices
            param['collectionFormat'] = 'multi'
        return param

An argument with choices must not generate a collectionFormat field

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions