diff --git a/.github/workflows/static_analysis.yml b/.github/workflows/static_analysis.yml index 6431e04..b69bd63 100644 --- a/.github/workflows/static_analysis.yml +++ b/.github/workflows/static_analysis.yml @@ -29,8 +29,8 @@ jobs: - run: composer global config --no-plugins allow-plugins.symfony/flex true - run: composer global require --no-scripts symfony/flex - - run: composer config extra.symfony.require ~7.3.0 + - run: composer config extra.symfony.require ~7.4.0 - - run: composer update --prefer-dist + - run: composer update --prefer-dist --with-all-dependencies - - run: composer ${{ matrix.script }} \ No newline at end of file + - run: composer ${{ matrix.script }} diff --git a/composer.json b/composer.json index 180612f..d1e167c 100644 --- a/composer.json +++ b/composer.json @@ -22,18 +22,18 @@ "minimum-stability": "beta", "require": { "php": ">=8.4", - "symfony/routing": "^7.3 || ^8.0", - "symfony/config": "^7.3 || ^8.0", - "symfony/dependency-injection": "^7.3 || ^8.0", - "symfony/event-dispatcher": "^7.3 || ^8.0", - "symfony/http-foundation": "^7.3 || ^8.0", - "symfony/http-kernel": "^7.3 || ^8.0", - "symfony/property-access": "^7.3 || ^8.0", - "symfony/framework-bundle": "^7.3 || ^8.0", - "symfony/console": "^7.3 || ^8.0", - "symfony/security-core": "^7.3 || ^8.0", - "symfony/security-http": "^7.3 || ^8.0", - "symfony/yaml": "^7.3 || ^8.0", + "symfony/routing": "^7.4.13 || ^8.0.13", + "symfony/http-foundation": "^7.4.13 || ^8.0.13", + "symfony/security-http": "^7.4.13 || ^8.0.13", + "symfony/yaml": "^7.4.12 || ^8.0.12", + "symfony/config": "^7.4 || ^8.0", + "symfony/dependency-injection": "^7.4 || ^8.0", + "symfony/event-dispatcher": "^7.4 || ^8.0", + "symfony/http-kernel": "^7.4 || ^8.0", + "symfony/property-access": "^7.4 || ^8.0", + "symfony/framework-bundle": "^7.4 || ^8.0", + "symfony/console": "^7.4 || ^8.0", + "symfony/security-core": "^7.4 || ^8.0", "api-platform/symfony": "^4.2", "api-platform/doctrine-orm": "^4.2", "lexik/jwt-authentication-bundle": "^3.1", diff --git a/src/ApiPlatform/JsonSchema/SchemaFactoryDecorator.php b/src/ApiPlatform/JsonSchema/SchemaFactoryDecorator.php index 96e39c1..db01349 100644 --- a/src/ApiPlatform/JsonSchema/SchemaFactoryDecorator.php +++ b/src/ApiPlatform/JsonSchema/SchemaFactoryDecorator.php @@ -58,38 +58,63 @@ public function buildSchema(string $className, string $format = 'json', string $ /** @param ArrayObject $definitions */ private function ensureJsonldInputPropertyForInputSchemas(string $reference, string $schemaPrefix, ArrayObject $definitions): void { - $definitionName = str_replace($schemaPrefix, '', $reference); + foreach ( + $this->collectReferences( + $definitions[ + $this->stripSchemaPrefix($schemaPrefix, $reference) + ]['properties'] ?? [], + $schemaPrefix, + ) as $definitionKey) { + $this->addJsonldInputProperty($definitionKey, $definitions); + } + } - foreach ($definitions[$definitionName]['properties'] ?? [] as $property) { - if (isset($property['type'])) { + /** + * @param array> $properties + * + * @return iterable + */ + private function collectReferences(array $properties, string $schemaPrefix): iterable + { + foreach ($properties as $property) { + if ( + isset($property['type']) + && !isset($property['items']) + ) { continue; } if (isset($property['$ref'])) { - $this->addJsonldInputProperty( - $definitions, - $schemaPrefix, - $property['$ref'], - ); + yield $this->stripSchemaPrefix($schemaPrefix, $property['$ref']); + + continue; + } - break; + if (isset($property['items']['$ref'])) { + yield $this->stripSchemaPrefix($schemaPrefix, $property['items']['$ref']); + + continue; } foreach (self::SCHEMA_LOGICAL_OPERATORS as $operator) { - if (!isset($property[$operator])) { - continue; - } + if (isset($property[$operator])) { + foreach ($property[$operator] as $subschema) { + if (!isset($subschema['$ref'])) { + continue; + } - foreach ($property[$operator] as $subschema) { - if (!isset($subschema['$ref'])) { - continue; + yield $this->stripSchemaPrefix($schemaPrefix, $subschema['$ref']); } + } - $this->addJsonldInputProperty( - $definitions, - $schemaPrefix, - $subschema['$ref'], - ); + if (isset($property['items'][$operator])) { + foreach ($property['items'][$operator] as $subschema) { + if (!isset($subschema['$ref'])) { + continue; + } + + yield $this->stripSchemaPrefix($schemaPrefix, $subschema['$ref']); + } } } } @@ -97,13 +122,15 @@ private function ensureJsonldInputPropertyForInputSchemas(string $reference, str /** @param ArrayObject $definitions */ private function addJsonldInputProperty( + string $definitionKey, ArrayObject $definitions, - string $schemaPrefix, - string $ref, ): void { - $definitionKey = str_replace($schemaPrefix, '', $ref); - $definitions[$definitionKey]['properties'][self::JSONLD_INPUT_OBJECT_PROPERTY_NAME] ??= self::JSONLD_INPUT_OBJECT_PROPERTY; } + + private function stripSchemaPrefix(string $schemaPrefix, string $reference): string + { + return str_replace($schemaPrefix, '', $reference); + } } diff --git a/src/Service/IriTemplatesService.php b/src/Service/IriTemplatesService.php index 750f9da..da757a4 100644 --- a/src/Service/IriTemplatesService.php +++ b/src/Service/IriTemplatesService.php @@ -13,6 +13,7 @@ use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouterInterface; +use function is_string; use function preg_replace; final class IriTemplatesService @@ -52,12 +53,16 @@ public function getIriTemplatesData(): array /** @var string $operationName */ $operationName = $operation->getName(); $route = $routeCollection->get($operationName); + $shortName = $resourceMetadata->getShortName(); - if (!$route instanceof Route) { + if ( + !$route instanceof Route + || !is_string($shortName) + ) { continue; } - $iriTemplates[$resourceMetadata->getShortName()] = $this->sanitizePath($route->getPath()); + $iriTemplates[$shortName] = $this->sanitizePath($route->getPath()); break; }