Commit b17f391c authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Name some unnamed routes and throw exception if api docs failed to

generate 200 repsonse
parent 84b97040
......@@ -6,22 +6,35 @@ namespace App\Documentation\Strategies;
use ReflectionClass;
use ReflectionMethod;
use RuntimeException;
use Illuminate\Routing\Route;
use Mpociot\ApiDoc\Extracting\Strategies\Strategy;
class GoodResponseValidationStrategy extends Strategy
{
protected const EXCLUDED = [
'logout',
'saml.login',
'saml.logout',
'saml.handle',
];
/**
* @inheritDoc
*/
public function __invoke(Route $route, ReflectionClass $controller, ReflectionMethod $method, array $routeRules, array $context = [])
{
dd($route, $context);
if (in_array($route->getName(), self::EXCLUDED, true)) {
return null;
}
foreach ($context['responses'] as $response) {
$status = $response['status'] ?? 0;
if ($status < 300 && $status >= 200) {
return null;
}
}
throw new RuntimeException('API docs failed to generate a 200 example response');
}
}
......@@ -17,10 +17,10 @@ use App\Http\Controllers\AuthController;
Route::get('/', static function () {
return new JsonResponse(['welcome' => 'Welcome to the elock API.']);
});
})->name('welcome');
Route::get('login', [AuthController::class, 'samlLogin']);
Route::get('login', [AuthController::class, 'samlLogin'])->name('saml.login');
Route::get('handle-login', [AuthController::class, 'handle']);
Route::get('handle-login', [AuthController::class, 'handle'])->name('saml.handle');
Route::get('logout', [AuthController::class, 'samlLogout']);
Route::get('logout', [AuthController::class, 'samlLogout'])->name('saml.logout');
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment