Swagger OpenAPI3 POST图像和媒体文件的数组

时间:2020-03-26 18:08:48

标签: python flask swagger swagger-ui openapi

我正在使用庞大的python-flask框架来创建OpenAPI 3 API,该API需要执行以下操作:

1. Upload a video file

2. Upload an array of images

3. Upload extra string data.

我可以成功使用以下方法成功上传单个文件:

MyFileUploadAPI:
 post:
  operationId: my_file_upload
  requestBody:
    content:
      multipart/form-data:
        schema:
          $ref: '#/components/schemas/videofile'

components:
  schemas:    
    videofile:
      type: object
      properties:
        upload:
         type: string
         format: binary


# This works fine
def my_file_upload(videofile):  
    file_name = videofile.filename

我可以使用以下命令上传图像和其他数据的数组:

MyMultipleImagesUploadAPI:
 post:
  operationId: multiple_files
  requestBody:
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/multiplefiles'
components:
  schemas:    
    multiplefiles:
      type: object
      properties:
        Images:
          items:
            $ref: '#/components/schemas/MyImage'
        TotalCount:
          type: integer

# This works fine
def multiple_files(body):    

    if connexion.request.is_json:
        body = multiplefiles.from_dict(connexion.request.get_json())                
        images = body._images
        count = body._totalcount

现在,我希望将两者结合在一起(视频上传+多张图片+额外数据) 所以我做了以下事情:

/MyEverythingAPI:
post:
  operationId: video_multiple_images
  requestBody:
    content:
      multipart/form-data:
        schema:
          $ref: '#/components/schemas/everything'

components:
  schemas:  
  everything:
    type: object
    properties:
      Video:
        type: string
        format: binary
      Images:
        type: array
        items:
          $ref: '#/components/schemas/MyImage'
      TotalCount:
        type: integer

# This has issues
def video_multiple_images(body, video_clip, **kwargs): 
   #body = {'images': ['[object File]'], 'totalcount': 2}
   uploaded_file_name = video_clip.filename

现在有2个我认为不正确的问题:

问题1。 video_clip没有传递到功能 video_multiple_images
我调试并跟踪它,发现它没有被添加,因为没有** kwargs添加到我的函数签名中。当我添加此内容时,视频文件开始通过。 这篇文章帮助我解决了这一部分:https://github.com/zalando/connexion/pull/753/files 我可以忍受这个问题,但想知道为什么会这样。

问题2。 图像数组以[object File]''[Object File]''等形式出现。这篇文章表明OpenAPI 3不支持此功能:In Swagger openapi v3.0.0, facing issue in multiple file uploads

那么如何传递视频文件和图像数组?

0 个答案:

没有答案