From 5b76ba4708d6f13c64848ad2a93369c4449921b5 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 17 Dec 2024 14:57:03 +0100 Subject: [PATCH] feat(generate-spec): Disallow unused schemas Signed-off-by: provokateurin --- generate-spec.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/generate-spec.php b/generate-spec.php index faf30c6..6fd18ad 100755 --- a/generate-spec.php +++ b/generate-spec.php @@ -930,6 +930,8 @@ } } +$usedSchemas = []; + foreach ($scopePaths as $scope => $paths) { $openapiScope = $openapi; @@ -981,6 +983,7 @@ } $scopedSchemas[$schemaName] = $schemas[$schemaName]; + $usedSchemas[] = $schemaName; } if (isset($schemas['Capabilities'])) { @@ -1021,6 +1024,11 @@ Logger::info('app', 'Generated scope ' . $scope . ' with ' . $pathsCount . ' routes!'); } +$unusedSchemas = array_diff(array_keys($schemas), $usedSchemas); +if ($unusedSchemas !== []) { + Logger::error('app', 'Unused schemas: ' . implode(', ', $unusedSchemas)); +} + if (Logger::$errorCount > 0) { Logger::panic('app', 'Encountered ' . Logger::$errorCount . ' errors that need to be fixed!'); }