Fix Enum rule handling for Laravel 12 compatibility#1066
Merged
romalytvynenko merged 1 commit intodedoc:mainfrom Jan 24, 2026
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix Enum rule handling for Laravel 12 compatibility
Summary
Laravel 12.48.0 added a
__toString()method toIlluminate\Validation\Rules\Enumthat converts the rule to anin:...string format. This caused theEnumRuletransformer 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 theIlluminate\Validation\Rules\Enumobject used for request validation. This causes the rule to be evaluated as a string rulein:a,b,cinstead of as a reference to the enum.When using
Rule::enum(MyEnum::class)in Laravel 12.48.0+:Enumrule was converted to"in:"foo","bar""via__toString()EnumRuletransformer never received the originalEnumobjectin:string rule handler instead{"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::classtoIGNORE_STRINGABLE_RULESinRuleSetToSchemaTransformerto preserve theEnumobject so it can be properly handled by theEnumRuletransformer.