Skip to content

Commit 0ff7306

Browse files
authored
Merge pull request #624 from jpswade/patch-1
Pass Data Format through to the method
2 parents b4f1c3d + 775ab3c commit 0ff7306

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/main/resources/handlebars/php/ObjectSerializer.mustache

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ class ObjectSerializer
3333
* Serialize data
3434
*
3535
* @param mixed $data the data to serialize
36-
* @param string $type the SwaggerType of the data
3736
* @param string $format the format of the Swagger type of the data
3837
*
3938
* @return string|object serialized form of $data
4039
*/
41-
public static function sanitizeForSerialization($data, $type = null, $format = null)
40+
public static function sanitizeForSerialization($data, $format = null)
4241
{
4342
if (is_scalar($data) || null === $data) {
4443
return $data;
@@ -109,22 +108,23 @@ class ObjectSerializer
109108
* later.
110109
*
111110
* @param string[]|string|\DateTime $object an object to be serialized to a string
111+
* @param string|null $format the format of the parameter
112112
*
113113
* @return string the serialized object
114114
*/
115-
public static function toQueryValue($object)
115+
public static function toQueryValue($object, $format = null)
116116
{
117117
if (is_array($object)) {
118118
return implode(',', $object);
119119
} else {
120-
return self::toString($object);
120+
return self::toString($object, $format);
121121
}
122122
}
123123

124124
/**
125125
* Take value and turn it into a string suitable for inclusion in
126126
* the header. If it's a string, pass through unchanged
127-
* If it's a datetime object, format it in ISO8601
127+
* If it's a datetime object, format it in RFC3339
128128
*
129129
* @param string $value a string which will be part of the header
130130
*
@@ -138,7 +138,7 @@ class ObjectSerializer
138138
/**
139139
* Take value and turn it into a string suitable for inclusion in
140140
* the http body (form parameter). If it's a string, pass through unchanged
141-
* If it's a datetime object, format it in ISO8601
141+
* If it's a datetime object, format it in RFC3339
142142
*
143143
* @param string|\SplFileObject $value the value of the form parameter
144144
*
@@ -156,16 +156,18 @@ class ObjectSerializer
156156
/**
157157
* Take value and turn it into a string suitable for inclusion in
158158
* the parameter. If it's a string, pass through unchanged
159-
* If it's a datetime object, format it in ISO8601
159+
* If it's a datetime object, format it in RFC3339
160+
* If it's a date, format it in Y-m-d
160161
*
161162
* @param string|\DateTime $value the value of the parameter
163+
* @param string|null $format the format of the parameter
162164
*
163165
* @return string the header string
164166
*/
165-
public static function toString($value)
167+
public static function toString($value, $format = null)
166168
{
167-
if ($value instanceof \DateTime) { // datetime in ISO8601 format
168-
return $value->format(\DateTime::ATOM);
169+
if ($value instanceof \DateTime) {
170+
return ($format === 'date') ? $value->format('Y-m-d') : $value->format(\DateTime::ATOM);
169171
} else {
170172
return $value;
171173
}

src/main/resources/handlebars/php/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ use {{invokerPackage}}\ObjectSerializer;
361361
}
362362
{{/collectionFormat}}
363363
if (${{paramName}} !== null) {
364-
$queryParams['{{baseName}}'] = ObjectSerializer::toQueryValue(${{paramName}});
364+
$queryParams['{{baseName}}'] = ObjectSerializer::toQueryValue(${{paramName}}, {{#dataFormat}}'{{{dataFormat}}}'{{/dataFormat}}{{^dataFormat}}null{{/dataFormat}});
365365
}
366366
{{/queryParams}}
367367
{{#headerParams}}

0 commit comments

Comments
 (0)