Open ramkumar-kr opened 7 years ago
In your example you send a single product, it cannot guess that it's an array, but maybe you're right and it should infer and coerce it it because of what's in the params
block. I say write a spec for this next and lets see if we can implement/fix this.
Hi, Sorry for the late reply. I have created a Spec and have sent a pull request for it.
We also bumped into this one the other day. This is due to the XML parsing of the arrays using the default ActiveSupport::XmlMini. We noticed that Nokogiri handles the XML arrays correctly using some test XML on the irb.
So the less intrusive solution is using MultiXML and Nokogiri as the parser in the project and not rewrite the params in the before hook.
So the use of an initializer like
require 'multi_xml'
# Force all the XML parsing to be handled by Nokogiri
MultiXml.parser = :nokogiri
MultiXml.parser = MultiXml::Parsers::Nokogiri # Same as above
will set the definition. The use of MultiXml will be picked up by the Grape framework and Bob's your uncle.
See: https://github.com/ruby-grape/grape#json-and-xml-processors
@Smeedy Do you think you can turn the spec linked above into a passing one and add some documentation and PR the thing?
Hi,
I have an API which accepts requests using XML. It accepts an array of products. However for a case where there is only one product in the array, validation errors occur. Sample request - `curl -X POST \ http://localhost:3000/v1/products \ -H 'cache-control: no-cache' \ -H 'content-type: application/xml' \ -d '<?xml version="1.0" encoding="UTF-8" ?>