diff --git a/src/Definition/Loader/OpenApiDefinitionLoader.php b/src/Definition/Loader/OpenApiDefinitionLoader.php index d36fcbc..bba1da5 100644 --- a/src/Definition/Loader/OpenApiDefinitionLoader.php +++ b/src/Definition/Loader/OpenApiDefinitionLoader.php @@ -298,6 +298,7 @@ private function getSecurities(array $securitySchemes, array $requirements = []) if ($scheme->type === 'http') { $collection[] = new HttpSecurity($name, $scheme->scheme, $scheme->bearerFormat); } + $supportedScopes = []; if ($scheme->type === 'oauth2' && $scheme->flows !== null) { $flows = (array) $scheme->flows->getSerializableData(); $notFoundRequirements = []; @@ -311,33 +312,32 @@ private function getSecurities(array $securitySchemes, array $requirements = []) if (is_object($flowScopes)) { $flowScopes = array_keys((array) $flowScopes); } - $diff = array_diff($scopes, $flowScopes); - if (\count($diff) > 0) { - $notFoundRequirements[$type] = $diff; + $flowSupportedScopes = array_values(array_intersect($scopes, $flowScopes)); + $supportedScopes[] = $flowSupportedScopes; + if (count($flowSupportedScopes) === 0) { continue; } - $notFoundRequirements = []; - $scopes = Scopes::fromNames($scopes); + $flowSupportedScopes = Scopes::fromNames($flowSupportedScopes); $securityName = $name . '_' . $type; if ($type === 'implicit') { $collection[] = new OAuth2ImplicitSecurity( $securityName, $flow->authorizationUrl, - $scopes + $flowSupportedScopes ); } if ($type === 'password') { $collection[] = new OAuth2PasswordSecurity( $securityName, $flow->tokenUrl, - $scopes + $flowSupportedScopes ); } if ($type === 'clientCredentials') { $collection[] = new OAuth2ClientCredentialsSecurity( $securityName, $flow->tokenUrl, - $scopes + $flowSupportedScopes ); } if ($type === 'authorizationCode') { @@ -345,11 +345,15 @@ private function getSecurities(array $securitySchemes, array $requirements = []) $securityName, $flow->authorizationUrl, $flow->tokenUrl, - $scopes, + $flowSupportedScopes, ); } } - if (count($notFoundRequirements) >= count($flows)) { + $notFoundRequirements = array_diff( + $requirements[$name], + array_unique(array_merge(...$supportedScopes)) + ); + if ($notFoundRequirements !== []) { $notFoundRequirements = Json::encode($notFoundRequirements); throw new DefinitionLoadingException( "Scopes '{$notFoundRequirements}' not configured in securitySchemes" @@ -400,7 +404,7 @@ private function getExamples(\cebe\openapi\spec\Operation $operation, array $par if ($parameter->schema instanceof Schema && $parameter->schema->example !== null) { $operationExample = $this->getExample('default', $examples, $successStatusCode); try { - $example = $this->extractDeepExamples($parameter->schema); + $example = $this->extractDeepExamples($parameter->schema, path: 'parameter.' . $parameter->name); } catch (InvalidExampleException $e) { $this->logger->warning($e->getMessage()); continue; diff --git a/src/Preparator/TestCasesPreparator.php b/src/Preparator/TestCasesPreparator.php index 60508cf..a437643 100644 --- a/src/Preparator/TestCasesPreparator.php +++ b/src/Preparator/TestCasesPreparator.php @@ -15,6 +15,8 @@ use APITester\Test\TestCase; use APITester\Util\Json; use APITester\Util\Object_; +use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; use Symfony\Component\Serializer\Exception\ExceptionInterface; use Symfony\Component\Yaml\Tag\TaggedValue; use Vural\OpenAPIFaker\Options; @@ -26,10 +28,13 @@ abstract class TestCasesPreparator protected PreparatorConfig $config; + protected LoggerInterface $logger; + public function __construct() { $this->tokens = new Tokens(); $this->config = $this->newConfigInstance(static::getConfigFQCN()); + $this->logger = new NullLogger(); } /** @@ -118,6 +123,11 @@ final public function getConfig(): PreparatorConfig return $this->config; } + final public function setLogger(LoggerInterface $logger): void + { + $this->logger = $logger; + } + /** * @return class-string */ diff --git a/src/Test/Suite.php b/src/Test/Suite.php index cef5e68..97e6edd 100644 --- a/src/Test/Suite.php +++ b/src/Test/Suite.php @@ -186,6 +186,7 @@ private function prepareTestCases(): void /** @var Collection $allTests */ $allTests = collect(); foreach ($this->preparators as $preparator) { + $preparator->setLogger($this->logger); $operations = $this->api->getOperations() ->map( static fn (Operation $op) => $op->setPreparator($preparator::getName())