From 1eaf6e4cae801aa869f08319718d8582a1a1375e Mon Sep 17 00:00:00 2001 From: DerManoMann Date: Wed, 14 Oct 2026 14:34:13 +1300 Subject: [PATCH] Suggest symfony/yaml, and say so when a YAML specification needs it --- README.md | 5 +++++ composer.json | 1 + src/OpenApiSpecificationLoader.php | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 87cf464..719416b 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,9 @@ composer require radebatz/openapi-verifier ``` After that all required classes should be available in your project. +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 ### The verifier `OpenApiVerifier` checks a response against the specification. It needs no test case and no framework, @@ -47,6 +50,8 @@ $verifier = OpenApiVerifier::fromSpecification(__DIR__ . '/specifications/users. $verifier->verify($request, $response); ``` +The specification can be a JSON or YAML file, or an already decoded object. + How the response is looked up: * **Path**: a literal match first, then the path templates, so `/user/1` finds `/user/{id}`. When several templates match, the one with the most literal characters wins. A base path from `servers` is stripped diff --git a/composer.json b/composer.json index c0c92ce..abf75b7 100644 --- a/composer.json +++ b/composer.json @@ -90,6 +90,7 @@ "guzzlehttp/guzzle": "To verify responses in a Guzzle client, with the Guzzle middleware", "laravel/framework": "To use the Laravel adapter", "slim/slim": "To use the Slim adapter", + "symfony/yaml": "To load YAML specifications", "zircote/swagger-php": "To generate the specification from PHP attributes when none is given" } } diff --git a/src/OpenApiSpecificationLoader.php b/src/OpenApiSpecificationLoader.php index 9180be4..e5ebdfd 100644 --- a/src/OpenApiSpecificationLoader.php +++ b/src/OpenApiSpecificationLoader.php @@ -22,6 +22,10 @@ protected function resolveSpecification(mixed $specification): \stdClass $resolved = null; if (is_string($specification)) { if (preg_match('/\.ya?ml$/i', $specification)) { + 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) {