Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,11 @@ use {{invokerPackage}}\ObjectSerializer;
if (isset(${{paramName}})) {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization(${{paramName}}));
try {
$httpBody = json_encode(ObjectSerializer::sanitizeForSerialization(${{paramName}}), JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
$httpBody = ${{paramName}};
}
Expand All @@ -787,7 +791,11 @@ use {{invokerPackage}}\ObjectSerializer;

} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
try {
$httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
Expand Down
12 changes: 10 additions & 2 deletions modules/openapi-generator/src/main/resources/php/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,11 @@ use {{invokerPackage}}\ObjectSerializer;
if (isset(${{paramName}})) {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization(${{paramName}}));
try {
$httpBody = json_encode(ObjectSerializer::sanitizeForSerialization(${{paramName}}), JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
$httpBody = ${{paramName}};
}
Expand All @@ -702,7 +706,11 @@ use {{invokerPackage}}\ObjectSerializer;

} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
try {
$httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
Expand Down
96 changes: 80 additions & 16 deletions samples/client/echo_api/php-nextgen-streaming/src/Api/BodyApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,11 @@ public function testBodyApplicationOctetstreamBinaryRequest(
if (isset($body)) {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($body));
try {
$httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($body), JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
$httpBody = $body;
}
Expand All @@ -619,7 +623,11 @@ public function testBodyApplicationOctetstreamBinaryRequest(

} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
try {
$httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
Expand Down Expand Up @@ -896,7 +904,11 @@ public function testBodyMultipartFormdataArrayOfBinaryRequest(

} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
try {
$httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
Expand Down Expand Up @@ -1167,7 +1179,11 @@ public function testBodyMultipartFormdataSingleBinaryRequest(

} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
try {
$httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
Expand Down Expand Up @@ -1415,7 +1431,11 @@ public function testEchoBodyAllOfPetRequest(
if (isset($pet)) {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pet));
try {
$httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($pet), JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
$httpBody = $pet;
}
Expand All @@ -1436,7 +1456,11 @@ public function testEchoBodyAllOfPetRequest(

} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
try {
$httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
Expand Down Expand Up @@ -1684,7 +1708,11 @@ public function testEchoBodyFreeFormObjectResponseStringRequest(
if (isset($body)) {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($body));
try {
$httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($body), JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
$httpBody = $body;
}
Expand All @@ -1705,7 +1733,11 @@ public function testEchoBodyFreeFormObjectResponseStringRequest(

} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
try {
$httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
Expand Down Expand Up @@ -1953,7 +1985,11 @@ public function testEchoBodyPetRequest(
if (isset($pet)) {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pet));
try {
$httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($pet), JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
$httpBody = $pet;
}
Expand All @@ -1974,7 +2010,11 @@ public function testEchoBodyPetRequest(

} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
try {
$httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
Expand Down Expand Up @@ -2222,7 +2262,11 @@ public function testEchoBodyPetResponseStringRequest(
if (isset($pet)) {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pet));
try {
$httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($pet), JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
$httpBody = $pet;
}
Expand All @@ -2243,7 +2287,11 @@ public function testEchoBodyPetResponseStringRequest(

} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
try {
$httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
Expand Down Expand Up @@ -2491,7 +2539,11 @@ public function testEchoBodyStringEnumRequest(
if (isset($body)) {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($body));
try {
$httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($body), JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
$httpBody = $body;
}
Expand All @@ -2512,7 +2564,11 @@ public function testEchoBodyStringEnumRequest(

} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
try {
$httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
Expand Down Expand Up @@ -2760,7 +2816,11 @@ public function testEchoBodyTagResponseStringRequest(
if (isset($tag)) {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($tag));
try {
$httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($tag), JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
$httpBody = $tag;
}
Expand All @@ -2781,7 +2841,11 @@ public function testEchoBodyTagResponseStringRequest(

} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
try {
$httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
Expand Down
18 changes: 15 additions & 3 deletions samples/client/echo_api/php-nextgen-streaming/src/Api/FormApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,11 @@ public function testFormIntegerBooleanStringRequest(

} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
try {
$httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
Expand Down Expand Up @@ -672,7 +676,11 @@ public function testFormObjectMultipartRequest(

} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
try {
$httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
Expand Down Expand Up @@ -998,7 +1006,11 @@ public function testFormOneofRequest(

} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
try {
$httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
}
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
Expand Down
Loading
Loading