forked from loafle/openapi-generator-original
Merge pull request #1499 from arnested/collectionFormat
Accept arrays as arguments to collection parameters in PHP client.
This commit is contained in:
commit
563cabe931
@ -161,6 +161,39 @@ class ObjectSerializer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize an array to a string.
|
||||||
|
*
|
||||||
|
* @param array $collection collection to serialize to a string
|
||||||
|
* @param string $collectionFormat the format use for serialization (csv,
|
||||||
|
* ssv, tsv, pipes, multi)
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function serializeCollection(array $collection, $collectionFormat, $allowCollectionFormatMulti=false)
|
||||||
|
{
|
||||||
|
if ($allowCollectionFormatMulti && ('multi' === $collectionFormat)) {
|
||||||
|
// http_build_query() almost does the job for us. We just
|
||||||
|
// need to fix the result of multidimensional arrays.
|
||||||
|
return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&'));
|
||||||
|
}
|
||||||
|
switch ($collectionFormat) {
|
||||||
|
case 'pipes':
|
||||||
|
return implode('|', $collection);
|
||||||
|
|
||||||
|
case 'tsv':
|
||||||
|
return implode("\t", $collection);
|
||||||
|
|
||||||
|
case 'ssv':
|
||||||
|
return implode(' ', $collection);
|
||||||
|
|
||||||
|
case 'csv':
|
||||||
|
// Deliberate fall through. CSV is default format.
|
||||||
|
default:
|
||||||
|
return implode(',', $collection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deserialize a JSON string into an object
|
* Deserialize a JSON string into an object
|
||||||
*
|
*
|
||||||
|
@ -139,14 +139,29 @@ use \{{invokerPackage}}\ObjectSerializer;
|
|||||||
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array({{#consumes}}'{{mediaType}}'{{#hasMore}},{{/hasMore}}{{/consumes}}));
|
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array({{#consumes}}'{{mediaType}}'{{#hasMore}},{{/hasMore}}{{/consumes}}));
|
||||||
|
|
||||||
{{#queryParams}}// query params
|
{{#queryParams}}// query params
|
||||||
|
{{#collectionFormat}}
|
||||||
|
if (is_array(${{paramName}})) {
|
||||||
|
${{paramName}} = $this->apiClient->getSerializer()->serializeCollection(${{paramName}}, '{{collectionFormat}}', true);
|
||||||
|
}
|
||||||
|
{{/collectionFormat}}
|
||||||
if (${{paramName}} !== null) {
|
if (${{paramName}} !== null) {
|
||||||
$queryParams['{{baseName}}'] = $this->apiClient->getSerializer()->toQueryValue(${{paramName}});
|
$queryParams['{{baseName}}'] = $this->apiClient->getSerializer()->toQueryValue(${{paramName}});
|
||||||
}{{/queryParams}}
|
}{{/queryParams}}
|
||||||
{{#headerParams}}// header params
|
{{#headerParams}}// header params
|
||||||
|
{{#collectionFormat}}
|
||||||
|
if (is_array(${{paramName}})) {
|
||||||
|
${{paramName}} = $this->apiClient->getSerializer()->serializeCollection(${{paramName}}, '{{collectionFormat}}');
|
||||||
|
}
|
||||||
|
{{/collectionFormat}}
|
||||||
if (${{paramName}} !== null) {
|
if (${{paramName}} !== null) {
|
||||||
$headerParams['{{baseName}}'] = $this->apiClient->getSerializer()->toHeaderValue(${{paramName}});
|
$headerParams['{{baseName}}'] = $this->apiClient->getSerializer()->toHeaderValue(${{paramName}});
|
||||||
}{{/headerParams}}
|
}{{/headerParams}}
|
||||||
{{#pathParams}}// path params
|
{{#pathParams}}// path params
|
||||||
|
{{#collectionFormat}}
|
||||||
|
if (is_array(${{paramName}})) {
|
||||||
|
${{paramName}} = $this->apiClient->getSerializer()->serializeCollection(${{paramName}}, '{{collectionFormat}}');
|
||||||
|
}
|
||||||
|
{{/collectionFormat}}
|
||||||
if (${{paramName}} !== null) {
|
if (${{paramName}} !== null) {
|
||||||
$resourcePath = str_replace(
|
$resourcePath = str_replace(
|
||||||
"{" . "{{baseName}}" . "}",
|
"{" . "{{baseName}}" . "}",
|
||||||
|
@ -301,6 +301,11 @@ class PetApi
|
|||||||
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
|
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
|
||||||
|
|
||||||
// query params
|
// query params
|
||||||
|
|
||||||
|
if (is_array($status)) {
|
||||||
|
$status = $this->apiClient->getSerializer()->serializeCollection($status, 'multi', true);
|
||||||
|
}
|
||||||
|
|
||||||
if ($status !== null) {
|
if ($status !== null) {
|
||||||
$queryParams['status'] = $this->apiClient->getSerializer()->toQueryValue($status);
|
$queryParams['status'] = $this->apiClient->getSerializer()->toQueryValue($status);
|
||||||
}
|
}
|
||||||
@ -391,6 +396,11 @@ class PetApi
|
|||||||
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
|
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
|
||||||
|
|
||||||
// query params
|
// query params
|
||||||
|
|
||||||
|
if (is_array($tags)) {
|
||||||
|
$tags = $this->apiClient->getSerializer()->serializeCollection($tags, 'multi', true);
|
||||||
|
}
|
||||||
|
|
||||||
if ($tags !== null) {
|
if ($tags !== null) {
|
||||||
$queryParams['tags'] = $this->apiClient->getSerializer()->toQueryValue($tags);
|
$queryParams['tags'] = $this->apiClient->getSerializer()->toQueryValue($tags);
|
||||||
}
|
}
|
||||||
@ -487,6 +497,7 @@ class PetApi
|
|||||||
|
|
||||||
|
|
||||||
// path params
|
// path params
|
||||||
|
|
||||||
if ($pet_id !== null) {
|
if ($pet_id !== null) {
|
||||||
$resourcePath = str_replace(
|
$resourcePath = str_replace(
|
||||||
"{" . "petId" . "}",
|
"{" . "petId" . "}",
|
||||||
@ -591,6 +602,7 @@ class PetApi
|
|||||||
|
|
||||||
|
|
||||||
// path params
|
// path params
|
||||||
|
|
||||||
if ($pet_id !== null) {
|
if ($pet_id !== null) {
|
||||||
$resourcePath = str_replace(
|
$resourcePath = str_replace(
|
||||||
"{" . "petId" . "}",
|
"{" . "petId" . "}",
|
||||||
@ -694,10 +706,12 @@ class PetApi
|
|||||||
|
|
||||||
|
|
||||||
// header params
|
// header params
|
||||||
|
|
||||||
if ($api_key !== null) {
|
if ($api_key !== null) {
|
||||||
$headerParams['api_key'] = $this->apiClient->getSerializer()->toHeaderValue($api_key);
|
$headerParams['api_key'] = $this->apiClient->getSerializer()->toHeaderValue($api_key);
|
||||||
}
|
}
|
||||||
// path params
|
// path params
|
||||||
|
|
||||||
if ($pet_id !== null) {
|
if ($pet_id !== null) {
|
||||||
$resourcePath = str_replace(
|
$resourcePath = str_replace(
|
||||||
"{" . "petId" . "}",
|
"{" . "petId" . "}",
|
||||||
@ -792,6 +806,7 @@ class PetApi
|
|||||||
|
|
||||||
|
|
||||||
// path params
|
// path params
|
||||||
|
|
||||||
if ($pet_id !== null) {
|
if ($pet_id !== null) {
|
||||||
$resourcePath = str_replace(
|
$resourcePath = str_replace(
|
||||||
"{" . "petId" . "}",
|
"{" . "petId" . "}",
|
||||||
|
@ -314,6 +314,7 @@ class StoreApi
|
|||||||
|
|
||||||
|
|
||||||
// path params
|
// path params
|
||||||
|
|
||||||
if ($order_id !== null) {
|
if ($order_id !== null) {
|
||||||
$resourcePath = str_replace(
|
$resourcePath = str_replace(
|
||||||
"{" . "orderId" . "}",
|
"{" . "orderId" . "}",
|
||||||
@ -407,6 +408,7 @@ class StoreApi
|
|||||||
|
|
||||||
|
|
||||||
// path params
|
// path params
|
||||||
|
|
||||||
if ($order_id !== null) {
|
if ($order_id !== null) {
|
||||||
$resourcePath = str_replace(
|
$resourcePath = str_replace(
|
||||||
"{" . "orderId" . "}",
|
"{" . "orderId" . "}",
|
||||||
|
@ -371,9 +371,11 @@ class UserApi
|
|||||||
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
|
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
|
||||||
|
|
||||||
// query params
|
// query params
|
||||||
|
|
||||||
if ($username !== null) {
|
if ($username !== null) {
|
||||||
$queryParams['username'] = $this->apiClient->getSerializer()->toQueryValue($username);
|
$queryParams['username'] = $this->apiClient->getSerializer()->toQueryValue($username);
|
||||||
}// query params
|
}// query params
|
||||||
|
|
||||||
if ($password !== null) {
|
if ($password !== null) {
|
||||||
$queryParams['password'] = $this->apiClient->getSerializer()->toQueryValue($password);
|
$queryParams['password'] = $this->apiClient->getSerializer()->toQueryValue($password);
|
||||||
}
|
}
|
||||||
@ -537,6 +539,7 @@ class UserApi
|
|||||||
|
|
||||||
|
|
||||||
// path params
|
// path params
|
||||||
|
|
||||||
if ($username !== null) {
|
if ($username !== null) {
|
||||||
$resourcePath = str_replace(
|
$resourcePath = str_replace(
|
||||||
"{" . "username" . "}",
|
"{" . "username" . "}",
|
||||||
@ -632,6 +635,7 @@ class UserApi
|
|||||||
|
|
||||||
|
|
||||||
// path params
|
// path params
|
||||||
|
|
||||||
if ($username !== null) {
|
if ($username !== null) {
|
||||||
$resourcePath = str_replace(
|
$resourcePath = str_replace(
|
||||||
"{" . "username" . "}",
|
"{" . "username" . "}",
|
||||||
@ -721,6 +725,7 @@ class UserApi
|
|||||||
|
|
||||||
|
|
||||||
// path params
|
// path params
|
||||||
|
|
||||||
if ($username !== null) {
|
if ($username !== null) {
|
||||||
$resourcePath = str_replace(
|
$resourcePath = str_replace(
|
||||||
"{" . "username" . "}",
|
"{" . "username" . "}",
|
||||||
|
@ -516,7 +516,7 @@ class Configuration
|
|||||||
$report = "PHP SDK (Swagger\Client) Debug Report:\n";
|
$report = "PHP SDK (Swagger\Client) Debug Report:\n";
|
||||||
$report .= " OS: ".php_uname()."\n";
|
$report .= " OS: ".php_uname()."\n";
|
||||||
$report .= " PHP Version: ".phpversion()."\n";
|
$report .= " PHP Version: ".phpversion()."\n";
|
||||||
$report .= " Swagger Spec Version: 1.0.0\n";
|
$report .= " OpenAPI Spec Version: 1.0.0\n";
|
||||||
$report .= " SDK Package Version: 1.0.0\n";
|
$report .= " SDK Package Version: 1.0.0\n";
|
||||||
$report .= " Temp Folder Path: ".self::getDefaultConfiguration()->getTempFolderPath()."\n";
|
$report .= " Temp Folder Path: ".self::getDefaultConfiguration()->getTempFolderPath()."\n";
|
||||||
|
|
||||||
|
@ -161,6 +161,39 @@ class ObjectSerializer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize an array to a string.
|
||||||
|
*
|
||||||
|
* @param array $collection collection to serialize to a string
|
||||||
|
* @param string $collectionFormat the format use for serialization (csv,
|
||||||
|
* ssv, tsv, pipes, multi)
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function serializeCollection(array $collection, $collectionFormat, $allowCollectionFormatMulti=false)
|
||||||
|
{
|
||||||
|
if ($allowCollectionFormatMulti && ('multi' === $collectionFormat)) {
|
||||||
|
// http_build_query() almost does the job for us. We just
|
||||||
|
// need to fix the result of multidimensional arrays.
|
||||||
|
return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&'));
|
||||||
|
}
|
||||||
|
switch ($collectionFormat) {
|
||||||
|
case 'pipes':
|
||||||
|
return implode('|', $collection);
|
||||||
|
|
||||||
|
case 'tsv':
|
||||||
|
return implode("\t", $collection);
|
||||||
|
|
||||||
|
case 'ssv':
|
||||||
|
return implode(' ', $collection);
|
||||||
|
|
||||||
|
case 'csv':
|
||||||
|
// Deliberate fall through. CSV is default format.
|
||||||
|
default:
|
||||||
|
return implode(',', $collection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deserialize a JSON string into an object
|
* Deserialize a JSON string into an object
|
||||||
*
|
*
|
||||||
@ -193,7 +226,7 @@ class ObjectSerializer
|
|||||||
$deserialized = $values;
|
$deserialized = $values;
|
||||||
} elseif ($class === '\DateTime') {
|
} elseif ($class === '\DateTime') {
|
||||||
$deserialized = new \DateTime($data);
|
$deserialized = new \DateTime($data);
|
||||||
} elseif (in_array($class, array('integer', 'int', 'void', 'number', 'object', 'double', 'float', 'byte', 'DateTime', 'string', 'mixed', 'boolean', 'bool'))) {
|
} elseif (in_array($class, array('void', 'bool', 'string', 'double', 'byte', 'mixed', 'integer', 'float', 'int', 'DateTime', 'number', 'boolean', 'object'))) {
|
||||||
settype($data, $class);
|
settype($data, $class);
|
||||||
$deserialized = $data;
|
$deserialized = $data;
|
||||||
} elseif ($class === '\SplFileObject') {
|
} elseif ($class === '\SplFileObject') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user