API: Load api info from yaml
This commit is contained in:
parent
b5d94971bc
commit
72649c9522
|
@ -26,6 +26,7 @@ COPY config/ /app/config
|
|||
COPY db/ /app/db
|
||||
COPY includes/ /app/includes
|
||||
COPY public/ /app/public
|
||||
COPY resources/api /app/resources/api
|
||||
COPY resources/views /app/resources/views
|
||||
COPY src/ /app/src
|
||||
COPY storage/ /app/storage
|
||||
|
|
|
@ -4,7 +4,7 @@ info:
|
|||
version: 0.0.1-beta
|
||||
title: Engelsystem
|
||||
description: |
|
||||
This API description is as stable as a **beta** version might be.
|
||||
This API is as stable as a **beta** version might be.
|
||||
It could burst into flames and morph into a monster at any second!
|
||||
(But we try to keep it somewhat consistent, at least during events).
|
||||
contact:
|
||||
|
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Engelsystem\Controllers\Api;
|
||||
|
||||
use Engelsystem\Http\Response;
|
||||
use League\OpenAPIValidation\PSR7\ValidatorBuilder as OpenApiValidatorBuilder;
|
||||
|
||||
class IndexController extends ApiController
|
||||
{
|
||||
|
@ -25,13 +26,22 @@ class IndexController extends ApiController
|
|||
|
||||
public function indexV0(): Response
|
||||
{
|
||||
$openApiDefinition = app()->get('path.resources.api') . '/openapi.yml';
|
||||
$schema = (new OpenApiValidatorBuilder())
|
||||
->fromYamlFile($openApiDefinition)
|
||||
->getResponseValidator()
|
||||
->getSchema();
|
||||
$info = $schema->info;
|
||||
$paths = [];
|
||||
foreach ($schema->paths->getIterator() as $path => $item) {
|
||||
$paths[] = $path;
|
||||
}
|
||||
|
||||
return $this->response
|
||||
->withContent(json_encode([
|
||||
'version' => '0.0.1-beta',
|
||||
'description' => 'Beta API, might break any second.',
|
||||
'paths' => [
|
||||
'/news',
|
||||
],
|
||||
'version' => $info->version,
|
||||
'description' => $info->description,
|
||||
'paths' => $paths,
|
||||
]));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue