18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/oas_parser/response_parser.rb', line 18
def xml(xml_options = {})
xml_options ||= {}
xml_options = default_xml_options.merge(xml_options)
raw_xml = parse('xml').to_xml(xml_options)
xml_document = Nokogiri::XML(raw_xml)
xml_document.xpath('//__attributes').each do |attributes|
attributes.children.each do |attribute|
next unless attribute.class == Nokogiri::XML::Element
attribute.parent.parent.css("> #{attribute.name}").remove
attribute.parent.parent[attribute.name] = attribute.content
end
end
xml_document.xpath('//__array_attributes').each do |attributes|
attributes.children.each do |attribute|
next unless attribute.class == Nokogiri::XML::Element
parameter = {}
parameter['example'] = attribute.css('example').text if attribute.css('example')
parameter['type'] = attribute.css('type').text if attribute.css('type')
attribute.parent.parent.parent[attribute.name] = parameter_value(parameter)
end
attributes.parent.remove
end
xml_document.xpath('//__text').each do |attribute|
value = attribute.children.last.content
attribute.parent.content = value
end
xml_document.xpath('//__attributes').each(&:remove)
xml_document.to_xml.each_line.reject { |x| x.strip == '' }.join
end
|