scramble icon indicating copy to clipboard operation
scramble copied to clipboard

[Bug] Enum Attribute Example Ignored in laravel-data Class

Open gigerIT opened this issue 4 months ago • 1 comments

What happened?

Hi there,

First of all, awesome package! Supporting this was a nobrainer, thanks for your great work.

We came across a small bug where our defined example is being ignored for an enum attribute in a Laravel Data class.

How to reproduce the bug

class EnquiryVehicleData extends Data
{
    public function __construct(
        /**
         * @example car
         */
        public VehicleType $type,
    ) {
    }
}
enum VehicleType: string
{
    case BICYCLE = 'bicycle';

    case MOTORCYCLE = 'motorcycle';

    case CAR = 'car';

    case CAMPER = 'camper';
}

This results in a default/example value in the documentation of:

Image

Package Version

0.12.28 / pro 0.7.12

PHP Version

8.4.10

Laravel Version

12.21.0

Which operating systems does with happen with?

Linux

Notes

No response

gigerIT avatar Aug 05 '25 07:08 gigerIT

Hey @gigerIT

This is the issue behind Stoplight Elements UI 🥲

Scramble generates the following schema:

{
    "type": "object",
    "properties": {
        "size": {
            "description": "The list of opened jobs of this company\n| |\n|---|\n| `1` <br\/> Single |\n| `2-10` <br\/>  |\n| `11-50` <br\/>  |\n| `51+` <br\/>  |",
            "examples": ["2-10"],
            "$ref": "#\/components\/schemas\/CompanySize"
        }
    },
    "required": [
        "size"
    ],
    "title": "CompanyData"
}

Which is legit and allowed (notice $ref together with examples).

But Stoplight is not taking this into account.

I'm working on my own UI where this will be taken into account, but I cannot give any time estimates.

romalytvynenko avatar Aug 12 '25 08:08 romalytvynenko