Permalink
Browse files

Catch serializer exception (#2074)

  • Loading branch information...
ossinkine authored and wing328 committed Feb 10, 2019
1 parent f76dca8 commit 73d309b9ba607e047ff4c9cff266b0169323b322
@@ -20,6 +20,7 @@
namespace {{controllerPackage}};

use \Exception;
use JMS\Serializer\Exception\RuntimeException as SerializerRuntimeException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
@@ -137,18 +138,24 @@ class {{controllerName}} extends Controller
{{/isContainer}}
{{/required}}

{{#hasParams}}
// Deserialize the input values that needs it
{{#allParams}}
{{^isFile}}
{{#isBodyParam}}
${{paramName}} = $this->deserialize(${{paramName}}, '{{#isContainer}}{{#items}}array<{{dataType}}>{{/items}}{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}', $inputFormat);
{{/isBodyParam}}
{{^isBodyParam}}
${{paramName}} = $this->deserialize(${{paramName}}, '{{#isContainer}}array<{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}{{^collectionFormat}}csv{{/collectionFormat}},{{dataType}}>{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}', 'string');
{{/isBodyParam}}
{{/isFile}}
{{/allParams}}
try {
{{#allParams}}
{{^isFile}}
{{#isBodyParam}}
${{paramName}} = $this->deserialize(${{paramName}}, '{{#isContainer}}{{#items}}array<{{dataType}}>{{/items}}{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}', $inputFormat);
{{/isBodyParam}}
{{^isBodyParam}}
${{paramName}} = $this->deserialize(${{paramName}}, '{{#isContainer}}array<{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}{{^collectionFormat}}csv{{/collectionFormat}},{{dataType}}>{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}', 'string');
{{/isBodyParam}}
{{/isFile}}
{{/allParams}}
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}

{{/hasParams}}
// Validate the input values
{{>api_input_validation}}

@@ -30,6 +30,7 @@
namespace OpenAPI\Server\Controller;
use \Exception;
use JMS\Serializer\Exception\RuntimeException as SerializerRuntimeException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
@@ -87,7 +88,11 @@ public function addPetAction(Request $request)
// Use the default value if no value was provided
// Deserialize the input values that needs it
$body = $this->deserialize($body, 'OpenAPI\Server\Model\Pet', $inputFormat);
try {
$body = $this->deserialize($body, 'OpenAPI\Server\Model\Pet', $inputFormat);
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
@@ -166,8 +171,12 @@ public function deletePetAction(Request $request, $petId)
// Use the default value if no value was provided
// Deserialize the input values that needs it
$petId = $this->deserialize($petId, 'int', 'string');
$apiKey = $this->deserialize($apiKey, 'string', 'string');
try {
$petId = $this->deserialize($petId, 'int', 'string');
$apiKey = $this->deserialize($apiKey, 'string', 'string');
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
@@ -252,7 +261,11 @@ public function findPetsByStatusAction(Request $request)
// Use the default value if no value was provided
// Deserialize the input values that needs it
$status = $this->deserialize($status, 'array<csv,string>', 'string');
try {
$status = $this->deserialize($status, 'array<csv,string>', 'string');
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
@@ -339,7 +352,11 @@ public function findPetsByTagsAction(Request $request)
// Use the default value if no value was provided
// Deserialize the input values that needs it
$tags = $this->deserialize($tags, 'array<csv,string>', 'string');
try {
$tags = $this->deserialize($tags, 'array<csv,string>', 'string');
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
@@ -422,7 +439,11 @@ public function getPetByIdAction(Request $request, $petId)
// Use the default value if no value was provided
// Deserialize the input values that needs it
$petId = $this->deserialize($petId, 'int', 'string');
try {
$petId = $this->deserialize($petId, 'int', 'string');
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
@@ -515,7 +536,11 @@ public function updatePetAction(Request $request)
// Use the default value if no value was provided
// Deserialize the input values that needs it
$body = $this->deserialize($body, 'OpenAPI\Server\Model\Pet', $inputFormat);
try {
$body = $this->deserialize($body, 'OpenAPI\Server\Model\Pet', $inputFormat);
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
@@ -601,9 +626,13 @@ public function updatePetWithFormAction(Request $request, $petId)
// Use the default value if no value was provided
// Deserialize the input values that needs it
$petId = $this->deserialize($petId, 'int', 'string');
$name = $this->deserialize($name, 'string', 'string');
$status = $this->deserialize($status, 'string', 'string');
try {
$petId = $this->deserialize($petId, 'int', 'string');
$name = $this->deserialize($name, 'string', 'string');
$status = $this->deserialize($status, 'string', 'string');
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
@@ -695,8 +724,12 @@ public function uploadFileAction(Request $request, $petId)
// Use the default value if no value was provided
// Deserialize the input values that needs it
$petId = $this->deserialize($petId, 'int', 'string');
$additionalMetadata = $this->deserialize($additionalMetadata, 'string', 'string');
try {
$petId = $this->deserialize($petId, 'int', 'string');
$additionalMetadata = $this->deserialize($additionalMetadata, 'string', 'string');
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
@@ -30,6 +30,7 @@
namespace OpenAPI\Server\Controller;
use \Exception;
use JMS\Serializer\Exception\RuntimeException as SerializerRuntimeException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
@@ -74,7 +75,11 @@ public function deleteOrderAction(Request $request, $orderId)
// Use the default value if no value was provided
// Deserialize the input values that needs it
$orderId = $this->deserialize($orderId, 'string', 'string');
try {
$orderId = $this->deserialize($orderId, 'string', 'string');
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
@@ -152,8 +157,6 @@ public function getInventoryAction(Request $request)
// Use the default value if no value was provided
// Deserialize the input values that needs it
// Validate the input values
@@ -220,7 +223,11 @@ public function getOrderByIdAction(Request $request, $orderId)
// Use the default value if no value was provided
// Deserialize the input values that needs it
$orderId = $this->deserialize($orderId, 'int', 'string');
try {
$orderId = $this->deserialize($orderId, 'int', 'string');
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
@@ -310,7 +317,11 @@ public function placeOrderAction(Request $request)
// Use the default value if no value was provided
// Deserialize the input values that needs it
$body = $this->deserialize($body, 'OpenAPI\Server\Model\Order', $inputFormat);
try {
$body = $this->deserialize($body, 'OpenAPI\Server\Model\Order', $inputFormat);
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
@@ -30,6 +30,7 @@
namespace OpenAPI\Server\Controller;
use \Exception;
use JMS\Serializer\Exception\RuntimeException as SerializerRuntimeException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
@@ -83,7 +84,11 @@ public function createUserAction(Request $request)
// Use the default value if no value was provided
// Deserialize the input values that needs it
$body = $this->deserialize($body, 'OpenAPI\Server\Model\User', $inputFormat);
try {
$body = $this->deserialize($body, 'OpenAPI\Server\Model\User', $inputFormat);
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
@@ -165,7 +170,11 @@ public function createUsersWithArrayInputAction(Request $request)
// Use the default value if no value was provided
// Deserialize the input values that needs it
$body = $this->deserialize($body, 'array<OpenAPI\Server\Model\User>', $inputFormat);
try {
$body = $this->deserialize($body, 'array<OpenAPI\Server\Model\User>', $inputFormat);
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
@@ -249,7 +258,11 @@ public function createUsersWithListInputAction(Request $request)
// Use the default value if no value was provided
// Deserialize the input values that needs it
$body = $this->deserialize($body, 'array<OpenAPI\Server\Model\User>', $inputFormat);
try {
$body = $this->deserialize($body, 'array<OpenAPI\Server\Model\User>', $inputFormat);
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
@@ -324,7 +337,11 @@ public function deleteUserAction(Request $request, $username)
// Use the default value if no value was provided
// Deserialize the input values that needs it
$username = $this->deserialize($username, 'string', 'string');
try {
$username = $this->deserialize($username, 'string', 'string');
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
@@ -400,7 +417,11 @@ public function getUserByNameAction(Request $request, $username)
// Use the default value if no value was provided
// Deserialize the input values that needs it
$username = $this->deserialize($username, 'string', 'string');
try {
$username = $this->deserialize($username, 'string', 'string');
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
@@ -481,8 +502,12 @@ public function loginUserAction(Request $request)
// Use the default value if no value was provided
// Deserialize the input values that needs it
$username = $this->deserialize($username, 'string', 'string');
$password = $this->deserialize($password, 'string', 'string');
try {
$username = $this->deserialize($username, 'string', 'string');
$password = $this->deserialize($password, 'string', 'string');
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
@@ -564,8 +589,6 @@ public function logoutUserAction(Request $request)
// Use the default value if no value was provided
// Deserialize the input values that needs it
// Validate the input values
@@ -639,8 +662,12 @@ public function updateUserAction(Request $request, $username)
// Use the default value if no value was provided
// Deserialize the input values that needs it
$username = $this->deserialize($username, 'string', 'string');
$body = $this->deserialize($body, 'OpenAPI\Server\Model\User', $inputFormat);
try {
$username = $this->deserialize($username, 'string', 'string');
$body = $this->deserialize($body, 'OpenAPI\Server\Model\User', $inputFormat);
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];

0 comments on commit 73d309b

Please sign in to comment.