Skip to content
Merged
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"require-dev": {
"adamwojs/php-cs-fixer-phpdoc-force-fqcn": "^2.0",
"friendsofphp/php-cs-fixer": "^3.0",
"guzzlehttp/guzzle": "^7.5",
"jasonmccreary/laravel-test-assertions": "^2.3",
"orchestra/testbench": "^7.0|^8.0|^9.0",
"phpunit/phpunit": "^9.5|^10.0",
Expand Down
6 changes: 0 additions & 6 deletions package-lock.json

This file was deleted.

3 changes: 2 additions & 1 deletion resources/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@
],
layout: 'StandaloneLayout',
@if (!is_null($data["validator_url"]))
validatorUrl: '{{ $data["validator_url"] }}'
validatorUrl: '{{ $data["validator_url"] }}',
@endif
oauth2RedirectUrl: '{{ url("{$data['path']}/oauth2-redirect") }}',
});

ui.initOAuth({
Expand Down
13 changes: 13 additions & 0 deletions src/Http/Controllers/SwaggerOAuth2RedirectController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace NextApps\SwaggerUi\Http\Controllers;

use Illuminate\Support\Facades\Http;

class SwaggerOAuth2RedirectController
{
public function __invoke() : string
{
return Http::get('https://unpkg.com/swagger-ui-dist@latest/oauth2-redirect.html')->body();
}
}
3 changes: 2 additions & 1 deletion src/Http/Controllers/SwaggerViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

use Illuminate\Http\Request;
use Illuminate\Support\ItemNotFoundException;
use Illuminate\View\View;

class SwaggerViewController
{
public function __invoke(Request $request)
public function __invoke(Request $request) : View
{
try {
$file = collect(config('swagger-ui.files'))->filter(function ($values) use ($request) {
Expand Down
3 changes: 2 additions & 1 deletion src/SwaggerUiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\ServiceProvider;
use NextApps\SwaggerUi\Console\InstallCommand;
use NextApps\SwaggerUi\Http\Controllers\OpenApiJsonController;
use NextApps\SwaggerUi\Http\Controllers\SwaggerOAuth2RedirectController;
use NextApps\SwaggerUi\Http\Controllers\SwaggerViewController;

class SwaggerUiServiceProvider extends ServiceProvider
Expand Down Expand Up @@ -40,7 +41,7 @@ protected function loadRoutes() : void
Route::middleware($values['middleware'])
->group(function () use ($values) {
Route::get($values['path'], SwaggerViewController::class)->name($values['path'] . '.index');

Route::get($values['path'] . '/oauth2-redirect', SwaggerOAuth2RedirectController::class)->name($values['path'] . '.oauth2-redirect');
Route::get($values['path'] . '/{filename}', OpenApiJsonController::class)->name($values['path'] . '.json');
});
});
Expand Down
40 changes: 40 additions & 0 deletions tests/SwaggerOAuth2RedirectRouteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace NextApps\SwaggerUi\Tests;

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Http;
use NextApps\SwaggerUi\SwaggerUiServiceProvider;

class SwaggerOAuth2RedirectRouteTest extends TestCase
{
protected function setUp() : void
{
parent::setUp();

config()->set('swagger-ui.files.0.versions', ['v1' => __DIR__ . '/testfiles/openapi.json']);
config()->set('swagger-ui.files.0.oauth', ['client_id' => 1, 'client_secret' => 'foobar']);

Gate::define('viewSwaggerUI', fn (?Authenticatable $user) => true);
}

protected function getPackageProviders($app) : array
{
return [SwaggerUiServiceProvider::class];
}

/** @test */
public function it_returns_swagger_ui_oauth2_redirect_html_file_content()
{
Http::fake([
'https://unpkg.com/swagger-ui-dist@latest/oauth2-redirect.html' => Http::response('foo'),
]);

$this->get('swagger/oauth2-redirect')
->assertStatus(200)
->assertSeeText('foo');

Http::assertSentCount(1);
}
}