Skip to content

Commit

Permalink
fix(scopes): Deduplicate finding used schemas
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Jan 12, 2024
1 parent 81fdbb1 commit a152105
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions generate-spec
Original file line number Diff line number Diff line change
Expand Up @@ -817,26 +817,10 @@ foreach ($scopePaths as $scope => $paths) {
Logger::error("app", "Schema $schemaName used by scope $scope is not defined");
}

// Queue potential sub-refs for exporting as well
foreach (['allOf', 'oneOf', 'anyOf', 'properties', 'additionalProperties'] as $group) {
if (isset($schemas[$schemaName][$group])) {
foreach ($schemas[$schemaName][$group] as $subType) {
$newRefs = Helpers::collectUsedRefs($subType);
foreach ($newRefs as $newRef) {
if (!isset($scopedSchemas[substr($newRef, strlen('#/components/schemas/'))])) {
$usedSchemas[] = $newRef;
}
}
}
}
}

if (isset($schemas[$schemaName]['items'])) {
$newRefs = Helpers::collectUsedRefs($schemas[$schemaName]['items']);
foreach ($newRefs as $newRef) {
if (!isset($scopedSchemas[substr($newRef, strlen('#/components/schemas/'))])) {
$usedSchemas[] = $newRef;
}
$newRefs = Helpers::collectUsedRefs($schemas[$schemaName]);
foreach ($newRefs as $newRef) {
if (!isset($scopedSchemas[substr($newRef, strlen('#/components/schemas/'))])) {
$usedSchemas[] = $newRef;
}
}

Expand Down

0 comments on commit a152105

Please sign in to comment.