Skip to content

Commit

Permalink
also filter entities
Browse files Browse the repository at this point in the history
  • Loading branch information
narcoticfresh committed May 23, 2024
1 parent bde2d6e commit 3475ded
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Graviton/RestBundle/Trait/SchemaTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ public function getResponseFromSchema(
}

$schema['paths'] = $newPaths;

// also filter entities!
$fullAsJson = json_encode($schema, JSON_UNESCAPED_SLASHES);
$pattern = '/#\/components\/schemas\/([a-zA-Z0-9]*)/m';
preg_match_all($pattern, $fullAsJson, $matches);

if (!empty($matches[1]) && !empty($schema['components']['schemas'])) {
$includedEntities = array_unique($matches[1]);
foreach ($schema['components']['schemas'] as $key => $content) {
if (!in_array($key, $includedEntities)) {
unset($schema['components']['schemas'][$key]);
}
}
}
}

if ($format == 'json') {
Expand Down

0 comments on commit 3475ded

Please sign in to comment.