Skip to content

[Bug]: datetime:Y-m-d eloquent cast should show as string<date> #873

@LiddleDev

Description

@LiddleDev

What happened?

I have a model with the following cast:

    protected function casts(): array
    {
        return [
            'start_date' => 'datetime:Y-m-d',
        ];
    }

Looking at the open API string formats

https://swagger.io/docs/specification/v3_0/data-models/data-types/#strings

I would expect scramble to add the date format in this case rather than the date-time, but I am seeing:

start_date: string<date-time>
created_at: string<date-time>

I came across this PR which seems to automatically apply the date format rather than date-time but only for request validation, NOT for eloquent casts

#725

Is this intended behaviour, or do you know of another way I can get it to say string?

Thanks!

How to reproduce the bug

Create an eloquent model with a date attribute named start_date and add the following cast:

    protected function casts(): array
    {
        return [
            'start_date' => 'datetime:Y-m-d',
        ];
    }

Create an API resource

    public function toArray(Request $request): array
    {
        return [
            'start_date' => $this->start_date,
        ];
    }

I expect to see this showing as string in the scramble docs rather than string

Package Version

0.12.19

PHP Version

8.3

Laravel Version

11.45.0

Which operating systems does with happen with?

No response

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions