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"
In Swagger terms, the request body is called a body parameter. There can be only one body parameter, although the operation may have other parameters (path, query, header).
An optional explode keyword controls the array and object serialization. Given the cookie named id , the cookie value is serialized as follows: style.
The OpenAPI Specification (OAS) defines a standard, language-agnostic interface to RESTful APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With