Reputation: 383
The parameter is not being exploded into separate fields, and i cant get my head wrapped around why.
This is my yaml, using 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'
this is the curl request swagger is giving me (BAD)
curl -X POST "https://editor.swagger.io/api/v1/match/started" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "game_uuid=test" -F "player_uuids=aaa,bbb,ccc"
where you can see the last parameter is -F "player_uuids=aaa,bbb,ccc"
and it should be -F "player_uuids=aaa" -F "player_uuids=bbb" -F "player_uuids=ccc"
so the full request should look like this:
curl -X POST "https://editor.swagger.io/api/v1/match/started" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "game_uuid=test" -F "player_uuids=aaa" -F "player_uuids=bbb" -F "player_uuids=ccc"
Upvotes: 7
Views: 1946
Reputation: 97757
There's currently no way to define your scenario (a multipart request with an exploded array) with OpenAPI, because the explode
and style
behavior is only defined for application/x-www-form-urlencoded
but not for 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
.
Related discussion: Swagger UI: Submit An Array of Integer Elements In formdata
You might want to file an enhancement request with the OpenAPI Spec.
Upvotes: 3