forked from loafle/openapi-generator-original
* Fix PHP Symfony OpenAPI 3.0 sample location * Update PHP Symfony OpenAPI 3.0 sample
This commit is contained in:
committed by
William Cheng
parent
581131e0fe
commit
ed82aaae97
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
/**
|
||||
* Controller
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package OpenAPI\Server\Controller
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace OpenAPI\Server\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use OpenAPI\Server\Service\SerializerInterface;
|
||||
use OpenAPI\Server\Service\ValidatorInterface;
|
||||
|
||||
/**
|
||||
* Controller Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @package OpenAPI\Server\Controller
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class Controller extends AbstractController
|
||||
{
|
||||
protected $validator;
|
||||
protected $serializer;
|
||||
protected $apiServer;
|
||||
|
||||
public function setValidator(ValidatorInterface $validator)
|
||||
{
|
||||
$this->validator = $validator;
|
||||
}
|
||||
|
||||
public function setSerializer(SerializerInterface $serializer)
|
||||
{
|
||||
$this->serializer = $serializer;
|
||||
}
|
||||
|
||||
public function setApiServer($server)
|
||||
{
|
||||
$this->apiServer = $server;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will return a response with code 400. Usage example:
|
||||
* return $this->createBadRequestResponse('Unable to access this page!');
|
||||
*
|
||||
* @param string $message A message
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function createBadRequestResponse($message = 'Bad Request.')
|
||||
{
|
||||
return new Response($message, 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will return an error response. Usage example:
|
||||
* return $this->createErrorResponse(new UnauthorizedHttpException());
|
||||
*
|
||||
* @param HttpException $exception An HTTP exception
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function createErrorResponse(HttpException $exception)
|
||||
{
|
||||
$statusCode = $exception->getStatusCode();
|
||||
$headers = array_merge($exception->getHeaders(), ['Content-Type' => 'application/json']);
|
||||
|
||||
$json = $this->exceptionToArray($exception);
|
||||
$json['statusCode'] = $statusCode;
|
||||
|
||||
return new Response(json_encode($json, 15, 512), $statusCode, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes data to a given type format.
|
||||
*
|
||||
* @param mixed $data The data to serialize.
|
||||
* @param string $class The source data class.
|
||||
* @param string $format The target serialization format.
|
||||
*
|
||||
* @return string A serialized data string.
|
||||
*/
|
||||
protected function serialize($data, $format)
|
||||
{
|
||||
return $this->serializer->serialize($data, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes data from a given type format.
|
||||
*
|
||||
* @param string $data The data to deserialize.
|
||||
* @param string $class The target data class.
|
||||
* @param string $format The source serialization format.
|
||||
*
|
||||
* @return mixed A deserialized data.
|
||||
*/
|
||||
protected function deserialize($data, $class, $format)
|
||||
{
|
||||
return $this->serializer->deserialize($data, $class, $format);
|
||||
}
|
||||
|
||||
protected function validate($data, $asserts = null)
|
||||
{
|
||||
$errors = $this->validator->validate($data, $asserts);
|
||||
|
||||
if (count($errors) > 0) {
|
||||
$errorsString = (string)$errors;
|
||||
return $this->createBadRequestResponse($errorsString);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an exception to a serializable array.
|
||||
*
|
||||
* @param \Exception|null $exception
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function exceptionToArray(\Exception $exception = null)
|
||||
{
|
||||
if (null === $exception) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$this->container->get('kernel')->isDebug()) {
|
||||
return [
|
||||
'message' => $exception->getMessage(),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'message' => $exception->getMessage(),
|
||||
'type' => get_class($exception),
|
||||
'previous' => $this->exceptionToArray($exception->getPrevious()),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getOutputFormat($accept, array $produced)
|
||||
{
|
||||
// Figure out what the client accepts
|
||||
$accept = preg_split("/[\s,]+/", $accept);
|
||||
|
||||
if (in_array('*/*', $accept) || in_array('application/*', $accept)) {
|
||||
// Prefer JSON if the client has no preference
|
||||
if (in_array('application/json', $produced)) {
|
||||
return 'application/json';
|
||||
}
|
||||
if (in_array('application/xml', $produced)) {
|
||||
return 'application/xml';
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array('application/json', $accept) && in_array('application/json', $produced)) {
|
||||
return 'application/json';
|
||||
}
|
||||
|
||||
if (in_array('application/xml', $accept) && in_array('application/xml', $produced)) {
|
||||
return 'application/xml';
|
||||
}
|
||||
|
||||
// If we reach this point, we don't have a common ground between server and client
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,771 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PetController
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package OpenAPI\Server\Controller
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
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;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use OpenAPI\Server\Api\PetApiInterface;
|
||||
use OpenAPI\Server\Model\ApiResponse;
|
||||
use OpenAPI\Server\Model\Pet;
|
||||
|
||||
/**
|
||||
* PetController Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @package OpenAPI\Server\Controller
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class PetController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Operation addPet
|
||||
*
|
||||
* Add a new pet to the store
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function addPetAction(Request $request)
|
||||
{
|
||||
// Make sure that the client is providing something that we can consume
|
||||
$consumes = ['application/json', 'application/xml'];
|
||||
$inputFormat = $request->headers->has('Content-Type')?$request->headers->get('Content-Type'):$consumes[0];
|
||||
if (!in_array($inputFormat, $consumes)) {
|
||||
// We can't consume the content that the client is sending us
|
||||
return new Response('', 415);
|
||||
}
|
||||
|
||||
// Handle authentication
|
||||
// Authentication 'petstore_auth' required
|
||||
// Oauth required
|
||||
$securitypetstore_auth = $request->headers->get('authorization');
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
$pet = $request->getContent();
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Deserialize the input values that needs it
|
||||
try {
|
||||
$pet = $this->deserialize($pet, 'OpenAPI\Server\Model\Pet', $inputFormat);
|
||||
} catch (SerializerRuntimeException $exception) {
|
||||
return $this->createBadRequestResponse($exception->getMessage());
|
||||
}
|
||||
|
||||
// Validate the input values
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\Type("OpenAPI\Server\Model\Pet");
|
||||
$asserts[] = new Assert\Valid();
|
||||
$response = $this->validate($pet, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
// Set authentication method 'petstore_auth'
|
||||
$handler->setpetstore_auth($securitypetstore_auth);
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 204;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->addPet($pet, $responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = '';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 405:
|
||||
$message = 'Invalid input';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation deletePet
|
||||
*
|
||||
* Deletes a pet
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function deletePetAction(Request $request, $petId)
|
||||
{
|
||||
// Handle authentication
|
||||
// Authentication 'petstore_auth' required
|
||||
// Oauth required
|
||||
$securitypetstore_auth = $request->headers->get('authorization');
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
$apiKey = $request->headers->get('api_key');
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Deserialize the input values that needs it
|
||||
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 = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\Type("int");
|
||||
$response = $this->validate($petId, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\Type("string");
|
||||
$response = $this->validate($apiKey, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
// Set authentication method 'petstore_auth'
|
||||
$handler->setpetstore_auth($securitypetstore_auth);
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 204;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->deletePet($petId, $apiKey, $responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = '';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 400:
|
||||
$message = 'Invalid pet value';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation findPetsByStatus
|
||||
*
|
||||
* Finds Pets by status
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function findPetsByStatusAction(Request $request)
|
||||
{
|
||||
// Figure out what data format to return to the client
|
||||
$produces = ['application/xml', 'application/json'];
|
||||
// Figure out what the client accepts
|
||||
$clientAccepts = $request->headers->has('Accept')?$request->headers->get('Accept'):'*/*';
|
||||
$responseFormat = $this->getOutputFormat($clientAccepts, $produces);
|
||||
if ($responseFormat === null) {
|
||||
return new Response('', 406);
|
||||
}
|
||||
|
||||
// Handle authentication
|
||||
// Authentication 'petstore_auth' required
|
||||
// Oauth required
|
||||
$securitypetstore_auth = $request->headers->get('authorization');
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
$status = $request->query->get('status');
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Deserialize the input values that needs it
|
||||
try {
|
||||
$status = $this->deserialize($status, 'array<csv,string>', 'string');
|
||||
} catch (SerializerRuntimeException $exception) {
|
||||
return $this->createBadRequestResponse($exception->getMessage());
|
||||
}
|
||||
|
||||
// Validate the input values
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\All([
|
||||
new Assert\Choice([ "available", "pending", "sold" ])
|
||||
]);
|
||||
$asserts[] = new Assert\All([
|
||||
new Assert\Type("string"),
|
||||
]);
|
||||
$response = $this->validate($status, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
// Set authentication method 'petstore_auth'
|
||||
$handler->setpetstore_auth($securitypetstore_auth);
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 200;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->findPetsByStatus($status, $responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = 'successful operation';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 200:
|
||||
$message = 'successful operation';
|
||||
break;
|
||||
case 400:
|
||||
$message = 'Invalid status value';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
$result !== null ?$this->serialize($result, $responseFormat):'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'Content-Type' => $responseFormat,
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation findPetsByTags
|
||||
*
|
||||
* Finds Pets by tags
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function findPetsByTagsAction(Request $request)
|
||||
{
|
||||
// Figure out what data format to return to the client
|
||||
$produces = ['application/xml', 'application/json'];
|
||||
// Figure out what the client accepts
|
||||
$clientAccepts = $request->headers->has('Accept')?$request->headers->get('Accept'):'*/*';
|
||||
$responseFormat = $this->getOutputFormat($clientAccepts, $produces);
|
||||
if ($responseFormat === null) {
|
||||
return new Response('', 406);
|
||||
}
|
||||
|
||||
// Handle authentication
|
||||
// Authentication 'petstore_auth' required
|
||||
// Oauth required
|
||||
$securitypetstore_auth = $request->headers->get('authorization');
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
$tags = $request->query->get('tags');
|
||||
$maxCount = $request->query->get('maxCount');
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Deserialize the input values that needs it
|
||||
try {
|
||||
$tags = $this->deserialize($tags, 'array<csv,string>', 'string');
|
||||
$maxCount = $this->deserialize($maxCount, 'int', 'string');
|
||||
} catch (SerializerRuntimeException $exception) {
|
||||
return $this->createBadRequestResponse($exception->getMessage());
|
||||
}
|
||||
|
||||
// Validate the input values
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\All([
|
||||
new Assert\Type("string"),
|
||||
]);
|
||||
$response = $this->validate($tags, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\Type("int");
|
||||
$response = $this->validate($maxCount, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
// Set authentication method 'petstore_auth'
|
||||
$handler->setpetstore_auth($securitypetstore_auth);
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 200;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->findPetsByTags($tags, $maxCount, $responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = 'successful operation';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 200:
|
||||
$message = 'successful operation';
|
||||
break;
|
||||
case 400:
|
||||
$message = 'Invalid tag value';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
$result !== null ?$this->serialize($result, $responseFormat):'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'Content-Type' => $responseFormat,
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation getPetById
|
||||
*
|
||||
* Find pet by ID
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function getPetByIdAction(Request $request, $petId)
|
||||
{
|
||||
// Figure out what data format to return to the client
|
||||
$produces = ['application/xml', 'application/json'];
|
||||
// Figure out what the client accepts
|
||||
$clientAccepts = $request->headers->has('Accept')?$request->headers->get('Accept'):'*/*';
|
||||
$responseFormat = $this->getOutputFormat($clientAccepts, $produces);
|
||||
if ($responseFormat === null) {
|
||||
return new Response('', 406);
|
||||
}
|
||||
|
||||
// Handle authentication
|
||||
// Authentication 'api_key' required
|
||||
// Set key with prefix in header
|
||||
$securityapi_key = $request->headers->get('api_key');
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Deserialize the input values that needs it
|
||||
try {
|
||||
$petId = $this->deserialize($petId, 'int', 'string');
|
||||
} catch (SerializerRuntimeException $exception) {
|
||||
return $this->createBadRequestResponse($exception->getMessage());
|
||||
}
|
||||
|
||||
// Validate the input values
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\Type("int");
|
||||
$response = $this->validate($petId, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
// Set authentication method 'api_key'
|
||||
$handler->setapi_key($securityapi_key);
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 200;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->getPetById($petId, $responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = 'successful operation';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 200:
|
||||
$message = 'successful operation';
|
||||
break;
|
||||
case 400:
|
||||
$message = 'Invalid ID supplied';
|
||||
break;
|
||||
case 404:
|
||||
$message = 'Pet not found';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
$result !== null ?$this->serialize($result, $responseFormat):'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'Content-Type' => $responseFormat,
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation updatePet
|
||||
*
|
||||
* Update an existing pet
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function updatePetAction(Request $request)
|
||||
{
|
||||
// Make sure that the client is providing something that we can consume
|
||||
$consumes = ['application/json', 'application/xml'];
|
||||
$inputFormat = $request->headers->has('Content-Type')?$request->headers->get('Content-Type'):$consumes[0];
|
||||
if (!in_array($inputFormat, $consumes)) {
|
||||
// We can't consume the content that the client is sending us
|
||||
return new Response('', 415);
|
||||
}
|
||||
|
||||
// Handle authentication
|
||||
// Authentication 'petstore_auth' required
|
||||
// Oauth required
|
||||
$securitypetstore_auth = $request->headers->get('authorization');
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
$pet = $request->getContent();
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Deserialize the input values that needs it
|
||||
try {
|
||||
$pet = $this->deserialize($pet, 'OpenAPI\Server\Model\Pet', $inputFormat);
|
||||
} catch (SerializerRuntimeException $exception) {
|
||||
return $this->createBadRequestResponse($exception->getMessage());
|
||||
}
|
||||
|
||||
// Validate the input values
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\Type("OpenAPI\Server\Model\Pet");
|
||||
$asserts[] = new Assert\Valid();
|
||||
$response = $this->validate($pet, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
// Set authentication method 'petstore_auth'
|
||||
$handler->setpetstore_auth($securitypetstore_auth);
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 204;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->updatePet($pet, $responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = '';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 400:
|
||||
$message = 'Invalid ID supplied';
|
||||
break;
|
||||
case 404:
|
||||
$message = 'Pet not found';
|
||||
break;
|
||||
case 405:
|
||||
$message = 'Validation exception';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation updatePetWithForm
|
||||
*
|
||||
* Updates a pet in the store with form data
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function updatePetWithFormAction(Request $request, $petId)
|
||||
{
|
||||
// Handle authentication
|
||||
// Authentication 'petstore_auth' required
|
||||
// Oauth required
|
||||
$securitypetstore_auth = $request->headers->get('authorization');
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
$name = $request->request->get('name');
|
||||
$status = $request->request->get('status');
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Deserialize the input values that needs it
|
||||
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 = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\Type("int");
|
||||
$response = $this->validate($petId, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\Type("string");
|
||||
$response = $this->validate($name, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\Type("string");
|
||||
$response = $this->validate($status, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
// Set authentication method 'petstore_auth'
|
||||
$handler->setpetstore_auth($securitypetstore_auth);
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 204;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->updatePetWithForm($petId, $name, $status, $responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = '';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 405:
|
||||
$message = 'Invalid input';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation uploadFile
|
||||
*
|
||||
* uploads an image
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function uploadFileAction(Request $request, $petId)
|
||||
{
|
||||
// Figure out what data format to return to the client
|
||||
$produces = ['application/json'];
|
||||
// Figure out what the client accepts
|
||||
$clientAccepts = $request->headers->has('Accept')?$request->headers->get('Accept'):'*/*';
|
||||
$responseFormat = $this->getOutputFormat($clientAccepts, $produces);
|
||||
if ($responseFormat === null) {
|
||||
return new Response('', 406);
|
||||
}
|
||||
|
||||
// Handle authentication
|
||||
// Authentication 'petstore_auth' required
|
||||
// Oauth required
|
||||
$securitypetstore_auth = $request->headers->get('authorization');
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
$additionalMetadata = $request->request->get('additionalMetadata');
|
||||
$file = $request->files->get('file');
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Deserialize the input values that needs it
|
||||
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 = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\Type("int");
|
||||
$response = $this->validate($petId, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\Type("string");
|
||||
$response = $this->validate($additionalMetadata, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\File();
|
||||
$response = $this->validate($file, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
// Set authentication method 'petstore_auth'
|
||||
$handler->setpetstore_auth($securitypetstore_auth);
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 200;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->uploadFile($petId, $additionalMetadata, $file, $responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = 'successful operation';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 200:
|
||||
$message = 'successful operation';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
$result !== null ?$this->serialize($result, $responseFormat):'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'Content-Type' => $responseFormat,
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the handler for this API controller.
|
||||
* @return PetApiInterface
|
||||
*/
|
||||
public function getApiHandler()
|
||||
{
|
||||
return $this->apiServer->getApiHandler('pet');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,373 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* StoreController
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package OpenAPI\Server\Controller
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
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;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use OpenAPI\Server\Api\StoreApiInterface;
|
||||
use OpenAPI\Server\Model\Order;
|
||||
|
||||
/**
|
||||
* StoreController Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @package OpenAPI\Server\Controller
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class StoreController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Operation deleteOrder
|
||||
*
|
||||
* Delete purchase order by ID
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function deleteOrderAction(Request $request, $orderId)
|
||||
{
|
||||
// Handle authentication
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Deserialize the input values that needs it
|
||||
try {
|
||||
$orderId = $this->deserialize($orderId, 'string', 'string');
|
||||
} catch (SerializerRuntimeException $exception) {
|
||||
return $this->createBadRequestResponse($exception->getMessage());
|
||||
}
|
||||
|
||||
// Validate the input values
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\Type("string");
|
||||
$response = $this->validate($orderId, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 204;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->deleteOrder($orderId, $responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = '';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 400:
|
||||
$message = 'Invalid ID supplied';
|
||||
break;
|
||||
case 404:
|
||||
$message = 'Order not found';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation getInventory
|
||||
*
|
||||
* Returns pet inventories by status
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function getInventoryAction(Request $request)
|
||||
{
|
||||
// Figure out what data format to return to the client
|
||||
$produces = ['application/json'];
|
||||
// Figure out what the client accepts
|
||||
$clientAccepts = $request->headers->has('Accept')?$request->headers->get('Accept'):'*/*';
|
||||
$responseFormat = $this->getOutputFormat($clientAccepts, $produces);
|
||||
if ($responseFormat === null) {
|
||||
return new Response('', 406);
|
||||
}
|
||||
|
||||
// Handle authentication
|
||||
// Authentication 'api_key' required
|
||||
// Set key with prefix in header
|
||||
$securityapi_key = $request->headers->get('api_key');
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Validate the input values
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
// Set authentication method 'api_key'
|
||||
$handler->setapi_key($securityapi_key);
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 200;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->getInventory($responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = 'successful operation';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 200:
|
||||
$message = 'successful operation';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
$result !== null ?$this->serialize($result, $responseFormat):'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'Content-Type' => $responseFormat,
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation getOrderById
|
||||
*
|
||||
* Find purchase order by ID
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function getOrderByIdAction(Request $request, $orderId)
|
||||
{
|
||||
// Figure out what data format to return to the client
|
||||
$produces = ['application/xml', 'application/json'];
|
||||
// Figure out what the client accepts
|
||||
$clientAccepts = $request->headers->has('Accept')?$request->headers->get('Accept'):'*/*';
|
||||
$responseFormat = $this->getOutputFormat($clientAccepts, $produces);
|
||||
if ($responseFormat === null) {
|
||||
return new Response('', 406);
|
||||
}
|
||||
|
||||
// Handle authentication
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Deserialize the input values that needs it
|
||||
try {
|
||||
$orderId = $this->deserialize($orderId, 'int', 'string');
|
||||
} catch (SerializerRuntimeException $exception) {
|
||||
return $this->createBadRequestResponse($exception->getMessage());
|
||||
}
|
||||
|
||||
// Validate the input values
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\Type("int");
|
||||
$asserts[] = new Assert\GreaterThanOrEqual(1);
|
||||
$asserts[] = new Assert\LessThanOrEqual(1);
|
||||
$response = $this->validate($orderId, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 200;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->getOrderById($orderId, $responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = 'successful operation';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 200:
|
||||
$message = 'successful operation';
|
||||
break;
|
||||
case 400:
|
||||
$message = 'Invalid ID supplied';
|
||||
break;
|
||||
case 404:
|
||||
$message = 'Order not found';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
$result !== null ?$this->serialize($result, $responseFormat):'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'Content-Type' => $responseFormat,
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation placeOrder
|
||||
*
|
||||
* Place an order for a pet
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function placeOrderAction(Request $request)
|
||||
{
|
||||
// Make sure that the client is providing something that we can consume
|
||||
$consumes = ['application/json'];
|
||||
$inputFormat = $request->headers->has('Content-Type')?$request->headers->get('Content-Type'):$consumes[0];
|
||||
if (!in_array($inputFormat, $consumes)) {
|
||||
// We can't consume the content that the client is sending us
|
||||
return new Response('', 415);
|
||||
}
|
||||
|
||||
// Figure out what data format to return to the client
|
||||
$produces = ['application/xml', 'application/json'];
|
||||
// Figure out what the client accepts
|
||||
$clientAccepts = $request->headers->has('Accept')?$request->headers->get('Accept'):'*/*';
|
||||
$responseFormat = $this->getOutputFormat($clientAccepts, $produces);
|
||||
if ($responseFormat === null) {
|
||||
return new Response('', 406);
|
||||
}
|
||||
|
||||
// Handle authentication
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
$order = $request->getContent();
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Deserialize the input values that needs it
|
||||
try {
|
||||
$order = $this->deserialize($order, 'OpenAPI\Server\Model\Order', $inputFormat);
|
||||
} catch (SerializerRuntimeException $exception) {
|
||||
return $this->createBadRequestResponse($exception->getMessage());
|
||||
}
|
||||
|
||||
// Validate the input values
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\Type("OpenAPI\Server\Model\Order");
|
||||
$asserts[] = new Assert\Valid();
|
||||
$response = $this->validate($order, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 200;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->placeOrder($order, $responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = 'successful operation';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 200:
|
||||
$message = 'successful operation';
|
||||
break;
|
||||
case 400:
|
||||
$message = 'Invalid Order';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
$result !== null ?$this->serialize($result, $responseFormat):'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'Content-Type' => $responseFormat,
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the handler for this API controller.
|
||||
* @return StoreApiInterface
|
||||
*/
|
||||
public function getApiHandler()
|
||||
{
|
||||
return $this->apiServer->getApiHandler('store');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,710 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* UserController
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package OpenAPI\Server\Controller
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
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;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use OpenAPI\Server\Api\UserApiInterface;
|
||||
use OpenAPI\Server\Model\User;
|
||||
|
||||
/**
|
||||
* UserController Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @package OpenAPI\Server\Controller
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class UserController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Operation createUser
|
||||
*
|
||||
* Create user
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function createUserAction(Request $request)
|
||||
{
|
||||
// Make sure that the client is providing something that we can consume
|
||||
$consumes = ['application/json'];
|
||||
$inputFormat = $request->headers->has('Content-Type')?$request->headers->get('Content-Type'):$consumes[0];
|
||||
if (!in_array($inputFormat, $consumes)) {
|
||||
// We can't consume the content that the client is sending us
|
||||
return new Response('', 415);
|
||||
}
|
||||
|
||||
// Handle authentication
|
||||
// Authentication 'auth_cookie' required
|
||||
// Set key with prefix in cookies
|
||||
$securityauth_cookie = $request->cookies->get('AUTH_KEY');
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
$user = $request->getContent();
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Deserialize the input values that needs it
|
||||
try {
|
||||
$user = $this->deserialize($user, 'OpenAPI\Server\Model\User', $inputFormat);
|
||||
} catch (SerializerRuntimeException $exception) {
|
||||
return $this->createBadRequestResponse($exception->getMessage());
|
||||
}
|
||||
|
||||
// Validate the input values
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\Type("OpenAPI\Server\Model\User");
|
||||
$asserts[] = new Assert\Valid();
|
||||
$response = $this->validate($user, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
// Set authentication method 'auth_cookie'
|
||||
$handler->setauth_cookie($securityauth_cookie);
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 204;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->createUser($user, $responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = 'successful operation';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 0:
|
||||
$message = 'successful operation';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation createUsersWithArrayInput
|
||||
*
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function createUsersWithArrayInputAction(Request $request)
|
||||
{
|
||||
// Make sure that the client is providing something that we can consume
|
||||
$consumes = ['application/json'];
|
||||
$inputFormat = $request->headers->has('Content-Type')?$request->headers->get('Content-Type'):$consumes[0];
|
||||
if (!in_array($inputFormat, $consumes)) {
|
||||
// We can't consume the content that the client is sending us
|
||||
return new Response('', 415);
|
||||
}
|
||||
|
||||
// Handle authentication
|
||||
// Authentication 'auth_cookie' required
|
||||
// Set key with prefix in cookies
|
||||
$securityauth_cookie = $request->cookies->get('AUTH_KEY');
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
$user = $request->getContent();
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Deserialize the input values that needs it
|
||||
try {
|
||||
$user = $this->deserialize($user, 'array<OpenAPI\Server\Model\User>', $inputFormat);
|
||||
} catch (SerializerRuntimeException $exception) {
|
||||
return $this->createBadRequestResponse($exception->getMessage());
|
||||
}
|
||||
|
||||
// Validate the input values
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\All([
|
||||
new Assert\Type("OpenAPI\Server\Model\User"),
|
||||
new Assert\Valid(),
|
||||
]);
|
||||
$response = $this->validate($user, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
// Set authentication method 'auth_cookie'
|
||||
$handler->setauth_cookie($securityauth_cookie);
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 204;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->createUsersWithArrayInput($user, $responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = 'successful operation';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 0:
|
||||
$message = 'successful operation';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation createUsersWithListInput
|
||||
*
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function createUsersWithListInputAction(Request $request)
|
||||
{
|
||||
// Make sure that the client is providing something that we can consume
|
||||
$consumes = ['application/json'];
|
||||
$inputFormat = $request->headers->has('Content-Type')?$request->headers->get('Content-Type'):$consumes[0];
|
||||
if (!in_array($inputFormat, $consumes)) {
|
||||
// We can't consume the content that the client is sending us
|
||||
return new Response('', 415);
|
||||
}
|
||||
|
||||
// Handle authentication
|
||||
// Authentication 'auth_cookie' required
|
||||
// Set key with prefix in cookies
|
||||
$securityauth_cookie = $request->cookies->get('AUTH_KEY');
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
$user = $request->getContent();
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Deserialize the input values that needs it
|
||||
try {
|
||||
$user = $this->deserialize($user, 'array<OpenAPI\Server\Model\User>', $inputFormat);
|
||||
} catch (SerializerRuntimeException $exception) {
|
||||
return $this->createBadRequestResponse($exception->getMessage());
|
||||
}
|
||||
|
||||
// Validate the input values
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\All([
|
||||
new Assert\Type("OpenAPI\Server\Model\User"),
|
||||
new Assert\Valid(),
|
||||
]);
|
||||
$response = $this->validate($user, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
// Set authentication method 'auth_cookie'
|
||||
$handler->setauth_cookie($securityauth_cookie);
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 204;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->createUsersWithListInput($user, $responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = 'successful operation';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 0:
|
||||
$message = 'successful operation';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation deleteUser
|
||||
*
|
||||
* Delete user
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function deleteUserAction(Request $request, $username)
|
||||
{
|
||||
// Handle authentication
|
||||
// Authentication 'auth_cookie' required
|
||||
// Set key with prefix in cookies
|
||||
$securityauth_cookie = $request->cookies->get('AUTH_KEY');
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Deserialize the input values that needs it
|
||||
try {
|
||||
$username = $this->deserialize($username, 'string', 'string');
|
||||
} catch (SerializerRuntimeException $exception) {
|
||||
return $this->createBadRequestResponse($exception->getMessage());
|
||||
}
|
||||
|
||||
// Validate the input values
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\Type("string");
|
||||
$response = $this->validate($username, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
// Set authentication method 'auth_cookie'
|
||||
$handler->setauth_cookie($securityauth_cookie);
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 204;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->deleteUser($username, $responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = '';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 400:
|
||||
$message = 'Invalid username supplied';
|
||||
break;
|
||||
case 404:
|
||||
$message = 'User not found';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation getUserByName
|
||||
*
|
||||
* Get user by user name
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function getUserByNameAction(Request $request, $username)
|
||||
{
|
||||
// Figure out what data format to return to the client
|
||||
$produces = ['application/xml', 'application/json'];
|
||||
// Figure out what the client accepts
|
||||
$clientAccepts = $request->headers->has('Accept')?$request->headers->get('Accept'):'*/*';
|
||||
$responseFormat = $this->getOutputFormat($clientAccepts, $produces);
|
||||
if ($responseFormat === null) {
|
||||
return new Response('', 406);
|
||||
}
|
||||
|
||||
// Handle authentication
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Deserialize the input values that needs it
|
||||
try {
|
||||
$username = $this->deserialize($username, 'string', 'string');
|
||||
} catch (SerializerRuntimeException $exception) {
|
||||
return $this->createBadRequestResponse($exception->getMessage());
|
||||
}
|
||||
|
||||
// Validate the input values
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\Type("string");
|
||||
$response = $this->validate($username, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 200;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->getUserByName($username, $responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = 'successful operation';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 200:
|
||||
$message = 'successful operation';
|
||||
break;
|
||||
case 400:
|
||||
$message = 'Invalid username supplied';
|
||||
break;
|
||||
case 404:
|
||||
$message = 'User not found';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
$result !== null ?$this->serialize($result, $responseFormat):'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'Content-Type' => $responseFormat,
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation loginUser
|
||||
*
|
||||
* Logs user into the system
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function loginUserAction(Request $request)
|
||||
{
|
||||
// Figure out what data format to return to the client
|
||||
$produces = ['application/xml', 'application/json'];
|
||||
// Figure out what the client accepts
|
||||
$clientAccepts = $request->headers->has('Accept')?$request->headers->get('Accept'):'*/*';
|
||||
$responseFormat = $this->getOutputFormat($clientAccepts, $produces);
|
||||
if ($responseFormat === null) {
|
||||
return new Response('', 406);
|
||||
}
|
||||
|
||||
// Handle authentication
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
$username = $request->query->get('username');
|
||||
$password = $request->query->get('password');
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Deserialize the input values that needs it
|
||||
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 = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\Type("string");
|
||||
$asserts[] = new Assert\Regex("/^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/");
|
||||
$response = $this->validate($username, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\Type("string");
|
||||
$response = $this->validate($password, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 200;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->loginUser($username, $password, $responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = 'successful operation';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 200:
|
||||
$message = 'successful operation';
|
||||
break;
|
||||
case 400:
|
||||
$message = 'Invalid username/password supplied';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
$result !== null ?$this->serialize($result, $responseFormat):'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'Content-Type' => $responseFormat,
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation logoutUser
|
||||
*
|
||||
* Logs out current logged in user session
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function logoutUserAction(Request $request)
|
||||
{
|
||||
// Handle authentication
|
||||
// Authentication 'auth_cookie' required
|
||||
// Set key with prefix in cookies
|
||||
$securityauth_cookie = $request->cookies->get('AUTH_KEY');
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Validate the input values
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
// Set authentication method 'auth_cookie'
|
||||
$handler->setauth_cookie($securityauth_cookie);
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 204;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->logoutUser($responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = 'successful operation';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 0:
|
||||
$message = 'successful operation';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation updateUser
|
||||
*
|
||||
* Updated user
|
||||
*
|
||||
* @param Request $request The Symfony request to handle.
|
||||
* @return Response The Symfony response.
|
||||
*/
|
||||
public function updateUserAction(Request $request, $username)
|
||||
{
|
||||
// Make sure that the client is providing something that we can consume
|
||||
$consumes = ['application/json'];
|
||||
$inputFormat = $request->headers->has('Content-Type')?$request->headers->get('Content-Type'):$consumes[0];
|
||||
if (!in_array($inputFormat, $consumes)) {
|
||||
// We can't consume the content that the client is sending us
|
||||
return new Response('', 415);
|
||||
}
|
||||
|
||||
// Handle authentication
|
||||
// Authentication 'auth_cookie' required
|
||||
// Set key with prefix in cookies
|
||||
$securityauth_cookie = $request->cookies->get('AUTH_KEY');
|
||||
|
||||
// Read out all input parameter values into variables
|
||||
$user = $request->getContent();
|
||||
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// Deserialize the input values that needs it
|
||||
try {
|
||||
$username = $this->deserialize($username, 'string', 'string');
|
||||
$user = $this->deserialize($user, 'OpenAPI\Server\Model\User', $inputFormat);
|
||||
} catch (SerializerRuntimeException $exception) {
|
||||
return $this->createBadRequestResponse($exception->getMessage());
|
||||
}
|
||||
|
||||
// Validate the input values
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\Type("string");
|
||||
$response = $this->validate($username, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
$asserts = [];
|
||||
$asserts[] = new Assert\NotNull();
|
||||
$asserts[] = new Assert\Type("OpenAPI\Server\Model\User");
|
||||
$asserts[] = new Assert\Valid();
|
||||
$response = $this->validate($user, $asserts);
|
||||
if ($response instanceof Response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$handler = $this->getApiHandler();
|
||||
|
||||
// Set authentication method 'auth_cookie'
|
||||
$handler->setauth_cookie($securityauth_cookie);
|
||||
|
||||
// Make the call to the business logic
|
||||
$responseCode = 204;
|
||||
$responseHeaders = [];
|
||||
$result = $handler->updateUser($username, $user, $responseCode, $responseHeaders);
|
||||
|
||||
// Find default response message
|
||||
$message = '';
|
||||
|
||||
// Find a more specific message, if available
|
||||
switch ($responseCode) {
|
||||
case 400:
|
||||
$message = 'Invalid user supplied';
|
||||
break;
|
||||
case 404:
|
||||
$message = 'User not found';
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
'',
|
||||
$responseCode,
|
||||
array_merge(
|
||||
$responseHeaders,
|
||||
[
|
||||
'X-OpenAPI-Message' => $message
|
||||
]
|
||||
)
|
||||
);
|
||||
} catch (Exception $fallthrough) {
|
||||
return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the handler for this API controller.
|
||||
* @return UserApiInterface
|
||||
*/
|
||||
public function getApiHandler()
|
||||
{
|
||||
return $this->apiServer->getApiHandler('user');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user