Skip to content

Commit

Permalink
Added endpoint for converting openapi yaml to json #281
Browse files Browse the repository at this point in the history
  • Loading branch information
dsbilling committed Jun 14, 2023
1 parent 6af879c commit a92a36d
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 1 deletion.
40 changes: 40 additions & 0 deletions app/Http/Controllers/API/v1/OpenAPIController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Http\Controllers\API\v1;

use App\Http\Controllers\Controller;
use App\Models\Post;
use cebe\openapi\exceptions\IOException;
use cebe\openapi\exceptions\TypeErrorException;
use cebe\openapi\exceptions\UnresolvableReferenceException;
use cebe\openapi\Reader;
use cebe\openapi\Writer;
use Illuminate\Http\Request;

/**
* @group OpenAPI
*
* APIs for OpenAPI.
*/
class OpenAPIController extends Controller
{

/**
* Show the OpenAPI documentation in JSON format.
*
* @response 200 {}
* @unauthenticated
**/
public function index()
{
# Get YAML from storage
$file_path = storage_path('app/scribe/openapi.yaml');
try {
$openapi = Reader::readFromYamlFile($file_path);
} catch (IOException|TypeErrorException|UnresolvableReferenceException $e) {
return response('', 500)->header('Content-Type', 'application/json');
}
$json = Writer::writeToJson($openapi);
return response($json, 200)->header('Content-Type', 'application/json');
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"beyondcode/laravel-favicon": "dev-l9",
"blade-ui-kit/blade-ui-kit": "^0.3.2",
"bolechen/nova-activitylog": "^0.4.0",
"cebe/php-openapi": "^1.7",
"cyrildewit/eloquent-viewable": "^6.0",
"digikraaft/laravel-review-rating": "^2.3",
"doctrine/dbal": "^3.3",
Expand Down
141 changes: 140 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Http\Controllers\API\v1\Game\BadgeController;
use App\Http\Controllers\API\v1\GamejoltAccountBanController;
use App\Http\Controllers\API\v1\GamejoltAccountController;
use App\Http\Controllers\API\v1\OpenAPIController;
use App\Http\Controllers\API\v1\PostController;
use App\Http\Controllers\API\v1\UserController;
use Illuminate\Support\Facades\Route;
Expand All @@ -30,3 +31,5 @@
Route::apiResource('game/badges', BadgeController::class);
Route::apiResource('post', PostController::class);
})->middleware(['api']);

Route::apiResource('openapi-json', OpenAPIController::class)->only('index');

0 comments on commit a92a36d

Please sign in to comment.