|
940 | 940 | } |
941 | 941 | } |
942 | 942 |
|
| 943 | +$usedSchemas = ['Capabilities', 'PublicCapabilities']; |
| 944 | + |
943 | 945 | foreach ($scopePaths as $scope => $paths) { |
944 | 946 | $openapiScope = $openapi; |
945 | 947 |
|
|
955 | 957 | $openapiScope['paths'] = array_merge(...$fullScopePathArrays); |
956 | 958 | $openapiScope['components']['schemas'] = $schemas; |
957 | 959 | } else { |
958 | | - $usedSchemas = []; |
| 960 | + $usedRefs = []; |
959 | 961 | foreach ($paths as $urlRoutes) { |
960 | 962 | foreach ($urlRoutes as $routeData) { |
961 | 963 | foreach ($routeData['responses'] as $responseData) { |
962 | 964 | if (isset($responseData['content']) && $responseData['content'] !== []) { |
963 | | - $usedSchemas[] = Helpers::collectUsedRefs($responseData['content']); |
| 965 | + $usedRefs[] = Helpers::collectUsedRefs($responseData['content']); |
964 | 966 | } |
965 | 967 | } |
966 | 968 | if (isset($routeData['requestBody']['content']) && $routeData['requestBody']['content'] !== []) { |
967 | | - $usedSchemas[] = Helpers::collectUsedRefs($routeData['requestBody']['content']); |
| 969 | + $usedRefs[] = Helpers::collectUsedRefs($routeData['requestBody']['content']); |
968 | 970 | } |
969 | 971 | } |
970 | 972 | } |
971 | 973 |
|
972 | | - $usedSchemas = array_merge(...$usedSchemas); |
| 974 | + $usedRefs = array_merge(...$usedRefs); |
973 | 975 |
|
974 | 976 | $scopedSchemas = []; |
975 | | - while ($usedSchema = array_shift($usedSchemas)) { |
976 | | - if (!str_starts_with((string)$usedSchema, '#/components/schemas/')) { |
| 977 | + while ($usedRef = array_shift($usedRefs)) { |
| 978 | + if (!str_starts_with((string)$usedRef, '#/components/schemas/')) { |
977 | 979 | continue; |
978 | 980 | } |
979 | 981 |
|
980 | | - $schemaName = substr((string)$usedSchema, strlen('#/components/schemas/')); |
| 982 | + $schemaName = substr((string)$usedRef, strlen('#/components/schemas/')); |
981 | 983 |
|
982 | 984 | if (!isset($schemas[$schemaName])) { |
983 | 985 | Logger::error('app', "Schema $schemaName used by scope $scope is not defined"); |
|
986 | 988 | $newRefs = Helpers::collectUsedRefs($schemas[$schemaName]); |
987 | 989 | foreach ($newRefs as $newRef) { |
988 | 990 | if (!isset($scopedSchemas[substr((string)$newRef, strlen('#/components/schemas/'))])) { |
989 | | - $usedSchemas[] = $newRef; |
| 991 | + $usedRefs[] = $newRef; |
990 | 992 | } |
991 | 993 | } |
992 | 994 |
|
993 | 995 | $scopedSchemas[$schemaName] = $schemas[$schemaName]; |
| 996 | + $usedSchemas[] = $schemaName; |
994 | 997 | } |
995 | 998 |
|
996 | 999 | if (isset($schemas['Capabilities'])) { |
|
1031 | 1034 | Logger::info('app', 'Generated scope ' . $scope . ' with ' . $pathsCount . ' routes!'); |
1032 | 1035 | } |
1033 | 1036 |
|
| 1037 | +$unusedSchemas = array_diff(array_keys($schemas), $usedSchemas); |
| 1038 | +if ($unusedSchemas !== []) { |
| 1039 | + Logger::error('app', 'Unused schemas: ' . implode(', ', $unusedSchemas)); |
| 1040 | +} |
| 1041 | + |
1034 | 1042 | if (Logger::$errorCount > 0) { |
1035 | 1043 | Logger::panic('app', 'Encountered ' . Logger::$errorCount . ' errors that need to be fixed!'); |
1036 | 1044 | } |
0 commit comments