首页 > 解决方案 > swagger-ui - 打开 api 3,multipart/form-data 数组问题

问题描述

我正在使用带有 OpenApi 3.0.2 规范的 swagger-ui。
我设置了一个包含多部分/表单数据内容的 requestBody。
当我执行来自 swagger-ui 的请求时,一切正常,但是......
如果我添加一个数组类型的参数,它将以这种方式在 curl 调用中进行转换:
-F "tags=my,tag"
我需要分解数组

-F 'tags[]=my' \
-F 'tags[]=tag'

我查看文档并找到一些样式和爆炸属性,但它们仅适用于参数属性,而不适用于 requestBody (?)。

在我的路线文件中:

post:
  tags:
  - media-image
  summary: Create a media image
  requestBody:
    description: A JSON object containing media image information
    required: true
    content:
      multipart/form-data:
        schema:
          allOf:
          - $ref: '../schemas/media-image-fillable.yaml'
          - required:
            - title
            - back_office_title
            - alt
            - file

media-image-fillable.yaml

type: object
allOf:
- $ref: './media-image-base.yaml'
- properties:
    file:
      type: string
      format: binary
    tags:
      type: array
      items:
        type: string

和 media-image-base.yaml

type: object
properties:
  title:
    type: string
  back_office_title:
    type: string
  description:
    type: string
  alt:
    type: string

标签: swagger-uiopenapi

解决方案


好的,我找到了解决方案。
我只需要在 中重命名tags属性tags[],现在它可以工作了。


推荐阅读