marshmallow-code / marshmallow-code/flask-smorest

Schema with dict field in query [OAS3]

Open
#197 5 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Python
Stars
717
Forks
77
Avg merge
7h 49m
Merged PRs (30d)
3

Description

Hi,

I've not been able to figure out if there is a supported way to control the [style](https://swagger.io/specification/#parameter-style) for an argument.

Example schema usage
```python
class Example (Schema):
f = fields.Dict()

@blp.route("/")
class Demo (MethodView):
@blp.arguments(Example, location='query')
def get(self, args):
return 'ok'
```

which yields this spec fragment:
```yaml
- name: "f"
in: "query"
schema:
type: "object"
```

But, as objects passed as query args, have a default style of `form` with `explode` true, the `f` part is not included in the request query when using swagger UI.

At the very least, `explode` needs to be set to `false` in order to reveal the `f` argument name in the query. Or, a `style` of `deepObject` should also work. Frankly, I don't really care which way, as long as it is parsed properly by webargs.

```yaml
- name: "attrs"
in: "query"
style: deepObject # this
explode: false # or this
schema:
type: "object"
```

Right now, I get a
```yaml
{
"code": 422,
"errors": {
"query": {
"moo": [
"Unknown field."
]
}
},
"status": "Unprocessable Entity"
}
```

for a request where `f` is provided as `{"moo":"data"}` in swagger ui.

Contributor guide

Open the contributing guide

Research direction

Start at the @blp.arguments(Example, location='query') entry point and trace how the OAS3 query parameter schema is generated and then parsed by webargs. Compare the emitted style and explode settings with the Dict field behavior; done means Swagger UI sends the f argument and the request parses without the shown 422 error.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, openapi, python
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.