该参数没有被分解为单独的字段,我无法理解为什么。
这是我的 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 定义您的场景(带有分解数组的多部分请求),因为 explode
和 style
行为仅针对 application/x-www-form-urlencoded
定义,但不适用于 multipart/*
:
style
... This property SHALL be ignored if the request body media type is notapplication/x-www-form-urlencoded
.
explode
... This property SHALL be ignored if the request body media type is notapplication/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/