Skip to content

fix: update native adapter property validation to check for optional … - #177

Merged
AhmadRAbuhussein merged 1 commit into
releases/r8.0from
hamza/fix/native-adapter-required-prop-validation
Jun 4, 2026
Merged

fix: update native adapter property validation to check for optional …#177
AhmadRAbuhussein merged 1 commit into
releases/r8.0from
hamza/fix/native-adapter-required-prop-validation

Conversation

@hamzahalq

@hamzahalq hamzahalq commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

…values

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Enhanced validation for native adapter properties in subscription operations. Required properties are now identified more accurately when saving and updating subscriptions, which may affect validation outcomes for certain configurations.

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR updates subscription validation to use an explicit Optional flag instead of a " *" suffix heuristic for determining which native adapter startup properties are required. The change is applied consistently across mapper save and subscription update validation paths for mapper, handler, and receiver properties.

Changes

Native Adapter Required Property Validation

Layer / File(s) Summary
Update validation from suffix heuristic to Optional flag
SW.Bitween.Api/Resources/Subscriptions/SaveMapper.cs, SW.Bitween.Api/Resources/Subscriptions/Update.cs
Native adapter required property keys are now derived from GetStartupValues(id) filtered by !p.Value.Optional, replacing the prior GetExpectedStartupValues(id) + " *" suffix-based selection in mapper save and subscription update validation for mapper, handler, and receiver properties.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • simplify9/Bitween-api#141: Both PRs update SaveMapper.cs to compute required mapper startup properties for native adapters, directly overlapping in validation behavior.
  • simplify9/Bitween-api#133: This PR's change to required property validation impacts how new native adapter configurations with required fields will be validated during subscription save/update.

Suggested reviewers

  • AhmadRAbuhussein

Poem

🐰 A heuristic softly fades away,
Its asterisks replaced by flags so true,
Required properties now clearly say
Which startup values must come through!
Three paths now march in harmony and grace. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: updating native adapter property validation to use an optional flag instead of a suffix heuristic.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hamza/fix/native-adapter-required-prop-validation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
SW.Bitween.Api/Resources/Subscriptions/SaveMapper.cs (1)

73-74: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Prevent null MapperProperties from crashing validation.

Line 74 assumes i is non-null. If MapperProperties is null, validation throws NullReferenceException instead of returning a validation failure.

