Skip to content

INTER-2244: Allow unknown enum values#232

Merged
erayaydin merged 3 commits into
mainfrom
fix/allow-unknown-enum-values-inter-2244
Jun 26, 2026
Merged

INTER-2244: Allow unknown enum values#232
erayaydin merged 3 commits into
mainfrom
fix/allow-unknown-enum-values-inter-2244

Conversation

@erayaydin

Copy link
Copy Markdown
Member

Summary

  • Remove strict enum validation from model setters and listing methods.
  • Use tryFrom() instead of from() for standalone enum deserialization, falling back to raw string
  • Add |string union types to standalone enum setter/getter type hints
  • Remove getAllowableEnumValues() check during serialization (see ObjectSerializer class)

Problem

The SDK throws InvalidArgumentException (inline enum) or ValueError (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.

@erayaydin erayaydin self-assigned this Jun 26, 2026
@erayaydin erayaydin added the bug Something isn't working label Jun 26, 2026
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

🟢 Coverage increased by 83.80%

Code Coverage Report

Coverage Report

St. Category Percentage Covered / Total
🟢 Statements 83.80% 2984 / 3561
🟢 Functions 82.18% 1213 / 1476
Files Coverage
St. File Methods Statements Total Coverage
🔴 src/Model/BotInfoCategory.php 0.00% 0.00% 0.00%
🔴 src/Model/BotInfoConfidence.php 0.00% 0.00% 0.00%
🔴 src/Model/BotInfoIdentity.php 0.00% 0.00% 0.00%
🔴 src/Model/BotResult.php 0.00% 0.00% 0.00%
🔴 src/Model/ErrorCode.php 0.00% 0.00% 0.00%
🔴 src/Model/IncrementalIdentificationStatus.php 0.00% 0.00% 0.00%
🔴 src/Model/ModelInterface.php 0.00% 0.00% 0.00%
🔴 src/Model/ProxyConfidence.php 0.00% 0.00% 0.00%
🔴 src/Model/RareDevicePercentileBucket.php 0.00% 0.00% 0.00%
🔴 src/Model/RuleActionType.php 0.00% 0.00% 0.00%
🔴 src/Model/SearchEventsBot.php 0.00% 0.00% 0.00%
🔴 src/Model/SearchEventsBotInfo.php 0.00% 0.00% 0.00%
🔴 src/Model/SearchEventsIncrementalIdentificationStatus.php 0.00% 0.00% 0.00%
🔴 src/Model/SearchEventsRareDevicePercentileBucket.php 0.00% 0.00% 0.00%
🔴 src/Model/SearchEventsSdkPlatform.php 0.00% 0.00% 0.00%
🔴 src/Model/SearchEventsVpnConfidence.php 0.00% 0.00% 0.00%
🔴 src/Model/TamperingConfidence.php 0.00% 0.00% 0.00%
🔴 src/Model/VpnConfidence.php 0.00% 0.00% 0.00%
🔴 src/Sealed/DecryptionAlgorithm.php 0.00% 0.00% 0.00%

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
@erayaydin erayaydin force-pushed the fix/allow-unknown-enum-values-inter-2244 branch from d2fb939 to 1b83c63 Compare June 26, 2026 08:30
@erayaydin erayaydin requested a review from Copilot June 26, 2026 08:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/Model/EventRuleAction.php Outdated
Comment thread src/Model/EventRuleAction.php Outdated
Comment thread src/Model/EventRuleActionAllow.php Outdated
Comment thread src/Model/EventRuleActionAllow.php Outdated
Comment thread src/Model/EventRuleActionBlock.php Outdated
Comment thread src/Model/Event.php Outdated
Comment thread src/Model/Event.php Outdated
Comment thread src/Model/Event.php Outdated
Comment thread src/Model/Event.php Outdated
Comment thread src/Model/Event.php Outdated
Update `@param` and `@return` annotations.

Related-Task: INTER-2244

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 6 comments.

Comment thread template/model_generic.mustache Outdated
Comment thread template/model_generic.mustache Outdated
Comment thread src/Model/Event.php
Comment thread src/Model/Event.php
Comment thread src/Model/Event.php
Comment thread src/Model/Event.php
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Following releases will be created using changesets from this PR:

@fingerprint/php-sdk@7.2.1

Patch Changes

  • Allow unknown enum values to prevent SDK breakage when new values are added server-side. (1b83c63)

@erayaydin erayaydin marked this pull request as ready for review June 26, 2026 09:08
@erayaydin erayaydin merged commit 8bd02e7 into main Jun 26, 2026
16 checks passed
@erayaydin erayaydin deleted the fix/allow-unknown-enum-values-inter-2244 branch June 26, 2026 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants