Skip to main content

Introducing Support for Complex Query Parameters in PHP SDKs

· 2 min read

PHP SDKs now support complex query parameters with which you can send a complex type as well as arrays/maps of complex types in query strings.

Details

OpenAPI specification allows sending any kind of payload as query parameter. The following example shows how you can set the required type for any query parameter.

"parameters": [
{
"name": "petId",
"in": "query",
"description": "ID of pet that needs to be updated",
"required": true,
"schema": {
"type": "string"
}
}
]

This payload could either be of a simple type i.e string, boolean, number, or could be a complex type i.e model, array, or map. Previously, PHP SDKs only supported simple types along with array/map of simple types but did not support complex types, array/map of complex types while sending them in query string.

What has Changed?

We are now introducing the support for complex query parameters. Now, PHP SDKs have the ability to send a complex type as well as arrays/maps of complex types in query strings. For example take the following model named Pet:

{
"petId": 345,
"petName": "PersianCat",
"siblings": ["catA", "catB", "catC"]
}

This model can now be sent in query string, and the resultant decoded query string would look like:

/sendPet?pet[petId]=345&pet[petName]=PersianCat&pet[siblings][0]=catA&pet[siblings][1]=catB&pet[siblings][2]=catC

APIMatic also added the support for different array serialization formats that would apply on arrays of simple types which may appear within a model. In the above given example of model Pet, the field siblings is an array of simple type i.e. string and it is being serialized by Indexed array serialization. Along with this, support for other array serialization formats like Plain, UnIndexed, CommaSeparated, TabSeparated, PipeSeperated has also been added. Default format is Indexed but one can set any of these formats in an OAS like:

{
"openapi": "3.0.0",
"info": {
"x-codegen-settings": {
"ArraySerialization": "Plain"
}
}

Lets take the same model and try applying other array serialization formats.

Plain Array Serialization

/sendPet?pet[petId]=345&pet[petName]=PersianCat&pet[siblings]=catA&pet[siblings]=catB&pet[siblings]=catC

UnIndexed Array Serialization

/sendPet?pet[petId]=345&pet[petName]=PersianCat&pet[siblings][]=catA&pet[siblings][]=catB&pet[siblings][]=catC

CommaSeparated Array Serialization

/sendPet?pet[petId]=345&pet[petName]=PersianCat&pet[siblings]=catA,catB,catC

TabSeparated Array Serialization

/sendPet?pet[petId]=345&pet[petName]=PersianCat&pet[siblings]=catA\tcatB\tcatC

PipeSeparated Array Serialization

/sendPet?pet[petId]=345&pet[petName]=PersianCat&pet[siblings]=catA|catB|catC