Added OpenAPI docs using nelmioAPIDocBundle.
CI / Docker Lint (push) Successful in 21s

This commit is contained in:
2024-09-20 21:29:23 +02:00
parent 0cf6f231a3
commit bfcd04c701
18 changed files with 610 additions and 20 deletions
+76 -4
View File
@@ -2,14 +2,35 @@
namespace App\Controller;
use App\Entity\ConfigVariable;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use App\Repository\ConfigVariableRepository;
use Nelmio\ApiDocBundle\Annotation\Model;
use OpenApi\Attributes as OA;
class ConfigVariableController extends AbstractController
{
#[Route('/api/config', name: 'app_config_variable')]
/**
* Get All config variables.
*/
#[Route('/api/config', name: 'app_config_allVariable', methods: ["GET"])]
#[OA\Tag(name: "Config")]
#[OA\Response(
response: 200,
description: 'Returns all public config variables.',
content: new OA\JsonContent(
type: 'object',
properties: [
new OA\Property(
property: "results",
type: "array",
items: new OA\Items(ref: new Model(type: ConfigVariable::class))
)
]
)
)]
public function getAllVariables(ConfigVariableRepository $repo): Response
{
$varList = $repo->findAllVariables();
@@ -17,7 +38,22 @@ class ConfigVariableController extends AbstractController
return $this->json(['results' => $varList]);
}
#[Route('/api/config/section', name: 'app_config_sections')]
#[Route('/api/config/section', name: 'app_config_sections', methods: ["GET"])]
#[OA\Tag(name: "Config")]
#[OA\Response(
response: 200,
description: 'Returns all public config sections.',
content: new OA\JsonContent(
type: 'object',
properties: [
new OA\Property(
property: "results",
type: "array",
items: new OA\Items(type: "string")
)
]
)
)]
public function getSections(ConfigVariableRepository $repo): Response
{
$sectionList = $repo->getAllSections();
@@ -30,7 +66,28 @@ class ConfigVariableController extends AbstractController
return $this->json(['results' => $returnList]);
}
#[Route('/api/config/section/{section}', name: 'app_config_variableBySection')]
#[Route('/api/config/section/{section}', name: 'app_config_variableBySection', methods: ["GET"])]
#[OA\Tag(name: "Config")]
#[OA\Response(
response: 200,
description: 'Returns all public config variables for given section.',
content: new OA\JsonContent(
type: 'object',
properties: [
new OA\Property(
property: "results",
type: "array",
items: new OA\Items(ref: new Model(type: ConfigVariable::class))
)
]
)
)]
#[OA\Parameter(
name: 'section',
in: 'path',
description: 'Config section.',
schema: new OA\Schema(type: 'string')
)]
public function getVariablesBySection(ConfigVariableRepository $repo, string $section): Response
{
if(\is_null($section) || $section == '') {
@@ -42,7 +99,22 @@ class ConfigVariableController extends AbstractController
return $this->json(['results' => $varList]);
}
#[Route('/api/config/var/{key}', name: 'app_config_variable')]
#[Route('/api/config/var/{key}', name: 'app_config_variable', methods: ["GET"])]
#[OA\Tag(name: "Config")]
#[OA\Response(
response: 200,
description: 'Get config variable by key.',
content: new OA\JsonContent(
type: 'object',
ref: new Model(type: ConfigVariable::class),
)
)]
#[OA\Parameter(
name: 'key',
in: 'path',
description: 'Variable key.',
schema: new OA\Schema(type: 'string')
)]
public function getByKey(ConfigVariableRepository $repo, string $key): Response
{
$var = $repo->findVariableByKey($key);