kimai / kimai

Kimai is a web-based multi-user time-tracking application. Works great for everyone: freelancers, companies, organizations - everyone can track their times, generate reports, create invoices and do so much more. SaaS version available at https://www.kimai.cloud
https://www.kimai.org
GNU Affero General Public License v3.0
3.32k stars 589 forks source link

Invalid Date Format in OpenAPI Specification Causes Error in PATCH Request for Project Update on Kimai Server #4132

Open hrirkslab opened 1 year ago

hrirkslab commented 1 year ago

Describe the issue

The OpenAPI specification file, "doc.json," contains the "date" format for the "start," "end," and "orderDate" fields. This format generates the OpenapiDateConverter annotation on these date fields. However, when sending a PATCH request for a Project on the Kimai server, the default DateTimeFormat of "yyyy-MM-dd" in the OpenapiDateConverter annotation is considered invalid.

Based on the provided log, it appears that the dates in the PATCH request are not valid. The log output suggests that the default DateTimeFormat of "yyyy-MM-dd" in the OpenapiDateConverter annotation is causing the issue. When attempting to update the Project on the Kimai server, the specified dates are not in the expected format, resulting in an error.

Fix : If we manually change the date to date-time, it will work. image

I already tried

Kimai version

2.0.23

How do you run Kimai?

Docker

Which PHP version are you using?

8.1

Logfile

2023-06-26 13:52:30,754 ERROR Error occurred while updating the project. System.AggregateException: One or more errors occurred. (Error calling PatchPatchProject: {"code":400,"message":"Validation Failed","errors":{"children":{"name":{},"comment":{},"invoiceText":{},"orderNumber":{},"orderDate":{"errors":["Please enter a valid date."]},"start":{"errors":["Please enter a valid date."]},"end":{"errors":["Please enter a valid date."]},"customer":{},"color":{},"budget":{},"timeBudget":{},"budgetType":{},"globalActivities":{},"visible":{},"billable":{}}}}) ---> Org.OpenAPITools.Kimai.Client.ApiException: Error calling PatchPatchProject: {"code":400,"message":"Validation Failed","errors":{"children":{"name":{},"comment":{},"invoiceText":{},"orderNumber":{},"orderDate":{"errors":["Please enter a valid date."]},"start":{"errors":["Please enter a valid date."]},"end":{"errors":["Please enter a valid date."]},"customer":{},"color":{},"budget":{},"timeBudget":{},"budgetType":{},"globalActivities":{},"visible":{},"billable":{}}}} at Org.OpenAPITools.Kimai.Api.ProjectApi.PatchPatchProjectWithHttpInfoAsync(String id, ProjectEditForm projectEditForm, Int32 operationIndex, CancellationToken cancellationToken) in C:\Users\ujwal\source\repos\Praxisphase\OpenprojectKimaiSyncService_gen\Org.OpenAPITools.Kimai\Api\ProjectApi.cs:line 1697 at Org.OpenAPITools.Kimai.Api.ProjectApi.PatchPatchProjectAsync(String id, ProjectEditForm projectEditForm, Int32 operationIndex, CancellationToken cancellationToken) in C:\Users\ujwal\source\repos\Praxisphase\OpenprojectKimaiSyncService_gen\Org.OpenAPITools.Kimai\Api\ProjectApi.cs:line 1621 --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait() at FromOpenprojectToKimai.Services.Implementations.WorkpackageKimaiExporterImpl.UpdateProjectAsync(ProjectApi projectApi, Int32 projectId, ProjectEditForm projectEditForm) in C:\Users\ujwal\source\repos\Praxisphase\OpenprojectKimaiSyncService\projects\FromOpenprojectToKimai\Services\Implementations\WorkpackageKimaiExporterImpl.cs:line 159 2023-06-26 13:52:31,343 ERROR One or more errors occurred. (Error calling PatchPatchProject: {"code":400,"message":"Validation Failed","errors":{"children":{"name":{},"comment":{},"invoiceText":{},"orderNumber":{},"orderDate":{"errors":["Please enter a valid date."]},"start":{"errors":["Please enter a valid date."]},"end":{"errors":["Please enter a valid date."]},"customer":{},"color":{},"budget":{},"timeBudget":{},"budgetType":{},"globalActivities":{},"visible":{},"billable":{}}}})

Screenshots

image

kevinpapst commented 1 year ago

Works for me when POSTing:

{
    "name": "API project",
    "comment": "date test",
    "customer": 6,
    "start": "2023-02-07",
        "visible": true
}

Maybe the serializer does a bad job here, but it is clearly defined as DateTime<'Y-m-d'>: https://github.com/kimai/kimai/blob/main/src/Entity/Project.php#L96

But you are right, it seems PATCH behaves differently, very strange. I'll look into it when I find some time.