noirbizarre / flask-restplus

Fully featured framework for fast, easy and documented API development with Flask
http://flask-restplus.readthedocs.org
Other
2.74k stars 506 forks source link

Swagger: multipart with json and file part #539

Open jojoob opened 6 years ago

jojoob commented 6 years ago

I've a resource excepting multipart form data with one part named "_json" with application/json encoding. The content is a json object described by the "post_schema". The other part is an optional binary file.

Want I want to achieve is the "_json" paramater should be rendered in swagger UI using the provided schema like it is done when using auto generated config via "@api.expected()".

I tried a lot but don't got it to work. I come somewhat close with this code:

params={
    '_json': {
        # 'required': True,
        'in': 'formData',
        'type': 'object',
        # 'format': 'application/json',
        'schema': post_schema.get_dereferenced_schema(),
        'description': 'The task log message.'},
    'attachment': {
        'in': 'formData',
        'type': 'file',
        'format': 'binary',
        'description': 'An optional file attachment to the task log.'}}

(When I set required to True swagger UI will reject the execution with "Required field is not provided")

It looks like this: screenshot from 2018-10-16 10-48-32 screenshot from 2018-10-16 10-38-34

But I want that the "_json" parameter get rendered like this: screenshot from 2018-10-16 10-50-24

jojoob commented 6 years ago

When using 'type': 'string' I get around the 'required': True problem. But then the input is rendered as a text input.