Skip to content

Commit

Permalink
feat(generate-spec): Disallow unused schemas
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Dec 17, 2024
1 parent 13a6559 commit 5b76ba4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions generate-spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,8 @@
}
}

$usedSchemas = [];

foreach ($scopePaths as $scope => $paths) {
$openapiScope = $openapi;

Expand Down Expand Up @@ -981,6 +983,7 @@
}

$scopedSchemas[$schemaName] = $schemas[$schemaName];
$usedSchemas[] = $schemaName;
}

if (isset($schemas['Capabilities'])) {
Expand Down Expand Up @@ -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!');
}

0 comments on commit 5b76ba4

Please sign in to comment.