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..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 @@ -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")); @@ -430,11 +431,26 @@ 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 { + 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 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..3ebcc0b43b0c 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 d342bf1d79bd..236e06f02ddf 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 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..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 @@ -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 b60e2c7b653d..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 @@ -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 000000000000..b86a5a7d41f2 --- /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 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/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/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/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/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..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 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 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..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) + 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) + 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) + 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) + 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) + 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) + 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) + 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) + 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 3d3e3b18c3ef..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) + 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 ... } @@ -211,7 +210,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 c00ce7309a8e..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) + 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) + 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) + 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) + 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) + 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) + 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() + 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) + 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 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/Service/JmsSerializer.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php index 7c8c1e1339a9..0ef6b708e9d7 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 @@ 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 @@ 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..62fee4cc7a49 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 000000000000..8e6977f6b85d --- /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 ee50cafca0d0..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 7db1e86545e8..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 bfa86e1d2ed3..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/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/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 @@ =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\\" : "./" + } } }