diff --git a/src/Graviton/RestBundle/Trait/SchemaTrait.php b/src/Graviton/RestBundle/Trait/SchemaTrait.php index de3d9a8a8..a99e3df90 100644 --- a/src/Graviton/RestBundle/Trait/SchemaTrait.php +++ b/src/Graviton/RestBundle/Trait/SchemaTrait.php @@ -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') {