Skip to content

Commit

Permalink
refactor(generate-spec): Use correct variable name for used refs
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 63bbc54 commit 13a6559
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions generate-spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -945,29 +945,29 @@
$openapiScope['paths'] = array_merge(...$fullScopePathArrays);
$openapiScope['components']['schemas'] = $schemas;
} else {
$usedSchemas = [];
$usedRefs = [];
foreach ($paths as $urlRoutes) {
foreach ($urlRoutes as $routeData) {
foreach ($routeData['responses'] as $responseData) {
if (isset($responseData['content']) && $responseData['content'] !== []) {
$usedSchemas[] = Helpers::collectUsedRefs($responseData['content']);
$usedRefs[] = Helpers::collectUsedRefs($responseData['content']);
}
}
if (isset($routeData['requestBody']['content']) && $routeData['requestBody']['content'] !== []) {
$usedSchemas[] = Helpers::collectUsedRefs($routeData['requestBody']['content']);
$usedRefs[] = Helpers::collectUsedRefs($routeData['requestBody']['content']);
}
}
}

$usedSchemas = array_merge(...$usedSchemas);
$usedRefs = array_merge(...$usedRefs);

$scopedSchemas = [];
while ($usedSchema = array_shift($usedSchemas)) {
if (!str_starts_with((string)$usedSchema, '#/components/schemas/')) {
while ($usedRef = array_shift($usedRefs)) {
if (!str_starts_with((string)$usedRef, '#/components/schemas/')) {
continue;
}

$schemaName = substr((string)$usedSchema, strlen('#/components/schemas/'));
$schemaName = substr((string)$usedRef, strlen('#/components/schemas/'));

if (!isset($schemas[$schemaName])) {
Logger::error('app', "Schema $schemaName used by scope $scope is not defined");
Expand All @@ -976,7 +976,7 @@
$newRefs = Helpers::collectUsedRefs($schemas[$schemaName]);
foreach ($newRefs as $newRef) {
if (!isset($scopedSchemas[substr((string)$newRef, strlen('#/components/schemas/'))])) {
$usedSchemas[] = $newRef;
$usedRefs[] = $newRef;
}
}

Expand Down

0 comments on commit 13a6559

Please sign in to comment.