From 77fa028bb3c67e78376499a0d4dca25bd7dec7a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=A4ublein?= Date: Wed, 25 May 2022 09:34:50 +0200 Subject: [PATCH] [php-symfony] Symfony6 support (#11810) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * support symfony6 * fix issues with StrictJsonDeserialization * regenerate samples * add suggestions * update samples * support php 7.4 and symfony 5 * allow versions based on semantic versioning * regenerate sample * change method of determining result types * update samples * describe usage of bundle in symfony app * better documentation * fix duplicate auth methods * do not set namespace for default types * fix UploadedFile type * next try fixing auth * regenerate samples * fix: auth method shall not be duplicated * Revert "fix duplicate auth methods" This reverts commit 0dc418737b1379a30b7f22e7937819ba965c9ddb. * chore: regenerate samples * fix tests * regenerate sample * more fixes for tests * update tests * add kernel shutdown Co-authored-by: Benjamin Haeublein Co-authored-by: Renaud de Chivré --- .../languages/PhpSymfonyServerCodegen.java | 18 ++- .../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 | 29 ++--- .../main/resources/php-symfony/api.mustache | 7 +- .../php-symfony/api_controller.mustache | 2 +- .../resources/php-symfony/api_doc.mustache | 7 +- .../resources/php-symfony/composer.mustache | 18 +-- .../main/resources/php-symfony/model.mustache | 2 +- .../resources/php-symfony/routing.mustache | 2 +- .../serialization/JmsSerializer.mustache | 16 ++- .../StrictJsonDeserializationVisitor.mustache | 115 ++++++++++++++-- ...JsonDeserializationVisitorFactory.mustache | 34 +++++ .../resources/php-symfony/services.mustache | 2 +- .../php-symfony/testing/AppKernel.mustache | 2 +- .../testing/ControllerTest.mustache | 2 +- .../php-symfony/testing/api_test.mustache | 18 ++- .../php-symfony/testing/model_test.mustache | 10 +- .../php-symfony/testing/test_config.yml | 2 +- .../.openapi-generator/FILES | 10 ++ .../php-symfony/SymfonyBundle-php/.travis.yml | 3 +- .../SymfonyBundle-php/Api/ApiServer.php | 4 +- .../SymfonyBundle-php/Api/PetApiInterface.php | 44 +++---- .../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/InlineObject.php | 123 ------------------ .../SymfonyBundle-php/Model/InlineObject1.php | 123 ------------------ .../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 | 29 ++--- .../Resources/config/routing.yml | 40 +++--- .../Resources/config/services.yml | 6 +- .../Resources/docs/Api/PetApiInterface.md | 21 ++- .../Resources/docs/Api/StoreApiInterface.md | 13 +- .../Resources/docs/Api/UserApiInterface.md | 21 ++- .../Resources/docs/Model/InlineObject.md | 11 -- .../Resources/docs/Model/InlineObject1.md | 11 -- .../Service/JmsSerializer.php | 16 ++- .../StrictJsonDeserializationVisitor.php | 115 ++++++++++++++-- ...trictJsonDeserializationVisitorFactory.php | 34 +++++ .../Tests/Api/PetApiInterfaceTest.php | 34 +++-- .../Tests/Api/StoreApiInterfaceTest.php | 26 ++-- .../Tests/Api/UserApiInterfaceTest.php | 34 +++-- .../SymfonyBundle-php/Tests/AppKernel.php | 2 +- .../Tests/Controller/ControllerTest.php | 2 +- .../Tests/Model/ApiResponseTest.php | 10 +- .../Tests/Model/CategoryTest.php | 10 +- .../Tests/Model/InlineObject1Test.php | 96 -------------- .../Tests/Model/InlineObjectTest.php | 96 -------------- .../Tests/Model/OrderTest.php | 10 +- .../SymfonyBundle-php/Tests/Model/PetTest.php | 10 +- .../SymfonyBundle-php/Tests/Model/TagTest.php | 10 +- .../Tests/Model/UserTest.php | 10 +- .../SymfonyBundle-php/Tests/test_config.yml | 2 +- .../SymfonyBundle-php/composer.json | 18 +-- 70 files changed, 603 insertions(+), 776 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitorFactory.mustache 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 create mode 100644 samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitorFactory.php 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/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 36048286d03..6c423de454c 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 @@ -348,6 +348,7 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg 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")); @@ -434,11 +435,26 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg } 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 { + if (defaultIncludes.contains(op.returnType)) { + 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"); + } // 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); } } 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 de5a983645f..2de2fe97882 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 10bf6bea00c..8a5f472014a 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 1e902459ef0..d200b0c6d1c 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 4bbbf5062d8..83ef7afa0af 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 8e214256045..9b0c16fdb00 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 4395c42aef0..00dd37411c8 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 2b959b0e3e5..3ebcc0b43b0 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.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" ``` @@ -112,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}}) + 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 ... } @@ -125,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.mustache b/modules/openapi-generator/src/main/resources/php-symfony/api.mustache index d342bf1d79b..236e06f02dd 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 @@ =7.4.0|>=8.0.2", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", - "symfony/validator": "*", - "jms/serializer-bundle": "^2.0", - "symfony/framework-bundle": "^4.4.8" + "symfony/validator": "^5.0|^6.0", + "jms/serializer-bundle": "^4.0", + "symfony/framework-bundle": "^5.0|^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": "^5.0|^6.0", + "symfony/yaml": "^5.0|^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 9d9831384fc..2435f607663 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 0b9ec929145..cd4a833df0a 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 a3dc976f08c..dc352aedc81 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,9 @@ namespace {{servicePackage}}; use JMS\Serializer\SerializerBuilder; use JMS\Serializer\Naming\CamelCaseNamingStrategy; use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; -use JMS\Serializer\XmlDeserializationVisitor; +use JMS\Serializer\Visitor\Factory\XmlDeserializationVisitorFactory; +use DateTime; +use RuntimeException; class JmsSerializer implements SerializerInterface { @@ -13,10 +15,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 +82,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 b60e2c7b653..9c279d2ed32 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,145 @@ * limitations under the License. */ +declare(strict_types=1); + namespace {{servicePackage}}; -use JMS\Serializer\Context; use JMS\Serializer\JsonDeserializationVisitor; +use JMS\Serializer\GraphNavigatorInterface; +use JMS\Serializer\Metadata\ClassMetadata; +use JMS\Serializer\Metadata\PropertyMetadata; +use JMS\Serializer\Visitor\DeserializationVisitorInterface; -class StrictJsonDeserializationVisitor extends JsonDeserializationVisitor +class StrictJsonDeserializationVisitor implements DeserializationVisitorInterface { + protected $jsonDeserializationVisitor: JsonDeserializationVisitor; + + public function __construct( + int $options = 0, + int $depth = 512 + ) { + $this->jsonDeserializationVisitor = new JsonDeserializationVisitor($options, $depth); + } + /** * {@inheritdoc} */ - public function visitString($data, array $type, Context $context) + public function visitNull($data, array $type) + { + return $this->jsonDeserializationVisitor->visitNull($data, $type); + } + + /** + * {@inheritdoc} + */ + 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, $metadata); + } + + /** + * {@inheritdoc} + */ + public function startVisitingObject(ClassMetadata $metadata, object $data, array $type): void + { + $this->jsonDeserializationVisitor->startVisitingObject($metadata, $data, $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, $data, $type); + } + + /** + * {@inheritdoc} + */ + 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/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 00000000000..b86a5a7d41f --- /dev/null +++ b/modules/openapi-generator/src/main/resources/php-symfony/serialization/StrictJsonDeserializationVisitorFactory.mustache @@ -0,0 +1,34 @@ +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 1432b4a82a9..042fb28f670 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/AppKernel.mustache b/modules/openapi-generator/src/main/resources/php-symfony/testing/AppKernel.mustache index 617189baa7a..cb6e0f46190 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/ControllerTest.mustache b/modules/openapi-generator/src/main/resources/php-symfony/testing/ControllerTest.mustache index 49861fd9672..730cba94a11 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 1070ad90944..f16d72ad381 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 7ee222ced8d..f28e356b381 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/InlineObject.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/InlineObject.php deleted file mode 100644 index 5ee480353c7..00000000000 --- 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 e27ed1bf082..00000000000 --- 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/Model/Order.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php index 35bd792c6db..7a6c985ae85 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 a7a30656954..f0375444f5c 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 abae962752e..e07427b1457 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 7222a65a6e9..4fab9c98f41 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 3e8304f2446..61d3eb42108 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 0e5ac7c2d21..a4214748921 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.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) + 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/config/routing.yml b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/config/routing.yml index a571a4df29d..4253fba9b1e 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 a9363de5efb..27503e2b433 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 b79ef732249..a3e606ce33a 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" } # ... @@ -58,7 +57,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#addPet */ - public function addPet(Pet $pet) + public function addPet(Pet $pet, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet { // Implement the operation ... } @@ -120,7 +119,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#deletePet */ - public function deletePet($petId, $apiKey = null) + public function deletePet($petId, $apiKey = null, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -183,7 +182,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#findPetsByStatus */ - public function findPetsByStatus(array $status) + public function findPetsByStatus(array $status, &$responseCode, array &$responseHeaders): iterable { // Implement the operation ... } @@ -245,7 +244,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#findPetsByTags */ - public function findPetsByTags(array $tags) + public function findPetsByTags(array $tags, &$responseCode, array &$responseHeaders): iterable { // Implement the operation ... } @@ -307,7 +306,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#getPetById */ - public function getPetById($petId) + public function getPetById($petId, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet { // Implement the operation ... } @@ -369,7 +368,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#updatePet */ - public function updatePet(Pet $pet) + public function updatePet(Pet $pet, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet { // Implement the operation ... } @@ -431,7 +430,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, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -495,7 +494,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, &$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 daada9239d1..d721b46d6c1 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) + 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() + 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) + public function getOrderById($orderId, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Order { // Implement the operation ... } @@ -213,7 +212,7 @@ class StoreApi implements StoreApiInterface /** * Implementation of StoreApiInterface#placeOrder */ - public function placeOrder(Order $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 35c79473feb..2ec5e011214 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) + public function createUser(User $user, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -120,7 +119,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#createUsersWithArrayInput */ - public function createUsersWithArrayInput(array $user) + public function createUsersWithArrayInput(array $user, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -182,7 +181,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#createUsersWithListInput */ - public function createUsersWithListInput(array $user) + public function createUsersWithListInput(array $user, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -244,7 +243,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#deleteUser */ - public function deleteUser($username) + public function deleteUser($username, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -298,7 +297,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#getUserByName */ - public function getUserByName($username) + public function getUserByName($username, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\User { // Implement the operation ... } @@ -352,7 +351,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#loginUser */ - public function loginUser($username, $password) + public function loginUser($username, $password, &$responseCode, array &$responseHeaders): array|\string { // Implement the operation ... } @@ -415,7 +414,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#logoutUser */ - public function logoutUser() + public function logoutUser(, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -474,7 +473,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#updateUser */ - public function updateUser($username, User $user) + public function updateUser($username, User $user, &$responseCode, array &$responseHeaders): void { // Implement the operation ... } 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 101275879be..00000000000 --- 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 a69b83edc6a..00000000000 --- 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/Service/JmsSerializer.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php index 7c8c1e1339a..0ef6b708e9d 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,9 @@ namespace OpenAPI\Server\Service; use JMS\Serializer\SerializerBuilder; use JMS\Serializer\Naming\CamelCaseNamingStrategy; use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; -use JMS\Serializer\XmlDeserializationVisitor; +use JMS\Serializer\Visitor\Factory\XmlDeserializationVisitorFactory; +use DateTime; +use RuntimeException; class JmsSerializer implements SerializerInterface { @@ -13,10 +15,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 +82,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/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitor.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitor.php index fbb811869a3..62fee4cc7a4 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,145 @@ * limitations under the License. */ +declare(strict_types=1); + namespace OpenAPI\Server\Service; -use JMS\Serializer\Context; use JMS\Serializer\JsonDeserializationVisitor; +use JMS\Serializer\GraphNavigatorInterface; +use JMS\Serializer\Metadata\ClassMetadata; +use JMS\Serializer\Metadata\PropertyMetadata; +use JMS\Serializer\Visitor\DeserializationVisitorInterface; -class StrictJsonDeserializationVisitor extends JsonDeserializationVisitor +class StrictJsonDeserializationVisitor implements DeserializationVisitorInterface { + protected $jsonDeserializationVisitor: JsonDeserializationVisitor; + + public function __construct( + int $options = 0, + int $depth = 512 + ) { + $this->jsonDeserializationVisitor = new JsonDeserializationVisitor($options, $depth); + } + /** * {@inheritdoc} */ - public function visitString($data, array $type, Context $context) + public function visitNull($data, array $type) + { + return $this->jsonDeserializationVisitor->visitNull($data, $type); + } + + /** + * {@inheritdoc} + */ + 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, $metadata); + } + + /** + * {@inheritdoc} + */ + public function startVisitingObject(ClassMetadata $metadata, object $data, array $type): void + { + $this->jsonDeserializationVisitor->startVisitingObject($metadata, $data, $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, $data, $type); + } + + /** + * {@inheritdoc} + */ + 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 new file mode 100644 index 00000000000..8e6977f6b85 --- /dev/null +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/StrictJsonDeserializationVisitorFactory.php @@ -0,0 +1,34 @@ +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/Api/PetApiInterfaceTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php index ee50cafca0d..f8fe90512b1 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 7db1e86545e..2acfddb51ee 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 bfa86e1d2ed..447113b321b 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/AppKernel.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/AppKernel.php index 5016d238d10..9aed375ad0d 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 @@ use Symfony\Component\Config\Loader\LoaderInterface; 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/Controller/ControllerTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Controller/ControllerTest.php index 1c5af7a0ffc..18671580c34 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 @@ =7.4.0|>=8.0.2", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", - "symfony/validator": "*", - "jms/serializer-bundle": "^2.0", - "symfony/framework-bundle": "^4.4.8" + "symfony/validator": "^5.0|^6.0", + "jms/serializer-bundle": "^4.0", + "symfony/framework-bundle": "^5.0|^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": "^5.0|^6.0", + "symfony/yaml": "^5.0|^6.0", "hoa/regex": "~1.0" }, "autoload": { - "psr-4": { "OpenAPI\\Server\\" : "./" } + "psr-4": { + "OpenAPI\\Server\\" : "./" + } } }