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

elementFormDefault="qualified" in types regression #916

Closed
lukaso opened this issue Dec 3, 2019 · 4 comments
Closed

elementFormDefault="qualified" in types regression #916

lukaso opened this issue Dec 3, 2019 · 4 comments
Labels

Comments

@lukaso
Copy link

lukaso commented Dec 3, 2019

Bug report

Current behavior:

Attributes within a nested type are no longer qualified.

<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="xxx" 
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><tns:CreateNewBusinessWithPolicy
xmlns="xxx"><tns:Business><SchemeCode>D</SchemeCode><SchemeBranch>[NO BRANCH]</SchemeBranch><BusinessType>78</BusinessType><NumInstalments>10</NumInstalments></tns:Business></tns:CreateNewBusinessWithPolicy></soap:Body></soap:Envelope>

Steps to reproduce current behavior:

Create any document with types with attributes and set elementFormDefault="qualified" in WSDL.
The attributes in the nested type will not be qualified.

Expected behavior:

Create any nested document with attributes and elementFormDefault="qualified" and see that attributes are qualified.

<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="xxx"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><tns:CreateNewBusinessWithPolicy
xmlns="xxx"><tns:Business><tns:SchemeCode>D</tns:SchemeCode><tns:SchemeBranch>[NO BRANCH]</tns:SchemeBranch><tns:BusinessType>78</tns:BusinessType><tns:NumInstalments>10</tns:NumInstalments></tns:Business></tns:CreateNewBusinessWithPolicy></soap:Body></soap:Envelope>

See also this example of a properly formatted document: https://www.intertech.com/Blog/xml-schema-elementformdefault-and-attributeformdefault/

System information:
Mac OS Mojave 10.14.6

  • ruby version: 2.6.5
  • savon version: 2.12.0

The bug was introduced in this PR: #676

From: gems/2.6.0/gems/savon-2.6.0/lib/savon/qualified_message.rb @ line 27 Savon::QualifiedMessage#to_hash:

    12: def to_hash(hash, path)
    13:   require 'pry'; binding.pry
    14:   return unless hash
    15:   return hash.map { |value| to_hash(value, path) } if hash.kind_of?(Array)
    16:   return hash.to_s unless hash.kind_of? Hash
    17:
    18:   hash.inject({}) do |newhash, (key, value)|
    19:     if key == :order!
    20:       add_namespaces_to_values(value, path)
    21:       newhash.merge(key => value)
    22:     else
    23:       translated_key = Gyoku.xml_tag(key, :key_converter => @key_converter).to_s
    24:       newpath = path + [translated_key]
    25:
    26:       if @used_namespaces[newpath]
    27:         newhash.merge(
    28:           "#{@used_namespaces[newpath]}:#{translated_key}" =>
  =>   29:             to_hash(value, @types[newpath] ? [@types[newpath]] : newpath)
    30:         )
    31:       else
    32:         newhash.merge(translated_key => value)
    33:       end
    34:     end
    35:   end
    36: end

There is no apparent test coverage of this area of the code. I looked at adding a breaking test to spec/savon/builder_spec.rb however not sure how to create nested types for the test

The following test passes without the fix:

    it "uses the global :element_form_default option if it's available " do
      globals[:element_form_default] = :qualified
      locals[:message] = {
        :username => "luke",
        :password => "secret",
        :nested_attributes => {
          :attr1 => "value",
          :attr2 => "value2"
        }
      }

      expect(builder.to_s).to include("<tns:nestedAttributes><tns:attr1>value</tns:attr1><tns:attr2>value2</tns:attr2></tns:nestedAttributes>")
    end

I will submit a PR to fix this shortly.

@lukaso
Copy link
Author

lukaso commented Dec 4, 2019

Same issue is fixed in #905.

@stale
Copy link

stale bot commented Feb 2, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 2, 2020
@stale stale bot closed this as completed Feb 9, 2020
@lukaso
Copy link
Author

lukaso commented May 24, 2020

This issue remains open.

@lukaso
Copy link
Author

lukaso commented May 25, 2020

Given the slow pace of incorporating changes, I've created a gem that patches this issue. All you have to do is include it in your Gemfile:

gem 'savon_fixes'

You can find the gem here: https://github.com/lukaso/savon_fixes. It currently covers off these issues and PRs: #916, #899, #820, #895, #862, #905 and #549 (they are all duplicates).

I haven't yet tested it in anger, but all tests pass, so please feedback if there are any issues. Adaptations of PRs here are also welcome.

@lukaso lukaso mentioned this issue May 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant