打开api 3发布文件数组 [英] open api 3 posting an array of files

查看:93
本文介绍了打开api 3发布文件数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用swagger集线器创建此API ;但它在用户界面中不支持多个文件,因此我不确定我是否这样做

I am using swagger hub to create this API; but it doesn't support multi files in the UI so I am unsure if I am doing this right

我的目标是拥有以下

item:{Json describe the item}
images[] = images for item posted as an array
titles[] = Parallel array to images that has the title for image
alt_texts[] = Parallel array to images that has the alt text for image

由于它是文件,因此必须是多部分的;但是不确定我是否正确设置了结构.

This has to be multipart since it is files; but am unsure if I setup the structure correctly.

Swagger/Open API代码

Swagger/Open API Code

post:
  summary: Add a new item to the store
  description: ''
  operationId: addItem
  requestBody:
    content:
      multipart/form-data:
        schema:
          $ref: '#/components/schemas/NewItemWithImage'
    description: Item object that needs to be added to the store
    required: true


NewItemWithImage:
  type: object
  properties:
    item:
      $ref: '#/components/schemas/NewItem'
    images[]:
      type: array
      items:
        type: string
        format: binary
    titles[]:
      type: array
      items:
        type: string
    alt_texts[]:
      type: array
      items:
        type: string
    variation_ids[]:
      type: array
      items:
        type: string
  required:
    - item

推荐答案

根据部分:

文件上传

文件使用带有format: binaryformat: base64type: string架构, 取决于文件内容的编码方式.

Files use a type: string schema with format: binary or format: base64, depending on how the file contents will be encoded.

多个文件上传

使用 多部分媒体类型,以定义上传任意数量的文件 (一组文件):

Use the multipart media type to define uploading an arbitrary number of files (an array of files):

      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                filename:
                  type: array
                  items:
                    type: string
                    format: binary

您当前的定义正好符合规范:

You current definition corresponds to the specification precisely:

requestBody:
  content:
    application/json:
      schema:
        $ref: '#/components/schemas/NewItemWithImageUrl'
    multipart/form-data:
      schema:
        $ref: '#/components/schemas/NewItemWithImage'

NewItemWithImage:
  type: object
  properties:
    item:
      $ref: '#/components/schemas/NewItem'
    images[]:
      type: array
      items:
        type: string
        format: binary
    titles[]:
      type: array
      items:
        type: string
    ...

这篇关于打开api 3发布文件数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