Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Console/Commands/ExportDocumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ExportDocumentation extends Command
protected $signature = 'scramble:export
{--path= : The path to save the exported JSON file}
{--api=default : The API to export a documentation for}
{--all : Ignore exclude attributes, export all routes}
';

protected $description = 'Export the OpenAPI document to a JSON file.';
Expand All @@ -20,6 +21,10 @@ public function handle(Generator $generator): void
{
$config = Scramble::getGeneratorConfig($api = $this->option('api'));

if ($this->option('all')) {
$config->set('ignore_exclude_attributes', true);
}

$specification = json_encode($generator($config), JSON_PRETTY_PRINT);

/** @var string $filename */
Expand Down
6 changes: 5 additions & 1 deletion src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,15 @@ private function getRoutes(GeneratorConfig $config): Collection
})
->filter($config->routes())
->filter(fn (Route $r) => $r->getAction('controller'))
->filter(function (Route $route) {
->filter(function (Route $route) use ($config) {
if (! is_string($route->getAction('uses'))) {
return true;
}

if ($config->get('ignore_exclude_attributes')) {
return true;
}

try {
$classReflection = new \ReflectionClass(explode('@', $route->getAction('uses'))[0]);

Expand Down
5 changes: 5 additions & 0 deletions src/GeneratorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,9 @@ public function get(string $key, mixed $default = null)
{
return Arr::get($this->config, $key, $default);
}

public function set(string $key, mixed $value): void
{
$this->config[$key] = $value;
}
}
9 changes: 9 additions & 0 deletions src/Scramble.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Dedoc\Scramble\Support\RouteInfo;
use Illuminate\Routing\Route;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Context;
use Illuminate\Support\Facades\Route as RouteFacade;

class Scramble
Expand Down Expand Up @@ -149,6 +150,10 @@ public static function registerUiRoute(string $path, string $api = 'default'): R
{
$config = static::getGeneratorConfig($api);

if (Context::hasHidden('scramble-all-access')) {
$config->set('ignore_exclude_attributes', true);
}

return RouteFacade::get($path, function (Generator $generator) use ($api) {
$config = static::getGeneratorConfig($api);

Expand All @@ -164,6 +169,10 @@ public static function registerJsonSpecificationRoute(string $path, string $api
{
$config = static::getGeneratorConfig($api);

if (Context::hasHidden('scramble-all-access')) {
$config->set('ignore_exclude_attributes', true);
}

return RouteFacade::get($path, function (Generator $generator) use ($api) {
$config = static::getGeneratorConfig($api);

Expand Down