Skip to content

Commit 3c0cc72

Browse files
authored
Merge pull request #93 from tailflow/next
v2.0 Release
2 parents 805a8e2 + 8f89e9d commit 3c0cc72

File tree

174 files changed

+7738
-2683
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+7738
-2683
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,10 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
php-version: [ '7.2', '7.3', '7.4', '8.0' ]
17+
php-version: [ '7.3', '7.4', '8.0' ]
1818
laravel-version: [ '5.7.*', '5.8.*', '^6.0', '^7.0', '^8.0' ]
1919
database: [ 'sqlite', 'mysql', 'pgsql' ]
2020
exclude:
21-
- php-version: '7.2'
22-
laravel-version: '^8.0'
23-
database: 'sqlite'
24-
- php-version: '7.2'
25-
laravel-version: '^8.0'
26-
database: 'mysql'
27-
- php-version: '7.2'
28-
laravel-version: '^8.0'
29-
database: 'pgsql'
3021
- php-version: '7.4'
3122
laravel-version: '5.7.*'
3223
database: 'sqlite'
@@ -54,12 +45,6 @@ jobs:
5445
- php-version: '8.0'
5546
laravel-version: '5.8.*'
5647
database: 'pgsql'
57-
- php-version: '8.0'
58-
laravel-version: '^8.0'
59-
database: 'pgsql'
60-
- php-version: '8.0'
61-
laravel-version: '^8.0'
62-
database: 'mysql'
6348

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

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
}
1818
],
1919
"require": {
20-
"php": ">=7.2",
20+
"php": ">=7.3",
2121
"ext-json": "*",
22+
"doctrine/dbal": "^2.9|^3.1",
2223
"illuminate/bus": ">=5.7",
2324
"illuminate/contracts": ">=5.7",
2425
"illuminate/database": ">=5.7",
2526
"illuminate/http": ">=5.7",
2627
"illuminate/pagination": ">=5.7",
27-
"illuminate/support": ">=5.7"
28+
"illuminate/support": ">=5.7",
29+
"symfony/yaml": "^5.3"
2830
},
2931
"require-dev": {
3032
"mockery/mockery": "^1.0",

config/orion.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
return [
4+
'namespaces' => [
5+
'models' => 'App\\Models\\',
6+
'controllers' => 'App\\Http\\Controllers\\'
7+
],
8+
'auth' => [
9+
'guard' => 'api'
10+
],
11+
'specs' => [
12+
'info' => [
13+
'title' => env('APP_NAME'),
14+
'description' => null,
15+
'terms_of_service' => null,
16+
'contact' => [
17+
'name' => null,
18+
'url' => null,
19+
'email' => null,
20+
],
21+
'license' => [
22+
'name' => null,
23+
'url' => null,
24+
],
25+
'version' => '1.0.0',
26+
],
27+
'servers' => [
28+
['url' => env('APP_URL').'/api', 'description' => 'Default Environment'],
29+
],
30+
],
31+
];

src/Commands/BuildSpecsCommand.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Orion\Commands;
6+
7+
use Illuminate\Console\Command;
8+
use Illuminate\Contracts\Container\BindingResolutionException;
9+
use InvalidArgumentException;
10+
use Orion\Contracts\Specs\Formatter;
11+
use Orion\Contracts\Specs\Parser;
12+
use Orion\Specs\Builders\Builder;
13+
use Orion\Specs\Formatters\JsonFormatter;
14+
use Orion\Specs\Formatters\YamlFormatter;
15+
use Orion\Specs\Parsers\JsonParser;
16+
use Orion\Specs\Parsers\YamlParser;
17+
use Storage;
18+
use Throwable;
19+
20+
class BuildSpecsCommand extends Command
21+
{
22+
protected $signature = 'orion:specs {--path=} {--format=json}';
23+
24+
protected $description = 'Generates API specifications in the given format';
25+
26+
/**
27+
* @param Builder $builder
28+
* @return int
29+
* @throws BindingResolutionException
30+
*/
31+
public function handle(Builder $builder): int
32+
{
33+
if (!$path = $this->option('path')) {
34+
$path = "specs/specs.{$this->option('format')}";
35+
}
36+
37+
$parser = $this->resolveParser($this->option('format'));
38+
$formatter = $this->resolveFormatter($this->option('format'));
39+
40+
$existingSpecs = [];
41+
42+
try {
43+
if (Storage::disk('local')->exists($path)) {
44+
$existingSpecs = $parser->parse(Storage::disk('local')->get($path));
45+
}
46+
} catch (Throwable $exception) {
47+
$this->error($exception->getMessage());
48+
49+
return -1;
50+
}
51+
52+
$specs = array_replace_recursive(
53+
$existingSpecs,
54+
$builder->build()
55+
);
56+
57+
$formattedSpecs = $formatter->format($specs);
58+
59+
try {
60+
Storage::disk('local')->put($path, $formattedSpecs);
61+
} catch (Throwable $exception) {
62+
$this->error($exception->getMessage());
63+
64+
return -1;
65+
}
66+
67+
$this->info("Specifications are saved in storage/app/{$path}");
68+
69+
return 0;
70+
}
71+
72+
/**
73+
* @param string $format
74+
* @return Parser
75+
* @throws BindingResolutionException
76+
*/
77+
protected function resolveParser(string $format): Parser
78+
{
79+
switch ($format) {
80+
case 'json':
81+
return app()->make(JsonParser::class);
82+
case 'yaml':
83+
return app()->make(YamlParser::class);
84+
default:
85+
throw new InvalidArgumentException("Unknown format provided: {$format}");
86+
}
87+
}
88+
89+
/**
90+
* @param string $format
91+
* @return Formatter
92+
* @throws BindingResolutionException
93+
*/
94+
protected function resolveFormatter(string $format): Formatter
95+
{
96+
switch ($format) {
97+
case 'json':
98+
return app()->make(JsonFormatter::class);
99+
case 'yaml':
100+
return app()->make(YamlFormatter::class);
101+
default:
102+
throw new InvalidArgumentException("Unknown format provided: {$format}");
103+
}
104+
}
105+
}

src/Concerns/ExtendsResources.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait ExtendsResources
1414
* @param array $mergeData
1515
* @return array
1616
*/
17-
public function toArrayWithMerge(Request $request, array $mergeData) : array
17+
public function toArrayWithMerge(Request $request, array $mergeData): array
1818
{
1919
return array_merge(parent::toArray($request), $mergeData);
2020
}

0 commit comments

Comments
 (0)