test(api): reproducer for DeserializeProvider enum validation bug#617
Open
vincentchalamon wants to merge 1 commit into4.3from
Open
test(api): reproducer for DeserializeProvider enum validation bug#617vincentchalamon wants to merge 1 commit into4.3from
vincentchalamon wants to merge 1 commit into4.3from
Conversation
Reproduces the bug that will occur when upgrading to Symfony 8.1. Symfony PR #62574 (commit 35b1aec) improves BackedEnumNormalizer error messages, but API Platform's DeserializeProvider does not handle the case where expectedTypes is null/empty, producing: "This value should be of type ." (empty type). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
7f4b450 to
ba9ce88
Compare
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.
Summary
Reproducer for #601 — API Platform's
DeserializeProvideruses the genericTypeconstraint message ("This value should be of type X.") even when the serializer exception provides a user-friendly message. This results in:"This value should be of type int|string."instead of the enum-specific message"This value should be of type ."(empty type) whenexpectedTypesisnullContext
Symfony PR #62574 (commit
35b1aec) improvesBackedEnumNormalizererror messages. This change was:388c311) — theexpectedTypes = nullbehavior was removed from 8.0.xOn the current Symfony 8.1 branch,
BackedEnumNormalizerdistinguishes:expectedTypes = [$backingType]expectedTypes = ['int', 'string'], message ="The data must belong to a backed enumeration of type $type"Where the bug is
In
api-platform/statev4.3.3 —DeserializeProvider.php:The
DeserializeProviderignorescanUseMessageForUser()for the violation message — it only uses the exception message as ahintparameter, not as the main violation message.What this PR does
BackedEnumNormalizerDecoratorthat simulates the Symfony 8.1 behavior (two distinct error paths withexpectedTypes = nullfor invalid values)BookTest::getInvalidData()to verify the expected correct behavior for both Symfony versions:Proposed fix (upstream in
api-platform/core)When
canUseMessageForUser()istrue, use the exception message directly as the violation message:A git patch is included in this PR:
0001-fix-DeserializeProvider-use-exception-message-when-available.patchTested locally — results
"This value should be of type int|string."— unhelpful"This value should be of type ."— broken"The data must belong to a backed enumeration of type App\Enum\BookCondition"— 7/7 tests pass"The data must be one of the following values: '...', ..."— 7/7 tests passTest plan
empty dataandinvalid conditioncases — this is expected and demonstrates the bug inDeserializeProviderapi-platform/core, the decorator can be removed and tests will pass nativelyCloses #601
🤖 Generated with Claude Code