fix: update native adapter property validation to check for optional … - #177
Conversation
📝 WalkthroughWalkthroughThis PR updates subscription validation to use an explicit ChangesNative Adapter Required Property Validation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 winPrevent null
MapperPropertiesfrom crashing validation.Line 74 assumes
iis non-null. IfMapperPropertiesis null, validation throwsNullReferenceExceptioninstead 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 winHandle 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
📒 Files selected for processing (2)
SW.Bitween.Api/Resources/Subscriptions/SaveMapper.csSW.Bitween.Api/Resources/Subscriptions/Update.cs
…values
Summary by CodeRabbit
Release Notes