Skip to content

Commit

Permalink
Merge pull request #80 from nextcloud/fix/helpers/ref-collection
Browse files Browse the repository at this point in the history
fix(Helpers): Fix ref collection
  • Loading branch information
nickvergessen authored Jan 18, 2024
2 parents 5c7fe08 + 7174bdf commit df8b4c8
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,25 +253,11 @@ public static function getOpenAPIAttributeTagsByScope(ClassMethod|Class_|Node $n

public static function collectUsedRefs(array $data): array {
$refs = [];
if (isset($data['$ref'])) {
$refs[] = [$data['$ref']];
}

foreach (['allOf', 'oneOf', 'anyOf', 'properties', 'additionalProperties'] as $group) {
if (!isset($data[$group]) || !is_array($data[$group])) {
continue;
array_walk_recursive($data, function ($value, $key) use (&$refs) {
if ($key === '$ref') {
$refs[] = $value;
}

foreach ($data[$group] as $property) {
if (is_array($property)) {
$refs[] = self::collectUsedRefs($property);
}
}
}

if (isset($data['items'])) {
$refs[] = self::collectUsedRefs($data['items']);
}
return array_merge(...$refs);
});
return $refs;
}
}

0 comments on commit df8b4c8

Please sign in to comment.