Skip to content

Conversation

@ySnoopyDogy
Copy link
Contributor

@ySnoopyDogy ySnoopyDogy commented Jan 8, 2026

The new XML validation functions just convert the data to JSON before validating the schema. With that, we can just convert the data on Request and Response validations just by looking at the content type.

Because in XML everything is a string, there can be problems to validating against a schema that includes other primitive types. Now, we convert the strings based on the schema types. If the property is a boolean, we convert to a boolean to pass the validation. If the value is not a valid boolean, we do nothing to let the schema validation to raise an error.

Also, now we are validating if the payload includes prefixes and namespaces defined in the schema (the XMLNS feature of XML).

Added a new option to ValidationOptions: AllowXMLBodyValidation to enable XML validations in request/response bodies (the default is false). Created a function WithXmlBodyValidation to enable the new validator option.

No breaking changes with the new code, as the updated function was internal, and the XML body validation setting is false by default.

@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

❌ Patch coverage is 98.14126% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.64%. Comparing base (0db7586) to head (09fe157).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
responses/validate_body.go 92.59% 2 Missing ⚠️
schema_validation/validate_xml.go 98.65% 2 Missing ⚠️
requests/validate_body.go 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #214      +/-   ##
==========================================
+ Coverage   97.61%   97.64%   +0.03%     
==========================================
  Files          56       57       +1     
  Lines        5240     5444     +204     
==========================================
+ Hits         5115     5316     +201     
- Misses        125      128       +3     
Flag Coverage Δ
unittests 97.64% <98.14%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ySnoopyDogy
Copy link
Contributor Author

Going to implement a smarter conversion, like the one used in Query Parameter validation, looking to the type defined in the schema. This idea can be used to convert the body to JSON with correct defined types, so we can validate application/xml, x-www-form-urlencoded and also multipart/form-data

@ySnoopyDogy ySnoopyDogy marked this pull request as draft January 22, 2026 21:16
@ySnoopyDogy ySnoopyDogy marked this pull request as ready for review February 2, 2026 19:37
@ySnoopyDogy ySnoopyDogy force-pushed the feat/xml_request_validation branch from a457bde to 09fe157 Compare February 2, 2026 19:53
@ySnoopyDogy ySnoopyDogy changed the title Add XML conversion to bodies Add XML conversion to bodies, and fix XML data conversion Feb 2, 2026
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.

1 participant