API improvements (#5494)
* hide logo in docs UI * always return a user in api base controller * added example for duration fields
This commit is contained in:
24
phpstan.neon
24
phpstan.neon
@@ -42,10 +42,6 @@ parameters:
|
||||
containerXmlPath: %rootDir%/../../../var/cache/dev/App_KernelDevDebugContainer.xml
|
||||
ignoreErrors:
|
||||
- '#^Method .*\(\) has parameter \$builder with generic interface Symfony\\Component\\Form\\FormBuilderInterface but does not specify its types\: TData$#'
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$user of class App\\\\Event\\\\PageActionsEvent constructor expects App\\\\Entity\\\\User, App\\\\Entity\\\\User\\|null given\\.$#"
|
||||
count: 4
|
||||
path: src/API/ActionsController.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$name of method App\\\\Entity\\\\Activity\\:\\:getMetaField\\(\\) expects string, mixed given\\.$#"
|
||||
@@ -62,11 +58,6 @@ parameters:
|
||||
count: 1
|
||||
path: src/API/Authentication/TokenAuthenticator.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$user of static method App\\\\Timesheet\\\\DateTimeFactory\\:\\:createByUser\\(\\) expects App\\\\Entity\\\\User, App\\\\Entity\\\\User\\|null given\\.$#"
|
||||
count: 1
|
||||
path: src/API/BaseApiController.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$name of method App\\\\Entity\\\\Customer\\:\\:getMetaField\\(\\) expects string, mixed given\\.$#"
|
||||
count: 1
|
||||
@@ -137,21 +128,6 @@ parameters:
|
||||
count: 3
|
||||
path: src/API/TimesheetController.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$user of class App\\\\Event\\\\RecentActivityEvent constructor expects App\\\\Entity\\\\User, App\\\\Entity\\\\User\\|null given\\.$#"
|
||||
count: 1
|
||||
path: src/API/TimesheetController.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$user of method App\\\\Repository\\\\TimesheetRepository\\:\\:getRecentActivities\\(\\) expects App\\\\Entity\\\\User, App\\\\Entity\\\\User\\|null given\\.$#"
|
||||
count: 1
|
||||
path: src/API/TimesheetController.php
|
||||
|
||||
-
|
||||
message: "#^Cannot call method getId\\(\\) on App\\\\Entity\\\\User\\|null\\.$#"
|
||||
count: 1
|
||||
path: src/API/UserController.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$statistic of class App\\\\Event\\\\ActivityStatisticEvent constructor expects App\\\\Model\\\\ActivityStatistic, App\\\\Model\\\\ActivityStatistic\\|null given\\.$#"
|
||||
count: 1
|
||||
|
||||
@@ -20,15 +20,22 @@ use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormTypeInterface;
|
||||
|
||||
/**
|
||||
* @method null|User getUser()
|
||||
*/
|
||||
abstract class BaseApiController extends AbstractController
|
||||
{
|
||||
public const DATE_ONLY_FORMAT = 'yyyy-MM-dd';
|
||||
public const DATE_FORMAT = DateTimeType::HTML5_FORMAT;
|
||||
public const DATE_FORMAT_PHP = 'Y-m-d\TH:i:s';
|
||||
|
||||
protected function getUser(): User
|
||||
{
|
||||
$user = parent::getUser();
|
||||
if (!$user instanceof User) {
|
||||
throw $this->createAccessDeniedException('Need a user for API access');
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template TFormType of FormTypeInterface<TData>
|
||||
* @template TData of BaseQuery
|
||||
|
||||
@@ -33,6 +33,11 @@ final class DurationType extends AbstractType
|
||||
'toggle' => false,
|
||||
'max_hours' => 24,
|
||||
'icon' => 'clock',
|
||||
'documentation' => [
|
||||
'type' => 'string',
|
||||
'description' => 'Duration - supports various formats: https://www.kimai.org/documentation/duration-format.html',
|
||||
'example' => '01:30',
|
||||
]
|
||||
]);
|
||||
$resolver->setAllowedTypes('max_hours', 'int');
|
||||
}
|
||||
|
||||
@@ -70,11 +70,20 @@ final class UserType extends AbstractType
|
||||
// includes the current user if it is a system-account, which is especially useful for forms pages,
|
||||
// which have a user switcher and display the logged-in user by default
|
||||
'include_current_user_if_system_account' => false,
|
||||
'documentation' => [
|
||||
]);
|
||||
|
||||
$resolver->setDefault('documentation', function (Options $options) {
|
||||
$example = 0;
|
||||
if ($options['user'] instanceof User) {
|
||||
$example = $options['user']->getId();
|
||||
}
|
||||
|
||||
return [
|
||||
'type' => 'integer',
|
||||
'description' => 'User ID',
|
||||
],
|
||||
]);
|
||||
'example' => $example
|
||||
];
|
||||
});
|
||||
|
||||
$resolver->setDefault('choices', function (Options $options) {
|
||||
$query = new UserFormTypeQuery();
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
{% extends '@!NelmioApiDoc/Stoplight/index.html.twig' %}
|
||||
|
||||
{% block stylesheets %}
|
||||
{{ parent() }}
|
||||
<style>
|
||||
#mosaic-provider-react-aria-0-1 > div > div > div > div.sl-flex > div.sl-flex.sl-overflow-y-auto.sl-flex-col.sl-sticky.sl-inset-y-0.sl-pt-8.sl-bg-canvas-100.sl-border-r > a {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
{% endblock stylesheets %}
|
||||
Reference in New Issue
Block a user