From ed82aaae978f158b1b6c6b7cb52d3d0ac40f7b36 Mon Sep 17 00:00:00 2001 From: Ivan Aksamentov <9403403+ivan-aksamentov@users.noreply.github.com> Date: Fri, 2 Aug 2019 00:55:58 +0200 Subject: [PATCH] Fix PHP Symfony OpenAPI 3 sample location. Fixes #3531 (#3532) * Fix PHP Symfony OpenAPI 3.0 sample location * Update PHP Symfony OpenAPI 3.0 sample --- bin/openapi3/php-symfony-petstore.sh | 2 +- .../php-symfony/SymfonyBundle-php/.gitignore | 54 ++ .../.openapi-generator-ignore | 23 + .../.openapi-generator/VERSION | 1 + .../php-symfony/SymfonyBundle-php/.php_cs | 18 + .../php-symfony/SymfonyBundle-php/.travis.yml | 10 + .../SymfonyBundle-php/Api/ApiServer.php | 80 ++ .../SymfonyBundle-php/Api/PetApiInterface.php | 190 +++++ .../Api/StoreApiInterface.php | 108 +++ .../Api/UserApiInterface.php | 166 ++++ .../Controller/Controller.php | 189 +++++ .../Controller/PetController.php | 771 ++++++++++++++++++ .../Controller/StoreController.php | 373 +++++++++ .../Controller/UserController.php | 710 ++++++++++++++++ .../Compiler/OpenAPIServerApiPass.php | 70 ++ .../OpenAPIServerExtension.php | 57 ++ .../SymfonyBundle-php/Model/ApiResponse.php | 154 ++++ .../SymfonyBundle-php/Model/Category.php | 122 +++ .../SymfonyBundle-php/Model/InlineObject.php | 123 +++ .../SymfonyBundle-php/Model/InlineObject1.php | 123 +++ .../SymfonyBundle-php/Model/Order.php | 256 ++++++ .../SymfonyBundle-php/Model/Pet.php | 262 ++++++ .../SymfonyBundle-php/Model/Tag.php | 121 +++ .../SymfonyBundle-php/Model/User.php | 321 ++++++++ .../SymfonyBundle-php/OpenAPIServerBundle.php | 50 ++ .../php-symfony/SymfonyBundle-php/README.md | 190 +++++ .../Resources/config/routing.yml | 145 ++++ .../Resources/config/services.yml | 50 ++ .../Resources/docs/Api/PetApiInterface.md | 520 ++++++++++++ .../Resources/docs/Api/StoreApiInterface.md | 243 ++++++ .../Resources/docs/Api/UserApiInterface.md | 497 +++++++++++ .../Resources/docs/Model/ApiResponse.md | 12 + .../Resources/docs/Model/Category.md | 11 + .../Resources/docs/Model/InlineObject.md | 11 + .../Resources/docs/Model/InlineObject1.md | 11 + .../Resources/docs/Model/Order.md | 15 + .../Resources/docs/Model/Pet.md | 15 + .../Resources/docs/Model/Tag.md | 11 + .../Resources/docs/Model/User.md | 17 + .../Service/JmsSerializer.php | 115 +++ .../Service/SerializerInterface.php | 27 + .../StrictJsonDeserializationVisitor.php | 72 ++ .../Service/SymfonyValidator.php | 20 + .../Service/TypeMismatchException.php | 52 ++ .../Service/ValidatorInterface.php | 25 + .../Tests/Api/PetApiInterfaceTest.php | 217 +++++ .../Tests/Api/StoreApiInterfaceTest.php | 151 ++++ .../Tests/Api/UserApiInterfaceTest.php | 214 +++++ .../SymfonyBundle-php/Tests/AppKernel.php | 21 + .../Tests/Model/ApiResponseTest.php | 101 +++ .../Tests/Model/CategoryTest.php | 94 +++ .../Tests/Model/InlineObject1Test.php | 94 +++ .../Tests/Model/InlineObjectTest.php | 94 +++ .../Tests/Model/OrderTest.php | 122 +++ .../SymfonyBundle-php/Tests/Model/PetTest.php | 122 +++ .../SymfonyBundle-php/Tests/Model/TagTest.php | 94 +++ .../Tests/Model/UserTest.php | 136 +++ .../SymfonyBundle-php/Tests/test_config.yml | 8 + .../SymfonyBundle-php/autoload.php | 54 ++ .../SymfonyBundle-php/composer.json | 38 + .../php-symfony/SymfonyBundle-php/git_push.sh | 52 ++ .../SymfonyBundle-php/phpunit.xml.dist | 24 + .../php-symfony/SymfonyBundle-php/pom.xml | 57 ++ 63 files changed, 8105 insertions(+), 1 deletion(-) create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.gitignore create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.openapi-generator-ignore create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.openapi-generator/VERSION create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.php_cs create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.travis.yml create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Api/ApiServer.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Api/StoreApiInterface.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Api/UserApiInterface.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Controller/Controller.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/DependencyInjection/Compiler/OpenAPIServerApiPass.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/DependencyInjection/OpenAPIServerExtension.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/InlineObject.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/InlineObject1.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/OpenAPIServerBundle.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/README.md create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/routing.yml create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/services.yml create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/ApiResponse.md create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Category.md create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/InlineObject.md create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/InlineObject1.md create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Order.md create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Pet.md create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Tag.md create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/User.md create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Service/SerializerInterface.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitor.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Service/SymfonyValidator.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Service/TypeMismatchException.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Service/ValidatorInterface.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/StoreApiInterfaceTest.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/UserApiInterfaceTest.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/AppKernel.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/ApiResponseTest.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/CategoryTest.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/InlineObject1Test.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/InlineObjectTest.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/OrderTest.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/PetTest.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/TagTest.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/UserTest.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/test_config.yml create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/autoload.php create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/composer.json create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/git_push.sh create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/phpunit.xml.dist create mode 100644 samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/pom.xml diff --git a/bin/openapi3/php-symfony-petstore.sh b/bin/openapi3/php-symfony-petstore.sh index 8e59eea2d40..8c6ce35bd0b 100755 --- a/bin/openapi3/php-symfony-petstore.sh +++ b/bin/openapi3/php-symfony-petstore.sh @@ -23,7 +23,7 @@ if [ ! -d "${APP_DIR}" ]; then fi # Make sure that we are regenerating the sample by removing any existing target directory -TARGET_DIR="$SCRIPT_DIR/../../samples/server/petstore/php-symfony/SymfonyBundle-php" +TARGET_DIR="$SCRIPT_DIR/../../samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php" if [ -d "$TARGET_DIR" ]; then rm -rf $TARGET_DIR fi diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.gitignore b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.gitignore new file mode 100644 index 00000000000..20b7b989760 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.gitignore @@ -0,0 +1,54 @@ +# ref: https://github.com/github/gitignore/blob/master/Symfony.gitignore + +# Cache and logs (Symfony2) +/app/cache/* +/app/logs/* +!app/cache/.gitkeep +!app/logs/.gitkeep + +# Email spool folder +/app/spool/* + +# Cache, session files and logs (Symfony3) +/var/cache/* +/var/logs/* +/var/sessions/* +!var/cache/.gitkeep +!var/logs/.gitkeep +!var/sessions/.gitkeep + +# Parameters +/app/config/parameters.yml +/app/config/parameters.ini + +# Managed by Composer +/app/bootstrap.php.cache +/var/bootstrap.php.cache +/bin/* +!bin/console +!bin/symfony_requirements +/vendor/ + +# Assets and user uploads +/web/bundles/ +/web/uploads/ + +# PHPUnit +/app/phpunit.xml +/phpunit.xml + +# Build data +/build/ + +# Composer PHAR +/composer.phar + +# Backup entities generated with doctrine:generate:entities command +**/Entity/*~ + +# Embedded web-server pid file +/.web-server-pid + +# From root gitignore +/Tests/cache/ +/Tests/logs/ \ No newline at end of file diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.openapi-generator-ignore b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.openapi-generator/VERSION b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.openapi-generator/VERSION new file mode 100644 index 00000000000..83a328a9227 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.openapi-generator/VERSION @@ -0,0 +1 @@ +4.1.0-SNAPSHOT \ No newline at end of file diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.php_cs b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.php_cs new file mode 100644 index 00000000000..6b8e23c818a --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.php_cs @@ -0,0 +1,18 @@ +level(Symfony\CS\FixerInterface::PSR2_LEVEL) + ->setUsingCache(true) + ->fixers( + [ + 'ordered_use', + 'phpdoc_order', + 'short_array_syntax', + 'strict', + 'strict_param' + ] + ) + ->finder( + Symfony\CS\Finder\DefaultFinder::create() + ->in(__DIR__) + ); diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.travis.yml b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.travis.yml new file mode 100644 index 00000000000..d77f3825f6f --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/.travis.yml @@ -0,0 +1,10 @@ +language: php +sudo: false +php: + - 5.4 + - 5.5 + - 5.6 + - 7.0 + - hhvm +before_install: "composer install" +script: "vendor/bin/phpunit" diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Api/ApiServer.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Api/ApiServer.php new file mode 100644 index 00000000000..f57c47b342c --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Api/ApiServer.php @@ -0,0 +1,80 @@ +apis[$api])) { + throw new \InvalidArgumentException('API has already a handler: '.$api); + } + + $this->apis[$api] = $handler; + } + + /** + * Returns an API handler. + * + * @param string $api An API name of the handle + * @return mixed Returns a handler + * @throws \InvalidArgumentException When no such handler exists + */ + public function getApiHandler($api) + { + if (!isset($this->apis[$api])) { + throw new \InvalidArgumentException('No handler for '.$api.' implemented.'); + } + + return $this->apis[$api]; + } +} diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php new file mode 100644 index 00000000000..ed2514bff96 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php @@ -0,0 +1,190 @@ +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; + } +} diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php new file mode 100644 index 00000000000..c1189b0fd49 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php @@ -0,0 +1,771 @@ +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', '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', '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'); + } +} diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php new file mode 100644 index 00000000000..bb80ccb66d5 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php @@ -0,0 +1,373 @@ +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'); + } +} diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php new file mode 100644 index 00000000000..736c755ded2 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php @@ -0,0 +1,710 @@ +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', $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', $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'); + } +} diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/DependencyInjection/Compiler/OpenAPIServerApiPass.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/DependencyInjection/Compiler/OpenAPIServerApiPass.php new file mode 100644 index 00000000000..62d9bb86716 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/DependencyInjection/Compiler/OpenAPIServerApiPass.php @@ -0,0 +1,70 @@ +has('open_api_server.api.api_server')) { + return; + } + + $definition = $container->findDefinition('open_api_server.api.api_server'); + + // find all service IDs with the open_api_server.api tag + $taggedServices = $container->findTaggedServiceIds('open_api_server.api'); + + foreach ($taggedServices as $id => $tags) { + foreach ($tags as $tag) { + // add the transport service to the ChainTransport service + $definition->addMethodCall('addApiHandler', [$tag['api'], new Reference($id)]); + } + } + } +} diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/DependencyInjection/OpenAPIServerExtension.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/DependencyInjection/OpenAPIServerExtension.php new file mode 100644 index 00000000000..ca829865f97 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/DependencyInjection/OpenAPIServerExtension.php @@ -0,0 +1,57 @@ +load('services.yml'); + } + + public function getAlias() + { + return 'open_api_server'; + } +} diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php new file mode 100644 index 00000000000..3c541cc76f9 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php @@ -0,0 +1,154 @@ +code = isset($data['code']) ? $data['code'] : null; + $this->type = isset($data['type']) ? $data['type'] : null; + $this->message = isset($data['message']) ? $data['message'] : null; + } + + /** + * Gets code. + * + * @return int|null + */ + public function getCode() + { + return $this->code; + } + + /** + * Sets code. + * + * @param int|null $code + * + * @return $this + */ + public function setCode($code = null) + { + $this->code = $code; + + return $this; + } + + /** + * Gets type. + * + * @return string|null + */ + public function getType() + { + return $this->type; + } + + /** + * Sets type. + * + * @param string|null $type + * + * @return $this + */ + public function setType($type = null) + { + $this->type = $type; + + return $this; + } + + /** + * Gets message. + * + * @return string|null + */ + public function getMessage() + { + return $this->message; + } + + /** + * Sets message. + * + * @param string|null $message + * + * @return $this + */ + public function setMessage($message = null) + { + $this->message = $message; + + return $this; + } +} + + diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php new file mode 100644 index 00000000000..cbaceb8d16e --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php @@ -0,0 +1,122 @@ +id = isset($data['id']) ? $data['id'] : null; + $this->name = isset($data['name']) ? $data['name'] : null; + } + + /** + * Gets id. + * + * @return int|null + */ + public function getId() + { + return $this->id; + } + + /** + * Sets id. + * + * @param int|null $id + * + * @return $this + */ + public function setId($id = null) + { + $this->id = $id; + + return $this; + } + + /** + * Gets name. + * + * @return string|null + */ + public function getName() + { + return $this->name; + } + + /** + * Sets name. + * + * @param string|null $name + * + * @return $this + */ + public function setName($name = null) + { + $this->name = $name; + + return $this; + } +} + + diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/InlineObject.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/InlineObject.php new file mode 100644 index 00000000000..3f5e8ff7339 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/InlineObject.php @@ -0,0 +1,123 @@ +name = isset($data['name']) ? $data['name'] : null; + $this->status = isset($data['status']) ? $data['status'] : null; + } + + /** + * Gets name. + * + * @return string|null + */ + public function getName() + { + return $this->name; + } + + /** + * Sets name. + * + * @param string|null $name Updated name of the pet + * + * @return $this + */ + public function setName($name = null) + { + $this->name = $name; + + return $this; + } + + /** + * Gets status. + * + * @return string|null + */ + public function getStatus() + { + return $this->status; + } + + /** + * Sets status. + * + * @param string|null $status Updated status of the pet + * + * @return $this + */ + public function setStatus($status = null) + { + $this->status = $status; + + return $this; + } +} + + diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/InlineObject1.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/InlineObject1.php new file mode 100644 index 00000000000..577331c4675 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/InlineObject1.php @@ -0,0 +1,123 @@ +additionalMetadata = isset($data['additionalMetadata']) ? $data['additionalMetadata'] : null; + $this->file = isset($data['file']) ? $data['file'] : null; + } + + /** + * Gets additionalMetadata. + * + * @return string|null + */ + public function getAdditionalMetadata() + { + return $this->additionalMetadata; + } + + /** + * Sets additionalMetadata. + * + * @param string|null $additionalMetadata Additional data to pass to server + * + * @return $this + */ + public function setAdditionalMetadata($additionalMetadata = null) + { + $this->additionalMetadata = $additionalMetadata; + + return $this; + } + + /** + * Gets file. + * + * @return UploadedFile|null + */ + public function getFile() + { + return $this->file; + } + + /** + * Sets file. + * + * @param UploadedFile|null $file file to upload + * + * @return $this + */ + public function setFile(UploadedFile $file = null) + { + $this->file = $file; + + return $this; + } +} + + diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php new file mode 100644 index 00000000000..2f8ecf8c140 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php @@ -0,0 +1,256 @@ +id = isset($data['id']) ? $data['id'] : null; + $this->petId = isset($data['petId']) ? $data['petId'] : null; + $this->quantity = isset($data['quantity']) ? $data['quantity'] : null; + $this->shipDate = isset($data['shipDate']) ? $data['shipDate'] : null; + $this->status = isset($data['status']) ? $data['status'] : null; + $this->complete = isset($data['complete']) ? $data['complete'] : false; + } + + /** + * Gets id. + * + * @return int|null + */ + public function getId() + { + return $this->id; + } + + /** + * Sets id. + * + * @param int|null $id + * + * @return $this + */ + public function setId($id = null) + { + $this->id = $id; + + return $this; + } + + /** + * Gets petId. + * + * @return int|null + */ + public function getPetId() + { + return $this->petId; + } + + /** + * Sets petId. + * + * @param int|null $petId + * + * @return $this + */ + public function setPetId($petId = null) + { + $this->petId = $petId; + + return $this; + } + + /** + * Gets quantity. + * + * @return int|null + */ + public function getQuantity() + { + return $this->quantity; + } + + /** + * Sets quantity. + * + * @param int|null $quantity + * + * @return $this + */ + public function setQuantity($quantity = null) + { + $this->quantity = $quantity; + + return $this; + } + + /** + * Gets shipDate. + * + * @return \DateTime|null + */ + public function getShipDate() + { + return $this->shipDate; + } + + /** + * Sets shipDate. + * + * @param \DateTime|null $shipDate + * + * @return $this + */ + public function setShipDate(\DateTime $shipDate = null) + { + $this->shipDate = $shipDate; + + return $this; + } + + /** + * Gets status. + * + * @return string|null + */ + public function getStatus() + { + return $this->status; + } + + /** + * Sets status. + * + * @param string|null $status Order Status + * + * @return $this + */ + public function setStatus($status = null) + { + $this->status = $status; + + return $this; + } + + /** + * Gets complete. + * + * @return bool|null + */ + public function isComplete() + { + return $this->complete; + } + + /** + * Sets complete. + * + * @param bool|null $complete + * + * @return $this + */ + public function setComplete($complete = null) + { + $this->complete = $complete; + + return $this; + } +} + + diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php new file mode 100644 index 00000000000..7c627be0439 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php @@ -0,0 +1,262 @@ +") + */ + protected $photoUrls; + + /** + * @var OpenAPI\Server\Model\Tag[]|null + * @SerializedName("tags") + * @Assert\All({ + * @Assert\Type("OpenAPI\Server\Model\Tag") + * }) + * @Type("array") + */ + protected $tags; + + /** + * pet status in the store + * + * @var string|null + * @SerializedName("status") + * @Assert\Choice({ "available", "pending", "sold" }) + * @Assert\Type("string") + * @Type("string") + */ + protected $status; + + /** + * Constructor + * @param mixed[] $data Associated array of property values initializing the model + */ + public function __construct(array $data = null) + { + $this->id = isset($data['id']) ? $data['id'] : null; + $this->category = isset($data['category']) ? $data['category'] : null; + $this->name = isset($data['name']) ? $data['name'] : null; + $this->photoUrls = isset($data['photoUrls']) ? $data['photoUrls'] : null; + $this->tags = isset($data['tags']) ? $data['tags'] : null; + $this->status = isset($data['status']) ? $data['status'] : null; + } + + /** + * Gets id. + * + * @return int|null + */ + public function getId() + { + return $this->id; + } + + /** + * Sets id. + * + * @param int|null $id + * + * @return $this + */ + public function setId($id = null) + { + $this->id = $id; + + return $this; + } + + /** + * Gets category. + * + * @return OpenAPI\Server\Model\Category|null + */ + public function getCategory() + { + return $this->category; + } + + /** + * Sets category. + * + * @param OpenAPI\Server\Model\Category|null $category + * + * @return $this + */ + public function setCategory(Category $category = null) + { + $this->category = $category; + + return $this; + } + + /** + * Gets name. + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Sets name. + * + * @param string $name + * + * @return $this + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Gets photoUrls. + * + * @return string[] + */ + public function getPhotoUrls() + { + return $this->photoUrls; + } + + /** + * Sets photoUrls. + * + * @param string[] $photoUrls + * + * @return $this + */ + public function setPhotoUrls(array $photoUrls) + { + $this->photoUrls = $photoUrls; + + return $this; + } + + /** + * Gets tags. + * + * @return OpenAPI\Server\Model\Tag[]|null + */ + public function getTags() + { + return $this->tags; + } + + /** + * Sets tags. + * + * @param OpenAPI\Server\Model\Tag[]|null $tags + * + * @return $this + */ + public function setTags(array $tags = null) + { + $this->tags = $tags; + + return $this; + } + + /** + * Gets status. + * + * @return string|null + */ + public function getStatus() + { + return $this->status; + } + + /** + * Sets status. + * + * @param string|null $status pet status in the store + * + * @return $this + */ + public function setStatus($status = null) + { + $this->status = $status; + + return $this; + } +} + + diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php new file mode 100644 index 00000000000..404309c8261 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php @@ -0,0 +1,121 @@ +id = isset($data['id']) ? $data['id'] : null; + $this->name = isset($data['name']) ? $data['name'] : null; + } + + /** + * Gets id. + * + * @return int|null + */ + public function getId() + { + return $this->id; + } + + /** + * Sets id. + * + * @param int|null $id + * + * @return $this + */ + public function setId($id = null) + { + $this->id = $id; + + return $this; + } + + /** + * Gets name. + * + * @return string|null + */ + public function getName() + { + return $this->name; + } + + /** + * Sets name. + * + * @param string|null $name + * + * @return $this + */ + public function setName($name = null) + { + $this->name = $name; + + return $this; + } +} + + diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php new file mode 100644 index 00000000000..b79d83bf0c2 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php @@ -0,0 +1,321 @@ +id = isset($data['id']) ? $data['id'] : null; + $this->username = isset($data['username']) ? $data['username'] : null; + $this->firstName = isset($data['firstName']) ? $data['firstName'] : null; + $this->lastName = isset($data['lastName']) ? $data['lastName'] : null; + $this->email = isset($data['email']) ? $data['email'] : null; + $this->password = isset($data['password']) ? $data['password'] : null; + $this->phone = isset($data['phone']) ? $data['phone'] : null; + $this->userStatus = isset($data['userStatus']) ? $data['userStatus'] : null; + } + + /** + * Gets id. + * + * @return int|null + */ + public function getId() + { + return $this->id; + } + + /** + * Sets id. + * + * @param int|null $id + * + * @return $this + */ + public function setId($id = null) + { + $this->id = $id; + + return $this; + } + + /** + * Gets username. + * + * @return string|null + */ + public function getUsername() + { + return $this->username; + } + + /** + * Sets username. + * + * @param string|null $username + * + * @return $this + */ + public function setUsername($username = null) + { + $this->username = $username; + + return $this; + } + + /** + * Gets firstName. + * + * @return string|null + */ + public function getFirstName() + { + return $this->firstName; + } + + /** + * Sets firstName. + * + * @param string|null $firstName + * + * @return $this + */ + public function setFirstName($firstName = null) + { + $this->firstName = $firstName; + + return $this; + } + + /** + * Gets lastName. + * + * @return string|null + */ + public function getLastName() + { + return $this->lastName; + } + + /** + * Sets lastName. + * + * @param string|null $lastName + * + * @return $this + */ + public function setLastName($lastName = null) + { + $this->lastName = $lastName; + + return $this; + } + + /** + * Gets email. + * + * @return string|null + */ + public function getEmail() + { + return $this->email; + } + + /** + * Sets email. + * + * @param string|null $email + * + * @return $this + */ + public function setEmail($email = null) + { + $this->email = $email; + + return $this; + } + + /** + * Gets password. + * + * @return string|null + */ + public function getPassword() + { + return $this->password; + } + + /** + * Sets password. + * + * @param string|null $password + * + * @return $this + */ + public function setPassword($password = null) + { + $this->password = $password; + + return $this; + } + + /** + * Gets phone. + * + * @return string|null + */ + public function getPhone() + { + return $this->phone; + } + + /** + * Sets phone. + * + * @param string|null $phone + * + * @return $this + */ + public function setPhone($phone = null) + { + $this->phone = $phone; + + return $this; + } + + /** + * Gets userStatus. + * + * @return int|null + */ + public function getUserStatus() + { + return $this->userStatus; + } + + /** + * Sets userStatus. + * + * @param int|null $userStatus User Status + * + * @return $this + */ + public function setUserStatus($userStatus = null) + { + $this->userStatus = $userStatus; + + return $this; + } +} + + diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/OpenAPIServerBundle.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/OpenAPIServerBundle.php new file mode 100644 index 00000000000..ff92f1c78a4 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/OpenAPIServerBundle.php @@ -0,0 +1,50 @@ +addCompilerPass(new OpenAPIServerApiPass()); + } +} diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/README.md b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/README.md new file mode 100644 index 00000000000..8bf887799e0 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/README.md @@ -0,0 +1,190 @@ +# OpenAPIServer +This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + +This [Symfony](https://symfony.com/) bundle is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: + +- API version: 1.0.0 +- Build package: org.openapitools.codegen.languages.PhpSymfonyServerCodegen + +## Requirements + +PHP 5.4.0 and later + +## Installation & Usage + +To install the dependencies via [Composer](http://getcomposer.org/), add the following repository to `composer.json` of your Symfony project: + +```json +{ + "repositories": [{ + "type": "path", + "url": "//Path to your generated openapi bundle" + }], +} +``` + +Then run: + +``` +composer require GIT_USER_ID/GIT_REPO_ID:dev-master +``` + +to add the generated openapi bundle as a dependency. + +## Tests + +To run the unit tests for the generated bundle, first navigate to the directory containing the code, then run the following commands: + +``` +composer install +./vendor/bin/phpunit +``` + + +## Getting Started + +Step 1: Please follow the [installation procedure](#installation--usage) first. + +Step 2: Enable the bundle in the kernel: + +```php + addPet($pet) + +Add a new pet to the store + +### Example Implementation +```php + deletePet($petId, $apiKey) + +Deletes a pet + +### Example Implementation +```php + OpenAPI\Server\Model\Pet findPetsByStatus($status) + +Finds Pets by status + +Multiple status values can be provided with comma separated strings + +### Example Implementation +```php + OpenAPI\Server\Model\Pet findPetsByTags($tags, $maxCount) + +Finds Pets by tags + +Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + +### Example Implementation +```php + OpenAPI\Server\Model\Pet getPetById($petId) + +Find pet by ID + +Returns a single pet + +### Example Implementation +```php + updatePet($pet) + +Update an existing pet + +### Example Implementation +```php + updatePetWithForm($petId, $name, $status) + +Updates a pet in the store with form data + +### Example Implementation +```php + OpenAPI\Server\Model\ApiResponse uploadFile($petId, $additionalMetadata, $file) + +uploads an image + +### Example Implementation +```php + deleteOrder($orderId) + +Delete purchase order by ID + +For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + +### Example Implementation +```php + int getInventory() + +Returns pet inventories by status + +Returns a map of status codes to quantities + +### Example Implementation +```php + OpenAPI\Server\Model\Order getOrderById($orderId) + +Find purchase order by ID + +For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + +### Example Implementation +```php + OpenAPI\Server\Model\Order placeOrder($order) + +Place an order for a pet + +### Example Implementation +```php + createUser($user) + +Create user + +This can only be done by the logged in user. + +### Example Implementation +```php + createUsersWithArrayInput($user) + +Creates list of users with given input array + +### Example Implementation +```php + createUsersWithListInput($user) + +Creates list of users with given input array + +### Example Implementation +```php + deleteUser($username) + +Delete user + +This can only be done by the logged in user. + +### Example Implementation +```php + OpenAPI\Server\Model\User getUserByName($username) + +Get user by user name + +### Example Implementation +```php + string loginUser($username, $password) + +Logs user into the system + +### Example Implementation +```php + logoutUser() + +Logs out current logged in user session + +### Example Implementation +```php + updateUser($username, $user) + +Updated user + +This can only be done by the logged in user. + +### Example Implementation +```php +serializer = SerializerBuilder::create() + ->setDeserializationVisitor('json', new StrictJsonDeserializationVisitor($naming_strategy)) + ->setDeserializationVisitor('xml', new XmlDeserializationVisitor($naming_strategy)) + ->build(); + } + + public function serialize($data, $format) + { + return SerializerBuilder::create()->build()->serialize($data, $this->convertFormat($format)); + } + + public function deserialize($data, $type, $format) + { + if ($format == 'string') { + return $this->deserializeString($data, $type); + } + + // If we end up here, let JMS serializer handle the deserialization + return $this->serializer->deserialize($data, $type, $this->convertFormat($format)); + } + + private function convertFormat($format) + { + switch ($format) { + case 'application/json': + return 'json'; + case 'application/xml': + return 'xml'; + } + + return null; + } + + private function deserializeString($data, $type) + { + // Figure out if we have an array format + if (1 === preg_match('/array<(csv|ssv|tsv|pipes),(int|string)>/i', $type, $matches)) { + return $this->deserializeArrayString($matches[1], $matches[2], $data); + } + + switch ($type) { + case 'int': + case 'integer': + if (is_int($data)) { + return $data; + } + + if (is_numeric($data)) { + return $data + 0; + } + + break; + case 'string': + break; + case 'boolean': + case 'bool': + if (strtolower($data) === 'true') { + return true; + } + + if (strtolower($data) === 'false') { + return false; + } + + break; + } + + // If we end up here, just return data + return $data; + } + + private function deserializeArrayString($format, $type, $data) + { + // Parse the string using the correct separator + switch ($format) { + case 'csv': + $data = explode(',', $data); + break; + case 'ssv': + $data = explode(' ', $data); + break; + case 'tsv': + $data = explode("\t", $data); + break; + case 'pipes': + $data = explode('|', $data); + break; + default; + $data = []; + } + + // Deserialize each of the array elements + foreach ($data as $key => $item) { + $data[$key] = $this->deserializeString($item, $type); + } + + return $data; + } +} diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Service/SerializerInterface.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Service/SerializerInterface.php new file mode 100644 index 00000000000..40ef08f44c9 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Service/SerializerInterface.php @@ -0,0 +1,27 @@ +validator = $validator; + } + + public function validate($value, $constraints = null, $groups = null) + { + return $this->validator->validate($value, $constraints, $groups); + } +} diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Service/TypeMismatchException.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Service/TypeMismatchException.php new file mode 100644 index 00000000000..33c9cb7ab74 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Service/TypeMismatchException.php @@ -0,0 +1,52 @@ +getCurrentPath()) > 0) { + $property = sprintf('property "%s" to be ', implode('.', $context->getCurrentPath())); + } else { + $property = ''; + } + + return new static(sprintf( + 'Expected %s%s, but got %s: %s', + $property, + $expected_type, + gettype($actual_value), + json_encode($actual_value) + )); + } +} diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Service/ValidatorInterface.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Service/ValidatorInterface.php new file mode 100644 index 00000000000..dea54184733 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Service/ValidatorInterface.php @@ -0,0 +1,25 @@ +request('POST', $path); + } + + /** + * Test case for deletePet + * + * Deletes a pet. + * + */ + public function testDeletePet() + { + $client = static::createClient(); + + $path = '/pet/{petId}'; + $pattern = '{petId}'; + $data = $this->genTestData('\d+'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('DELETE', $path); + } + + /** + * Test case for findPetsByStatus + * + * Finds Pets by status. + * + */ + public function testFindPetsByStatus() + { + $client = static::createClient(); + + $path = '/pet/findByStatus'; + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for findPetsByTags + * + * Finds Pets by tags. + * + */ + public function testFindPetsByTags() + { + $client = static::createClient(); + + $path = '/pet/findByTags'; + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for getPetById + * + * Find pet by ID. + * + */ + public function testGetPetById() + { + $client = static::createClient(); + + $path = '/pet/{petId}'; + $pattern = '{petId}'; + $data = $this->genTestData('\d+'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for updatePet + * + * Update an existing pet. + * + */ + public function testUpdatePet() + { + $client = static::createClient(); + + $path = '/pet'; + + $crawler = $client->request('PUT', $path); + } + + /** + * Test case for updatePetWithForm + * + * Updates a pet in the store with form data. + * + */ + public function testUpdatePetWithForm() + { + $client = static::createClient(); + + $path = '/pet/{petId}'; + $pattern = '{petId}'; + $data = $this->genTestData('\d+'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('POST', $path); + } + + /** + * Test case for uploadFile + * + * uploads an image. + * + */ + public function testUploadFile() + { + $client = static::createClient(); + + $path = '/pet/{petId}/uploadImage'; + $pattern = '{petId}'; + $data = $this->genTestData('\d+'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('POST', $path); + } + + protected function genTestData($regexp) + { + $grammar = new \Hoa\File\Read('hoa://Library/Regex/Grammar.pp'); + $compiler = \Hoa\Compiler\Llk\Llk::load($grammar); + $ast = $compiler->parse($regexp); + $generator = new \Hoa\Regex\Visitor\Isotropic(new \Hoa\Math\Sampler\Random()); + + return $generator->visit($ast); + } +} diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/StoreApiInterfaceTest.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/StoreApiInterfaceTest.php new file mode 100644 index 00000000000..919d30cf9a1 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/StoreApiInterfaceTest.php @@ -0,0 +1,151 @@ +genTestData('[a-z0-9]+'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('DELETE', $path); + } + + /** + * Test case for getInventory + * + * Returns pet inventories by status. + * + */ + public function testGetInventory() + { + $client = static::createClient(); + + $path = '/store/inventory'; + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for getOrderById + * + * Find purchase order by ID. + * + */ + public function testGetOrderById() + { + $client = static::createClient(); + + $path = '/store/order/{orderId}'; + $pattern = '{orderId}'; + $data = $this->genTestData('\d+'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for placeOrder + * + * Place an order for a pet. + * + */ + public function testPlaceOrder() + { + $client = static::createClient(); + + $path = '/store/order'; + + $crawler = $client->request('POST', $path); + } + + protected function genTestData($regexp) + { + $grammar = new \Hoa\File\Read('hoa://Library/Regex/Grammar.pp'); + $compiler = \Hoa\Compiler\Llk\Llk::load($grammar); + $ast = $compiler->parse($regexp); + $generator = new \Hoa\Regex\Visitor\Isotropic(new \Hoa\Math\Sampler\Random()); + + return $generator->visit($ast); + } +} diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/UserApiInterfaceTest.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/UserApiInterfaceTest.php new file mode 100644 index 00000000000..6f2e3ba0b6c --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/UserApiInterfaceTest.php @@ -0,0 +1,214 @@ +request('POST', $path); + } + + /** + * Test case for createUsersWithArrayInput + * + * Creates list of users with given input array. + * + */ + public function testCreateUsersWithArrayInput() + { + $client = static::createClient(); + + $path = '/user/createWithArray'; + + $crawler = $client->request('POST', $path); + } + + /** + * Test case for createUsersWithListInput + * + * Creates list of users with given input array. + * + */ + public function testCreateUsersWithListInput() + { + $client = static::createClient(); + + $path = '/user/createWithList'; + + $crawler = $client->request('POST', $path); + } + + /** + * Test case for deleteUser + * + * Delete user. + * + */ + public function testDeleteUser() + { + $client = static::createClient(); + + $path = '/user/{username}'; + $pattern = '{username}'; + $data = $this->genTestData('[a-z0-9]+'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('DELETE', $path); + } + + /** + * Test case for getUserByName + * + * Get user by user name. + * + */ + public function testGetUserByName() + { + $client = static::createClient(); + + $path = '/user/{username}'; + $pattern = '{username}'; + $data = $this->genTestData('[a-z0-9]+'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for loginUser + * + * Logs user into the system. + * + */ + public function testLoginUser() + { + $client = static::createClient(); + + $path = '/user/login'; + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for logoutUser + * + * Logs out current logged in user session. + * + */ + public function testLogoutUser() + { + $client = static::createClient(); + + $path = '/user/logout'; + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for updateUser + * + * Updated user. + * + */ + public function testUpdateUser() + { + $client = static::createClient(); + + $path = '/user/{username}'; + $pattern = '{username}'; + $data = $this->genTestData('[a-z0-9]+'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('PUT', $path); + } + + protected function genTestData($regexp) + { + $grammar = new \Hoa\File\Read('hoa://Library/Regex/Grammar.pp'); + $compiler = \Hoa\Compiler\Llk\Llk::load($grammar); + $ast = $compiler->parse($regexp); + $generator = new \Hoa\Regex\Visitor\Isotropic(new \Hoa\Math\Sampler\Random()); + + return $generator->visit($ast); + } +} diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/AppKernel.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/AppKernel.php new file mode 100644 index 00000000000..631690bc978 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/AppKernel.php @@ -0,0 +1,21 @@ +load(__DIR__.'/test_config.yml'); + } +} diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/ApiResponseTest.php b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/ApiResponseTest.php new file mode 100644 index 00000000000..3bbfe7c96e5 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/ApiResponseTest.php @@ -0,0 +1,101 @@ +=5.4", + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*", + "symfony/validator": "*", + "jms/serializer-bundle": "^2.0", + "symfony/framework-bundle": "^3.3|^4.1" + }, + "require-dev": { + "phpunit/phpunit": "~4.8", + "satooshi/php-coveralls": "~1.0", + "squizlabs/php_codesniffer": "~2.6", + "friendsofphp/php-cs-fixer": "~1.12", + "symfony/browser-kit": "*", + "hoa/regex": "~1.0" + }, + "autoload": { + "psr-4": { "OpenAPI\\Server\\" : "./" } + } +} diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/git_push.sh b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/git_push.sh new file mode 100644 index 00000000000..4d22bfef4d7 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/git_push.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 + +if [ "$git_user_id" = "" ]; then + git_user_id="GIT_USER_ID" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="GIT_REPO_ID" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=`git remote` +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' + diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/phpunit.xml.dist b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/phpunit.xml.dist new file mode 100644 index 00000000000..6f8b5ca0f93 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/phpunit.xml.dist @@ -0,0 +1,24 @@ + + + + + ./Tests/Api + ./Tests/Model + + + + + ././Api + ././Model + + + + + + + diff --git a/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/pom.xml b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/pom.xml new file mode 100644 index 00000000000..672956a1b51 --- /dev/null +++ b/samples/openapi3/server/petstore/php-symfony/SymfonyBundle-php/pom.xml @@ -0,0 +1,57 @@ + + 4.0.0 + com.penneo + PhpSymfonyPetstoreServerTests + pom + 1.0-SNAPSHOT + PHP Symfony Petstore Server + + + + maven-dependency-plugin + + + package + + copy-dependencies + + + ${project.build.directory} + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + bundle-install + pre-integration-test + + exec + + + composer + + install + + + + + bundle-test + integration-test + + exec + + + vendor/bin/phpunit + + + + + + + +