Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix namespace problem for array schema elements and respect XML schem… #802

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/savon/qualified_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ def to_hash(hash, path)
return hash.map { |value| to_hash(value, path) } if hash.kind_of?(Array)
return hash.to_s unless hash.kind_of? Hash

hash.inject({}) do |newhash, (key, value)|
if hash[:order!] == :use_schema || @order_with_schema
@order_with_schema = true
ordered_keys = @used_namespaces.select { |t| t.first == path.first && t.length == 2 }.keys.collect { |k| k.last }
hash[:order!] = ordered_keys
end

result = hash.inject({}) do |newhash, (key, value)|
if key == :order!
add_namespaces_to_values(value, path)
newhash.merge(key => value)
Expand All @@ -33,6 +39,8 @@ def to_hash(hash, path)
end
end
end

update_order_keys(result)
end

private
Expand All @@ -46,5 +54,13 @@ def add_namespaces_to_values(values, path)
}
end

def update_order_keys(hash)
return hash unless @order_with_schema

order_keys = hash.delete(:order!)
present_order_keys = order_keys & hash.keys
hash[:order!] = present_order_keys + (hash.keys - present_order_keys)
hash
end
end
end