flasgger / flasgger/flasgger

Unable to validate formData when spec is in docstring

Open
#378 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
3.7k
Forks
525
PR merge metrics
No merged PRs in 30d

Description

In the project I'm working on, the endpoint specifications are located in the docstrings of the endpoints. For example:

```py
@app.route("/foo")
def get_foo():
"""
Get foo.
---
tags: [Foo]
parameters:
# ...
```

I have been able to use Flasgger to validate POST body content **that is described by a schema**; by using the `@swagger.validate(...)` decorator. For example:

```py
@app.route("/foo")
@swagger.validate('MySchemaId')
def get_foo():
```

...where the schema whose ID is `MySchemaId` is defined in either the same or a different endpoint specification.

However, I have not been able to use Flasgger to validate **form data**. 🔥

For example, here's the endpoint specification I'm dealing with now (minus my employer's proprietary parts). Note: In reality, this is still in the docstring of an endpoint; I'm just formatting it as a YAML snippet here to facilitate reading.

```yaml
Store a file in an Amazon S3 bucket.
---
tags: [SomeTag]
consumes:
- multipart/form-data
parameters:
- name: file
in: formData
required: true
type: file
description: The file you want to store
- name: file_name
in: formData
description: The name you want the file to have while in storage
required: true
type: string
enum:
- data.csv
- summary.txt
responses:
200: {description: The file was stored successfully.}
```

Notice there is no schema in this case.

1) Can Flasgger validate `formData` described in a docstring (as opposed to described in a dedicated YAML file)?

2) As I wrote above, I am familiar with getting Flasgger to validate things that are described by a schema. Is it possible to define a schema that describes those two parameters, neither of which is an object that has properties?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.