marshmallow-code / marshmallow-code/apispec
Minor issues with field2choices
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.2k
- Forks
- 202
- Avg merge
- 3h 38m
- Merged PRs (30d)
- 3
Description
I think that in marshmallow swagger, some pathological cases are not handled the best way.
This
```python
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
```python
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the field2choices logic and reproduce the two validator examples from the issue. Check how multiple Equal validators and a combination of Equal with OneOf are converted into an enum. Done means both cases produce the correct enum output; the payload does not name a test file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100