wash_away_the_soap 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +7 -0
- data/LICENSE +19 -0
- data/README.md +16 -0
- data/Rakefile +14 -0
- data/bin/wash_away_the_soap +5 -0
- data/lib/wash_away_the_soap.rb +97 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/wash_away_the_soap_spec.rb +122 -0
- metadata +113 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2010 Michael Schubert <michael@schubert.cx>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Wash Away The Soap
|
|
2
|
+
=============
|
|
3
|
+
|
|
4
|
+
WashAwayTheSoap parses WSDL and XSD files and attempts to
|
|
5
|
+
pretty-print the service structure so you can make sense
|
|
6
|
+
of a legacy (or just poorly written) system.
|
|
7
|
+
|
|
8
|
+
Usage
|
|
9
|
+
-------------
|
|
10
|
+
|
|
11
|
+
$ wash_away_the_soap *.wsdl *.xsd
|
|
12
|
+
|
|
13
|
+
License
|
|
14
|
+
-------------
|
|
15
|
+
|
|
16
|
+
See the LICENSE file
|
data/Rakefile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require "rspec/core/rake_task"
|
|
3
|
+
|
|
4
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
5
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
6
|
+
spec.rspec_opts = ['--color']
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
desc "Build gem from gemspec"
|
|
10
|
+
task :build do
|
|
11
|
+
sh "gem build wash_away_the_soap.gemspec"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
task :default => :spec
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
require "rubygems"
|
|
2
|
+
require "bundler/setup"
|
|
3
|
+
require "nokogiri"
|
|
4
|
+
|
|
5
|
+
class WashAwayTheSoap
|
|
6
|
+
attr_accessor :wsdls, :xsds, :wsdl_operations, :xsd_objects
|
|
7
|
+
|
|
8
|
+
class << self
|
|
9
|
+
def parse
|
|
10
|
+
self.new.parse
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
@wsdl_operations = []
|
|
16
|
+
@xsd_objects = {}
|
|
17
|
+
@wsdls = []
|
|
18
|
+
@xsds = []
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def parse
|
|
22
|
+
ARGV.each do |argv|
|
|
23
|
+
@wsdls << argv if argv =~ /.wsdl$/
|
|
24
|
+
@xsds << argv if argv =~ /.xsd$/
|
|
25
|
+
end
|
|
26
|
+
wsdls.flatten!
|
|
27
|
+
xsds.flatten!
|
|
28
|
+
wsdls.each { |wsdl_file| parse_wsdl(File.read(wsdl_file), wsdl_file) }
|
|
29
|
+
xsds.each { |xsd_file| parse_xsd(File.read(xsd_file), xsd_file) }
|
|
30
|
+
build_results
|
|
31
|
+
print_results
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def parse_wsdl(wsdl, filename = nil)
|
|
35
|
+
doc = Nokogiri::XML(wsdl)
|
|
36
|
+
doc.xpath("//wsdl:operation", doc.root.namespaces).each do |operation|
|
|
37
|
+
wsdl_operations << operation.attributes["name"].value
|
|
38
|
+
end
|
|
39
|
+
rescue => e
|
|
40
|
+
puts "Error parsing wsdl file #{filename}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def parse_xsd(xsd, filename = nil)
|
|
44
|
+
doc = Nokogiri::XML(xsd)
|
|
45
|
+
doc.xpath("//xs:sequence//xs:element", doc.root.namespaces).each do |field|
|
|
46
|
+
operation = field.parent.parent.parent.attributes["name"]
|
|
47
|
+
unless operation.nil?
|
|
48
|
+
next unless operation.value
|
|
49
|
+
next unless field.attributes["name"]
|
|
50
|
+
operation_name = operation.value
|
|
51
|
+
field_name = field.attributes["name"].value
|
|
52
|
+
field_type, allow_blank, required = "unknown", false, false
|
|
53
|
+
field_type = field.attributes["type"].value.gsub(/^xs:/, "") if field.attributes["type"]
|
|
54
|
+
allow_blank = (field.attributes["nillable"].value ? true : false) if field.attributes["nillable"]
|
|
55
|
+
required = (field.attributes["minOccurs"].value.to_i > 0 ? true : false) if field.attributes["minOccurs"]
|
|
56
|
+
xsd_objects[operation_name] ||= {}
|
|
57
|
+
xsd_objects[operation_name][field_name] ||= {"type" => field_type, "allow_blank" => allow_blank, "required" => required}
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
rescue => e
|
|
61
|
+
puts "Error parsing xsd file #{filename}\nReason: #{e.to_s}, #{e.backtrace}"
|
|
62
|
+
exit 1
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def build_results
|
|
66
|
+
output = []
|
|
67
|
+
longest_field_name = 0
|
|
68
|
+
wsdl_operations.each do |operation|
|
|
69
|
+
if xsd_objects[operation]
|
|
70
|
+
xsd_objects[operation].each do |field, values|
|
|
71
|
+
longest_field_name = field.length if field.length > longest_field_name
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
wsdl_operations.each do |operation|
|
|
77
|
+
output << operation
|
|
78
|
+
if xsd_objects[operation]
|
|
79
|
+
xsd_objects[operation].each do |field, values|
|
|
80
|
+
field_options = []
|
|
81
|
+
field_options << values["type"]
|
|
82
|
+
field_options << "required" if values["required"]
|
|
83
|
+
field_options << "no_blanks" unless values["allow_blank"]
|
|
84
|
+
output << " #{field.rjust(longest_field_name)}: #{field_options.join(', ')}"
|
|
85
|
+
end
|
|
86
|
+
else
|
|
87
|
+
output << " - no fields found?"
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
output.join("\n") + "\n"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def print_results
|
|
94
|
+
puts build_results
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe WashAwayTheSoap do
|
|
4
|
+
|
|
5
|
+
describe "#parse_wsdl" do
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
@wsdl_doc = <<-XML
|
|
9
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
10
|
+
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
|
|
11
|
+
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
|
|
12
|
+
name="Sample" targetNamespace="http://tempuri.org/">
|
|
13
|
+
<wsdl:binding>
|
|
14
|
+
<wsdl:operation name="OperationFoo">
|
|
15
|
+
<soap:operation soapAction="http://tempuri.org/SomeService/OperationFoo" style="document" />
|
|
16
|
+
<wsdl:input>
|
|
17
|
+
<soap:body use="literal" />
|
|
18
|
+
</wsdl:input>
|
|
19
|
+
<wsdl:output>
|
|
20
|
+
<soap:body use="literal" />
|
|
21
|
+
</wsdl:output>
|
|
22
|
+
</wsdl:operation>
|
|
23
|
+
</wsdl:binding>
|
|
24
|
+
</wsdl:definitions>
|
|
25
|
+
XML
|
|
26
|
+
subject.parse_wsdl(@wsdl_doc)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "records the operations it finds" do
|
|
30
|
+
subject.wsdl_operations.should include("OperationFoo")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe "#parse_xsd" do
|
|
36
|
+
before do
|
|
37
|
+
@xsd_doc = <<-XML
|
|
38
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
39
|
+
<xs:element name="OperationFoo">
|
|
40
|
+
<xs:complexType>
|
|
41
|
+
<xs:sequence>
|
|
42
|
+
<xs:element minOccurs="0" name="UnrequiredNumberField" type="xs:decimal" />
|
|
43
|
+
<xs:element minOccurs="1" name="RequiredDateField" type="xs:dateTime" />
|
|
44
|
+
<xs:element minOccurs="0" name="NillableStringField" nillable="true" ype="xs:string" />
|
|
45
|
+
</xs:sequence>
|
|
46
|
+
</xs:complexType>
|
|
47
|
+
</xs:element>
|
|
48
|
+
<xs:element name="ignoredElement" nillable="true" type="xs:anyType" />
|
|
49
|
+
<xs:simpleType name="ignoredSimpleType">
|
|
50
|
+
<xs:restriction base="xs:int" />
|
|
51
|
+
</xs:simpleType>
|
|
52
|
+
</xs:schema>
|
|
53
|
+
XML
|
|
54
|
+
subject.parse_xsd(@xsd_doc)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "records the fields for a given object type" do
|
|
58
|
+
subject.xsd_objects["OperationFoo"].keys.should =~ ["UnrequiredNumberField", "RequiredDateField", "NillableStringField"]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "records the data type of a given field" do
|
|
62
|
+
subject.xsd_objects["OperationFoo"]["UnrequiredNumberField"]["type"].should == "decimal"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "records whether or not a field is required" do
|
|
66
|
+
subject.xsd_objects["OperationFoo"]["UnrequiredNumberField"]["required"].should be_false
|
|
67
|
+
subject.xsd_objects["OperationFoo"]["RequiredDateField"]["required"].should be_true
|
|
68
|
+
subject.xsd_objects["OperationFoo"]["NillableStringField"]["required"].should be_false
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "records whether or not a field can be nil if it is provided" do
|
|
72
|
+
subject.xsd_objects["OperationFoo"]["UnrequiredNumberField"]["allow_blank"].should be_false
|
|
73
|
+
subject.xsd_objects["OperationFoo"]["RequiredDateField"]["allow_blank"].should be_false
|
|
74
|
+
subject.xsd_objects["OperationFoo"]["NillableStringField"]["allow_blank"].should be_true
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
describe "#build_results" do
|
|
79
|
+
before do
|
|
80
|
+
@wsdl_doc = <<-XML
|
|
81
|
+
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
|
|
82
|
+
<wsdl:binding>
|
|
83
|
+
<wsdl:operation name="OperationFoo">
|
|
84
|
+
<soap:operation soapAction="http://tempuri.org/SomeService/OperationFoo" style="document" />
|
|
85
|
+
<wsdl:input>
|
|
86
|
+
<soap:body use="literal" />
|
|
87
|
+
</wsdl:input>
|
|
88
|
+
<wsdl:output>
|
|
89
|
+
<soap:body use="literal" />
|
|
90
|
+
</wsdl:output>
|
|
91
|
+
</wsdl:operation>
|
|
92
|
+
</wsdl:binding>
|
|
93
|
+
</wsdl:definitions>
|
|
94
|
+
XML
|
|
95
|
+
subject.parse_wsdl(@wsdl_doc)
|
|
96
|
+
@xsd_doc = <<-XML
|
|
97
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
98
|
+
<xs:element name="OperationFoo">
|
|
99
|
+
<xs:complexType>
|
|
100
|
+
<xs:sequence>
|
|
101
|
+
<xs:element minOccurs="0" name="UnrequiredNumberField" type="xs:decimal" />
|
|
102
|
+
<xs:element minOccurs="1" name="RequiredDateField" type="xs:dateTime" />
|
|
103
|
+
<xs:element minOccurs="0" name="NillableStringField" nillable="true" type="xs:string" />
|
|
104
|
+
</xs:sequence>
|
|
105
|
+
</xs:complexType>
|
|
106
|
+
</xs:element>
|
|
107
|
+
</xs:schema>
|
|
108
|
+
XML
|
|
109
|
+
subject.parse_xsd(@xsd_doc)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "outputs a wsdl web service, it's required fields and their details" do
|
|
113
|
+
subject.build_results.should == <<-EOS
|
|
114
|
+
OperationFoo
|
|
115
|
+
UnrequiredNumberField: decimal, no_blanks
|
|
116
|
+
RequiredDateField: dateTime, required, no_blanks
|
|
117
|
+
NillableStringField: string
|
|
118
|
+
EOS
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: wash_away_the_soap
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease: false
|
|
5
|
+
segments:
|
|
6
|
+
- 0
|
|
7
|
+
- 1
|
|
8
|
+
- 0
|
|
9
|
+
version: 0.1.0
|
|
10
|
+
platform: ruby
|
|
11
|
+
authors:
|
|
12
|
+
- Michael Schubert
|
|
13
|
+
autorequire:
|
|
14
|
+
bindir: bin
|
|
15
|
+
cert_chain: []
|
|
16
|
+
|
|
17
|
+
date: 2010-12-07 00:00:00 +00:00
|
|
18
|
+
default_executable:
|
|
19
|
+
dependencies:
|
|
20
|
+
- !ruby/object:Gem::Dependency
|
|
21
|
+
name: nokogiri
|
|
22
|
+
prerelease: false
|
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
24
|
+
none: false
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
segments:
|
|
29
|
+
- 1
|
|
30
|
+
- 4
|
|
31
|
+
version: "1.4"
|
|
32
|
+
type: :runtime
|
|
33
|
+
version_requirements: *id001
|
|
34
|
+
- !ruby/object:Gem::Dependency
|
|
35
|
+
name: bundler
|
|
36
|
+
prerelease: false
|
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
38
|
+
none: false
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
segments:
|
|
43
|
+
- 1
|
|
44
|
+
- 0
|
|
45
|
+
version: "1.0"
|
|
46
|
+
type: :runtime
|
|
47
|
+
version_requirements: *id002
|
|
48
|
+
- !ruby/object:Gem::Dependency
|
|
49
|
+
name: rspec
|
|
50
|
+
prerelease: false
|
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
52
|
+
none: false
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
segments:
|
|
57
|
+
- 2
|
|
58
|
+
- 0
|
|
59
|
+
version: "2.0"
|
|
60
|
+
type: :development
|
|
61
|
+
version_requirements: *id003
|
|
62
|
+
description: " WashAwayTheSoap parses WSDL and XSD files and attempts to\n pretty-print the service structure so you can make sense\n of a legacy (or just poorly written) system.\n"
|
|
63
|
+
email:
|
|
64
|
+
- michael@schubert.cx
|
|
65
|
+
executables:
|
|
66
|
+
- wash_away_the_soap
|
|
67
|
+
extensions: []
|
|
68
|
+
|
|
69
|
+
extra_rdoc_files:
|
|
70
|
+
- README.md
|
|
71
|
+
files:
|
|
72
|
+
- lib/wash_away_the_soap.rb
|
|
73
|
+
- bin/wash_away_the_soap
|
|
74
|
+
- Gemfile
|
|
75
|
+
- LICENSE
|
|
76
|
+
- Rakefile
|
|
77
|
+
- README.md
|
|
78
|
+
- spec/spec_helper.rb
|
|
79
|
+
- spec/wash_away_the_soap_spec.rb
|
|
80
|
+
has_rdoc: true
|
|
81
|
+
homepage: https://github.com/schubert/wash_away_the_soap
|
|
82
|
+
licenses:
|
|
83
|
+
- MIT
|
|
84
|
+
post_install_message:
|
|
85
|
+
rdoc_options: []
|
|
86
|
+
|
|
87
|
+
require_paths:
|
|
88
|
+
- lib
|
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
|
+
none: false
|
|
91
|
+
requirements:
|
|
92
|
+
- - ">="
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
segments:
|
|
95
|
+
- 0
|
|
96
|
+
version: "0"
|
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
|
+
none: false
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
segments:
|
|
103
|
+
- 0
|
|
104
|
+
version: "0"
|
|
105
|
+
requirements: []
|
|
106
|
+
|
|
107
|
+
rubyforge_project: wash_away_the_soap
|
|
108
|
+
rubygems_version: 1.3.7
|
|
109
|
+
signing_key:
|
|
110
|
+
specification_version: 3
|
|
111
|
+
summary: Parse WSDL/XSD files for clues how to implement or talk to services
|
|
112
|
+
test_files: []
|
|
113
|
+
|