feat: enhance ScribanJsonHelper to support root array input and outpu… - #180
Conversation
…t with comprehensive unit tests
ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughScribanJsonHelper.Render now accepts root JSON arrays or objects, exposes arrays as ChangesRoot Array Support in Scriban JSON Rendering
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 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)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
SW.Bitween.NativeAdapters/JsonMapper/ScribanJsonHelper.cs (1)
87-87: 💤 Low valueConsider security implications of including rendered output in exception messages.
The error message now includes the full rendered template output via
\n\nRendered:\n{rendered}. While this significantly aids debugging, the rendered output might contain sensitive data (PII, secrets, or business-critical values) that could be exposed in logs or error tracking systems.🔒 Optional mitigation strategies
- Truncate the rendered output to a reasonable length (e.g., first 500 characters)
- Add a configuration flag to control whether full output is included
- Redact sensitive patterns before including in the exception
- Document that exception handlers should treat this as sensitive data
Example truncation:
-throw new InvalidOperationException($"Template produced invalid JSON: {ex.Message}\n\nRendered:\n{rendered}"); +var preview = rendered.Length > 500 ? rendered.Substring(0, 500) + "..." : rendered; +throw new InvalidOperationException($"Template produced invalid JSON: {ex.Message}\n\nRendered:\n{preview}");🤖 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.NativeAdapters/JsonMapper/ScribanJsonHelper.cs` at line 87, The current throw in ScribanJsonHelper that appends the full rendered string (the InvalidOperationException using rendered) can expose sensitive data; modify the code that throws the exception so it does not include the entire rendered output: truncate the rendered variable to a safe length (e.g., first 500 characters) and append an explicit marker like "...(truncated)" or gate inclusion behind a configuration flag (e.g., a boolean in ScribanJsonHelper settings) so full output is only included when explicitly enabled; locate the throw site referencing rendered in ScribanJsonHelper.cs and replace the message construction to use the truncated (or config-guarded) value.
🤖 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.
Inline comments:
In `@SW.Bitween.UnitTests/ScribanJsonHelperRootArrayTests.cs`:
- Around line 90-114: The Preview integration only injects __partner__ /
__globals__ when inputJson parses to a JObject (the code path in Preview.Handle
checks if (JToken.Parse(inputJson) is JObject parsedObj)), so root-array
payloads never get enrichment and templates miss those fields; update
Preview.Handle to detect root JArray cases, wrap or transform the array into an
enriched object (e.g., add __partner__ / __globals__ to each element or create a
wrapper object that contains the array plus the hoisted fields) before passing
to the Scriban rendering pipeline, ensuring the same enrichment logic used for
JObject is applied to root arrays so templates can access __partner__ and
__globals__ end-to-end.
---
Nitpick comments:
In `@SW.Bitween.NativeAdapters/JsonMapper/ScribanJsonHelper.cs`:
- Line 87: The current throw in ScribanJsonHelper that appends the full rendered
string (the InvalidOperationException using rendered) can expose sensitive data;
modify the code that throws the exception so it does not include the entire
rendered output: truncate the rendered variable to a safe length (e.g., first
500 characters) and append an explicit marker like "...(truncated)" or gate
inclusion behind a configuration flag (e.g., a boolean in ScribanJsonHelper
settings) so full output is only included when explicitly enabled; locate the
throw site referencing rendered in ScribanJsonHelper.cs and replace the message
construction to use the truncated (or config-guarded) value.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 60fd5c07-b2cc-494a-8eef-f13180e691ea
📒 Files selected for processing (3)
SW.Bitween.NativeAdapters/JsonMapper/ScribanJsonHelper.csSW.Bitween.UnitTests/ScribanJsonHelperRootArrayTests.csSW.Bitween.UnitTests/ScribanJsonTestHelper.cs
…th partner and global properties
…t with comprehensive unit tests
Summary by CodeRabbit
New Features
Tests