Fspes 117#36
Conversation
Agent-Logs-Url: https://github.com/FrendsPlatform/Frends.JSON2/sessions/73a1e239-08c8-420b-a943-a42ec2ba075d Co-authored-by: MichalFrends1 <[email protected]>
Agent-Logs-Url: https://github.com/FrendsPlatform/Frends.JSON2/sessions/73a1e239-08c8-420b-a943-a42ec2ba075d Co-authored-by: MichalFrends1 <[email protected]>
…port Add optional XSD-driven schema mapping to ConvertXMLStringToJToken
WalkthroughThis PR adds optional XSD schema support to the XML-to-JSON conversion task. The ChangesXSD-Based Array Mapping Feature
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
Frends.JSON.ConvertXMLStringToJToken/Frends.JSON.ConvertXMLStringToJToken.Tests/UnitTests.cs (1)
33-75: ⚡ Quick winAdd tests for the XSD validation-failure path and the
maxOccurs=1(no-array) case.The current test suite only exercises the happy path. The
XmlSchemaValidationException-throwing branch inLoadXmlDocumentWithSchemaHintshas no coverage, and there is no test confirming that an element withmaxOccurs='1'(or default) is correctly serialized as aJObjectrather than aJArray.Suggested additions:
[TestMethod] [ExpectedException(typeof(XmlSchemaValidationException))] public void ShouldThrowWhenXmlFailsXsdValidation() { var input = new Input() { XML = @"<?xml version='1.0' standalone='no'?> <root> <unknown>value</unknown> </root>", XSD = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'> <xs:element name='root'> <xs:complexType> <xs:sequence> <xs:element name='person' maxOccurs='unbounded' /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>" }; JSON.ConvertXMLStringToJToken(input); } [TestMethod] public void ShouldNotMapElementAsArrayWhenMaxOccursIsOne() { var input = new Input() { XML = @"<?xml version='1.0' standalone='no'?> <root> <person id='1'> <name>Alan</name> </person> </root>", XSD = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'> <xs:element name='root'> <xs:complexType> <xs:sequence> <xs:element name='person' maxOccurs='1'> <xs:complexType> <xs:sequence> <xs:element name='name' type='xs:string' /> </xs:sequence> <xs:attribute name='id' type='xs:string' /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>" }; var result = JSON.ConvertXMLStringToJToken(input); Assert.IsTrue(result.Success); var root = ((JObject)result.Jtoken)["root"]; Assert.IsNotInstanceOfType(root["person"], typeof(JArray)); }🤖 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 `@Frends.JSON.ConvertXMLStringToJToken/Frends.JSON.ConvertXMLStringToJToken.Tests/UnitTests.cs` around lines 33 - 75, Add two unit tests to cover the XSD validation-failure path and the maxOccurs=1 non-array case: create a test ShouldThrowWhenXmlFailsXsdValidation that calls JSON.ConvertXMLStringToJToken with XML that doesn't match the provided XSD and asserts an XmlSchemaValidationException is thrown (exercising the XmlSchemaValidationException branch in LoadXmlDocumentWithSchemaHints), and create ShouldNotMapElementAsArrayWhenMaxOccursIsOne that supplies an XSD where person has maxOccurs='1', calls JSON.ConvertXMLStringToJToken and asserts root["person"] is not a JArray (should be a JObject); name the tests exactly as above so they integrate with the existing UnitTests.cs suite and reference JSON.ConvertXMLStringToJToken and LoadXmlDocumentWithSchemaHints in comments if needed for maintainability.
🤖 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
`@Frends.JSON.ConvertXMLStringToJToken/Frends.JSON.ConvertXMLStringToJToken.Tests/UnitTests.cs`:
- Around line 62-65: Assert result.Success before accessing result.Jtoken: in
the test that calls JSON.ConvertXMLStringToJToken, move the
Assert.IsTrue(result.Success) to immediately after obtaining result and before
the cast that accesses ((JObject)result.Jtoken)["root"] (or perform the cast
only after asserting success). This ensures the test fails with a clear
assertion instead of throwing a NullReferenceException when result.Jtoken is
null.
---
Nitpick comments:
In
`@Frends.JSON.ConvertXMLStringToJToken/Frends.JSON.ConvertXMLStringToJToken.Tests/UnitTests.cs`:
- Around line 33-75: Add two unit tests to cover the XSD validation-failure path
and the maxOccurs=1 non-array case: create a test
ShouldThrowWhenXmlFailsXsdValidation that calls JSON.ConvertXMLStringToJToken
with XML that doesn't match the provided XSD and asserts an
XmlSchemaValidationException is thrown (exercising the
XmlSchemaValidationException branch in LoadXmlDocumentWithSchemaHints), and
create ShouldNotMapElementAsArrayWhenMaxOccursIsOne that supplies an XSD where
person has maxOccurs='1', calls JSON.ConvertXMLStringToJToken and asserts
root["person"] is not a JArray (should be a JObject); name the tests exactly as
above so they integrate with the existing UnitTests.cs suite and reference
JSON.ConvertXMLStringToJToken and LoadXmlDocumentWithSchemaHints in comments if
needed for maintainability.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e815f948-0905-457b-ac90-360181a78487
📒 Files selected for processing (5)
Frends.JSON.ConvertXMLStringToJToken/CHANGELOG.mdFrends.JSON.ConvertXMLStringToJToken/Frends.JSON.ConvertXMLStringToJToken.Tests/UnitTests.csFrends.JSON.ConvertXMLStringToJToken/Frends.JSON.ConvertXMLStringToJToken/ConvertXMLStringToJToken.csFrends.JSON.ConvertXMLStringToJToken/Frends.JSON.ConvertXMLStringToJToken/Definitions/Input.csFrends.JSON.ConvertXMLStringToJToken/Frends.JSON.ConvertXMLStringToJToken/Frends.JSON.ConvertXMLStringToJToken.csproj
Please review my changes :)
Task Update PR template
Review Checklist
Summary by CodeRabbit
Version: 1.2.0