forked from loafle/openapi-generator-original
* Set PHP 7.1.3 required version I've tried to specify ^7.0 version at first, but main package which is symfony/framework-bundle@v4.4.8 requires PHP ^7.1.3. * Bump Symfony FrameworkBundle to ^4.4.8 Current Symfony Framework stable version is v5.0.8, but I guess it requires significant codebase upgrade, so I've sticked with 4.4.8 which shouldn't cause any breaking changes. Old requirement was ^3.3|^4.1 which compatible with 4.4.8. * Bump PHPUnit version to ^7.0 PHPUnit 8.x version required PHP ^7.2, so I'm setting 7.x version to support PHP 7.1. There is new way to specify Kernel class, related PR: https://github.com/symfony/symfony/pull/22668 * Bump PHP CS Fixer version to ^2.16.3 Configuration and all renamed rules fixed. Config file renamed to .php_cs.dist as recommended in migration guide. Migration guide from 1.x to 2.x: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/UPGRADE.md#config-file * Remove PHP_CodeSniffer package Second linter doesn't make sense. I think Symfony user would prefer PHP CS Fixer over PHP_CodeSniffer because first one maintained by Symfony members. * Remove satooshi/php-coveralls package from Composer This package is abandoned and Coveralls recommends to install it directly in Travis-CI task script. * Update Travic-CI config I've changed test versions to PHP 7.1.3 and 7.2. PHPUnit generates coverage report in report/logs/clover.xml file. Then PHP CS Fixer runs with --dry-run option to not override anything just to show coding style errors. * Add basic Coveralls config This is basic recommended config for a PHP based project. * Add symfony/yaml package This package was part of satooshi/php-coveralls, now it should be defined as dev dependency. * Do not commit composer.lock I think committed composer.lock can cause CI errors while tests on fresh installs are better. * Remove confusing Ruby comment
680 lines
22 KiB
PHP
680 lines
22 KiB
PHP
<?php
|
|
|
|
/**
|
|
* UserController
|
|
* PHP version 7.1.3
|
|
*
|
|
* @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 = [];
|
|
if (!static::isContentTypeAllowed($request, $consumes)) {
|
|
// We can't consume the content that the client is sending us
|
|
return new Response('', 415);
|
|
}
|
|
|
|
// Handle authentication
|
|
|
|
// Read out all input parameter values into variables
|
|
$body = $request->getContent();
|
|
|
|
// Use the default value if no value was provided
|
|
|
|
// Deserialize the input values that needs it
|
|
try {
|
|
$inputFormat = $request->getMimeType($request->getContentType());
|
|
$body = $this->deserialize($body, '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($body, $asserts);
|
|
if ($response instanceof Response) {
|
|
return $response;
|
|
}
|
|
|
|
|
|
try {
|
|
$handler = $this->getApiHandler();
|
|
|
|
|
|
// Make the call to the business logic
|
|
$responseCode = 204;
|
|
$responseHeaders = [];
|
|
$result = $handler->createUser($body, $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 = [];
|
|
if (!static::isContentTypeAllowed($request, $consumes)) {
|
|
// We can't consume the content that the client is sending us
|
|
return new Response('', 415);
|
|
}
|
|
|
|
// Handle authentication
|
|
|
|
// Read out all input parameter values into variables
|
|
$body = $request->getContent();
|
|
|
|
// Use the default value if no value was provided
|
|
|
|
// Deserialize the input values that needs it
|
|
try {
|
|
$inputFormat = $request->getMimeType($request->getContentType());
|
|
$body = $this->deserialize($body, '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($body, $asserts);
|
|
if ($response instanceof Response) {
|
|
return $response;
|
|
}
|
|
|
|
|
|
try {
|
|
$handler = $this->getApiHandler();
|
|
|
|
|
|
// Make the call to the business logic
|
|
$responseCode = 204;
|
|
$responseHeaders = [];
|
|
$result = $handler->createUsersWithArrayInput($body, $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 = [];
|
|
if (!static::isContentTypeAllowed($request, $consumes)) {
|
|
// We can't consume the content that the client is sending us
|
|
return new Response('', 415);
|
|
}
|
|
|
|
// Handle authentication
|
|
|
|
// Read out all input parameter values into variables
|
|
$body = $request->getContent();
|
|
|
|
// Use the default value if no value was provided
|
|
|
|
// Deserialize the input values that needs it
|
|
try {
|
|
$inputFormat = $request->getMimeType($request->getContentType());
|
|
$body = $this->deserialize($body, '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($body, $asserts);
|
|
if ($response instanceof Response) {
|
|
return $response;
|
|
}
|
|
|
|
|
|
try {
|
|
$handler = $this->getApiHandler();
|
|
|
|
|
|
// Make the call to the business logic
|
|
$responseCode = 204;
|
|
$responseHeaders = [];
|
|
$result = $handler->createUsersWithListInput($body, $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
|
|
|
|
// 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 = 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");
|
|
$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
|
|
|
|
// 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();
|
|
|
|
|
|
// 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 = [];
|
|
if (!static::isContentTypeAllowed($request, $consumes)) {
|
|
// We can't consume the content that the client is sending us
|
|
return new Response('', 415);
|
|
}
|
|
|
|
// Handle authentication
|
|
|
|
// Read out all input parameter values into variables
|
|
$body = $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');
|
|
$inputFormat = $request->getMimeType($request->getContentType());
|
|
$body = $this->deserialize($body, '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($body, $asserts);
|
|
if ($response instanceof Response) {
|
|
return $response;
|
|
}
|
|
|
|
|
|
try {
|
|
$handler = $this->getApiHandler();
|
|
|
|
|
|
// Make the call to the business logic
|
|
$responseCode = 204;
|
|
$responseHeaders = [];
|
|
$result = $handler->updateUser($username, $body, $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');
|
|
}
|
|
}
|