Add XML conversion to bodies, and fix XML data conversion #214
Add XML conversion to bodies, and fix XML data conversion #214ySnoopyDogy wants to merge 6 commits intopb33f:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #214 +/- ##
==========================================
+ Coverage 97.63% 97.73% +0.10%
==========================================
Files 56 57 +1
Lines 5323 5527 +204
==========================================
+ Hits 5197 5402 +205
+ Misses 126 125 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
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 |
a457bde to
09fe157
Compare
|
A few missing lines of coverage, any chance of a bump? |
also added a validation for XML namespaces and prefix
09fe157 to
fb2fe21
Compare
|
The coverage lines from Looking the code from the The other line is the validation for the marshal error, but the xml lib only returns valid json. If the lib receives wrong XML data, they just return an empty buffer, that the line 53 ensures to return early. For that reason, the line 59 is practically unreachable, as the xml2json will only generate valid JSON with string values, so we can't even force NaN conversions. For that, I would say there is no way of covering that lines, the IFs are just safeguards for impossible errors. What could we do in this situation about that two uncovered lines? |
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:AllowXMLBodyValidationto enable XML validations in request/response bodies (the default isfalse). Created a functionWithXmlBodyValidationto 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
falseby default.