Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHP-Symfony] Catch serializer exception #2074

Merged
merged 1 commit into from Feb 10, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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;
Expand Down Expand Up @@ -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}}

Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [];
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [];
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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 = [];
Expand Down