From bbe090fb14147e989ff83bd043e0fb6b77b0fec8 Mon Sep 17 00:00:00 2001 From: DerManoMann Date: Wed, 14 Oct 2026 16:33:26 +1300 Subject: [PATCH] Suggest symfony/yaml, and say so when a YAML specification needs it Backport of #87 to 2.x. --- README.md | 3 +++ composer.json | 1 + src/OpenApiSpecificationLoader.php | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/README.md b/README.md index 8d7a13b..523cf63 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,9 @@ composer require radebatz/openapi-verifier ``` After that all required classes should be availabe in your project to add routing support. +Some features need further packages, such as a framework adapter or YAML support. They are listed +as suggestions, and `composer suggests radebatz/openapi-verifier` shows them. + ## Usage ### Manual verification The `VerifiesOpenApi` trait can be used directly and customized in 3 ways in order to provide the reqired OpenApi specifications: diff --git a/composer.json b/composer.json index 99fde82..741b8d4 100644 --- a/composer.json +++ b/composer.json @@ -69,6 +69,7 @@ "suggest": { "laravel/laravel": "A PHP framework", "slim/slim": "A PHP framework", + "symfony/yaml": "To load YAML specifications", "zircote/swagger-php": "OpenApi library to generate OpenAPI documentation from PHP annotations." } } diff --git a/src/OpenApiSpecificationLoader.php b/src/OpenApiSpecificationLoader.php index 0f853b7..b2f064c 100644 --- a/src/OpenApiSpecificationLoader.php +++ b/src/OpenApiSpecificationLoader.php @@ -23,6 +23,10 @@ protected function resolveSpecification($specification) $resolved = null; if (is_string($specification)) { if (false !== strpos($specification, '.yaml') || false !== strpos($specification, '.yml')) { + if (!class_exists(Yaml::class)) { + throw new \LogicException(sprintf('Unable to load specification "%s" as symfony/yaml is not installed. Try running "composer require symfony/yaml".', $specification)); + } + try { $resolved = (object) Yaml::parseFile($specification, Yaml::PARSE_OBJECT_FOR_MAP); } catch (ParseException $parseException) {