Skip to content

Fix Enum rule handling for Laravel 12 compatibility#1066

Merged
romalytvynenko merged 1 commit intodedoc:mainfrom
Nau-media-AG:fix/enum-rule-laravel-12-compatibility
Jan 24, 2026
Merged

Fix Enum rule handling for Laravel 12 compatibility#1066
romalytvynenko merged 1 commit intodedoc:mainfrom
Nau-media-AG:fix/enum-rule-laravel-12-compatibility

Conversation

@finalgamer
Copy link
Contributor

Fix Enum rule handling for Laravel 12 compatibility

Summary

Laravel 12.48.0 added a __toString() method to Illuminate\Validation\Rules\Enum that converts the rule to an in:... string format. This caused the EnumRule transformer to be bypassed, resulting in inline enum schemas instead of component $refs.

Problem

Dedoc\Scramble\Support\RuleTransforming\RuleSetToSchemaTransformer::normalizeAndPrioritizeRules() calls the newly added __toString() method on the Illuminate\Validation\Rules\Enum object used for request validation. This causes the rule to be evaluated as a string rule in:a,b,c instead of as a reference to the enum.

When using Rule::enum(MyEnum::class) in Laravel 12.48.0+:

  • The Enum rule was converted to "in:"foo","bar"" via __toString()
  • The EnumRule transformer never received the original Enum object
  • The schema was handled by the in: string rule handler instead
  • Result: inline {"type": "string", "enum": ["foo", "bar"]} instead of {"$ref": "#/components/schemas/MyEnum"}

Root cause

The __toString() method was added in Laravel 12.48.0:

Note: Some CI test workers pass because they downgrade Laravel with prefer-lowest.

Solution

Add Enum::class to IGNORE_STRINGABLE_RULES in RuleSetToSchemaTransformer to preserve the Enum object so it can be properly handled by the EnumRule transformer.

Laravel 12 added __toString() to Illuminate\Validation\Rules\Enum which
converts it to "in:..." string format. This caused the EnumRule transformer
to be bypassed, resulting in inline enum schemas instead of component $refs.

Adding Enum::class to IGNORE_STRINGABLE_RULES preserves the Enum object so
it can be properly handled by the EnumRule transformer.
@romalytvynenko romalytvynenko merged commit 3f962e4 into dedoc:main Jan 24, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants