-
-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API specification generation #178
Changes from 1 commit
b6e5a22
82da576
01f0df5
51ef401
f8086ab
8d6d188
64fa1a4
b5b3119
c36badb
7bc331f
4f04d94
e56690d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,52 @@ | ||||||
on: | ||||||
schedule: | ||||||
- cron: '0 7 * * *' | ||||||
|
||||||
env: | ||||||
DOCS_REPOSITORY: romalytvynenko/cachet-docs | ||||||
DOCS_BRANCH: feat/api-docs-generation | ||||||
|
||||||
jbrooksuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
jobs: | ||||||
build: | ||||||
name: Build | ||||||
runs-on: ubuntu-latest | ||||||
steps: | ||||||
- name: Checkout | ||||||
uses: actions/checkout@v2 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
- name: Setup PHP | ||||||
uses: shivammathur/setup-php@v2 | ||||||
with: | ||||||
php-version: 8.3 | ||||||
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo | ||||||
|
||||||
- name: Install dependencies | ||||||
run: composer install | ||||||
|
||||||
- name: Install Scramble PRO | ||||||
run: | | ||||||
composer config repositories.scramble-pro '{"type": "composer", "url": "https://satis.dedoc.co"}' | ||||||
composer config http-basic.satis.dedoc.co ${{ secrets.SCRAMBLE_USERNAME }} ${{ secrets.SCRAMBLE_KEY }} | ||||||
composer require dedoc/scramble-pro:dev-feat/timacdonald-json-api-support --dev | ||||||
|
||||||
- name: Checkout documentation repository | ||||||
uses: actions/checkout@v2 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
with: | ||||||
repository: ${{ env.DOCS_REPOSITORY }} | ||||||
ref: ${{ env.DOCS_BRANCH }} | ||||||
path: 'docs-repository' | ||||||
|
||||||
- name: Build API docs | ||||||
run: php vendor/bin/testbench scramble:export --path=docs-repository/api-reference/openapi.json | ||||||
|
||||||
- name: Setup git config | ||||||
run: | | ||||||
git config --global user.name "GitHub Actions" | ||||||
git config --global user.email "<>" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can replace this with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, could not make it work, but found this gem used in other Cachet's workflows! I'll use it |
||||||
|
||||||
- name: Commit and push generated template | ||||||
run: | | ||||||
export COMMIT_MESSAGE="Generated API specification from ${{ github.repository }}/${{ github.ref}}@${{ github.sha }}" | ||||||
cd docs-repository | ||||||
git add . | ||||||
git diff-index --quiet HEAD || (git commit -m "$COMMIT_MESSAGE" && git push) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,9 +3,13 @@ | |||||
namespace Cachet; | ||||||
|
||||||
use BladeUI\Icons\Factory; | ||||||
use Cachet\Documentation\AddAuthenticationToOperation; | ||||||
use Cachet\Models\Incident; | ||||||
use Cachet\Models\Schedule; | ||||||
use Cachet\Settings\AppSettings; | ||||||
use Dedoc\Scramble\Scramble; | ||||||
use Dedoc\Scramble\Support\Generator\OpenApi; | ||||||
use Dedoc\Scramble\Support\Generator\SecurityScheme; | ||||||
use Filament\Support\Colors\Color; | ||||||
use Filament\Support\Facades\FilamentColor; | ||||||
use Illuminate\Cache\RateLimiting\Limit; | ||||||
|
@@ -63,6 +67,8 @@ public function boot(): void | |||||
FilamentColor::register([ | ||||||
'cachet' => Color::rgb('rgb(4, 193, 71)'), | ||||||
]); | ||||||
|
||||||
$this->configureScramble(); | ||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -182,4 +188,24 @@ private function registerSchedules(): void | |||||
$schedule->command('cachet:beacon')->daily(); | ||||||
}); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Scramble is installed as dev dependency hence the class existence check. | ||||||
*/ | ||||||
private function configureScramble(): void | ||||||
{ | ||||||
if (! class_exists(Scramble::class)) { | ||||||
return; | ||||||
} | ||||||
|
||||||
Scramble::afterOpenApiGenerated(function (OpenApi $openApi) { | ||||||
$openApi->info->description = 'API documentation for Cachet, the open source status page system.'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
$openApi->secure( | ||||||
SecurityScheme::http('bearer') | ||||||
); | ||||||
}); | ||||||
|
||||||
Scramble::registerExtension(AddAuthenticationToOperation::class); | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Cachet\Documentation; | ||
|
||
use Dedoc\Scramble\Extensions\OperationExtension; | ||
use Dedoc\Scramble\Support\Generator\Operation; | ||
use Dedoc\Scramble\Support\RouteInfo; | ||
|
||
class AddAuthenticationToOperation extends OperationExtension | ||
{ | ||
public function handle(Operation $operation, RouteInfo $routeInfo) | ||
{ | ||
jbrooksuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// @todo find out if a route is protected by auth by looking at route's middleware to avoid manually annotating methods | ||
|
||
if (in_array('GET', $routeInfo->route->methods())) { | ||
$operation->addSecurity([]); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to update these to the real docs and
main
branch.