rest - 编码不会在 swagger-ui 中爆炸 requestBody 中的属性

标签 rest swagger swagger-ui openapi

该参数没有被分解为单独的字段,我无法理解为什么。

这是我的 yaml,使用 OpenApi 3.0

paths:
  /match/started:
    post:
      tags:
        - match
      summary: 'Callback for when a game has started.'
      operationId: 'App\Http\Controllers\Api\V1\MatchController::started'
      requestBody:
        description: 'Something something batman!'
        required: true
        content:
          multipart/form-data:
            schema:
              required:
                - match_uuid
              properties:
                game_uuid:
                  type: string
                player_uuids:
                  type: array
                  items:
                    type: string
              type: object
            encoding:
              player_uuids:
                style: form
                explode: true
      responses:
        200:
          description: 'success response'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Api_V1_Match_Started'

这是 swagger 给我的 curl 请求()

curl -X POST“https://editor.swagger.io/api/v1/match/started”-H“接受:application/json”-H“内容类型:multipart/form-data "-F "game_uuid=test"-F "player_uuids=aaa,bbb,ccc"

你可以看到最后一个参数是-F“player_uuids=aaa,bbb,ccc”,它应该是-F“player_uuids=aaa”-F“player_uuids=bbb” -F“player_uuids=ccc”

因此完整的请求应如下所示:

curl -X POST“https://editor.swagger.io/api/v1/match/started”-H“接受:application/json”-H“内容类型:multipart/form-data "-F "game_uuid=test"-F "player_uuids=aaa"-F "player_uuids=bbb"-F "player_uuids=ccc"

最佳答案

目前无法使用 OpenAPI 定义您的场景(带有分解数组的多部分请求),因为 explodestyle 行为仅针对 application/x-www-form-urlencoded 定义,但不适用于 multipart/*:

style
... This property SHALL be ignored if the request body media type is not application/x-www-form-urlencoded.

explode
... This property SHALL be ignored if the request body media type is not application/x-www-form-urlencoded.

相关讨论:Swagger UI: Submit An Array of Integer Elements In formdata

您可能想要file an enhancement request符合 OpenAPI 规范。

关于rest - 编码不会在 swagger-ui 中爆炸 requestBody 中的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54035457/

相关文章:

android - 使用 REST Api 的移动应用程序开发计划是个好主意吗?

swagger - 如何从 Swagger API 声明生成 JSON-Schema

java - Swagger 的 Spring API

python - 如何使用 FastAPI 在 Swagger UI 中显示来自 HTMLResponse 的实际 HTML 页面?

rest - 对于未导致任何更改的 HTTP PUT REST 调用,我应该返回什么?

spring - Rest Controller 与 spring-data-rest RepositoryRestResource

java - Spring - 在 Controller 中检查路径变量是否为空

node.js - Swagger - 更改项目目录

hashmap - 具有动态键值 HashMap 的 Swagger 复杂响应模型

c# - Swashbuckle - 在 swagger 文档中将字符串视为枚举