-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added endpoint for converting openapi yaml to json #281
- Loading branch information
Showing
4 changed files
with
184 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters