INTER-2244: Allow unknown enum values#232
Merged
Merged
Conversation
Contributor
|
🟢 Coverage increased by 83.80% Code Coverage ReportCoverage Report
Files Coverage
|
Previously, the SDK threw `InvalidArgumentException` or `ValueError` when the API returned enum values not yet defined in the SDK. This caused breakage whenever new enum values were added server-side. Related-Task: INTER-2244
d2fb939 to
1b83c63
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the PHP SDK’s enum handling so that unknown enum values returned by the API no longer break deserialization/serialization. The approach is to stop strict enum validation and to preserve unknown enum values as raw strings (while still mapping known values to native enums).
Changes:
- Relax enum validation in generated models and during serialization so unknown values are accepted and preserved.
- Update enum deserialization to use
tryFrom()(fallback to raw value) and widen model enum-ref setter/getter type hints to...|string. - Add/adjust PHPUnit coverage to assert unknown enum values round-trip safely.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 20 comments.
Show a summary per file
| File | Description |
|---|---|
| test/Model/UnknownEnumDeserializationTest.php | Adds coverage ensuring unknown enum values deserialize and reserialize without throwing. |
| test/Model/SDKTest.php | Updates expectations: unknown enum values should be accepted and not reported as invalid. |
| test/Model/ProxyDetailsTest.php | Updates enum validation tests and adds a deserialization round-trip test for unknown proxy_type. |
| test/Model/ProximityTest.php | Updates expectations so unknown “enum-like” values don’t invalidate the model. |
| test/Model/BotInfoTest.php | Updates expectations so unknown “enum-like” values don’t throw and don’t invalidate the model. |
| template/ObjectSerializer.mustache | Removes enum validation during serialization and switches enum deserialization to tryFrom() + fallback. |
| template/model_generic.mustache | Removes generated enum validation and widens enum-ref getter/setter type hints to include ` |
| src/ObjectSerializer.php | Mirrors template changes in runtime serializer/deserializer behavior. |
| src/Model/SDK.php | Removes platform allowable-values validation in setter and listInvalidProperties(). |
| src/Model/ProxyDetails.php | Removes proxy_type allowable-values validation in setter and listInvalidProperties(). |
| src/Model/Proximity.php | Removes precision_radius allowable-values validation in setter and listInvalidProperties(). |
| src/Model/BotInfo.php | Removes identity/confidence allowable-values validation in setters and listInvalidProperties(). |
| src/Model/EventRuleActionBlock.php | Widens enum-ref type hints for type to include ` |
| src/Model/EventRuleActionAllow.php | Widens enum-ref type hints for type to include ` |
| src/Model/EventRuleAction.php | Widens enum-ref type hints for type to include ` |
| src/Model/Event.php | Widens enum-ref type hints for several enum-backed properties to include ` |
| src/Model/Error.php | Widens enum-ref type hints for code to include ` |
| .changeset/allow-unknown-enum-values.md | Adds a patch changeset describing the behavior change. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Update `@param` and `@return` annotations. Related-Task: INTER-2244
Contributor
🚀 Following releases will be created using changesets from this PR:@fingerprint/php-sdk@7.2.1Patch Changes
|
Orkuncakilkaya
approved these changes
Jun 26, 2026
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
tryFrom()instead offrom()for standalone enum deserialization, falling back to raw string|stringunion types to standalone enum setter/getter type hintsgetAllowableEnumValues()check during serialization (see ObjectSerializer class)Problem
The SDK throws
InvalidArgumentException(inline enum) orValueError(native enum) when the API returns an enum value not yet defined in the SDK. This means any new enum value added server-side breaks all SDK users who haven't updated yet.Solution
Accept unknown enum values gracefully. Known values still resolve to their enum types, unknown values pass through as raw strings. No breaking changes to the public API.