From adf268290f281e7ac3b19ca97d8c584bdc72aba3 Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Sat, 5 Mar 2022 19:31:12 +0100 Subject: [PATCH 01/25] support symfony6 --- .../languages/PhpSymfonyServerCodegen.java | 1 + .../main/resources/php-symfony/.travis.yml | 3 +- .../resources/php-symfony/ApiPass.mustache | 2 +- .../resources/php-symfony/ApiServer.mustache | 4 +- .../resources/php-symfony/Bundle.mustache | 2 +- .../resources/php-symfony/Controller.mustache | 2 +- .../resources/php-symfony/Extension.mustache | 4 +- .../resources/php-symfony/README.mustache | 4 +- .../main/resources/php-symfony/api.mustache | 7 +- .../php-symfony/api_controller.mustache | 2 +- .../resources/php-symfony/api_doc.mustache | 2 +- .../resources/php-symfony/composer.mustache | 18 ++-- .../main/resources/php-symfony/model.mustache | 2 +- .../resources/php-symfony/routing.mustache | 2 +- .../serialization/JmsSerializer.mustache | 15 ++- .../StrictJsonDeserializationVisitor.mustache | 95 ++++++++++++++++--- ...JsonDeserializationVisitorFactory.mustache | 39 ++++++++ .../resources/php-symfony/services.mustache | 2 +- .../testing/ControllerTest.mustache | 2 +- .../php-symfony/testing/api_test.mustache | 2 +- .../php-symfony/testing/model_test.mustache | 10 +- .../.openapi-generator/FILES | 1 + .../php-symfony/SymfonyBundle-php/.travis.yml | 3 +- .../SymfonyBundle-php/Api/ApiServer.php | 4 +- .../SymfonyBundle-php/Api/PetApiInterface.php | 35 +++---- .../Api/StoreApiInterface.php | 19 ++-- .../Api/UserApiInterface.php | 35 +++---- .../Controller/Controller.php | 2 +- .../Controller/PetController.php | 2 +- .../Controller/StoreController.php | 2 +- .../Controller/UserController.php | 2 +- .../Compiler/OpenAPIServerApiPass.php | 2 +- .../OpenAPIServerExtension.php | 4 +- .../SymfonyBundle-php/Model/ApiResponse.php | 2 +- .../SymfonyBundle-php/Model/Category.php | 2 +- .../SymfonyBundle-php/Model/Order.php | 2 +- .../SymfonyBundle-php/Model/Pet.php | 2 +- .../SymfonyBundle-php/Model/Tag.php | 2 +- .../SymfonyBundle-php/Model/User.php | 2 +- .../SymfonyBundle-php/OpenAPIServerBundle.php | 2 +- .../php-symfony/SymfonyBundle-php/README.md | 4 +- .../Resources/config/routing.yml | 40 ++++---- .../Resources/config/services.yml | 6 +- .../Resources/docs/Api/PetApiInterface.md | 16 ++-- .../Resources/docs/Api/StoreApiInterface.md | 8 +- .../Resources/docs/Api/UserApiInterface.md | 16 ++-- .../Service/JmsSerializer.php | 15 ++- .../StrictJsonDeserializationVisitor.php | 95 ++++++++++++++++--- ...trictJsonDeserializationVisitorFactory.php | 39 ++++++++ .../Tests/Controller/ControllerTest.php | 2 +- .../SymfonyBundle-php/composer.json | 18 ++-- 51 files changed, 421 insertions(+), 183 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitorFactory.mustache create mode 100644 samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitorFactory.php diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java index 7ffaf723136a..9dbf2a37e748 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java @@ -344,6 +344,7 @@ public void processOpts() { supportingFiles.add(new SupportingFile("serialization/SerializerInterface.mustache", toSrcPath(servicePackage, srcBasePath), "SerializerInterface.php")); supportingFiles.add(new SupportingFile("serialization/JmsSerializer.mustache", toSrcPath(servicePackage, srcBasePath), "JmsSerializer.php")); supportingFiles.add(new SupportingFile("serialization/StrictJsonDeserializationVisitor.mustache", toSrcPath(servicePackage, srcBasePath), "StrictJsonDeserializationVisitor.php")); + supportingFiles.add(new SupportingFile("serialization/StrictJsonDeserializationVisitorFactory.mustache", toSrcPath(servicePackage, srcBasePath), "StrictJsonDeserializationVisitorFactory.php")); supportingFiles.add(new SupportingFile("serialization/TypeMismatchException.mustache", toSrcPath(servicePackage, srcBasePath), "TypeMismatchException.php")); // Validation components supportingFiles.add(new SupportingFile("validation/ValidatorInterface.mustache", toSrcPath(servicePackage, srcBasePath), "ValidatorInterface.php")); diff --git a/modules/openapi-generator/src/main/resources/php-symfony/.travis.yml b/modules/openapi-generator/src/main/resources/php-symfony/.travis.yml index de5a983645fc..2de2fe978823 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/.travis.yml +++ b/modules/openapi-generator/src/main/resources/php-symfony/.travis.yml @@ -1,8 +1,7 @@ language: php dist: trusty php: - - 7.1.3 - - 7.2 + - 8.1.1 install: - composer install --dev --no-interaction diff --git a/modules/openapi-generator/src/main/resources/php-symfony/ApiPass.mustache b/modules/openapi-generator/src/main/resources/php-symfony/ApiPass.mustache index 10bf6bea00cb..8a5f472014a0 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/ApiPass.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/ApiPass.mustache @@ -2,7 +2,7 @@ /** * {{bundleName}}ApiPass * - * PHP version 7.1.3 + * PHP version 8.1.1 * * @category Class * @package {{invokerPackage}}\DependencyInjection\Compiler diff --git a/modules/openapi-generator/src/main/resources/php-symfony/ApiServer.mustache b/modules/openapi-generator/src/main/resources/php-symfony/ApiServer.mustache index 1e902459ef00..d200b0c6d1c9 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/ApiServer.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/ApiServer.mustache @@ -2,7 +2,7 @@ /** * ApiServer * - * PHP version 7.1.3 + * PHP version 8.1.1 * * @category Class * @package {{apiPackage}} @@ -22,7 +22,7 @@ namespace {{apiPackage}}; /** * ApiServer Class Doc Comment * - * PHP version 5 + * PHP version 8.1.1 * * @category Class * @package {{apiPackage}} diff --git a/modules/openapi-generator/src/main/resources/php-symfony/Bundle.mustache b/modules/openapi-generator/src/main/resources/php-symfony/Bundle.mustache index 4bbbf5062d8f..83ef7afa0af0 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/Bundle.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/Bundle.mustache @@ -2,7 +2,7 @@ /** * {{bundleClassName}} * - * PHP version 7.1.3 + * PHP version 8.1.1 * * @category Class * @package {{invokerPackage}} diff --git a/modules/openapi-generator/src/main/resources/php-symfony/Controller.mustache b/modules/openapi-generator/src/main/resources/php-symfony/Controller.mustache index 8e2142560457..9b0c16fdb004 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/Controller.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/Controller.mustache @@ -2,7 +2,7 @@ /** * Controller * - * PHP version 7.1.3 + * PHP version 8.1.1 * * @category Class * @package {{controllerPackage}} diff --git a/modules/openapi-generator/src/main/resources/php-symfony/Extension.mustache b/modules/openapi-generator/src/main/resources/php-symfony/Extension.mustache index 4395c42aef0a..00dd37411c84 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/Extension.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/Extension.mustache @@ -2,7 +2,7 @@ /** * {{bundleExtensionName}} * - * PHP version 7.1.3 + * PHP version 8.1.1 * * @category Class * @package {{invokerPackage}}\DependencyInjection @@ -40,7 +40,7 @@ class {{bundleExtensionName}} extends Extension $loader->load('services.yml'); } - public function getAlias() + public function getAlias(): string { return '{{bundleAlias}}'; } diff --git a/modules/openapi-generator/src/main/resources/php-symfony/README.mustache b/modules/openapi-generator/src/main/resources/php-symfony/README.mustache index 2b959b0e3e59..67e62330925c 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/README.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/README.mustache @@ -19,7 +19,7 @@ For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) ## Requirements -PHP 7.1.3 and later +PHP 8.1.1 and later ## Installation & Usage @@ -112,7 +112,7 @@ class {{baseName}}Api implements {{classname}} // An interface is autogenerated /** * Implementation of {{classname}}#{{operationId}} */ - public function {{operationId}}({{#allParams}}{{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) + public function {{operationId}}({{#allParams}}{{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}): {{#isArray}}iterable{{/isArray}}{{^isArray}}array|{{{vendorExtensions.x-comment-type}}}{{/isArray}} { // Implement the operation ... } diff --git a/modules/openapi-generator/src/main/resources/php-symfony/api.mustache b/modules/openapi-generator/src/main/resources/php-symfony/api.mustache index d342bf1d79bd..fc7cc173e240 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/api.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/api.mustache @@ -1,7 +1,8 @@ =8.0.2", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", - "symfony/validator": "*", - "jms/serializer-bundle": "^2.0", - "symfony/framework-bundle": "^4.4.8" + "symfony/validator": "6.0.*", + "jms/serializer-bundle": "4.0.*", + "symfony/framework-bundle": "6.0.*" }, "require-dev": { - "phpunit/phpunit": "^7.0", + "phpunit/phpunit": "^9.5", "friendsofphp/php-cs-fixer": "^2.16.3", - "symfony/browser-kit": "*", - "symfony/yaml": "^4.4.8", + "symfony/browser-kit": "6.0.*", + "symfony/yaml": "6.0.*", "hoa/regex": "~1.0" }, "autoload": { - "psr-4": { "{{escapedInvokerPackage}}\\" : "{{srcBasePath}}/" } + "psr-4": { + "{{escapedInvokerPackage}}\\" : "{{srcBasePath}}/" + } } } diff --git a/modules/openapi-generator/src/main/resources/php-symfony/model.mustache b/modules/openapi-generator/src/main/resources/php-symfony/model.mustache index 9d9831384fce..2435f607663a 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/model.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/model.mustache @@ -4,7 +4,7 @@ /** * {{classname}} * - * PHP version 7.1.3 + * PHP version 8.1.1 * * @category Class * @package {{modelPackage}} diff --git a/modules/openapi-generator/src/main/resources/php-symfony/routing.mustache b/modules/openapi-generator/src/main/resources/php-symfony/routing.mustache index 0b9ec9291458..cd4a833df0ac 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/routing.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/routing.mustache @@ -11,7 +11,7 @@ path: {{path}} methods: [{{httpMethod}}] defaults: - _controller: {{bundleAlias}}.controller.{{pathPrefix}}:{{operationId}}Action + _controller: {{bundleAlias}}.controller.{{pathPrefix}}::{{operationId}}Action {{#hasPathParams}} requirements: {{/hasPathParams}} diff --git a/modules/openapi-generator/src/main/resources/php-symfony/serialization/JmsSerializer.mustache b/modules/openapi-generator/src/main/resources/php-symfony/serialization/JmsSerializer.mustache index a3dc976f08c1..54a959f2d64e 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/serialization/JmsSerializer.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/serialization/JmsSerializer.mustache @@ -5,7 +5,10 @@ namespace {{servicePackage}}; use JMS\Serializer\SerializerBuilder; use JMS\Serializer\Naming\CamelCaseNamingStrategy; use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; +use JMS\Serializer\Visitor\Factory\XmlDeserializationVisitorFactory; use JMS\Serializer\XmlDeserializationVisitor; +use DateTime; +use RuntimeException; class JmsSerializer implements SerializerInterface { @@ -13,10 +16,11 @@ class JmsSerializer implements SerializerInterface public function __construct() { - $naming_strategy = new SerializedNameAnnotationStrategy(new CamelCaseNamingStrategy()); + $namingStrategy = new SerializedNameAnnotationStrategy(new CamelCaseNamingStrategy()); $this->serializer = SerializerBuilder::create() - ->setDeserializationVisitor('json', new StrictJsonDeserializationVisitor($naming_strategy)) - ->setDeserializationVisitor('xml', new XmlDeserializationVisitor($naming_strategy)) + ->setDeserializationVisitor('json', new StrictJsonDeserializationVisitorFactory()) + ->setDeserializationVisitor('xml', new XmlDeserializationVisitorFactory()) + ->setPropertyNamingStrategy($namingStrategy) ->build(); } @@ -79,6 +83,11 @@ class JmsSerializer implements SerializerInterface } break; + case 'DateTime': + case '\DateTime': + return new DateTime($data); + default: + throw new RuntimeException(sprintf("Type %s is unsupported", $type)); } // If we end up here, just return data diff --git a/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitor.mustache b/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitor.mustache index b60e2c7b653d..d2e6ef6fc4b4 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitor.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitor.mustache @@ -15,58 +15,125 @@ * limitations under the License. */ +declare(strict_types=1); + namespace {{servicePackage}}; -use JMS\Serializer\Context; use JMS\Serializer\JsonDeserializationVisitor; +use JMS\Serializer\Vistor\DeserializationVisitorInterface; -class StrictJsonDeserializationVisitor extends JsonDeserializationVisitor +class StrictJsonDeserializationVisitor implements DeserializationVisitorInterface { + protected $jsonDeserializationVisitor; + + public function __construct( + int $options = 0, + int $depth = 512 + ) { + $this->jsonDeserializationVisitor = new JsonDeserializationVisitor($options, $depth); + } + + /** + * {@inheritdoc} + */ + public function visitNull($data, array $type) + { + return $this->jsonDeserializationVisitor->visitNull($data, $type); + } + /** * {@inheritdoc} */ - public function visitString($data, array $type, Context $context) + public function visitString($data, array $type): string { if (!is_string($data)) { - throw TypeMismatchException::fromValue('string', $data, $context); + throw TypeMismatchException::fromValue('string', $data); } - return parent::visitString($data, $type, $context); + return $this->jsonDeserializationVisitor->visitString($data, $type); } /** * {@inheritdoc} */ - public function visitBoolean($data, array $type, Context $context) + public function visitBoolean($data, array $type): bool { if (!is_bool($data)) { - throw TypeMismatchException::fromValue('boolean', $data, $context); + throw TypeMismatchException::fromValue('boolean', $data); } - return parent::visitBoolean($data, $type, $context); + return $this->jsonDeserializationVisitor->visitBoolean($data, $type); } /** * {@inheritdoc} */ - public function visitInteger($data, array $type, Context $context) + public function visitInteger($data, array $type): int { if (!is_int($data)) { - throw TypeMismatchException::fromValue('integer', $data, $context); + throw TypeMismatchException::fromValue('integer', $data); } - return parent::visitInteger($data, $type, $context); + return $this->jsonDeserializationVisitor->visitInteger($data, $type); } /** * {@inheritdoc} */ - public function visitDouble($data, array $type, Context $context) + public function visitDouble($data, array $type): float { if (!is_float($data) && !is_integer($data)) { - throw TypeMismatchException::fromValue('double', $data, $context); + throw TypeMismatchException::fromValue('double', $data); } - return parent::visitDouble($data, $type, $context); + return $this->jsonDeserializationVisitor->visitDouble($data, $type); + } + + /** + * {@inheritdoc} + */ + public function visitArray($data, array $type): array + { + return $this->jsonDeserializationVisitor->visitArray($data, $type); + } + + /** + * {@inheritdoc} + */ + public function visitDiscriminatorMapProperty($data, ClassMetadata $metadata): string + { + return $this->jsonDeserializationVisitor->visitDiscriminatorMapProperty($data, $type); + } + + /** + * {@inheritdoc} + */ + public function startVisitingObject(ClassMetadata $metadata, object $object, array $type): void + { + return $this->jsonDeserializationVisitor->startVisitingObject($metadata, $object, $type); + } + + /** + * {@inheritdoc} + */ + public function visitProperty(PropertyMetadata $metadata, $data) + { + return $this->jsonDeserializationVisitor->visitProperty($metadata, $data); + } + + /** + * {@inheritdoc} + */ + public function endVisitingObject(ClassMetadata $metadata, $data, array $type): object + { + return $this->jsonDeserializationVisitor->endVisitingObject($metadata, $object, $type); + } + + /** + * {@inheritdoc} + */ + public function getResult($data) + { + return $this->jsonDeserializationVisitor->getResult($data); } } diff --git a/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitorFactory.mustache b/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitorFactory.mustache new file mode 100644 index 000000000000..df09f0c41028 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitorFactory.mustache @@ -0,0 +1,39 @@ +options, $this->depth); + } + + public function setOptions(int $options): self + { + $this->options = $options; + + return $this; + } + + public function setDepth(int $depth): self + { + $this->depth = $depth; + + return $this; + } +} diff --git a/modules/openapi-generator/src/main/resources/php-symfony/services.mustache b/modules/openapi-generator/src/main/resources/php-symfony/services.mustache index 1432b4a82a93..042fb28f6709 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/services.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/services.mustache @@ -30,8 +30,8 @@ services: - [setSerializer, ['@{{bundleAlias}}.service.serializer']] - [setValidator, ['@{{bundleAlias}}.service.validator']] - [setApiServer, ['@{{bundleAlias}}.api.api_server']] + - [setContainer, ['@service_container']] tags: ['controller.service_arguments'] - autowire: true {{/operations}} {{/apis}} diff --git a/modules/openapi-generator/src/main/resources/php-symfony/testing/ControllerTest.mustache b/modules/openapi-generator/src/main/resources/php-symfony/testing/ControllerTest.mustache index 49861fd96722..730cba94a113 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/testing/ControllerTest.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/testing/ControllerTest.mustache @@ -1,7 +1,7 @@ load('services.yml'); } - public function getAlias() + public function getAlias(): string { return 'open_api_server'; } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php index 1070ad90944c..f16d72ad3814 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php @@ -2,7 +2,7 @@ /** * ApiResponse * - * PHP version 7.1.3 + * PHP version 8.1.1 * * @category Class * @package OpenAPI\Server\Model diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php index 7ee222ced8d6..f28e356b3812 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php @@ -2,7 +2,7 @@ /** * Category * - * PHP version 7.1.3 + * PHP version 8.1.1 * * @category Class * @package OpenAPI\Server\Model diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php index 35bd792c6db3..7a6c985ae859 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php @@ -2,7 +2,7 @@ /** * Order * - * PHP version 7.1.3 + * PHP version 8.1.1 * * @category Class * @package OpenAPI\Server\Model diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php index a7a306569540..f0375444f5ce 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php @@ -2,7 +2,7 @@ /** * Pet * - * PHP version 7.1.3 + * PHP version 8.1.1 * * @category Class * @package OpenAPI\Server\Model diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php index abae962752eb..e07427b14576 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php @@ -2,7 +2,7 @@ /** * Tag * - * PHP version 7.1.3 + * PHP version 8.1.1 * * @category Class * @package OpenAPI\Server\Model diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php index 7222a65a6e92..4fab9c98f419 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php @@ -2,7 +2,7 @@ /** * User * - * PHP version 7.1.3 + * PHP version 8.1.1 * * @category Class * @package OpenAPI\Server\Model diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/OpenAPIServerBundle.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/OpenAPIServerBundle.php index 3e8304f24461..61d3eb421086 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/OpenAPIServerBundle.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/OpenAPIServerBundle.php @@ -2,7 +2,7 @@ /** * OpenAPIServerBundle * - * PHP version 7.1.3 + * PHP version 8.1.1 * * @category Class * @package OpenAPI\Server diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md index 0e5ac7c2d212..bbd8488f3ab1 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md @@ -8,7 +8,7 @@ This [Symfony](https://symfony.com/) bundle is automatically generated by the [O ## Requirements -PHP 7.1.3 and later +PHP 8.1.1 and later ## Installation & Usage @@ -93,7 +93,7 @@ class PetApi implements PetApiInterface // An interface is autogenerated /** * Implementation of PetApiInterface#addPet */ - public function addPet(Pet $pet) + public function addPet(Pet $pet): array|\OpenAPI\Server\Model\Pet { // Implement the operation ... } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/routing.yml b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/routing.yml index a571a4df29dd..4253fba9b1e9 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/routing.yml +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/routing.yml @@ -7,13 +7,13 @@ open_api_server_pet_addpet: path: /pet methods: [POST] defaults: - _controller: open_api_server.controller.pet:addPetAction + _controller: open_api_server.controller.pet::addPetAction open_api_server_pet_deletepet: path: /pet/{petId} methods: [DELETE] defaults: - _controller: open_api_server.controller.pet:deletePetAction + _controller: open_api_server.controller.pet::deletePetAction requirements: petId: '\d+' @@ -21,19 +21,19 @@ open_api_server_pet_findpetsbystatus: path: /pet/findByStatus methods: [GET] defaults: - _controller: open_api_server.controller.pet:findPetsByStatusAction + _controller: open_api_server.controller.pet::findPetsByStatusAction open_api_server_pet_findpetsbytags: path: /pet/findByTags methods: [GET] defaults: - _controller: open_api_server.controller.pet:findPetsByTagsAction + _controller: open_api_server.controller.pet::findPetsByTagsAction open_api_server_pet_getpetbyid: path: /pet/{petId} methods: [GET] defaults: - _controller: open_api_server.controller.pet:getPetByIdAction + _controller: open_api_server.controller.pet::getPetByIdAction requirements: petId: '\d+' @@ -41,13 +41,13 @@ open_api_server_pet_updatepet: path: /pet methods: [PUT] defaults: - _controller: open_api_server.controller.pet:updatePetAction + _controller: open_api_server.controller.pet::updatePetAction open_api_server_pet_updatepetwithform: path: /pet/{petId} methods: [POST] defaults: - _controller: open_api_server.controller.pet:updatePetWithFormAction + _controller: open_api_server.controller.pet::updatePetWithFormAction requirements: petId: '\d+' @@ -55,7 +55,7 @@ open_api_server_pet_uploadfile: path: /pet/{petId}/uploadImage methods: [POST] defaults: - _controller: open_api_server.controller.pet:uploadFileAction + _controller: open_api_server.controller.pet::uploadFileAction requirements: petId: '\d+' @@ -64,7 +64,7 @@ open_api_server_store_deleteorder: path: /store/order/{orderId} methods: [DELETE] defaults: - _controller: open_api_server.controller.store:deleteOrderAction + _controller: open_api_server.controller.store::deleteOrderAction requirements: orderId: '[a-z0-9]+' @@ -72,13 +72,13 @@ open_api_server_store_getinventory: path: /store/inventory methods: [GET] defaults: - _controller: open_api_server.controller.store:getInventoryAction + _controller: open_api_server.controller.store::getInventoryAction open_api_server_store_getorderbyid: path: /store/order/{orderId} methods: [GET] defaults: - _controller: open_api_server.controller.store:getOrderByIdAction + _controller: open_api_server.controller.store::getOrderByIdAction requirements: orderId: '\d+' @@ -86,32 +86,32 @@ open_api_server_store_placeorder: path: /store/order methods: [POST] defaults: - _controller: open_api_server.controller.store:placeOrderAction + _controller: open_api_server.controller.store::placeOrderAction # user open_api_server_user_createuser: path: /user methods: [POST] defaults: - _controller: open_api_server.controller.user:createUserAction + _controller: open_api_server.controller.user::createUserAction open_api_server_user_createuserswitharrayinput: path: /user/createWithArray methods: [POST] defaults: - _controller: open_api_server.controller.user:createUsersWithArrayInputAction + _controller: open_api_server.controller.user::createUsersWithArrayInputAction open_api_server_user_createuserswithlistinput: path: /user/createWithList methods: [POST] defaults: - _controller: open_api_server.controller.user:createUsersWithListInputAction + _controller: open_api_server.controller.user::createUsersWithListInputAction open_api_server_user_deleteuser: path: /user/{username} methods: [DELETE] defaults: - _controller: open_api_server.controller.user:deleteUserAction + _controller: open_api_server.controller.user::deleteUserAction requirements: username: '[a-z0-9]+' @@ -119,7 +119,7 @@ open_api_server_user_getuserbyname: path: /user/{username} methods: [GET] defaults: - _controller: open_api_server.controller.user:getUserByNameAction + _controller: open_api_server.controller.user::getUserByNameAction requirements: username: '[a-z0-9]+' @@ -127,19 +127,19 @@ open_api_server_user_loginuser: path: /user/login methods: [GET] defaults: - _controller: open_api_server.controller.user:loginUserAction + _controller: open_api_server.controller.user::loginUserAction open_api_server_user_logoutuser: path: /user/logout methods: [GET] defaults: - _controller: open_api_server.controller.user:logoutUserAction + _controller: open_api_server.controller.user::logoutUserAction open_api_server_user_updateuser: path: /user/{username} methods: [PUT] defaults: - _controller: open_api_server.controller.user:updateUserAction + _controller: open_api_server.controller.user::updateUserAction requirements: username: '[a-z0-9]+' diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/services.yml b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/services.yml index a9363de5efbf..27503e2b4337 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/services.yml +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/services.yml @@ -27,8 +27,8 @@ services: - [setSerializer, ['@open_api_server.service.serializer']] - [setValidator, ['@open_api_server.service.validator']] - [setApiServer, ['@open_api_server.api.api_server']] + - [setContainer, ['@service_container']] tags: ['controller.service_arguments'] - autowire: true open_api_server.controller.store: class: OpenAPI\Server\Controller\StoreController @@ -36,8 +36,8 @@ services: - [setSerializer, ['@open_api_server.service.serializer']] - [setValidator, ['@open_api_server.service.validator']] - [setApiServer, ['@open_api_server.api.api_server']] + - [setContainer, ['@service_container']] tags: ['controller.service_arguments'] - autowire: true open_api_server.controller.user: class: OpenAPI\Server\Controller\UserController @@ -45,6 +45,6 @@ services: - [setSerializer, ['@open_api_server.service.serializer']] - [setValidator, ['@open_api_server.service.validator']] - [setApiServer, ['@open_api_server.api.api_server']] + - [setContainer, ['@service_container']] tags: ['controller.service_arguments'] - autowire: true diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md index 01bd0ee88ae7..251036f55383 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md @@ -56,7 +56,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#addPet */ - public function addPet(Pet $pet) + public function addPet(Pet $pet): array|\OpenAPI\Server\Model\Pet { // Implement the operation ... } @@ -116,7 +116,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#deletePet */ - public function deletePet($petId, $apiKey = null) + public function deletePet($petId, $apiKey = null): array|void { // Implement the operation ... } @@ -179,7 +179,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#findPetsByStatus */ - public function findPetsByStatus(array $status) + public function findPetsByStatus(array $status): iterable { // Implement the operation ... } @@ -241,7 +241,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#findPetsByTags */ - public function findPetsByTags(array $tags) + public function findPetsByTags(array $tags): iterable { // Implement the operation ... } @@ -303,7 +303,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#getPetById */ - public function getPetById($petId) + public function getPetById($petId): array|\OpenAPI\Server\Model\Pet { // Implement the operation ... } @@ -363,7 +363,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#updatePet */ - public function updatePet(Pet $pet) + public function updatePet(Pet $pet): array|\OpenAPI\Server\Model\Pet { // Implement the operation ... } @@ -423,7 +423,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#updatePetWithForm */ - public function updatePetWithForm($petId, $name = null, $status = null) + public function updatePetWithForm($petId, $name = null, $status = null): array|void { // Implement the operation ... } @@ -485,7 +485,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#uploadFile */ - public function uploadFile($petId, $additionalMetadata = null, UploadedFile $file = null) + public function uploadFile($petId, $additionalMetadata = null, UploadedFile $file = null): array|\OpenAPI\Server\Model\ApiResponse { // Implement the operation ... } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md index 3d3e3b18c3ef..3323108a4779 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md @@ -46,7 +46,7 @@ class StoreApi implements StoreApiInterface /** * Implementation of StoreApiInterface#deleteOrder */ - public function deleteOrder($orderId) + public function deleteOrder($orderId): array|void { // Implement the operation ... } @@ -108,7 +108,7 @@ class StoreApi implements StoreApiInterface /** * Implementation of StoreApiInterface#getInventory */ - public function getInventory() + public function getInventory(): array|\int { // Implement the operation ... } @@ -159,7 +159,7 @@ class StoreApi implements StoreApiInterface /** * Implementation of StoreApiInterface#getOrderById */ - public function getOrderById($orderId) + public function getOrderById($orderId): array|\OpenAPI\Server\Model\Order { // Implement the operation ... } @@ -211,7 +211,7 @@ class StoreApi implements StoreApiInterface /** * Implementation of StoreApiInterface#placeOrder */ - public function placeOrder(Order $order) + public function placeOrder(Order $order): array|\OpenAPI\Server\Model\Order { // Implement the operation ... } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md index c00ce7309a8e..5c98ee2a4f74 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md @@ -58,7 +58,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#createUser */ - public function createUser(User $user) + public function createUser(User $user): array|void { // Implement the operation ... } @@ -118,7 +118,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#createUsersWithArrayInput */ - public function createUsersWithArrayInput(array $user) + public function createUsersWithArrayInput(array $user): array|void { // Implement the operation ... } @@ -178,7 +178,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#createUsersWithListInput */ - public function createUsersWithListInput(array $user) + public function createUsersWithListInput(array $user): array|void { // Implement the operation ... } @@ -240,7 +240,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#deleteUser */ - public function deleteUser($username) + public function deleteUser($username): array|void { // Implement the operation ... } @@ -292,7 +292,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#getUserByName */ - public function getUserByName($username) + public function getUserByName($username): array|\OpenAPI\Server\Model\User { // Implement the operation ... } @@ -344,7 +344,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#loginUser */ - public function loginUser($username, $password) + public function loginUser($username, $password): array|\string { // Implement the operation ... } @@ -405,7 +405,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#logoutUser */ - public function logoutUser() + public function logoutUser(): array|void { // Implement the operation ... } @@ -464,7 +464,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#updateUser */ - public function updateUser($username, User $user) + public function updateUser($username, User $user): array|void { // Implement the operation ... } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php index 7c8c1e1339a9..360f8253a56d 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php @@ -5,7 +5,10 @@ use JMS\Serializer\SerializerBuilder; use JMS\Serializer\Naming\CamelCaseNamingStrategy; use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; +use JMS\Serializer\Visitor\Factory\XmlDeserializationVisitorFactory; use JMS\Serializer\XmlDeserializationVisitor; +use DateTime; +use RuntimeException; class JmsSerializer implements SerializerInterface { @@ -13,10 +16,11 @@ class JmsSerializer implements SerializerInterface public function __construct() { - $naming_strategy = new SerializedNameAnnotationStrategy(new CamelCaseNamingStrategy()); + $namingStrategy = new SerializedNameAnnotationStrategy(new CamelCaseNamingStrategy()); $this->serializer = SerializerBuilder::create() - ->setDeserializationVisitor('json', new StrictJsonDeserializationVisitor($naming_strategy)) - ->setDeserializationVisitor('xml', new XmlDeserializationVisitor($naming_strategy)) + ->setDeserializationVisitor('json', new StrictJsonDeserializationVisitorFactory()) + ->setDeserializationVisitor('xml', new XmlDeserializationVisitorFactory()) + ->setPropertyNamingStrategy($namingStrategy) ->build(); } @@ -79,6 +83,11 @@ private function deserializeString($data, $type) } break; + case 'DateTime': + case '\DateTime': + return new DateTime($data); + default: + throw new RuntimeException(sprintf("Type %s is unsupported", $type)); } // If we end up here, just return data diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitor.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitor.php index fbb811869a30..cdf3fb9a0141 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitor.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitor.php @@ -15,58 +15,125 @@ * limitations under the License. */ +declare(strict_types=1); + namespace OpenAPI\Server\Service; -use JMS\Serializer\Context; use JMS\Serializer\JsonDeserializationVisitor; +use JMS\Serializer\Vistor\DeserializationVisitorInterface; -class StrictJsonDeserializationVisitor extends JsonDeserializationVisitor +class StrictJsonDeserializationVisitor implements DeserializationVisitorInterface { + protected $jsonDeserializationVisitor; + + public function __construct( + int $options = 0, + int $depth = 512 + ) { + $this->jsonDeserializationVisitor = new JsonDeserializationVisitor($options, $depth); + } + + /** + * {@inheritdoc} + */ + public function visitNull($data, array $type) + { + return $this->jsonDeserializationVisitor->visitNull($data, $type); + } + /** * {@inheritdoc} */ - public function visitString($data, array $type, Context $context) + public function visitString($data, array $type): string { if (!is_string($data)) { - throw TypeMismatchException::fromValue('string', $data, $context); + throw TypeMismatchException::fromValue('string', $data); } - return parent::visitString($data, $type, $context); + return $this->jsonDeserializationVisitor->visitString($data, $type); } /** * {@inheritdoc} */ - public function visitBoolean($data, array $type, Context $context) + public function visitBoolean($data, array $type): bool { if (!is_bool($data)) { - throw TypeMismatchException::fromValue('boolean', $data, $context); + throw TypeMismatchException::fromValue('boolean', $data); } - return parent::visitBoolean($data, $type, $context); + return $this->jsonDeserializationVisitor->visitBoolean($data, $type); } /** * {@inheritdoc} */ - public function visitInteger($data, array $type, Context $context) + public function visitInteger($data, array $type): int { if (!is_int($data)) { - throw TypeMismatchException::fromValue('integer', $data, $context); + throw TypeMismatchException::fromValue('integer', $data); } - return parent::visitInteger($data, $type, $context); + return $this->jsonDeserializationVisitor->visitInteger($data, $type); } /** * {@inheritdoc} */ - public function visitDouble($data, array $type, Context $context) + public function visitDouble($data, array $type): float { if (!is_float($data) && !is_integer($data)) { - throw TypeMismatchException::fromValue('double', $data, $context); + throw TypeMismatchException::fromValue('double', $data); } - return parent::visitDouble($data, $type, $context); + return $this->jsonDeserializationVisitor->visitDouble($data, $type); + } + + /** + * {@inheritdoc} + */ + public function visitArray($data, array $type): array + { + return $this->jsonDeserializationVisitor->visitArray($data, $type); + } + + /** + * {@inheritdoc} + */ + public function visitDiscriminatorMapProperty($data, ClassMetadata $metadata): string + { + return $this->jsonDeserializationVisitor->visitDiscriminatorMapProperty($data, $type); + } + + /** + * {@inheritdoc} + */ + public function startVisitingObject(ClassMetadata $metadata, object $object, array $type): void + { + return $this->jsonDeserializationVisitor->startVisitingObject($metadata, $object, $type); + } + + /** + * {@inheritdoc} + */ + public function visitProperty(PropertyMetadata $metadata, $data) + { + return $this->jsonDeserializationVisitor->visitProperty($metadata, $data); + } + + /** + * {@inheritdoc} + */ + public function endVisitingObject(ClassMetadata $metadata, $data, array $type): object + { + return $this->jsonDeserializationVisitor->endVisitingObject($metadata, $object, $type); + } + + /** + * {@inheritdoc} + */ + public function getResult($data) + { + return $this->jsonDeserializationVisitor->getResult($data); } } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitorFactory.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitorFactory.php new file mode 100644 index 000000000000..cf60b531b6d0 --- /dev/null +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitorFactory.php @@ -0,0 +1,39 @@ +options, $this->depth); + } + + public function setOptions(int $options): self + { + $this->options = $options; + + return $this; + } + + public function setDepth(int $depth): self + { + $this->depth = $depth; + + return $this; + } +} diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Controller/ControllerTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Controller/ControllerTest.php index 1c5af7a0ffc2..18671580c34e 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Controller/ControllerTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Controller/ControllerTest.php @@ -1,7 +1,7 @@ =8.0.2", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", - "symfony/validator": "*", - "jms/serializer-bundle": "^2.0", - "symfony/framework-bundle": "^4.4.8" + "symfony/validator": "6.0.*", + "jms/serializer-bundle": "4.0.*", + "symfony/framework-bundle": "6.0.*" }, "require-dev": { - "phpunit/phpunit": "^7.0", + "phpunit/phpunit": "^9.5", "friendsofphp/php-cs-fixer": "^2.16.3", - "symfony/browser-kit": "*", - "symfony/yaml": "^4.4.8", + "symfony/browser-kit": "6.0.*", + "symfony/yaml": "6.0.*", "hoa/regex": "~1.0" }, "autoload": { - "psr-4": { "OpenAPI\\Server\\" : "./" } + "psr-4": { + "OpenAPI\\Server\\" : "./" + } } } From c37e7b26de0e5406e2350d50de1431b0bcccb6ab Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Sun, 6 Mar 2022 17:10:35 +0100 Subject: [PATCH 02/25] fix issues with StrictJsonDeserialization --- .../StrictJsonDeserializationVisitor.mustache | 26 ++++++++++++++++--- ...JsonDeserializationVisitorFactory.mustache | 1 + 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitor.mustache b/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitor.mustache index d2e6ef6fc4b4..e48ba1eb369c 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitor.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitor.mustache @@ -20,7 +20,10 @@ declare(strict_types=1); namespace {{servicePackage}}; use JMS\Serializer\JsonDeserializationVisitor; -use JMS\Serializer\Vistor\DeserializationVisitorInterface; +use JMS\Serializer\GraphNavigatorInterface; +use JMS\Serializer\Metadata\ClassMetadata; +use JMS\Serializer\Metadata\PropertyMetadata; +use JMS\Serializer\Visitor\DeserializationVisitorInterface; class StrictJsonDeserializationVisitor implements DeserializationVisitorInterface { @@ -110,7 +113,7 @@ class StrictJsonDeserializationVisitor implements DeserializationVisitorInterfac */ public function startVisitingObject(ClassMetadata $metadata, object $object, array $type): void { - return $this->jsonDeserializationVisitor->startVisitingObject($metadata, $object, $type); + $this->jsonDeserializationVisitor->startVisitingObject($metadata, $object, $type); } /** @@ -126,7 +129,7 @@ class StrictJsonDeserializationVisitor implements DeserializationVisitorInterfac */ public function endVisitingObject(ClassMetadata $metadata, $data, array $type): object { - return $this->jsonDeserializationVisitor->endVisitingObject($metadata, $object, $type); + return $this->jsonDeserializationVisitor->endVisitingObject($metadata, $data, $type); } /** @@ -136,4 +139,21 @@ class StrictJsonDeserializationVisitor implements DeserializationVisitorInterfac { return $this->jsonDeserializationVisitor->getResult($data); } + + /** + * {@inheritdoc} + */ + public function prepare($data) + { + return $this->jsonDeserializationVisitor->prepare($data); + } + + /** + * {@inheritdoc} + */ + public function setNavigator(GraphNavigatorInterface $navigator): void + { + $this->jsonDeserializationVisitor->setNavigator($navigator); + } + } diff --git a/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitorFactory.mustache b/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitorFactory.mustache index df09f0c41028..8e6ef4ed1eef 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitorFactory.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitorFactory.mustache @@ -5,6 +5,7 @@ declare(strict_types=1); namespace {{servicePackage}}; use JMS\Serializer\Visitor\DeserializationVisitorInterface; +use JMS\Serializer\Visitor\Factory\DeserializationVisitorFactory; final class StrictJsonDeserializationVisitorFactory implements DeserializationVisitorFactory { From b3ce222f5b9c689981a55cfbfd7c1802dfe796ff Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Sun, 6 Mar 2022 17:48:49 +0100 Subject: [PATCH 03/25] regenerate samples --- .../StrictJsonDeserializationVisitor.php | 26 ++++++++++++++++--- ...trictJsonDeserializationVisitorFactory.php | 1 + 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitor.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitor.php index cdf3fb9a0141..a7ce0d92b918 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitor.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitor.php @@ -20,7 +20,10 @@ namespace OpenAPI\Server\Service; use JMS\Serializer\JsonDeserializationVisitor; -use JMS\Serializer\Vistor\DeserializationVisitorInterface; +use JMS\Serializer\GraphNavigatorInterface; +use JMS\Serializer\Metadata\ClassMetadata; +use JMS\Serializer\Metadata\PropertyMetadata; +use JMS\Serializer\Visitor\DeserializationVisitorInterface; class StrictJsonDeserializationVisitor implements DeserializationVisitorInterface { @@ -110,7 +113,7 @@ public function visitDiscriminatorMapProperty($data, ClassMetadata $metadata): s */ public function startVisitingObject(ClassMetadata $metadata, object $object, array $type): void { - return $this->jsonDeserializationVisitor->startVisitingObject($metadata, $object, $type); + $this->jsonDeserializationVisitor->startVisitingObject($metadata, $object, $type); } /** @@ -126,7 +129,7 @@ public function visitProperty(PropertyMetadata $metadata, $data) */ public function endVisitingObject(ClassMetadata $metadata, $data, array $type): object { - return $this->jsonDeserializationVisitor->endVisitingObject($metadata, $object, $type); + return $this->jsonDeserializationVisitor->endVisitingObject($metadata, $data, $type); } /** @@ -136,4 +139,21 @@ public function getResult($data) { return $this->jsonDeserializationVisitor->getResult($data); } + + /** + * {@inheritdoc} + */ + public function prepare($data) + { + return $this->jsonDeserializationVisitor->prepare($data); + } + + /** + * {@inheritdoc} + */ + public function setNavigator(GraphNavigatorInterface $navigator): void + { + $this->jsonDeserializationVisitor->setNavigator($navigator); + } + } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitorFactory.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitorFactory.php index cf60b531b6d0..cab688be182f 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitorFactory.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitorFactory.php @@ -5,6 +5,7 @@ namespace OpenAPI\Server\Service; use JMS\Serializer\Visitor\DeserializationVisitorInterface; +use JMS\Serializer\Visitor\Factory\DeserializationVisitorFactory; final class StrictJsonDeserializationVisitorFactory implements DeserializationVisitorFactory { From b282ff4151af76c810a4d4a0b0ec9574ab84269c Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Tue, 29 Mar 2022 19:39:52 +0200 Subject: [PATCH 04/25] add suggestions --- .../php-symfony/serialization/JmsSerializer.mustache | 1 - .../StrictJsonDeserializationVisitor.mustache | 8 ++++---- .../StrictJsonDeserializationVisitorFactory.mustache | 12 +++--------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php-symfony/serialization/JmsSerializer.mustache b/modules/openapi-generator/src/main/resources/php-symfony/serialization/JmsSerializer.mustache index 54a959f2d64e..dc352aedc81e 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/serialization/JmsSerializer.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/serialization/JmsSerializer.mustache @@ -6,7 +6,6 @@ use JMS\Serializer\SerializerBuilder; use JMS\Serializer\Naming\CamelCaseNamingStrategy; use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; use JMS\Serializer\Visitor\Factory\XmlDeserializationVisitorFactory; -use JMS\Serializer\XmlDeserializationVisitor; use DateTime; use RuntimeException; diff --git a/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitor.mustache b/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitor.mustache index e48ba1eb369c..9c279d2ed321 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitor.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitor.mustache @@ -27,7 +27,7 @@ use JMS\Serializer\Visitor\DeserializationVisitorInterface; class StrictJsonDeserializationVisitor implements DeserializationVisitorInterface { - protected $jsonDeserializationVisitor; + protected $jsonDeserializationVisitor: JsonDeserializationVisitor; public function __construct( int $options = 0, @@ -105,15 +105,15 @@ class StrictJsonDeserializationVisitor implements DeserializationVisitorInterfac */ public function visitDiscriminatorMapProperty($data, ClassMetadata $metadata): string { - return $this->jsonDeserializationVisitor->visitDiscriminatorMapProperty($data, $type); + return $this->jsonDeserializationVisitor->visitDiscriminatorMapProperty($data, $metadata); } /** * {@inheritdoc} */ - public function startVisitingObject(ClassMetadata $metadata, object $object, array $type): void + public function startVisitingObject(ClassMetadata $metadata, object $data, array $type): void { - $this->jsonDeserializationVisitor->startVisitingObject($metadata, $object, $type); + $this->jsonDeserializationVisitor->startVisitingObject($metadata, $data, $type); } /** diff --git a/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitorFactory.mustache b/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitorFactory.mustache index 8e6ef4ed1eef..b86a5a7d41f2 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitorFactory.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitorFactory.mustache @@ -9,15 +9,9 @@ use JMS\Serializer\Visitor\Factory\DeserializationVisitorFactory; final class StrictJsonDeserializationVisitorFactory implements DeserializationVisitorFactory { - /** - * @var int - */ - private $options = 0; - - /** - * @var int - */ - private $depth = 512; + private int $options = 0; + + private int $depth = 512; public function getVisitor(): DeserializationVisitorInterface { From ddcd3e31d4e7f897a0058d8ec056dfd169e4261a Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Tue, 29 Mar 2022 20:21:05 +0200 Subject: [PATCH 05/25] update samples --- .../SymfonyBundle-php/Service/JmsSerializer.php | 1 - .../Service/StrictJsonDeserializationVisitor.php | 8 ++++---- .../StrictJsonDeserializationVisitorFactory.php | 12 +++--------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php index 360f8253a56d..0ef6b708e9d7 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php @@ -6,7 +6,6 @@ use JMS\Serializer\Naming\CamelCaseNamingStrategy; use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; use JMS\Serializer\Visitor\Factory\XmlDeserializationVisitorFactory; -use JMS\Serializer\XmlDeserializationVisitor; use DateTime; use RuntimeException; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitor.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitor.php index a7ce0d92b918..62fee4cc7a49 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitor.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitor.php @@ -27,7 +27,7 @@ class StrictJsonDeserializationVisitor implements DeserializationVisitorInterface { - protected $jsonDeserializationVisitor; + protected $jsonDeserializationVisitor: JsonDeserializationVisitor; public function __construct( int $options = 0, @@ -105,15 +105,15 @@ public function visitArray($data, array $type): array */ public function visitDiscriminatorMapProperty($data, ClassMetadata $metadata): string { - return $this->jsonDeserializationVisitor->visitDiscriminatorMapProperty($data, $type); + return $this->jsonDeserializationVisitor->visitDiscriminatorMapProperty($data, $metadata); } /** * {@inheritdoc} */ - public function startVisitingObject(ClassMetadata $metadata, object $object, array $type): void + public function startVisitingObject(ClassMetadata $metadata, object $data, array $type): void { - $this->jsonDeserializationVisitor->startVisitingObject($metadata, $object, $type); + $this->jsonDeserializationVisitor->startVisitingObject($metadata, $data, $type); } /** diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitorFactory.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitorFactory.php index cab688be182f..8e6977f6b85d 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitorFactory.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitorFactory.php @@ -9,15 +9,9 @@ final class StrictJsonDeserializationVisitorFactory implements DeserializationVisitorFactory { - /** - * @var int - */ - private $options = 0; - - /** - * @var int - */ - private $depth = 512; + private int $options = 0; + + private int $depth = 512; public function getVisitor(): DeserializationVisitorInterface { From 5804252d0b94bfe3ef5f0b2e1eafd985b032c4ba Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Tue, 29 Mar 2022 20:29:02 +0200 Subject: [PATCH 06/25] support php 7.4 and symfony 5 --- .../src/main/resources/php-symfony/composer.mustache | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php-symfony/composer.mustache b/modules/openapi-generator/src/main/resources/php-symfony/composer.mustache index 81e3e46eba99..c2e79c047d85 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/composer.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/composer.mustache @@ -19,19 +19,19 @@ } ], "require": { - "php": ">=8.0.2", + "php": ">=7.4.0|>=8.0.2", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", - "symfony/validator": "6.0.*", + "symfony/validator": "5.*|6.0.*", "jms/serializer-bundle": "4.0.*", - "symfony/framework-bundle": "6.0.*" + "symfony/framework-bundle": "5.*|6.0.*" }, "require-dev": { "phpunit/phpunit": "^9.5", "friendsofphp/php-cs-fixer": "^2.16.3", - "symfony/browser-kit": "6.0.*", - "symfony/yaml": "6.0.*", + "symfony/browser-kit": "5.*|6.0.*", + "symfony/yaml": "5.*|6.0.*", "hoa/regex": "~1.0" }, "autoload": { From de50943c2aa9c3ce20300267caf9311c1f27e89c Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Tue, 29 Mar 2022 20:34:57 +0200 Subject: [PATCH 07/25] allow versions based on semantic versioning --- .../src/main/resources/php-symfony/composer.mustache | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php-symfony/composer.mustache b/modules/openapi-generator/src/main/resources/php-symfony/composer.mustache index c2e79c047d85..b337e44bb824 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/composer.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/composer.mustache @@ -23,15 +23,15 @@ "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", - "symfony/validator": "5.*|6.0.*", - "jms/serializer-bundle": "4.0.*", - "symfony/framework-bundle": "5.*|6.0.*" + "symfony/validator": "^5.0|^6.0", + "jms/serializer-bundle": "^4.0", + "symfony/framework-bundle": "^5.0|^6.0" }, "require-dev": { "phpunit/phpunit": "^9.5", "friendsofphp/php-cs-fixer": "^2.16.3", - "symfony/browser-kit": "5.*|6.0.*", - "symfony/yaml": "5.*|6.0.*", + "symfony/browser-kit": "^5.0|^6.0", + "symfony/yaml": "^5.0|^6.0", "hoa/regex": "~1.0" }, "autoload": { From 24c5ed461574c1502c1bfc365700e5c940bbc48a Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Tue, 29 Mar 2022 20:41:53 +0200 Subject: [PATCH 08/25] regenerate sample --- .../php-symfony/SymfonyBundle-php/composer.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/composer.json b/samples/server/petstore/php-symfony/SymfonyBundle-php/composer.json index e3443feca82b..7374fe0ceca8 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/composer.json +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/composer.json @@ -16,19 +16,19 @@ } ], "require": { - "php": ">=8.0.2", + "php": ">=7.4.0|>=8.0.2", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", - "symfony/validator": "6.0.*", - "jms/serializer-bundle": "4.0.*", - "symfony/framework-bundle": "6.0.*" + "symfony/validator": "^5.0|^6.0", + "jms/serializer-bundle": "^4.0", + "symfony/framework-bundle": "^5.0|^6.0" }, "require-dev": { "phpunit/phpunit": "^9.5", "friendsofphp/php-cs-fixer": "^2.16.3", - "symfony/browser-kit": "6.0.*", - "symfony/yaml": "6.0.*", + "symfony/browser-kit": "^5.0|^6.0", + "symfony/yaml": "^5.0|^6.0", "hoa/regex": "~1.0" }, "autoload": { From 580c30c51f82ee46bcd9e15ebd65b5e7a0356045 Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Sun, 8 May 2022 10:18:40 +0200 Subject: [PATCH 09/25] change method of determining result types --- .../codegen/languages/PhpSymfonyServerCodegen.java | 10 ++++++++++ .../src/main/resources/php-symfony/api.mustache | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java index 9dbf2a37e748..7e43dce62cd2 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java @@ -431,6 +431,16 @@ public Map postProcessOperationsWithModels(Map o } else { op.vendorExtensions.put("x-comment-type", "void"); } + // Create a variable to add typing for return value of interface + if (op.returnType != null) { + if ("array".equals(op.returnContainer)) { + op.vendorExtensions.put("x-return-type", "iterable"); + } else { + op.vendorExtensions.put("x-return-type", "array|\\" + op.returnType); + } + } else { + op.vendorExtensions.put("x-return-type", "void"); + } // Add operation's authentication methods to whole interface if (op.authMethods != null) { diff --git a/modules/openapi-generator/src/main/resources/php-symfony/api.mustache b/modules/openapi-generator/src/main/resources/php-symfony/api.mustache index fc7cc173e240..236e06f02ddf 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/api.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/api.mustache @@ -67,7 +67,7 @@ interface {{classname}} * @deprecated {{/isDeprecated}} */ - public function {{operationId}}({{#allParams}}{{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{paramName}}{{^required}} = {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}}{{/required}}, {{/allParams}}&$responseCode, array &$responseHeaders): {{#isArray}}iterable{{/isArray}}{{^isArray}}array|{{{vendorExtensions.x-comment-type}}}{{/isArray}}; + public function {{operationId}}({{#allParams}}{{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{paramName}}{{^required}} = {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}}{{/required}}, {{/allParams}}&$responseCode, array &$responseHeaders): {{{vendorExtensions.x-return-type}}}; {{/operation}} } From 06fdf15d7a2fe92ebd35caabba5cc023efea4056 Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Sun, 8 May 2022 10:18:54 +0200 Subject: [PATCH 10/25] update samples --- .../SymfonyBundle-php/Api/PetApiInterface.php | 4 ++-- .../SymfonyBundle-php/Api/StoreApiInterface.php | 2 +- .../SymfonyBundle-php/Api/UserApiInterface.php | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php index e150f6119428..db3804fe511c 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php @@ -95,7 +95,7 @@ public function addPet(Pet $pet, &$responseCode, array &$responseHeaders): array * * @return void */ - public function deletePet($petId, $apiKey = null, &$responseCode, array &$responseHeaders): array|void; + public function deletePet($petId, $apiKey = null, &$responseCode, array &$responseHeaders): void; /** @@ -163,7 +163,7 @@ public function updatePet(Pet $pet, &$responseCode, array &$responseHeaders): ar * * @return void */ - public function updatePetWithForm($petId, $name = null, $status = null, &$responseCode, array &$responseHeaders): array|void; + public function updatePetWithForm($petId, $name = null, $status = null, &$responseCode, array &$responseHeaders): void; /** diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/StoreApiInterface.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/StoreApiInterface.php index 77755e0ab7d4..d5390b916f4e 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/StoreApiInterface.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/StoreApiInterface.php @@ -62,7 +62,7 @@ public function setapi_key($value); * * @return void */ - public function deleteOrder($orderId, &$responseCode, array &$responseHeaders): array|void; + public function deleteOrder($orderId, &$responseCode, array &$responseHeaders): void; /** diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/UserApiInterface.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/UserApiInterface.php index 4ab59e7de8c6..3a5df7cd4d8e 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/UserApiInterface.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/UserApiInterface.php @@ -62,7 +62,7 @@ public function setapi_key($value); * * @return void */ - public function createUser(User $user, &$responseCode, array &$responseHeaders): array|void; + public function createUser(User $user, &$responseCode, array &$responseHeaders): void; /** @@ -75,7 +75,7 @@ public function createUser(User $user, &$responseCode, array &$responseHeaders): * * @return void */ - public function createUsersWithArrayInput(array $user, &$responseCode, array &$responseHeaders): array|void; + public function createUsersWithArrayInput(array $user, &$responseCode, array &$responseHeaders): void; /** @@ -88,7 +88,7 @@ public function createUsersWithArrayInput(array $user, &$responseCode, array &$r * * @return void */ - public function createUsersWithListInput(array $user, &$responseCode, array &$responseHeaders): array|void; + public function createUsersWithListInput(array $user, &$responseCode, array &$responseHeaders): void; /** @@ -101,7 +101,7 @@ public function createUsersWithListInput(array $user, &$responseCode, array &$re * * @return void */ - public function deleteUser($username, &$responseCode, array &$responseHeaders): array|void; + public function deleteUser($username, &$responseCode, array &$responseHeaders): void; /** @@ -140,7 +140,7 @@ public function loginUser($username, $password, &$responseCode, array &$response * * @return void */ - public function logoutUser(&$responseCode, array &$responseHeaders): array|void; + public function logoutUser(&$responseCode, array &$responseHeaders): void; /** @@ -154,6 +154,6 @@ public function logoutUser(&$responseCode, array &$responseHeaders): array|void; * * @return void */ - public function updateUser($username, User $user, &$responseCode, array &$responseHeaders): array|void; + public function updateUser($username, User $user, &$responseCode, array &$responseHeaders): void; } From ca47e6292b5059e94cec148464a82eb1fdca7150 Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Sun, 8 May 2022 17:44:48 +0200 Subject: [PATCH 11/25] describe usage of bundle in symfony app --- .../resources/php-symfony/README.mustache | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php-symfony/README.mustache b/modules/openapi-generator/src/main/resources/php-symfony/README.mustache index 67e62330925c..55fe9645cf58 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/README.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/README.mustache @@ -19,7 +19,7 @@ For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) ## Requirements -PHP 8.1.1 and later +PHP 8.0 and later ## Installation & Usage @@ -56,26 +56,20 @@ composer install Step 1: Please follow the [installation procedure](#installation--usage) first. -Step 2: Enable the bundle in the kernel: +Step 2: Enable the bundle in the bundle configuration: ```php - ['all' => true], +]; ``` Step 3: Register the routes: ```yaml -# app/config/routing.yml +# app/config/routes.yaml {{bundleAlias}}: resource: "@{{bundleName}}Bundle/Resources/config/routing.yml" ``` From 9e20af400db7a3097f9d6448d55f2a9e482f93be Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Wed, 11 May 2022 20:29:00 +0200 Subject: [PATCH 12/25] better documentation --- .../src/main/resources/php-symfony/README.mustache | 7 +++---- .../src/main/resources/php-symfony/api_doc.mustache | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php-symfony/README.mustache b/modules/openapi-generator/src/main/resources/php-symfony/README.mustache index 55fe9645cf58..3ebcc0b43b0c 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/README.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/README.mustache @@ -106,7 +106,7 @@ class {{baseName}}Api implements {{classname}} // An interface is autogenerated /** * Implementation of {{classname}}#{{operationId}} */ - public function {{operationId}}({{#allParams}}{{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}): {{#isArray}}iterable{{/isArray}}{{^isArray}}array|{{{vendorExtensions.x-comment-type}}}{{/isArray}} + public function {{operationId}}({{#allParams}}{{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}, &$responseCode, array &$responseHeaders): {{#isArray}}iterable{{/isArray}}{{^isArray}}array|{{{vendorExtensions.x-comment-type}}}{{/isArray}} { // Implement the operation ... } @@ -119,11 +119,10 @@ class {{baseName}}Api implements {{classname}} // An interface is autogenerated Step 5: Tag your API implementation: ```yaml -# src/Acme/MyBundle/Resources/services.yml +# config/services.yml services: # ... - acme.my_bundle.api.{{pathPrefix}}: - class: Acme\MyBundle\Api\{{baseName}}Api + Acme\MyBundle\Api\{{baseName}}Api: tags: - { name: "{{bundleAlias}}.api", api: "{{pathPrefix}}" } # ... diff --git a/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache b/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache index d8dd843f2c76..b5823f934b19 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache @@ -11,11 +11,10 @@ Method | HTTP request | Description {{#operations}} ## Service Declaration ```yaml -# src/Acme/MyBundle/Resources/services.yml +# config/services.yml services: # ... - acme.my_bundle.api.{{pathPrefix}}: - class: Acme\MyBundle\Api\{{baseName}}Api + Acme\MyBundle\Api\{{baseName}}Api: tags: - { name: "{{bundleAlias}}.api", api: "{{pathPrefix}}" } # ... @@ -62,7 +61,7 @@ class {{baseName}}Api implements {{classname}} /** * Implementation of {{classname}}#{{operationId}} */ - public function {{operationId}}({{#allParams}}{{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}): {{#isArray}}iterable{{/isArray}}{{^isArray}}array|{{{vendorExtensions.x-comment-type}}}{{/isArray}} + public function {{operationId}}({{#allParams}}{{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}, &$responseCode, array &$responseHeaders): {{{vendorExtensions.x-return-type}}} { // Implement the operation ... } From 0dc418737b1379a30b7f22e7937819ba965c9ddb Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Thu, 12 May 2022 21:18:01 +0200 Subject: [PATCH 13/25] fix duplicate auth methods --- .../src/main/resources/php-symfony/README.mustache | 4 ++-- .../src/main/resources/php-symfony/api.mustache | 6 +++--- .../src/main/resources/php-symfony/api_controller.mustache | 6 +++--- .../src/main/resources/php-symfony/api_doc.mustache | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php-symfony/README.mustache b/modules/openapi-generator/src/main/resources/php-symfony/README.mustache index 3ebcc0b43b0c..340bedb3aa39 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/README.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/README.mustache @@ -90,7 +90,7 @@ class {{baseName}}Api implements {{classname}} // An interface is autogenerated /** * Configure API key authorization: {{{name}}} */ - public function set{{name}}($apiKey) + public function set_api_key_auth($apiKey) { // Retrieve logged in user from $apiKey ... } @@ -98,7 +98,7 @@ class {{baseName}}Api implements {{classname}} // An interface is autogenerated /** * Configure OAuth2 access token for authorization: {{{name}}} */ - public function set{{name}}($oauthToken) + public function set_oAuth_auth($oauthToken) { // Retrieve logged in user from $oauthToken ... } diff --git a/modules/openapi-generator/src/main/resources/php-symfony/api.mustache b/modules/openapi-generator/src/main/resources/php-symfony/api.mustache index 236e06f02ddf..35b0543f738c 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/api.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/api.mustache @@ -36,13 +36,13 @@ interface {{classname}} {{#authMethods}} /** - * Sets authentication method {{name}} + * Sets authentication method {{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}} * - * @param string $value Value of the {{name}} authentication method. + * @param string $value Value of the {{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}} authentication method. * * @return void */ - public function set{{name}}($value); + public function set_{{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}}_auth($value); {{/authMethods}} {{#operation}} diff --git a/modules/openapi-generator/src/main/resources/php-symfony/api_controller.mustache b/modules/openapi-generator/src/main/resources/php-symfony/api_controller.mustache index 219343cd5b5a..8cb2807128f7 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/api_controller.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/api_controller.mustache @@ -82,7 +82,7 @@ class {{controllerName}} extends Controller {{/returnType}} // Handle authentication {{#authMethods}} - // Authentication '{{name}}' required + // Authentication '{{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}}' required {{#isApiKey}} {{#isKeyInHeader}} // Set key with prefix in header @@ -168,8 +168,8 @@ class {{controllerName}} extends Controller $handler = $this->getApiHandler(); {{#authMethods}} - // Set authentication method '{{name}}' - $handler->set{{name}}($security{{name}}); + // Set authentication method '{{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}}' + $handler->set_{{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}}_auth($security{{name}}); {{/authMethods}} // Make the call to the business logic diff --git a/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache b/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache index b5823f934b19..067b4c7c9faf 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache @@ -43,7 +43,7 @@ class {{baseName}}Api implements {{classname}} /** * Configure API key authorization: {{{name}}} */ - public function set{{name}}($apiKey) + public function set_api_key_auth($apiKey) { // Retrieve logged in user from $apiKey ... } @@ -51,7 +51,7 @@ class {{baseName}}Api implements {{classname}} /** * Configure OAuth2 access token for authorization: {{{name}}} */ - public function set{{name}}($oauthToken) + public function set_oAuth_auth($oauthToken) { // Retrieve logged in user from $oauthToken ... } From f4e6744721073c1c34d4e2ac165a4165c971bf15 Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Thu, 12 May 2022 21:29:48 +0200 Subject: [PATCH 14/25] do not set namespace for default types --- .../codegen/languages/PhpSymfonyServerCodegen.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java index 7e43dce62cd2..a8ad1609ba2f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java @@ -436,7 +436,12 @@ public Map postProcessOperationsWithModels(Map o if ("array".equals(op.returnContainer)) { op.vendorExtensions.put("x-return-type", "iterable"); } else { - op.vendorExtensions.put("x-return-type", "array|\\" + op.returnType); + if (defaultIncludes.contains(type)) { + op.vendorExtensions.put("x-return-type", "array|" + op.returnType); + } + else { + op.vendorExtensions.put("x-return-type", "array|\\" + op.returnType); + } } } else { op.vendorExtensions.put("x-return-type", "void"); From 0140c47bcf8b52303d1af72208e0288128d0d214 Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Sat, 14 May 2022 13:17:52 +0200 Subject: [PATCH 15/25] fix UploadedFile type --- .../openapitools/codegen/languages/PhpSymfonyServerCodegen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java index a8ad1609ba2f..c6630c3160e7 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java @@ -436,7 +436,7 @@ public Map postProcessOperationsWithModels(Map o if ("array".equals(op.returnContainer)) { op.vendorExtensions.put("x-return-type", "iterable"); } else { - if (defaultIncludes.contains(type)) { + if (defaultIncludes.contains(op.returnType)) { op.vendorExtensions.put("x-return-type", "array|" + op.returnType); } else { From f37afb9c7c27fc6e6ce922cb8012dea3f17f5107 Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Sat, 14 May 2022 13:18:32 +0200 Subject: [PATCH 16/25] next try fixing auth --- .../src/main/resources/php-symfony/api.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/php-symfony/api.mustache b/modules/openapi-generator/src/main/resources/php-symfony/api.mustache index 35b0543f738c..289c1ce2d660 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/api.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/api.mustache @@ -42,7 +42,7 @@ interface {{classname}} * * @return void */ - public function set_{{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}}_auth($value); + public function set_{{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}}_{{name}}($value); {{/authMethods}} {{#operation}} From acbe959af976308deae2d8b10827e3b3e55e3d03 Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Sat, 14 May 2022 13:18:44 +0200 Subject: [PATCH 17/25] regenerate samples --- .../SymfonyBundle-php/Api/PetApiInterface.php | 14 +++--- .../Api/StoreApiInterface.php | 2 +- .../Api/UserApiInterface.php | 2 +- .../Controller/PetController.php | 44 +++++++++---------- .../Controller/StoreController.php | 2 +- .../Controller/UserController.php | 12 ++--- .../php-symfony/SymfonyBundle-php/README.md | 31 +++++-------- .../Resources/docs/Api/PetApiInterface.md | 37 ++++++++-------- .../Resources/docs/Api/StoreApiInterface.md | 15 +++---- .../Resources/docs/Api/UserApiInterface.md | 33 +++++++------- 10 files changed, 91 insertions(+), 101 deletions(-) diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php index db3804fe511c..babfe4377f67 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php @@ -45,22 +45,22 @@ interface PetApiInterface { /** - * Sets authentication method petstore_auth + * Sets authentication method oAuth * - * @param string $value Value of the petstore_auth authentication method. + * @param string $value Value of the oAuth authentication method. * * @return void */ - public function setpetstore_auth($value); + public function set_oAuth_petstore_auth($value); /** - * Sets authentication method petstore_auth + * Sets authentication method oAuth * - * @param string $value Value of the petstore_auth authentication method. + * @param string $value Value of the oAuth authentication method. * * @return void */ - public function setpetstore_auth($value); + public function set_oAuth_petstore_auth($value); /** * Sets authentication method api_key @@ -69,7 +69,7 @@ public function setpetstore_auth($value); * * @return void */ - public function setapi_key($value); + public function set_api_key_api_key($value); /** * Operation addPet diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/StoreApiInterface.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/StoreApiInterface.php index d5390b916f4e..2eb30fd11037 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/StoreApiInterface.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/StoreApiInterface.php @@ -50,7 +50,7 @@ interface StoreApiInterface * * @return void */ - public function setapi_key($value); + public function set_api_key_api_key($value); /** * Operation deleteOrder diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/UserApiInterface.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/UserApiInterface.php index 3a5df7cd4d8e..6f427225a339 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/UserApiInterface.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/UserApiInterface.php @@ -50,7 +50,7 @@ interface UserApiInterface * * @return void */ - public function setapi_key($value); + public function set_api_key_api_key($value); /** * Operation createUser diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php index 8b1cd18657f9..4fb6d07d5cf9 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php @@ -77,7 +77,7 @@ public function addPetAction(Request $request) } // Handle authentication - // Authentication 'petstore_auth' required + // Authentication 'oAuth' required // Oauth required $securitypetstore_auth = $request->headers->get('authorization'); @@ -108,8 +108,8 @@ public function addPetAction(Request $request) try { $handler = $this->getApiHandler(); - // Set authentication method 'petstore_auth' - $handler->setpetstore_auth($securitypetstore_auth); + // Set authentication method 'oAuth' + $handler->set_oAuth_auth($securitypetstore_auth); // Make the call to the business logic $responseCode = 200; @@ -156,7 +156,7 @@ public function addPetAction(Request $request) public function deletePetAction(Request $request, $petId) { // Handle authentication - // Authentication 'petstore_auth' required + // Authentication 'oAuth' required // Oauth required $securitypetstore_auth = $request->headers->get('authorization'); @@ -192,8 +192,8 @@ public function deletePetAction(Request $request, $petId) try { $handler = $this->getApiHandler(); - // Set authentication method 'petstore_auth' - $handler->setpetstore_auth($securitypetstore_auth); + // Set authentication method 'oAuth' + $handler->set_oAuth_auth($securitypetstore_auth); // Make the call to the business logic $responseCode = 204; @@ -245,7 +245,7 @@ public function findPetsByStatusAction(Request $request) } // Handle authentication - // Authentication 'petstore_auth' required + // Authentication 'oAuth' required // Oauth required $securitypetstore_auth = $request->headers->get('authorization'); @@ -280,8 +280,8 @@ public function findPetsByStatusAction(Request $request) try { $handler = $this->getApiHandler(); - // Set authentication method 'petstore_auth' - $handler->setpetstore_auth($securitypetstore_auth); + // Set authentication method 'oAuth' + $handler->set_oAuth_auth($securitypetstore_auth); // Make the call to the business logic $responseCode = 200; @@ -338,7 +338,7 @@ public function findPetsByTagsAction(Request $request) } // Handle authentication - // Authentication 'petstore_auth' required + // Authentication 'oAuth' required // Oauth required $securitypetstore_auth = $request->headers->get('authorization'); @@ -370,8 +370,8 @@ public function findPetsByTagsAction(Request $request) try { $handler = $this->getApiHandler(); - // Set authentication method 'petstore_auth' - $handler->setpetstore_auth($securitypetstore_auth); + // Set authentication method 'oAuth' + $handler->set_oAuth_auth($securitypetstore_auth); // Make the call to the business logic $responseCode = 200; @@ -456,7 +456,7 @@ public function getPetByIdAction(Request $request, $petId) $handler = $this->getApiHandler(); // Set authentication method 'api_key' - $handler->setapi_key($securityapi_key); + $handler->set_api_key_auth($securityapi_key); // Make the call to the business logic $responseCode = 200; @@ -522,7 +522,7 @@ public function updatePetAction(Request $request) } // Handle authentication - // Authentication 'petstore_auth' required + // Authentication 'oAuth' required // Oauth required $securitypetstore_auth = $request->headers->get('authorization'); @@ -553,8 +553,8 @@ public function updatePetAction(Request $request) try { $handler = $this->getApiHandler(); - // Set authentication method 'petstore_auth' - $handler->setpetstore_auth($securitypetstore_auth); + // Set authentication method 'oAuth' + $handler->set_oAuth_auth($securitypetstore_auth); // Make the call to the business logic $responseCode = 200; @@ -607,7 +607,7 @@ public function updatePetAction(Request $request) public function updatePetWithFormAction(Request $request, $petId) { // Handle authentication - // Authentication 'petstore_auth' required + // Authentication 'oAuth' required // Oauth required $securitypetstore_auth = $request->headers->get('authorization'); @@ -651,8 +651,8 @@ public function updatePetWithFormAction(Request $request, $petId) try { $handler = $this->getApiHandler(); - // Set authentication method 'petstore_auth' - $handler->setpetstore_auth($securitypetstore_auth); + // Set authentication method 'oAuth' + $handler->set_oAuth_auth($securitypetstore_auth); // Make the call to the business logic $responseCode = 204; @@ -704,7 +704,7 @@ public function uploadFileAction(Request $request, $petId) } // Handle authentication - // Authentication 'petstore_auth' required + // Authentication 'oAuth' required // Oauth required $securitypetstore_auth = $request->headers->get('authorization'); @@ -747,8 +747,8 @@ public function uploadFileAction(Request $request, $petId) try { $handler = $this->getApiHandler(); - // Set authentication method 'petstore_auth' - $handler->setpetstore_auth($securitypetstore_auth); + // Set authentication method 'oAuth' + $handler->set_oAuth_auth($securitypetstore_auth); // Make the call to the business logic $responseCode = 200; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php index 7ae4ba95a925..03f7035a16e4 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php @@ -154,7 +154,7 @@ public function getInventoryAction(Request $request) $handler = $this->getApiHandler(); // Set authentication method 'api_key' - $handler->setapi_key($securityapi_key); + $handler->set_api_key_auth($securityapi_key); // Make the call to the business logic $responseCode = 200; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php index ce07da883e30..c1452d616316 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php @@ -99,7 +99,7 @@ public function createUserAction(Request $request) $handler = $this->getApiHandler(); // Set authentication method 'api_key' - $handler->setapi_key($securityapi_key); + $handler->set_api_key_auth($securityapi_key); // Make the call to the business logic $responseCode = 204; @@ -183,7 +183,7 @@ public function createUsersWithArrayInputAction(Request $request) $handler = $this->getApiHandler(); // Set authentication method 'api_key' - $handler->setapi_key($securityapi_key); + $handler->set_api_key_auth($securityapi_key); // Make the call to the business logic $responseCode = 204; @@ -267,7 +267,7 @@ public function createUsersWithListInputAction(Request $request) $handler = $this->getApiHandler(); // Set authentication method 'api_key' - $handler->setapi_key($securityapi_key); + $handler->set_api_key_auth($securityapi_key); // Make the call to the business logic $responseCode = 204; @@ -339,7 +339,7 @@ public function deleteUserAction(Request $request, $username) $handler = $this->getApiHandler(); // Set authentication method 'api_key' - $handler->setapi_key($securityapi_key); + $handler->set_api_key_auth($securityapi_key); // Make the call to the business logic $responseCode = 204; @@ -574,7 +574,7 @@ public function logoutUserAction(Request $request) $handler = $this->getApiHandler(); // Set authentication method 'api_key' - $handler->setapi_key($securityapi_key); + $handler->set_api_key_auth($securityapi_key); // Make the call to the business logic $responseCode = 204; @@ -664,7 +664,7 @@ public function updateUserAction(Request $request, $username) $handler = $this->getApiHandler(); // Set authentication method 'api_key' - $handler->setapi_key($securityapi_key); + $handler->set_api_key_auth($securityapi_key); // Make the call to the business logic $responseCode = 204; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md index bbd8488f3ab1..16e6867de323 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md @@ -8,7 +8,7 @@ This [Symfony](https://symfony.com/) bundle is automatically generated by the [O ## Requirements -PHP 8.1.1 and later +PHP 8.0 and later ## Installation & Usage @@ -45,26 +45,20 @@ composer install Step 1: Please follow the [installation procedure](#installation--usage) first. -Step 2: Enable the bundle in the kernel: +Step 2: Enable the bundle in the bundle configuration: ```php - ['all' => true], +]; ``` Step 3: Register the routes: ```yaml -# app/config/routing.yml +# app/config/routes.yaml open_api_server: resource: "@OpenAPIServerBundle/Resources/config/routing.yml" ``` @@ -85,7 +79,7 @@ class PetApi implements PetApiInterface // An interface is autogenerated /** * Configure OAuth2 access token for authorization: petstore_auth */ - public function setpetstore_auth($oauthToken) + public function set_oAuth_auth($oauthToken) { // Retrieve logged in user from $oauthToken ... } @@ -93,7 +87,7 @@ class PetApi implements PetApiInterface // An interface is autogenerated /** * Implementation of PetApiInterface#addPet */ - public function addPet(Pet $pet): array|\OpenAPI\Server\Model\Pet + public function addPet(Pet $pet, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet { // Implement the operation ... } @@ -105,11 +99,10 @@ class PetApi implements PetApiInterface // An interface is autogenerated Step 5: Tag your API implementation: ```yaml -# src/Acme/MyBundle/Resources/services.yml +# config/services.yml services: # ... - acme.my_bundle.api.pet: - class: Acme\MyBundle\Api\PetApi + Acme\MyBundle\Api\PetApi: tags: - { name: "open_api_server.api", api: "pet" } # ... diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md index 251036f55383..467d43622220 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md @@ -16,11 +16,10 @@ Method | HTTP request | Description ## Service Declaration ```yaml -# src/Acme/MyBundle/Resources/services.yml +# config/services.yml services: # ... - acme.my_bundle.api.pet: - class: Acme\MyBundle\Api\PetApi + Acme\MyBundle\Api\PetApi: tags: - { name: "open_api_server.api", api: "pet" } # ... @@ -46,7 +45,7 @@ class PetApi implements PetApiInterface /** * Configure OAuth2 access token for authorization: petstore_auth */ - public function setpetstore_auth($oauthToken) + public function set_oAuth_auth($oauthToken) { // Retrieve logged in user from $oauthToken ... } @@ -56,7 +55,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#addPet */ - public function addPet(Pet $pet): array|\OpenAPI\Server\Model\Pet + public function addPet(Pet $pet, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet { // Implement the operation ... } @@ -106,7 +105,7 @@ class PetApi implements PetApiInterface /** * Configure OAuth2 access token for authorization: petstore_auth */ - public function setpetstore_auth($oauthToken) + public function set_oAuth_auth($oauthToken) { // Retrieve logged in user from $oauthToken ... } @@ -116,7 +115,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#deletePet */ - public function deletePet($petId, $apiKey = null): array|void + public function deletePet($petId, $apiKey = null, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -169,7 +168,7 @@ class PetApi implements PetApiInterface /** * Configure OAuth2 access token for authorization: petstore_auth */ - public function setpetstore_auth($oauthToken) + public function set_oAuth_auth($oauthToken) { // Retrieve logged in user from $oauthToken ... } @@ -179,7 +178,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#findPetsByStatus */ - public function findPetsByStatus(array $status): iterable + public function findPetsByStatus(array $status, &$responseCode, array &$responseHeaders): iterable { // Implement the operation ... } @@ -231,7 +230,7 @@ class PetApi implements PetApiInterface /** * Configure OAuth2 access token for authorization: petstore_auth */ - public function setpetstore_auth($oauthToken) + public function set_oAuth_auth($oauthToken) { // Retrieve logged in user from $oauthToken ... } @@ -241,7 +240,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#findPetsByTags */ - public function findPetsByTags(array $tags): iterable + public function findPetsByTags(array $tags, &$responseCode, array &$responseHeaders): iterable { // Implement the operation ... } @@ -293,7 +292,7 @@ class PetApi implements PetApiInterface /** * Configure API key authorization: api_key */ - public function setapi_key($apiKey) + public function set_api_key_auth($apiKey) { // Retrieve logged in user from $apiKey ... } @@ -303,7 +302,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#getPetById */ - public function getPetById($petId): array|\OpenAPI\Server\Model\Pet + public function getPetById($petId, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet { // Implement the operation ... } @@ -353,7 +352,7 @@ class PetApi implements PetApiInterface /** * Configure OAuth2 access token for authorization: petstore_auth */ - public function setpetstore_auth($oauthToken) + public function set_oAuth_auth($oauthToken) { // Retrieve logged in user from $oauthToken ... } @@ -363,7 +362,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#updatePet */ - public function updatePet(Pet $pet): array|\OpenAPI\Server\Model\Pet + public function updatePet(Pet $pet, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet { // Implement the operation ... } @@ -413,7 +412,7 @@ class PetApi implements PetApiInterface /** * Configure OAuth2 access token for authorization: petstore_auth */ - public function setpetstore_auth($oauthToken) + public function set_oAuth_auth($oauthToken) { // Retrieve logged in user from $oauthToken ... } @@ -423,7 +422,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#updatePetWithForm */ - public function updatePetWithForm($petId, $name = null, $status = null): array|void + public function updatePetWithForm($petId, $name = null, $status = null, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -475,7 +474,7 @@ class PetApi implements PetApiInterface /** * Configure OAuth2 access token for authorization: petstore_auth */ - public function setpetstore_auth($oauthToken) + public function set_oAuth_auth($oauthToken) { // Retrieve logged in user from $oauthToken ... } @@ -485,7 +484,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#uploadFile */ - public function uploadFile($petId, $additionalMetadata = null, UploadedFile $file = null): array|\OpenAPI\Server\Model\ApiResponse + public function uploadFile($petId, $additionalMetadata = null, UploadedFile $file = null, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\ApiResponse { // Implement the operation ... } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md index 3323108a4779..c9c108dcf8d3 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md @@ -12,11 +12,10 @@ Method | HTTP request | Description ## Service Declaration ```yaml -# src/Acme/MyBundle/Resources/services.yml +# config/services.yml services: # ... - acme.my_bundle.api.store: - class: Acme\MyBundle\Api\StoreApi + Acme\MyBundle\Api\StoreApi: tags: - { name: "open_api_server.api", api: "store" } # ... @@ -46,7 +45,7 @@ class StoreApi implements StoreApiInterface /** * Implementation of StoreApiInterface#deleteOrder */ - public function deleteOrder($orderId): array|void + public function deleteOrder($orderId, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -98,7 +97,7 @@ class StoreApi implements StoreApiInterface /** * Configure API key authorization: api_key */ - public function setapi_key($apiKey) + public function set_api_key_auth($apiKey) { // Retrieve logged in user from $apiKey ... } @@ -108,7 +107,7 @@ class StoreApi implements StoreApiInterface /** * Implementation of StoreApiInterface#getInventory */ - public function getInventory(): array|\int + public function getInventory(, &$responseCode, array &$responseHeaders): array|\int { // Implement the operation ... } @@ -159,7 +158,7 @@ class StoreApi implements StoreApiInterface /** * Implementation of StoreApiInterface#getOrderById */ - public function getOrderById($orderId): array|\OpenAPI\Server\Model\Order + public function getOrderById($orderId, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Order { // Implement the operation ... } @@ -211,7 +210,7 @@ class StoreApi implements StoreApiInterface /** * Implementation of StoreApiInterface#placeOrder */ - public function placeOrder(Order $order): array|\OpenAPI\Server\Model\Order + public function placeOrder(Order $order, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Order { // Implement the operation ... } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md index 5c98ee2a4f74..6f7ee933803c 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md @@ -16,11 +16,10 @@ Method | HTTP request | Description ## Service Declaration ```yaml -# src/Acme/MyBundle/Resources/services.yml +# config/services.yml services: # ... - acme.my_bundle.api.user: - class: Acme\MyBundle\Api\UserApi + Acme\MyBundle\Api\UserApi: tags: - { name: "open_api_server.api", api: "user" } # ... @@ -48,7 +47,7 @@ class UserApi implements UserApiInterface /** * Configure API key authorization: api_key */ - public function setapi_key($apiKey) + public function set_api_key_auth($apiKey) { // Retrieve logged in user from $apiKey ... } @@ -58,7 +57,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#createUser */ - public function createUser(User $user): array|void + public function createUser(User $user, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -108,7 +107,7 @@ class UserApi implements UserApiInterface /** * Configure API key authorization: api_key */ - public function setapi_key($apiKey) + public function set_api_key_auth($apiKey) { // Retrieve logged in user from $apiKey ... } @@ -118,7 +117,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#createUsersWithArrayInput */ - public function createUsersWithArrayInput(array $user): array|void + public function createUsersWithArrayInput(array $user, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -168,7 +167,7 @@ class UserApi implements UserApiInterface /** * Configure API key authorization: api_key */ - public function setapi_key($apiKey) + public function set_api_key_auth($apiKey) { // Retrieve logged in user from $apiKey ... } @@ -178,7 +177,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#createUsersWithListInput */ - public function createUsersWithListInput(array $user): array|void + public function createUsersWithListInput(array $user, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -230,7 +229,7 @@ class UserApi implements UserApiInterface /** * Configure API key authorization: api_key */ - public function setapi_key($apiKey) + public function set_api_key_auth($apiKey) { // Retrieve logged in user from $apiKey ... } @@ -240,7 +239,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#deleteUser */ - public function deleteUser($username): array|void + public function deleteUser($username, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -292,7 +291,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#getUserByName */ - public function getUserByName($username): array|\OpenAPI\Server\Model\User + public function getUserByName($username, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\User { // Implement the operation ... } @@ -344,7 +343,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#loginUser */ - public function loginUser($username, $password): array|\string + public function loginUser($username, $password, &$responseCode, array &$responseHeaders): array|\string { // Implement the operation ... } @@ -395,7 +394,7 @@ class UserApi implements UserApiInterface /** * Configure API key authorization: api_key */ - public function setapi_key($apiKey) + public function set_api_key_auth($apiKey) { // Retrieve logged in user from $apiKey ... } @@ -405,7 +404,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#logoutUser */ - public function logoutUser(): array|void + public function logoutUser(, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -454,7 +453,7 @@ class UserApi implements UserApiInterface /** * Configure API key authorization: api_key */ - public function setapi_key($apiKey) + public function set_api_key_auth($apiKey) { // Retrieve logged in user from $apiKey ... } @@ -464,7 +463,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#updateUser */ - public function updateUser($username, User $user): array|void + public function updateUser($username, User $user, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } From 5a2674a898fae5bca612abaae2c16f65c526f402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renaud=20de=20Chivr=C3=A9?= Date: Mon, 16 May 2022 11:12:24 -1000 Subject: [PATCH 18/25] fix: auth method shall not be duplicated --- .../openapitools/codegen/languages/PhpSymfonyServerCodegen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java index c6630c3160e7..46337c26f351 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java @@ -450,7 +450,7 @@ public Map postProcessOperationsWithModels(Map o // Add operation's authentication methods to whole interface if (op.authMethods != null) { for (CodegenSecurity am : op.authMethods) { - if (!authMethods.contains(am)) { + if (authMethods.stream().noneMatch(m -> Objects.equals(m.name, am.name))) { authMethods.add(am); } } From 511f3119847e4ce282fcbddb9ebad31e0f5e52b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renaud=20de=20Chivr=C3=A9?= Date: Mon, 16 May 2022 11:20:13 -1000 Subject: [PATCH 19/25] Revert "fix duplicate auth methods" This reverts commit 0dc418737b1379a30b7f22e7937819ba965c9ddb. --- .../src/main/resources/php-symfony/README.mustache | 4 ++-- .../src/main/resources/php-symfony/api.mustache | 6 +++--- .../src/main/resources/php-symfony/api_controller.mustache | 6 +++--- .../src/main/resources/php-symfony/api_doc.mustache | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php-symfony/README.mustache b/modules/openapi-generator/src/main/resources/php-symfony/README.mustache index 340bedb3aa39..3ebcc0b43b0c 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/README.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/README.mustache @@ -90,7 +90,7 @@ class {{baseName}}Api implements {{classname}} // An interface is autogenerated /** * Configure API key authorization: {{{name}}} */ - public function set_api_key_auth($apiKey) + public function set{{name}}($apiKey) { // Retrieve logged in user from $apiKey ... } @@ -98,7 +98,7 @@ class {{baseName}}Api implements {{classname}} // An interface is autogenerated /** * Configure OAuth2 access token for authorization: {{{name}}} */ - public function set_oAuth_auth($oauthToken) + public function set{{name}}($oauthToken) { // Retrieve logged in user from $oauthToken ... } diff --git a/modules/openapi-generator/src/main/resources/php-symfony/api.mustache b/modules/openapi-generator/src/main/resources/php-symfony/api.mustache index 35b0543f738c..236e06f02ddf 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/api.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/api.mustache @@ -36,13 +36,13 @@ interface {{classname}} {{#authMethods}} /** - * Sets authentication method {{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}} + * Sets authentication method {{name}} * - * @param string $value Value of the {{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}} authentication method. + * @param string $value Value of the {{name}} authentication method. * * @return void */ - public function set_{{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}}_auth($value); + public function set{{name}}($value); {{/authMethods}} {{#operation}} diff --git a/modules/openapi-generator/src/main/resources/php-symfony/api_controller.mustache b/modules/openapi-generator/src/main/resources/php-symfony/api_controller.mustache index 8cb2807128f7..219343cd5b5a 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/api_controller.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/api_controller.mustache @@ -82,7 +82,7 @@ class {{controllerName}} extends Controller {{/returnType}} // Handle authentication {{#authMethods}} - // Authentication '{{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}}' required + // Authentication '{{name}}' required {{#isApiKey}} {{#isKeyInHeader}} // Set key with prefix in header @@ -168,8 +168,8 @@ class {{controllerName}} extends Controller $handler = $this->getApiHandler(); {{#authMethods}} - // Set authentication method '{{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}}' - $handler->set_{{#isBasic}}basic{{/isBasic}}{{#isApiKey}}api_key{{/isApiKey}}{{#isOAuth}}oAuth{{/isOAuth}}_auth($security{{name}}); + // Set authentication method '{{name}}' + $handler->set{{name}}($security{{name}}); {{/authMethods}} // Make the call to the business logic diff --git a/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache b/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache index 067b4c7c9faf..b5823f934b19 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache @@ -43,7 +43,7 @@ class {{baseName}}Api implements {{classname}} /** * Configure API key authorization: {{{name}}} */ - public function set_api_key_auth($apiKey) + public function set{{name}}($apiKey) { // Retrieve logged in user from $apiKey ... } @@ -51,7 +51,7 @@ class {{baseName}}Api implements {{classname}} /** * Configure OAuth2 access token for authorization: {{{name}}} */ - public function set_oAuth_auth($oauthToken) + public function set{{name}}($oauthToken) { // Retrieve logged in user from $oauthToken ... } From 2d87054ee3cd64518a8958d4e3ac42831b492b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renaud=20de=20Chivr=C3=A9?= Date: Mon, 16 May 2022 11:32:11 -1000 Subject: [PATCH 20/25] chore: regenerate samples --- .../SymfonyBundle-php/Api/PetApiInterface.php | 9 ------ .../php-symfony/SymfonyBundle-php/README.md | 29 +++++++------------ .../Resources/docs/Api/PetApiInterface.md | 21 +++++++------- .../Resources/docs/Api/StoreApiInterface.md | 13 ++++----- .../Resources/docs/Api/UserApiInterface.md | 21 +++++++------- 5 files changed, 37 insertions(+), 56 deletions(-) diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php index db3804fe511c..f344890fca40 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php @@ -53,15 +53,6 @@ interface PetApiInterface */ public function setpetstore_auth($value); - /** - * Sets authentication method petstore_auth - * - * @param string $value Value of the petstore_auth authentication method. - * - * @return void - */ - public function setpetstore_auth($value); - /** * Sets authentication method api_key * diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md index bbd8488f3ab1..a42147489214 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md @@ -8,7 +8,7 @@ This [Symfony](https://symfony.com/) bundle is automatically generated by the [O ## Requirements -PHP 8.1.1 and later +PHP 8.0 and later ## Installation & Usage @@ -45,26 +45,20 @@ composer install Step 1: Please follow the [installation procedure](#installation--usage) first. -Step 2: Enable the bundle in the kernel: +Step 2: Enable the bundle in the bundle configuration: ```php - ['all' => true], +]; ``` Step 3: Register the routes: ```yaml -# app/config/routing.yml +# app/config/routes.yaml open_api_server: resource: "@OpenAPIServerBundle/Resources/config/routing.yml" ``` @@ -93,7 +87,7 @@ class PetApi implements PetApiInterface // An interface is autogenerated /** * Implementation of PetApiInterface#addPet */ - public function addPet(Pet $pet): array|\OpenAPI\Server\Model\Pet + public function addPet(Pet $pet, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet { // Implement the operation ... } @@ -105,11 +99,10 @@ class PetApi implements PetApiInterface // An interface is autogenerated Step 5: Tag your API implementation: ```yaml -# src/Acme/MyBundle/Resources/services.yml +# config/services.yml services: # ... - acme.my_bundle.api.pet: - class: Acme\MyBundle\Api\PetApi + Acme\MyBundle\Api\PetApi: tags: - { name: "open_api_server.api", api: "pet" } # ... diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md index 251036f55383..1a3f42e6b30d 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md @@ -16,11 +16,10 @@ Method | HTTP request | Description ## Service Declaration ```yaml -# src/Acme/MyBundle/Resources/services.yml +# config/services.yml services: # ... - acme.my_bundle.api.pet: - class: Acme\MyBundle\Api\PetApi + Acme\MyBundle\Api\PetApi: tags: - { name: "open_api_server.api", api: "pet" } # ... @@ -56,7 +55,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#addPet */ - public function addPet(Pet $pet): array|\OpenAPI\Server\Model\Pet + public function addPet(Pet $pet, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet { // Implement the operation ... } @@ -116,7 +115,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#deletePet */ - public function deletePet($petId, $apiKey = null): array|void + public function deletePet($petId, $apiKey = null, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -179,7 +178,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#findPetsByStatus */ - public function findPetsByStatus(array $status): iterable + public function findPetsByStatus(array $status, &$responseCode, array &$responseHeaders): iterable { // Implement the operation ... } @@ -241,7 +240,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#findPetsByTags */ - public function findPetsByTags(array $tags): iterable + public function findPetsByTags(array $tags, &$responseCode, array &$responseHeaders): iterable { // Implement the operation ... } @@ -303,7 +302,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#getPetById */ - public function getPetById($petId): array|\OpenAPI\Server\Model\Pet + public function getPetById($petId, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet { // Implement the operation ... } @@ -363,7 +362,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#updatePet */ - public function updatePet(Pet $pet): array|\OpenAPI\Server\Model\Pet + public function updatePet(Pet $pet, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet { // Implement the operation ... } @@ -423,7 +422,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#updatePetWithForm */ - public function updatePetWithForm($petId, $name = null, $status = null): array|void + public function updatePetWithForm($petId, $name = null, $status = null, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -485,7 +484,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#uploadFile */ - public function uploadFile($petId, $additionalMetadata = null, UploadedFile $file = null): array|\OpenAPI\Server\Model\ApiResponse + public function uploadFile($petId, $additionalMetadata = null, UploadedFile $file = null, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\ApiResponse { // Implement the operation ... } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md index 3323108a4779..78d346aa0e33 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md @@ -12,11 +12,10 @@ Method | HTTP request | Description ## Service Declaration ```yaml -# src/Acme/MyBundle/Resources/services.yml +# config/services.yml services: # ... - acme.my_bundle.api.store: - class: Acme\MyBundle\Api\StoreApi + Acme\MyBundle\Api\StoreApi: tags: - { name: "open_api_server.api", api: "store" } # ... @@ -46,7 +45,7 @@ class StoreApi implements StoreApiInterface /** * Implementation of StoreApiInterface#deleteOrder */ - public function deleteOrder($orderId): array|void + public function deleteOrder($orderId, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -108,7 +107,7 @@ class StoreApi implements StoreApiInterface /** * Implementation of StoreApiInterface#getInventory */ - public function getInventory(): array|\int + public function getInventory(, &$responseCode, array &$responseHeaders): array|\int { // Implement the operation ... } @@ -159,7 +158,7 @@ class StoreApi implements StoreApiInterface /** * Implementation of StoreApiInterface#getOrderById */ - public function getOrderById($orderId): array|\OpenAPI\Server\Model\Order + public function getOrderById($orderId, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Order { // Implement the operation ... } @@ -211,7 +210,7 @@ class StoreApi implements StoreApiInterface /** * Implementation of StoreApiInterface#placeOrder */ - public function placeOrder(Order $order): array|\OpenAPI\Server\Model\Order + public function placeOrder(Order $order, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Order { // Implement the operation ... } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md index 5c98ee2a4f74..3b36fb3f48fb 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md @@ -16,11 +16,10 @@ Method | HTTP request | Description ## Service Declaration ```yaml -# src/Acme/MyBundle/Resources/services.yml +# config/services.yml services: # ... - acme.my_bundle.api.user: - class: Acme\MyBundle\Api\UserApi + Acme\MyBundle\Api\UserApi: tags: - { name: "open_api_server.api", api: "user" } # ... @@ -58,7 +57,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#createUser */ - public function createUser(User $user): array|void + public function createUser(User $user, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -118,7 +117,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#createUsersWithArrayInput */ - public function createUsersWithArrayInput(array $user): array|void + public function createUsersWithArrayInput(array $user, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -178,7 +177,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#createUsersWithListInput */ - public function createUsersWithListInput(array $user): array|void + public function createUsersWithListInput(array $user, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -240,7 +239,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#deleteUser */ - public function deleteUser($username): array|void + public function deleteUser($username, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -292,7 +291,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#getUserByName */ - public function getUserByName($username): array|\OpenAPI\Server\Model\User + public function getUserByName($username, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\User { // Implement the operation ... } @@ -344,7 +343,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#loginUser */ - public function loginUser($username, $password): array|\string + public function loginUser($username, $password, &$responseCode, array &$responseHeaders): array|\string { // Implement the operation ... } @@ -405,7 +404,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#logoutUser */ - public function logoutUser(): array|void + public function logoutUser(, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -464,7 +463,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#updateUser */ - public function updateUser($username, User $user): array|void + public function updateUser($username, User $user, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } From c536995ed566b6341f3f253dd243fd941b80bcc2 Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Mon, 23 May 2022 21:21:23 +0200 Subject: [PATCH 21/25] fix tests --- .../main/resources/php-symfony/testing/AppKernel.mustache | 2 +- .../main/resources/php-symfony/testing/api_test.mustache | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php-symfony/testing/AppKernel.mustache b/modules/openapi-generator/src/main/resources/php-symfony/testing/AppKernel.mustache index 617189baa7a5..cb6e0f461905 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/testing/AppKernel.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/testing/AppKernel.mustache @@ -8,7 +8,7 @@ use Symfony\Component\Config\Loader\LoaderInterface; class AppKernel extends Kernel { - public function registerBundles() + public function registerBundles(): iterable { $bundles = array( new FrameworkBundle() diff --git a/modules/openapi-generator/src/main/resources/php-symfony/testing/api_test.mustache b/modules/openapi-generator/src/main/resources/php-symfony/testing/api_test.mustache index 1af37ed1d76a..286dc14ca4d6 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/testing/api_test.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/testing/api_test.mustache @@ -38,28 +38,28 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; /** * Setup before running any test cases */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { } /** * Setup before running each test case */ - public function setUp() + public function setUp(): void { } /** * Clean up after running each test case */ - public function tearDown() + public function tearDown(): void { } /** * Clean up after running all test cases */ - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { } {{#operation}} From 292b638ff9dca9c4fd8cb8a6e69bc32d1eae15f0 Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Mon, 23 May 2022 21:53:32 +0200 Subject: [PATCH 22/25] regenerate sample --- .../SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php | 8 ++++---- .../SymfonyBundle-php/Tests/Api/StoreApiInterfaceTest.php | 8 ++++---- .../SymfonyBundle-php/Tests/Api/UserApiInterfaceTest.php | 8 ++++---- .../php-symfony/SymfonyBundle-php/Tests/AppKernel.php | 2 +- .../SymfonyBundle-php/Tests/Model/ApiResponseTest.php | 8 ++++---- .../SymfonyBundle-php/Tests/Model/CategoryTest.php | 8 ++++---- .../SymfonyBundle-php/Tests/Model/InlineObject1Test.php | 8 ++++---- .../SymfonyBundle-php/Tests/Model/InlineObjectTest.php | 8 ++++---- .../SymfonyBundle-php/Tests/Model/OrderTest.php | 8 ++++---- .../php-symfony/SymfonyBundle-php/Tests/Model/PetTest.php | 8 ++++---- .../php-symfony/SymfonyBundle-php/Tests/Model/TagTest.php | 8 ++++---- .../SymfonyBundle-php/Tests/Model/UserTest.php | 8 ++++---- 12 files changed, 45 insertions(+), 45 deletions(-) diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php index ee50cafca0d0..c6cf9bb80661 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php @@ -48,28 +48,28 @@ class PetApiInterfaceTest extends WebTestCase /** * Setup before running any test cases */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { } /** * Setup before running each test case */ - public function setUp() + public function setUp(): void { } /** * Clean up after running each test case */ - public function tearDown() + public function tearDown(): void { } /** * Clean up after running all test cases */ - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/StoreApiInterfaceTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/StoreApiInterfaceTest.php index 7db1e86545e8..d078530a7554 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/StoreApiInterfaceTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/StoreApiInterfaceTest.php @@ -48,28 +48,28 @@ class StoreApiInterfaceTest extends WebTestCase /** * Setup before running any test cases */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { } /** * Setup before running each test case */ - public function setUp() + public function setUp(): void { } /** * Clean up after running each test case */ - public function tearDown() + public function tearDown(): void { } /** * Clean up after running all test cases */ - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/UserApiInterfaceTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/UserApiInterfaceTest.php index bfa86e1d2ed3..79d3564dcab0 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/UserApiInterfaceTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/UserApiInterfaceTest.php @@ -48,28 +48,28 @@ class UserApiInterfaceTest extends WebTestCase /** * Setup before running any test cases */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { } /** * Setup before running each test case */ - public function setUp() + public function setUp(): void { } /** * Clean up after running each test case */ - public function tearDown() + public function tearDown(): void { } /** * Clean up after running all test cases */ - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/AppKernel.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/AppKernel.php index 5016d238d10b..9aed375ad0d7 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/AppKernel.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/AppKernel.php @@ -8,7 +8,7 @@ class AppKernel extends Kernel { - public function registerBundles() + public function registerBundles(): iterable { $bundles = array( new FrameworkBundle() diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/ApiResponseTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/ApiResponseTest.php index e6f4356f8fe9..55838f4718dc 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/ApiResponseTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/ApiResponseTest.php @@ -47,28 +47,28 @@ class ApiResponseTest extends TestCase /** * Setup before running any test case */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { } /** * Setup before running each test case */ - public function setUp() + public function setUp(): void { } /** * Clean up after running each test case */ - public function tearDown() + public function tearDown(): void { } /** * Clean up after running all test cases */ - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/CategoryTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/CategoryTest.php index a8955022a2bc..11c20ad08a54 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/CategoryTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/CategoryTest.php @@ -47,28 +47,28 @@ class CategoryTest extends TestCase /** * Setup before running any test case */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { } /** * Setup before running each test case */ - public function setUp() + public function setUp(): void { } /** * Clean up after running each test case */ - public function tearDown() + public function tearDown(): void { } /** * Clean up after running all test cases */ - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/InlineObject1Test.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/InlineObject1Test.php index 9d9ee881a0da..7cd8f68f3c81 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/InlineObject1Test.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/InlineObject1Test.php @@ -47,28 +47,28 @@ class InlineObject1Test extends TestCase /** * Setup before running any test case */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { } /** * Setup before running each test case */ - public function setUp() + public function setUp(): void { } /** * Clean up after running each test case */ - public function tearDown() + public function tearDown(): void { } /** * Clean up after running all test cases */ - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/InlineObjectTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/InlineObjectTest.php index 2f22469729d4..efbf3fac9d30 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/InlineObjectTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/InlineObjectTest.php @@ -47,28 +47,28 @@ class InlineObjectTest extends TestCase /** * Setup before running any test case */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { } /** * Setup before running each test case */ - public function setUp() + public function setUp(): void { } /** * Clean up after running each test case */ - public function tearDown() + public function tearDown(): void { } /** * Clean up after running all test cases */ - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/OrderTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/OrderTest.php index 634b42c24f25..61741148b78e 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/OrderTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/OrderTest.php @@ -47,28 +47,28 @@ class OrderTest extends TestCase /** * Setup before running any test case */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { } /** * Setup before running each test case */ - public function setUp() + public function setUp(): void { } /** * Clean up after running each test case */ - public function tearDown() + public function tearDown(): void { } /** * Clean up after running all test cases */ - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/PetTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/PetTest.php index e31a31b3872c..8c9581bfbf5b 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/PetTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/PetTest.php @@ -47,28 +47,28 @@ class PetTest extends TestCase /** * Setup before running any test case */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { } /** * Setup before running each test case */ - public function setUp() + public function setUp(): void { } /** * Clean up after running each test case */ - public function tearDown() + public function tearDown(): void { } /** * Clean up after running all test cases */ - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/TagTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/TagTest.php index 115cebc38c57..6af54c85741c 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/TagTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/TagTest.php @@ -47,28 +47,28 @@ class TagTest extends TestCase /** * Setup before running any test case */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { } /** * Setup before running each test case */ - public function setUp() + public function setUp(): void { } /** * Clean up after running each test case */ - public function tearDown() + public function tearDown(): void { } /** * Clean up after running all test cases */ - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/UserTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/UserTest.php index 4d0a9d135e74..761341ff78eb 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/UserTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/UserTest.php @@ -47,28 +47,28 @@ class UserTest extends TestCase /** * Setup before running any test case */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { } /** * Setup before running each test case */ - public function setUp() + public function setUp(): void { } /** * Clean up after running each test case */ - public function tearDown() + public function tearDown(): void { } /** * Clean up after running all test cases */ - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { } From 108c5957584dac5d89195c148c51730c11000525 Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Tue, 24 May 2022 08:45:47 +0200 Subject: [PATCH 23/25] more fixes for tests --- .../php-symfony/testing/api_test.mustache | 7 ++++++- .../php-symfony/testing/test_config.yml | 2 +- .../Tests/Api/PetApiInterfaceTest.php | 21 ++++++++++++------- .../SymfonyBundle-php/Tests/test_config.yml | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php-symfony/testing/api_test.mustache b/modules/openapi-generator/src/main/resources/php-symfony/testing/api_test.mustache index 286dc14ca4d6..54f03fa39668 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/testing/api_test.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/testing/api_test.mustache @@ -22,6 +22,7 @@ use {{invokerPackage}}\Configuration; use {{invokerPackage}}\ApiClient; use {{invokerPackage}}\ApiException; use {{invokerPackage}}\ObjectSerializer; +use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; /** @@ -34,6 +35,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; */ {{#operations}}class {{classname}}Test extends WebTestCase { + private static ?KernelBrowser $client = null; /** * Setup before running any test cases @@ -47,6 +49,9 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; */ public function setUp(): void { + if (null === self::$client) { + self::$client = static::createClient(); + } } /** @@ -72,7 +77,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; */ public function test{{operationIdCamelCase}}() { - $client = static::createClient(); + $client = self::$client; $path = '{{path}}'; {{#pathParams}} diff --git a/modules/openapi-generator/src/main/resources/php-symfony/testing/test_config.yml b/modules/openapi-generator/src/main/resources/php-symfony/testing/test_config.yml index 10c88a274c97..a06bcfef45aa 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/testing/test_config.yml +++ b/modules/openapi-generator/src/main/resources/php-symfony/testing/test_config.yml @@ -5,4 +5,4 @@ framework: secret: "testsecret" test: ~ router: - resource: "%kernel.root_dir%/../Resources/config/routing.yml" + resource: "%kernel.project_dir%/../Resources/config/routing.yml" diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php index c6cf9bb80661..e5f1be3a418e 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php @@ -33,6 +33,7 @@ use OpenAPI\Server\ApiException; use OpenAPI\Server\ObjectSerializer; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Bundle\FrameworkBundle\KernelBrowser; /** * PetApiInterfaceTest Class Doc Comment @@ -44,6 +45,7 @@ */ class PetApiInterfaceTest extends WebTestCase { + private static ?KernelBrowser $client = null; /** * Setup before running any test cases @@ -57,6 +59,9 @@ public static function setUpBeforeClass(): void */ public function setUp(): void { + if (null === self::$client) { + self::$client = static::createClient(); + } } /** @@ -81,7 +86,7 @@ public static function tearDownAfterClass(): void */ public function testAddPet() { - $client = static::createClient(); + $client = self::$client; $path = '/pet'; @@ -96,7 +101,7 @@ public function testAddPet() */ public function testDeletePet() { - $client = static::createClient(); + $client = self::$client; $path = '/pet/{petId}'; $pattern = '{petId}'; @@ -114,7 +119,7 @@ public function testDeletePet() */ public function testFindPetsByStatus() { - $client = static::createClient(); + $client = self::$client; $path = '/pet/findByStatus'; @@ -129,7 +134,7 @@ public function testFindPetsByStatus() */ public function testFindPetsByTags() { - $client = static::createClient(); + $client = self::$client; $path = '/pet/findByTags'; @@ -144,7 +149,7 @@ public function testFindPetsByTags() */ public function testGetPetById() { - $client = static::createClient(); + $client = self::$client; $path = '/pet/{petId}'; $pattern = '{petId}'; @@ -162,7 +167,7 @@ public function testGetPetById() */ public function testUpdatePet() { - $client = static::createClient(); + $client = self::$client; $path = '/pet'; @@ -177,7 +182,7 @@ public function testUpdatePet() */ public function testUpdatePetWithForm() { - $client = static::createClient(); + $client = self::$client; $path = '/pet/{petId}'; $pattern = '{petId}'; @@ -195,7 +200,7 @@ public function testUpdatePetWithForm() */ public function testUploadFile() { - $client = static::createClient(); + $client = self::$client; $path = '/pet/{petId}/uploadImage'; $pattern = '{petId}'; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/test_config.yml b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/test_config.yml index 10c88a274c97..a06bcfef45aa 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/test_config.yml +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/test_config.yml @@ -5,4 +5,4 @@ framework: secret: "testsecret" test: ~ router: - resource: "%kernel.root_dir%/../Resources/config/routing.yml" + resource: "%kernel.project_dir%/../Resources/config/routing.yml" From f84d2d73bd520fdf478f8877eb96fea159e3e1ac Mon Sep 17 00:00:00 2001 From: Benjamin Haeublein Date: Tue, 24 May 2022 09:09:48 +0200 Subject: [PATCH 24/25] update tests --- .../.openapi-generator/FILES | 9 ++ .../SymfonyBundle-php/Model/InlineObject.php | 123 ------------------ .../SymfonyBundle-php/Model/InlineObject1.php | 123 ------------------ .../Resources/docs/Model/InlineObject.md | 11 -- .../Resources/docs/Model/InlineObject1.md | 11 -- .../Tests/Api/PetApiInterfaceTest.php | 7 +- .../Tests/Api/StoreApiInterfaceTest.php | 18 ++- .../Tests/Api/UserApiInterfaceTest.php | 26 ++-- .../Tests/Model/ApiResponseTest.php | 2 +- .../Tests/Model/CategoryTest.php | 2 +- .../Tests/Model/InlineObject1Test.php | 96 -------------- .../Tests/Model/InlineObjectTest.php | 96 -------------- .../Tests/Model/OrderTest.php | 2 +- .../SymfonyBundle-php/Tests/Model/PetTest.php | 2 +- .../SymfonyBundle-php/Tests/Model/TagTest.php | 2 +- .../Tests/Model/UserTest.php | 2 +- 16 files changed, 47 insertions(+), 485 deletions(-) delete mode 100644 samples/server/petstore/php-symfony/SymfonyBundle-php/Model/InlineObject.php delete mode 100644 samples/server/petstore/php-symfony/SymfonyBundle-php/Model/InlineObject1.php delete mode 100644 samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/InlineObject.md delete mode 100644 samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/InlineObject1.md delete mode 100644 samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/InlineObject1Test.php delete mode 100644 samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/InlineObjectTest.php diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/.openapi-generator/FILES b/samples/server/petstore/php-symfony/SymfonyBundle-php/.openapi-generator/FILES index 4130cde47f9e..a3834148b61d 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/.openapi-generator/FILES +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/.openapi-generator/FILES @@ -38,8 +38,17 @@ Service/StrictJsonDeserializationVisitorFactory.php Service/SymfonyValidator.php Service/TypeMismatchException.php Service/ValidatorInterface.php +Tests/Api/PetApiInterfaceTest.php +Tests/Api/StoreApiInterfaceTest.php +Tests/Api/UserApiInterfaceTest.php Tests/AppKernel.php Tests/Controller/ControllerTest.php +Tests/Model/ApiResponseTest.php +Tests/Model/CategoryTest.php +Tests/Model/OrderTest.php +Tests/Model/PetTest.php +Tests/Model/TagTest.php +Tests/Model/UserTest.php Tests/test_config.yml autoload.php composer.json diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/InlineObject.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/InlineObject.php deleted file mode 100644 index 5ee480353c79..000000000000 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/InlineObject.php +++ /dev/null @@ -1,123 +0,0 @@ -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/server/petstore/php-symfony/SymfonyBundle-php/Model/InlineObject1.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/InlineObject1.php deleted file mode 100644 index e27ed1bf0827..000000000000 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/InlineObject1.php +++ /dev/null @@ -1,123 +0,0 @@ -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(): ?UploadedFile - { - 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/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/InlineObject.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/InlineObject.md deleted file mode 100644 index 101275879be3..000000000000 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/InlineObject.md +++ /dev/null @@ -1,11 +0,0 @@ -# InlineObject - -## Properties -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**name** | **string** | Updated name of the pet | [optional] -**status** | **string** | Updated status of the pet | [optional] - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - - diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/InlineObject1.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/InlineObject1.md deleted file mode 100644 index a69b83edc6a1..000000000000 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/InlineObject1.md +++ /dev/null @@ -1,11 +0,0 @@ -# InlineObject1 - -## Properties -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**additionalMetadata** | **string** | Additional data to pass to server | [optional] -**file** | [**UploadedFile**](UploadedFile.md) | file to upload | [optional] - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - - diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php index e5f1be3a418e..f8fe90512b12 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php @@ -1,7 +1,7 @@ parse($regexp); $generator = new \Hoa\Regex\Visitor\Isotropic(new \Hoa\Math\Sampler\Random()); - return $generator->visit($ast); + return $generator->visit($ast); } } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/StoreApiInterfaceTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/StoreApiInterfaceTest.php index d078530a7554..2acfddb51ee4 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/StoreApiInterfaceTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/StoreApiInterfaceTest.php @@ -1,7 +1,7 @@ parse($regexp); $generator = new \Hoa\Regex\Visitor\Isotropic(new \Hoa\Math\Sampler\Random()); - return $generator->visit($ast); + return $generator->visit($ast); } } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/UserApiInterfaceTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/UserApiInterfaceTest.php index 79d3564dcab0..447113b321b8 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/UserApiInterfaceTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/UserApiInterfaceTest.php @@ -1,7 +1,7 @@ parse($regexp); $generator = new \Hoa\Regex\Visitor\Isotropic(new \Hoa\Math\Sampler\Random()); - return $generator->visit($ast); + return $generator->visit($ast); } } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/ApiResponseTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/ApiResponseTest.php index 55838f4718dc..8bbaee822e3d 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/ApiResponseTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/ApiResponseTest.php @@ -2,7 +2,7 @@ /** * ApiResponseTest * - * PHP version 7.1.3 + * PHP version 8.1.1 * * @category Class * @package OpenAPI\Server\Tests\Model diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/CategoryTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/CategoryTest.php index 11c20ad08a54..8b225b838ca2 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/CategoryTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/CategoryTest.php @@ -2,7 +2,7 @@ /** * CategoryTest * - * PHP version 7.1.3 + * PHP version 8.1.1 * * @category Class * @package OpenAPI\Server\Tests\Model diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/InlineObject1Test.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/InlineObject1Test.php deleted file mode 100644 index 7cd8f68f3c81..000000000000 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/InlineObject1Test.php +++ /dev/null @@ -1,96 +0,0 @@ - Date: Tue, 24 May 2022 09:10:52 +0200 Subject: [PATCH 25/25] add kernel shutdown --- .../src/main/resources/php-symfony/testing/api_test.mustache | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/openapi-generator/src/main/resources/php-symfony/testing/api_test.mustache b/modules/openapi-generator/src/main/resources/php-symfony/testing/api_test.mustache index 54f03fa39668..ebdbc2fa835b 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/testing/api_test.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/testing/api_test.mustache @@ -59,6 +59,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; */ public function tearDown(): void { + static::ensureKernelShutdown(); } /**