API: Load api info from yaml

This commit is contained in:
Igor Scheller 2023-07-22 22:47:55 +02:00 committed by Michael Weimann
parent b5d94971bc
commit 72649c9522
3 changed files with 17 additions and 6 deletions

View File

@ -26,6 +26,7 @@ COPY config/ /app/config
COPY db/ /app/db COPY db/ /app/db
COPY includes/ /app/includes COPY includes/ /app/includes
COPY public/ /app/public COPY public/ /app/public
COPY resources/api /app/resources/api
COPY resources/views /app/resources/views COPY resources/views /app/resources/views
COPY src/ /app/src COPY src/ /app/src
COPY storage/ /app/storage COPY storage/ /app/storage

View File

@ -4,7 +4,7 @@ info:
version: 0.0.1-beta version: 0.0.1-beta
title: Engelsystem title: Engelsystem
description: | 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! 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). (But we try to keep it somewhat consistent, at least during events).
contact: contact:

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Engelsystem\Controllers\Api; namespace Engelsystem\Controllers\Api;
use Engelsystem\Http\Response; use Engelsystem\Http\Response;
use League\OpenAPIValidation\PSR7\ValidatorBuilder as OpenApiValidatorBuilder;
class IndexController extends ApiController class IndexController extends ApiController
{ {
@ -25,13 +26,22 @@ class IndexController extends ApiController
public function indexV0(): Response 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 return $this->response
->withContent(json_encode([ ->withContent(json_encode([
'version' => '0.0.1-beta', 'version' => $info->version,
'description' => 'Beta API, might break any second.', 'description' => $info->description,
'paths' => [ 'paths' => $paths,
'/news',
],
])); ]));
} }