-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from tailflow/next
v2.0 Release
- Loading branch information
Showing
174 changed files
with
7,738 additions
and
2,683 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
return [ | ||
'namespaces' => [ | ||
'models' => 'App\\Models\\', | ||
'controllers' => 'App\\Http\\Controllers\\' | ||
], | ||
'auth' => [ | ||
'guard' => 'api' | ||
], | ||
'specs' => [ | ||
'info' => [ | ||
'title' => env('APP_NAME'), | ||
'description' => null, | ||
'terms_of_service' => null, | ||
'contact' => [ | ||
'name' => null, | ||
'url' => null, | ||
'email' => null, | ||
], | ||
'license' => [ | ||
'name' => null, | ||
'url' => null, | ||
], | ||
'version' => '1.0.0', | ||
], | ||
'servers' => [ | ||
['url' => env('APP_URL').'/api', 'description' => 'Default Environment'], | ||
], | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Orion\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Contracts\Container\BindingResolutionException; | ||
use InvalidArgumentException; | ||
use Orion\Contracts\Specs\Formatter; | ||
use Orion\Contracts\Specs\Parser; | ||
use Orion\Specs\Builders\Builder; | ||
use Orion\Specs\Formatters\JsonFormatter; | ||
use Orion\Specs\Formatters\YamlFormatter; | ||
use Orion\Specs\Parsers\JsonParser; | ||
use Orion\Specs\Parsers\YamlParser; | ||
use Storage; | ||
use Throwable; | ||
|
||
class BuildSpecsCommand extends Command | ||
{ | ||
protected $signature = 'orion:specs {--path=} {--format=json}'; | ||
|
||
protected $description = 'Generates API specifications in the given format'; | ||
|
||
/** | ||
* @param Builder $builder | ||
* @return int | ||
* @throws BindingResolutionException | ||
*/ | ||
public function handle(Builder $builder): int | ||
{ | ||
if (!$path = $this->option('path')) { | ||
$path = "specs/specs.{$this->option('format')}"; | ||
} | ||
|
||
$parser = $this->resolveParser($this->option('format')); | ||
$formatter = $this->resolveFormatter($this->option('format')); | ||
|
||
$existingSpecs = []; | ||
|
||
try { | ||
if (Storage::disk('local')->exists($path)) { | ||
$existingSpecs = $parser->parse(Storage::disk('local')->get($path)); | ||
} | ||
} catch (Throwable $exception) { | ||
$this->error($exception->getMessage()); | ||
|
||
return -1; | ||
} | ||
|
||
$specs = array_replace_recursive( | ||
$existingSpecs, | ||
$builder->build() | ||
); | ||
|
||
$formattedSpecs = $formatter->format($specs); | ||
|
||
try { | ||
Storage::disk('local')->put($path, $formattedSpecs); | ||
} catch (Throwable $exception) { | ||
$this->error($exception->getMessage()); | ||
|
||
return -1; | ||
} | ||
|
||
$this->info("Specifications are saved in storage/app/{$path}"); | ||
|
||
return 0; | ||
} | ||
|
||
/** | ||
* @param string $format | ||
* @return Parser | ||
* @throws BindingResolutionException | ||
*/ | ||
protected function resolveParser(string $format): Parser | ||
{ | ||
switch ($format) { | ||
case 'json': | ||
return app()->make(JsonParser::class); | ||
case 'yaml': | ||
return app()->make(YamlParser::class); | ||
default: | ||
throw new InvalidArgumentException("Unknown format provided: {$format}"); | ||
} | ||
} | ||
|
||
/** | ||
* @param string $format | ||
* @return Formatter | ||
* @throws BindingResolutionException | ||
*/ | ||
protected function resolveFormatter(string $format): Formatter | ||
{ | ||
switch ($format) { | ||
case 'json': | ||
return app()->make(JsonFormatter::class); | ||
case 'yaml': | ||
return app()->make(YamlFormatter::class); | ||
default: | ||
throw new InvalidArgumentException("Unknown format provided: {$format}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.