Skip to content

Commit

Permalink
Merge pull request #93 from tailflow/next
Browse files Browse the repository at this point in the history
v2.0 Release
  • Loading branch information
alexzarbn authored Jun 13, 2021
2 parents 805a8e2 + 8f89e9d commit 3c0cc72
Show file tree
Hide file tree
Showing 174 changed files with 7,738 additions and 2,683 deletions.
17 changes: 1 addition & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,10 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [ '7.2', '7.3', '7.4', '8.0' ]
php-version: [ '7.3', '7.4', '8.0' ]
laravel-version: [ '5.7.*', '5.8.*', '^6.0', '^7.0', '^8.0' ]
database: [ 'sqlite', 'mysql', 'pgsql' ]
exclude:
- php-version: '7.2'
laravel-version: '^8.0'
database: 'sqlite'
- php-version: '7.2'
laravel-version: '^8.0'
database: 'mysql'
- php-version: '7.2'
laravel-version: '^8.0'
database: 'pgsql'
- php-version: '7.4'
laravel-version: '5.7.*'
database: 'sqlite'
Expand Down Expand Up @@ -54,12 +45,6 @@ jobs:
- php-version: '8.0'
laravel-version: '5.8.*'
database: 'pgsql'
- php-version: '8.0'
laravel-version: '^8.0'
database: 'pgsql'
- php-version: '8.0'
laravel-version: '^8.0'
database: 'mysql'

name: Tests on PHP ${{ matrix.php-version }} with Laravel ${{ matrix.laravel-version }} and ${{ matrix.database }}

Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
}
],
"require": {
"php": ">=7.2",
"php": ">=7.3",
"ext-json": "*",
"doctrine/dbal": "^2.9|^3.1",
"illuminate/bus": ">=5.7",
"illuminate/contracts": ">=5.7",
"illuminate/database": ">=5.7",
"illuminate/http": ">=5.7",
"illuminate/pagination": ">=5.7",
"illuminate/support": ">=5.7"
"illuminate/support": ">=5.7",
"symfony/yaml": "^5.3"
},
"require-dev": {
"mockery/mockery": "^1.0",
Expand Down
31 changes: 31 additions & 0 deletions config/orion.php
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'],
],
],
];
105 changes: 105 additions & 0 deletions src/Commands/BuildSpecsCommand.php
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}");
}
}
}
2 changes: 1 addition & 1 deletion src/Concerns/ExtendsResources.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait ExtendsResources
* @param array $mergeData
* @return array
*/
public function toArrayWithMerge(Request $request, array $mergeData) : array
public function toArrayWithMerge(Request $request, array $mergeData): array
{
return array_merge(parent::toArray($request), $mergeData);
}
Expand Down
Loading

0 comments on commit 3c0cc72

Please sign in to comment.