mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-28 19:50:49 +00:00
Merge pull request #504 from wing328/php_param_supppor_datetime
PHP parameters to suppport datetime (ISO8601)
This commit is contained in:
commit
ad7a5967ff
@ -178,7 +178,7 @@ class APIClient {
|
||||
* @return string the serialized object
|
||||
*/
|
||||
public static function toPathValue($value) {
|
||||
return rawurlencode($value);
|
||||
return rawurlencode(toString($value));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -193,19 +193,47 @@ class APIClient {
|
||||
if (is_array($object)) {
|
||||
return implode(',', $object);
|
||||
} else {
|
||||
return $object;
|
||||
return toString($object);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Just pass through the header value for now. Placeholder in case we
|
||||
* find out we need to do something with header values.
|
||||
* Take value and turn it into a string suitable for inclusion in
|
||||
* the header. If it's a string, pass through unchanged
|
||||
* If it's a datetime object, format it in ISO8601
|
||||
* @param string $value a string which will be part of the header
|
||||
* @return string the header string
|
||||
*/
|
||||
public static function toHeaderValue($value) {
|
||||
return toString($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take value and turn it into a string suitable for inclusion in
|
||||
* the http body (form parameter). If it's a string, pass through unchanged
|
||||
* If it's a datetime object, format it in ISO8601
|
||||
* @param string $value the value of the form parameter
|
||||
* @return string the form string
|
||||
*/
|
||||
public static function toFormValue($value) {
|
||||
return toString($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take value and turn it into a string suitable for inclusion in
|
||||
* the parameter. If it's a string, pass through unchanged
|
||||
* If it's a datetime object, format it in ISO8601
|
||||
* @param string $value the value of the parameter
|
||||
* @return string the header string
|
||||
*/
|
||||
public static function toString($value) {
|
||||
if ($value instanceof \DateTime) { // datetime in ISO8601 format
|
||||
return $value->format(\DateTime::ISO8601);
|
||||
}
|
||||
else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a JSON string into an object
|
||||
|
@ -63,7 +63,7 @@ class {{classname}} {
|
||||
}{{/pathParams}}
|
||||
{{#formParams}}// form params
|
||||
if (${{paramName}} !== null) {
|
||||
$formParams['{{baseName}}'] = {{#isFile}}'@' . {{/isFile}}${{paramName}};
|
||||
$formParams['{{baseName}}'] = {{#isFile}}'@' . {{/isFile}}$this->apiClient->toFormValue(${{paramName}});
|
||||
}{{/formParams}}
|
||||
{{#bodyParams}}// body params
|
||||
$body = null;
|
||||
|
@ -304,10 +304,10 @@ class PetApi {
|
||||
}
|
||||
// form params
|
||||
if ($name !== null) {
|
||||
$formParams['name'] = $name;
|
||||
$formParams['name'] = $this->apiClient->toFormValue($name);
|
||||
}// form params
|
||||
if ($status !== null) {
|
||||
$formParams['status'] = $status;
|
||||
$formParams['status'] = $this->apiClient->toFormValue($status);
|
||||
}
|
||||
|
||||
|
||||
@ -408,10 +408,10 @@ class PetApi {
|
||||
}
|
||||
// form params
|
||||
if ($additionalMetadata !== null) {
|
||||
$formParams['additionalMetadata'] = $additionalMetadata;
|
||||
$formParams['additionalMetadata'] = $this->apiClient->toFormValue($additionalMetadata);
|
||||
}// form params
|
||||
if ($file !== null) {
|
||||
$formParams['file'] = '@' . $file;
|
||||
$formParams['file'] = '@' . $this->apiClient->toFormValue($file);
|
||||
}
|
||||
|
||||
|
||||
|
@ -127,19 +127,19 @@ class APIClient {
|
||||
|
||||
// Handle the response
|
||||
if ($response_info['http_code'] == 0) {
|
||||
throw new Exception("TIMEOUT: api call to " . $url .
|
||||
" took more than 5s to return" );
|
||||
throw new APIClientException("TIMEOUT: api call to " . $url .
|
||||
" took more than 5s to return", 0, $response_info, $response);
|
||||
} else if ($response_info['http_code'] == 200) {
|
||||
$data = json_decode($response);
|
||||
} else if ($response_info['http_code'] == 401) {
|
||||
throw new Exception("Unauthorized API request to " . $url .
|
||||
": ".json_decode($response)->message );
|
||||
throw new APIClientException("Unauthorized API request to " . $url .
|
||||
": " . json_decode($response)->message, 0, $response_info, $response);
|
||||
} else if ($response_info['http_code'] == 404) {
|
||||
$data = null;
|
||||
} else {
|
||||
throw new Exception("Can't connect to the api: " . $url .
|
||||
throw new APIClientException("Can't connect to the api: " . $url .
|
||||
" response code: " .
|
||||
$response_info['http_code']);
|
||||
$response_info['http_code'], 0, $response_info, $response);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
@ -178,7 +178,7 @@ class APIClient {
|
||||
* @return string the serialized object
|
||||
*/
|
||||
public static function toPathValue($value) {
|
||||
return rawurlencode($value);
|
||||
return rawurlencode(toString($value));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -193,19 +193,47 @@ class APIClient {
|
||||
if (is_array($object)) {
|
||||
return implode(',', $object);
|
||||
} else {
|
||||
return $object;
|
||||
return toString($object);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Just pass through the header value for now. Placeholder in case we
|
||||
* find out we need to do something with header values.
|
||||
* Take value and turn it into a string suitable for inclusion in
|
||||
* the header. If it's a string, pass through unchanged
|
||||
* If it's a datetime object, format it in ISO8601
|
||||
* @param string $value a string which will be part of the header
|
||||
* @return string the header string
|
||||
*/
|
||||
public static function toHeaderValue($value) {
|
||||
return toString($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take value and turn it into a string suitable for inclusion in
|
||||
* the http body (form parameter). If it's a string, pass through unchanged
|
||||
* If it's a datetime object, format it in ISO8601
|
||||
* @param string $value the value of the form parameter
|
||||
* @return string the form string
|
||||
*/
|
||||
public static function toFormValue($value) {
|
||||
return toString($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take value and turn it into a string suitable for inclusion in
|
||||
* the parameter. If it's a string, pass through unchanged
|
||||
* If it's a datetime object, format it in ISO8601
|
||||
* @param string $value the value of the parameter
|
||||
* @return string the header string
|
||||
*/
|
||||
public static function toString($value) {
|
||||
if ($value instanceof \DateTime) { // datetime in ISO8601 format
|
||||
return $value->format(\DateTime::ISO8601);
|
||||
}
|
||||
else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a JSON string into an object
|
||||
@ -257,3 +285,20 @@ class APIClient {
|
||||
|
||||
}
|
||||
|
||||
class APIClientException extends Exception {
|
||||
protected $response, $response_info;
|
||||
|
||||
public function __construct($message="", $code=0, $response_info=null, $response=null) {
|
||||
parent::__construct($message, $code);
|
||||
$this->response_info = $response_info;
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
public function getResponse() {
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
public function getResponseInfo() {
|
||||
return $this->response_info;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user