diff --git a/composer.json b/composer.json index 2a51504..c4f91c5 100644 --- a/composer.json +++ b/composer.json @@ -27,13 +27,19 @@ "psr/http-message": "^1.0", "ringcentral/psr7": "^1.3", "symfony/yaml": "^5.2", - "wyrihaximus/composer-update-bin-autoload-path": "^1 || ^1.0.1" + "wyrihaximus/composer-update-bin-autoload-path": "^1 || ^1.0.1", + "wyrihaximus/hydrator": "dev-master" }, "autoload": { "psr-4": { "ApiClients\\Tools\\OpenApiClientGenerator\\": "src/" } }, + "config": { + "platform": { + "php": "7.4.7" + } + }, "autoload-dev": { "psr-4": { "ApiClients\\Tests\\Tools\\OpenApiClientGenerator\\": "tests/" diff --git a/composer.lock b/composer.lock index 67c43c9..99256c6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b8f8d368c9240b9aec0613c908ac044d", + "content-hash": "4074f2fce53ecdb657fee06d71c3f026", "packages": [ { "name": "cebe/php-openapi", @@ -72,6 +72,156 @@ }, "time": "2021-02-16T09:31:22+00:00" }, + { + "name": "doctrine/annotations", + "version": "1.12.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/annotations.git", + "reference": "b17c5014ef81d212ac539f07a1001832df1b6d3b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/b17c5014ef81d212ac539f07a1001832df1b6d3b", + "reference": "b17c5014ef81d212ac539f07a1001832df1b6d3b", + "shasum": "" + }, + "require": { + "doctrine/lexer": "1.*", + "ext-tokenizer": "*", + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "doctrine/cache": "1.*", + "doctrine/coding-standard": "^6.0 || ^8.1", + "phpstan/phpstan": "^0.12.20", + "phpunit/phpunit": "^7.5 || ^9.1.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Docblock Annotations Parser", + "homepage": "https://www.doctrine-project.org/projects/annotations.html", + "keywords": [ + "annotations", + "docblock", + "parser" + ], + "support": { + "issues": "https://github.com/doctrine/annotations/issues", + "source": "https://github.com/doctrine/annotations/tree/1.12.1" + }, + "time": "2021-02-21T21:00:45+00:00" + }, + { + "name": "doctrine/lexer", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/lexer.git", + "reference": "e864bbf5904cb8f5bb334f99209b48018522f042" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/e864bbf5904cb8f5bb334f99209b48018522f042", + "reference": "e864bbf5904cb8f5bb334f99209b48018522f042", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "doctrine/coding-standard": "^6.0", + "phpstan/phpstan": "^0.11.8", + "phpunit/phpunit": "^8.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Lexer\\": "lib/Doctrine/Common/Lexer" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.", + "homepage": "https://www.doctrine-project.org/projects/lexer.html", + "keywords": [ + "annotations", + "docblock", + "lexer", + "parser", + "php" + ], + "support": { + "issues": "https://github.com/doctrine/lexer/issues", + "source": "https://github.com/doctrine/lexer/tree/1.2.1" + }, + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Flexer", + "type": "tidelift" + } + ], + "time": "2020-05-25T17:44:05+00:00" + }, { "name": "jawira/case-converter", "version": "v3.4.2", @@ -204,6 +354,200 @@ }, "time": "2020-05-27T16:41:55+00:00" }, + { + "name": "laminas/laminas-hydrator", + "version": "3.2.0", + "source": { + "type": "git", + "url": "https://github.com/laminas/laminas-hydrator.git", + "reference": "f0336699910478cc45c7e34ca0fc83bf118e48bc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laminas/laminas-hydrator/zipball/f0336699910478cc45c7e34ca0fc83bf118e48bc", + "reference": "f0336699910478cc45c7e34ca0fc83bf118e48bc", + "shasum": "" + }, + "require": { + "laminas/laminas-stdlib": "^3.3", + "laminas/laminas-zendframework-bridge": "^1.0", + "php": "^7.3 || ~8.0.0" + }, + "replace": { + "zendframework/zend-hydrator": "^3.0.2" + }, + "require-dev": { + "laminas/laminas-coding-standard": "~1.0.0", + "laminas/laminas-eventmanager": "^3.2.1", + "laminas/laminas-modulemanager": "^2.8", + "laminas/laminas-serializer": "^2.9", + "laminas/laminas-servicemanager": "^3.3.2", + "phpunit/phpunit": "~9.3.0", + "vimeo/psalm": "^3.16" + }, + "suggest": { + "laminas/laminas-eventmanager": "^3.2, to support aggregate hydrator usage", + "laminas/laminas-serializer": "^2.9, to use the SerializableStrategy", + "laminas/laminas-servicemanager": "^3.3, to support hydrator plugin manager usage" + }, + "type": "library", + "extra": { + "laminas": { + "component": "Laminas\\Hydrator", + "config-provider": "Laminas\\Hydrator\\ConfigProvider" + } + }, + "autoload": { + "psr-4": { + "Laminas\\Hydrator\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Serialize objects to arrays, and vice versa", + "homepage": "https://laminas.dev", + "keywords": [ + "hydrator", + "laminas" + ], + "support": { + "chat": "https://laminas.dev/chat", + "docs": "https://docs.laminas.dev/laminas-hydrator/", + "forum": "https://discourse.laminas.dev", + "issues": "https://github.com/laminas/laminas-hydrator/issues", + "rss": "https://github.com/laminas/laminas-hydrator/releases.atom", + "source": "https://github.com/laminas/laminas-hydrator" + }, + "funding": [ + { + "url": "https://funding.communitybridge.org/projects/laminas-project", + "type": "community_bridge" + } + ], + "time": "2020-10-06T19:45:29+00:00" + }, + { + "name": "laminas/laminas-stdlib", + "version": "3.3.1", + "source": { + "type": "git", + "url": "https://github.com/laminas/laminas-stdlib.git", + "reference": "d81c7ffe602ed0e6ecb18691019111c0f4bf1efe" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laminas/laminas-stdlib/zipball/d81c7ffe602ed0e6ecb18691019111c0f4bf1efe", + "reference": "d81c7ffe602ed0e6ecb18691019111c0f4bf1efe", + "shasum": "" + }, + "require": { + "laminas/laminas-zendframework-bridge": "^1.0", + "php": "^7.3 || ^8.0" + }, + "replace": { + "zendframework/zend-stdlib": "^3.2.1" + }, + "require-dev": { + "laminas/laminas-coding-standard": "~1.0.0", + "phpbench/phpbench": "^0.17.1", + "phpunit/phpunit": "~9.3.7" + }, + "type": "library", + "autoload": { + "psr-4": { + "Laminas\\Stdlib\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "SPL extensions, array utilities, error handlers, and more", + "homepage": "https://laminas.dev", + "keywords": [ + "laminas", + "stdlib" + ], + "support": { + "chat": "https://laminas.dev/chat", + "docs": "https://docs.laminas.dev/laminas-stdlib/", + "forum": "https://discourse.laminas.dev", + "issues": "https://github.com/laminas/laminas-stdlib/issues", + "rss": "https://github.com/laminas/laminas-stdlib/releases.atom", + "source": "https://github.com/laminas/laminas-stdlib" + }, + "funding": [ + { + "url": "https://funding.communitybridge.org/projects/laminas-project", + "type": "community_bridge" + } + ], + "time": "2020-11-19T20:18:59+00:00" + }, + { + "name": "laminas/laminas-zendframework-bridge", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/laminas/laminas-zendframework-bridge.git", + "reference": "6cccbddfcfc742eb02158d6137ca5687d92cee32" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laminas/laminas-zendframework-bridge/zipball/6cccbddfcfc742eb02158d6137ca5687d92cee32", + "reference": "6cccbddfcfc742eb02158d6137ca5687d92cee32", + "shasum": "" + }, + "require": { + "php": "^7.3 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7 || ^6.5 || ^7.5 || ^8.1 || ^9.3", + "psalm/plugin-phpunit": "^0.15.1", + "squizlabs/php_codesniffer": "^3.5", + "vimeo/psalm": "^4.6" + }, + "type": "library", + "extra": { + "laminas": { + "module": "Laminas\\ZendFrameworkBridge" + } + }, + "autoload": { + "files": [ + "src/autoload.php" + ], + "psr-4": { + "Laminas\\ZendFrameworkBridge\\": "src//" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Alias legacy ZF class names to Laminas Project equivalents.", + "keywords": [ + "ZendFramework", + "autoloading", + "laminas", + "zf" + ], + "support": { + "forum": "https://discourse.laminas.dev/", + "issues": "https://github.com/laminas/laminas-zendframework-bridge/issues", + "rss": "https://github.com/laminas/laminas-zendframework-bridge/releases.atom", + "source": "https://github.com/laminas/laminas-zendframework-bridge" + }, + "funding": [ + { + "url": "https://funding.communitybridge.org/projects/laminas-project", + "type": "community_bridge" + } + ], + "time": "2021-02-25T21:54:58+00:00" + }, { "name": "nikic/php-parser", "version": "v4.10.4", @@ -260,6 +604,150 @@ }, "time": "2020-12-20T10:01:03+00:00" }, + { + "name": "ocramius/code-generator-utils", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/Ocramius/CodeGenerationUtils.git", + "reference": "3c207127e8dc6e9a3eb4d4a1f3041f17c0171aba" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Ocramius/CodeGenerationUtils/zipball/3c207127e8dc6e9a3eb4d4a1f3041f17c0171aba", + "reference": "3c207127e8dc6e9a3eb4d4a1f3041f17c0171aba", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.10.4", + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "doctrine/coding-standard": "^8.2.0", + "phpunit/phpunit": "^9.5.1", + "psalm/plugin-phpunit": "^0.15.0", + "roave/infection-static-analysis-plugin": "^1.7", + "squizlabs/php_codesniffer": "^3.5.8", + "vimeo/psalm": "^4.4.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "CodeGenerationUtils\\": "src/CodeGenerationUtils" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A set of code generator utilities built on top of PHP-Parsers that ease its use when combined with Reflection", + "homepage": "https://github.com/Ocramius/CodeGenerationUtils", + "keywords": [ + "code generation", + "compiler", + "parser", + "php code", + "reflection" + ], + "support": { + "issues": "https://github.com/Ocramius/CodeGenerationUtils/issues", + "source": "https://github.com/Ocramius/CodeGenerationUtils/tree/1.1.0" + }, + "funding": [ + { + "url": "https://github.com/Ocramius", + "type": "github" + } + ], + "time": "2021-01-17T16:27:24+00:00" + }, + { + "name": "ocramius/generated-hydrator", + "version": "4.1.0", + "source": { + "type": "git", + "url": "https://github.com/Ocramius/GeneratedHydrator.git", + "reference": "e1d2919b31631195f3f45a2dfcf84812daa15384" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Ocramius/GeneratedHydrator/zipball/e1d2919b31631195f3f45a2dfcf84812daa15384", + "reference": "e1d2919b31631195f3f45a2dfcf84812daa15384", + "shasum": "" + }, + "require": { + "laminas/laminas-hydrator": "^3.1.1", + "nikic/php-parser": "^4.10.4", + "ocramius/code-generator-utils": "^1.1.0", + "php": "^7.4.7" + }, + "require-dev": { + "doctrine/coding-standard": "^8.2.0", + "infection/infection": "^0.20.2", + "laminas/laminas-filter": "^2.9.4", + "laminas/laminas-servicemanager": "^3.6.2", + "laminas/laminas-stdlib": "^3.2.1", + "phpbench/phpbench": "^0.17.1", + "phpunit/phpunit": "^9.5.1", + "psalm/plugin-phpunit": "^0.12.2", + "roave/backward-compatibility-check": "^5.0.0", + "squizlabs/php_codesniffer": "^3.5.8", + "vimeo/psalm": "^3.18" + }, + "type": "library", + "autoload": { + "psr-4": { + "GeneratedHydrator\\": "src/GeneratedHydrator" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "An Object Hydrator that allows very fast array to object to array conversion", + "homepage": "https://github.com/Ocramius/GeneratedHydrator", + "keywords": [ + "array conversion", + "hydrator", + "object conversion", + "performance", + "serializer" + ], + "support": { + "issues": "https://github.com/Ocramius/GeneratedHydrator/issues", + "source": "https://github.com/Ocramius/GeneratedHydrator/tree/4.1.0" + }, + "funding": [ + { + "url": "https://github.com/Ocramius", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/ocramius/generated-hydrator", + "type": "tidelift" + } + ], + "time": "2021-01-17T19:09:21+00:00" + }, { "name": "psr/http-message", "version": "1.0.1", @@ -800,17 +1288,75 @@ } ], "time": "2021-03-14T20:55:38+00:00" + }, + { + "name": "wyrihaximus/hydrator", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/WyriHaximus/php-hydrator.git", + "reference": "b3e2b5ac7a8ff1d8b1f0ca6e13962a0d19687609" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WyriHaximus/php-hydrator/zipball/b3e2b5ac7a8ff1d8b1f0ca6e13962a0d19687609", + "reference": "b3e2b5ac7a8ff1d8b1f0ca6e13962a0d19687609", + "shasum": "" + }, + "require": { + "doctrine/annotations": "^1.12", + "ocramius/generated-hydrator": "^4.0", + "php": "^7.4" + }, + "require-dev": { + "wyrihaximus/test-utilities": "^3.7" + }, + "default-branch": true, + "type": "library", + "autoload": { + "psr-4": { + "WyriHaximus\\Hydrator\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Cees-Jan Kiewiet", + "email": "ceesjank@gmail.com", + "homepage": "https://www.wyrihaximus.net/" + } + ], + "description": "Middleware infused hydrator", + "support": { + "issues": "https://github.com/WyriHaximus/php-hydrator/issues", + "source": "https://github.com/WyriHaximus/php-hydrator/tree/master" + }, + "funding": [ + { + "url": "https://github.com/WyriHaximus", + "type": "github" + } + ], + "time": "2021-05-05T16:33:32+00:00" } ], "packages-dev": [], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "wyrihaximus/hydrator": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { "php": "^7.4" }, "platform-dev": [], + "platform-overrides": { + "php": "7.4.7" + }, "plugin-api-version": "2.0.0" } diff --git a/src/Generator/Schema.php b/src/Generator/Schema.php index 0308e1d..c14af18 100644 --- a/src/Generator/Schema.php +++ b/src/Generator/Schema.php @@ -76,6 +76,7 @@ public static function generate(string $name, string $namespace, string $classNa if (is_string($property->type)) { if ($property->type === 'array' && $property->items instanceof OpenAPiSchema && array_key_exists(spl_object_hash($property->items), $schemaClassNameMap)) { $docBlock[] = '@var array<\\' . $namespace . '\\' . $schemaClassNameMap[spl_object_hash($property->items)] . '>'; + $docBlock[] = '@\WyriHaximus\Hydrator\Attribute\HydrateArray(\\' . $namespace . '\\' . $schemaClassNameMap[spl_object_hash($property->items)] . '::class)'; } $t = str_replace([ 'integer', @@ -96,9 +97,10 @@ public static function generate(string $name, string $namespace, string $classNa $method->setReturnType($t); } } else if (is_array($property->anyOf) && $property->anyOf[0] instanceof OpenAPiSchema && array_key_exists(spl_object_hash($property->anyOf[0]), $schemaClassNameMap)) { - $fqcnn = '?\\' . $namespace . '\\' . $schemaClassNameMap[spl_object_hash($property->anyOf[0])]; - $propertyStmt->setType($fqcnn)->setDefault(null); - $method->setReturnType($fqcnn); + $fqcnn = '\\' . $namespace . '\\' . $schemaClassNameMap[spl_object_hash($property->anyOf[0])]; + $propertyStmt->setType('?' . $fqcnn)->setDefault(null); + $method->setReturnType('?' . $fqcnn); + $docBlock[] = '@\WyriHaximus\Hydrator\Attribute\Hydrate(' . $fqcnn . '::class)'; } if (count($docBlock) > 0) {