Suggested fix
-                        var missing = mustProps.ToHashSet(StringComparer.OrdinalIgnoreCase)
-                            .Except(i.Where(p => !string.IsNullOrEmpty(p.Value)).Select(p => p.Key));
+                        var providedKeys = (i ?? Enumerable.Empty<KeyAndValue>())
+                            .Where(p => !string.IsNullOrEmpty(p.Value))
+                            .Select(p => p.Key);
+                        var missing = mustProps.ToHashSet(StringComparer.OrdinalIgnoreCase)
+                            .Except(providedKeys);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@SW.Bitween.Api/Resources/Subscriptions/SaveMapper.cs` around lines 73 - 74,
The validation currently assumes MapperProperties (variable i) is non-null and
will throw a NullReferenceException; update the validation in SaveMapper.cs to
treat null MapperProperties as an empty collection (or explicitly fail
validation) by guarding the computation of missing—e.g., use a null-safe
enumeration for i (e.g., i?.Where(...) ??
Enumerable.Empty<KeyValuePair<string,string>>()) or check if i is null and add
all mustProps to missing so the validator returns a failure instead of throwing;
adjust the logic around mustProps, i, and missing accordingly.
SW.Bitween.Api/Resources/Subscriptions/Update.cs (1)

159-160: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Handle null property collections in all three validators.

Line 160, Line 189, and Line 234 dereference collections that may be null (MapperProperties, HandlerProperties, ReceiverProperties). This can throw during validation and return 500s for malformed/partial payloads.

Suggested fix pattern
-                        var missing = mustProps.ToHashSet(StringComparer.OrdinalIgnoreCase)
-                            .Except(i.Where(p => !string.IsNullOrEmpty(p.Value)).Select(p => p.Key));
+                        var providedKeys = (i ?? Enumerable.Empty<KeyAndValue>())
+                            .Where(p => !string.IsNullOrEmpty(p.Value))
+                            .Select(p => p.Key);
+                        var missing = mustProps.ToHashSet(StringComparer.OrdinalIgnoreCase)
+                            .Except(providedKeys);
-                            var missing = mustProps.ToHashSet(StringComparer.OrdinalIgnoreCase)
-                                .Except(model.ReceiverProperties.Where(p => !string.IsNullOrEmpty(p.Value)).Select(p => p.Key));
+                            var providedReceiverKeys = (model.ReceiverProperties ?? Array.Empty<KeyAndValue>())
+                                .Where(p => !string.IsNullOrEmpty(p.Value))
+                                .Select(p => p.Key);
+                            var missing = mustProps.ToHashSet(StringComparer.OrdinalIgnoreCase)
+                                .Except(providedReceiverKeys);

Also applies to: 188-190, 233-234

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@SW.Bitween.Api/Resources/Subscriptions/Update.cs` around lines 159 - 160, The
validators compute "missing" by calling .Where/.Select on property collections
that can be null (MapperProperties, HandlerProperties, ReceiverProperties) which
can throw; update each validator in Update.cs to null-safe the property
enumeration before LINQ (e.g., use null-coalescing to an empty IEnumerable or
call .Empty if the collection is null) when computing mustProps/missing so the
.Where and .Select never dereference null — specifically fix the places that
reference MapperProperties, HandlerProperties, and ReceiverProperties where
missing is computed and used so they operate on (collection ??
Enumerable.Empty<KeyValuePair<string,string>>()) or equivalent null-safe
enumeration.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@SW.Bitween.Api/Resources/Subscriptions/SaveMapper.cs`:
- Around line 73-74: The validation currently assumes MapperProperties (variable
i) is non-null and will throw a NullReferenceException; update the validation in
SaveMapper.cs to treat null MapperProperties as an empty collection (or
explicitly fail validation) by guarding the computation of missing—e.g., use a
null-safe enumeration for i (e.g., i?.Where(...) ??
Enumerable.Empty<KeyValuePair<string,string>>()) or check if i is null and add
all mustProps to missing so the validator returns a failure instead of throwing;
adjust the logic around mustProps, i, and missing accordingly.

In `@SW.Bitween.Api/Resources/Subscriptions/Update.cs`:
- Around line 159-160: The validators compute "missing" by calling
.Where/.Select on property collections that can be null (MapperProperties,
HandlerProperties, ReceiverProperties) which can throw; update each validator in
Update.cs to null-safe the property enumeration before LINQ (e.g., use
null-coalescing to an empty IEnumerable or call .Empty if the collection is
null) when computing mustProps/missing so the .Where and .Select never
dereference null — specifically fix the places that reference MapperProperties,
HandlerProperties, and ReceiverProperties where missing is computed and used so
they operate on (collection ?? Enumerable.Empty<KeyValuePair<string,string>>())
or equivalent null-safe enumeration.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bd1a2943-7c7f-4d30-b321-86dfde14168c

📥 Commits

Reviewing files that changed from the base of the PR and between 63ab32a and 3b89b5d.

📒 Files selected for processing (2)
  • SW.Bitween.Api/Resources/Subscriptions/SaveMapper.cs
  • SW.Bitween.Api/Resources/Subscriptions/Update.cs

@AhmadRAbuhussein
AhmadRAbuhussein merged commit e2891c1 into releases/r8.0 Jun 4, 2026
2 checks passed
@MusaMisto
MusaMisto deleted the hamza/fix/native-adapter-required-prop-validation branch July 2, 2026 09:29
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