Class: WSDL::Definition
- Inherits:
-
Object
- Object
- WSDL::Definition
- Defined in:
- lib/wsdl/definition.rb,
lib/wsdl/definition/builder.rb,
lib/wsdl/definition/element_hash.rb
Overview
Abstract representation of a parsed WSDL service.
A Definition is a frozen, serializable snapshot of everything the library knows about a WSDL service — its services, ports, operations, and message structures stored as plain hashes. It serves as the intermediate representation (IR) that downstream consumers (Client, Operation, Response) operate on.
Create a Definition via parse or restore one from a cached hash via load.
Defined Under Namespace
Classes: AttributeHash, Builder, ElementHash
Class Method Summary collapse
-
.from_h(hash) ⇒ Definition
Restores a Definition from a serialized Hash.
Instance Method Summary collapse
-
#build_issues ⇒ Array<Hash{Symbol => String}>
Returns build issues encountered during Definition construction.
-
#endpoint(service_name, port_name) ⇒ String
private
Returns the endpoint URL for a specific service and port.
-
#fingerprint ⇒ String
Returns the content-based fingerprint for this Definition.
-
#initialize(data) ⇒ Definition
constructor
private
Creates a new Definition from internal data.
-
#input ⇒ Array<Hash>
Returns a developer-friendly view of an operation's input body.
-
#input_header ⇒ Array<Hash>
Returns a developer-friendly view of an operation's input headers.
-
#operation_data(input_name: nil) ⇒ Hash
private
Returns the full internal operation data for use by Client/Operation.
-
#operations(service_name = nil, port_name = nil) ⇒ Array<Hash>
Returns all operations.
-
#output ⇒ Array<Hash>
Returns a developer-friendly view of an operation's output body.
-
#output_header ⇒ Array<Hash>
Returns a developer-friendly view of an operation's output headers.
-
#port_type(service_name, port_name) ⇒ String
private
Returns the SOAP type namespace URI for a port.
-
#ports(service_name = nil) ⇒ Array<Hash>
Returns all ports.
-
#resolve_service_and_port ⇒ Array(String, String)
private
Resolves the single service and port for auto-resolution.
-
#schema_version ⇒ Integer
Returns the schema version of this Definition's internal format.
-
#service_name ⇒ String?
Returns the name of the primary service.
-
#services ⇒ Array<Hash>
Returns all services.
-
#sources ⇒ Array<Hash{Symbol => Object}>
Returns source provenance for all documents fetched during parsing.
-
#to_dsl ⇒ String
Returns a pasteable DSL snippet for building a request.
-
#to_h ⇒ Hash{String => Object}
Serializes this Definition to a plain Hash.
-
#to_json ⇒ String
Serializes this Definition to a JSON string.
-
#verify! ⇒ self
Raises if any build issues were recorded during construction.
Constructor Details
#initialize(data) ⇒ Definition
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new Definition from internal data.
This constructor is intended for internal use by Builder and from_h. Users should create Definitions via WSDL.parse or WSDL.load.
37 38 39 40 |
# File 'lib/wsdl/definition.rb', line 37 def initialize(data) @data = deep_freeze(data) freeze end |
Class Method Details
.from_h(hash) ⇒ Definition
Restores a Definition from a serialized Hash.
Validates the schema version and raises if it doesn't match the current library version.
317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/wsdl/definition.rb', line 317 def self.from_h(hash) version = hash['schema_version'] || hash[:schema_version] unless version == Builder::SCHEMA_VERSION raise ArgumentError, "Definition schema version mismatch: expected #{Builder::SCHEMA_VERSION}, " \ "got #{version.inspect}. Please re-parse the WSDL with WSDL.parse." end new(deserialize(hash)) end |
Instance Method Details
#build_issues ⇒ Array<Hash{Symbol => String}>
Returns build issues encountered during Definition construction.
Each entry records an operation that could not be fully resolved and the reason. These operations are included in the Definition with empty message parts.
95 96 97 |
# File 'lib/wsdl/definition.rb', line 95 def build_issues @data[:build_issues] || [] end |
#endpoint(service_name, port_name) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the endpoint URL for a specific service and port.
251 252 253 |
# File 'lib/wsdl/definition.rb', line 251 def endpoint(service_name, port_name) @data[:services][service_name][:ports][port_name][:endpoint] end |
#fingerprint ⇒ String
Returns the content-based fingerprint for this Definition.
The fingerprint is derived from all source digests and statuses. It changes when any source document changes or when a previously failing import starts resolving (or vice versa).
63 64 65 |
# File 'lib/wsdl/definition.rb', line 63 def fingerprint @data[:fingerprint] end |
#input(operation_name) ⇒ Array<Hash> #input(service_name, port_name, operation_name) ⇒ Array<Hash>
Returns a developer-friendly view of an operation's input body.
Auto-resolves service and port for single-service/port WSDLs. For multiple services/ports, pass them explicitly.
175 176 177 178 |
# File 'lib/wsdl/definition.rb', line 175 def input(*) op = resolve_operation(*) op[:input][:body].map { |el| project_element(el) } end |
#input_header(operation_name) ⇒ Array<Hash> #input_header(service_name, port_name, operation_name) ⇒ Array<Hash>
Returns a developer-friendly view of an operation's input headers.
185 186 187 188 |
# File 'lib/wsdl/definition.rb', line 185 def input_header(*) op = resolve_operation(*) op[:input][:header].map { |el| project_element(el) } end |
#operation_data(operation_name) ⇒ Hash #operation_data(service_name, port_name, operation_name) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the full internal operation data for use by Client/Operation.
221 222 223 |
# File 'lib/wsdl/definition.rb', line 221 def operation_data(*, input_name: nil) resolve_operation(*, input_name:) end |
#operations(service_name = nil, port_name = nil) ⇒ Array<Hash>
Returns all operations. Pass service and port names to filter.
154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/wsdl/definition.rb', line 154 def operations(service_name = nil, port_name = nil) result = [] each_operation(service_name, port_name) do |svc, port, op| entry = { service: svc, port:, name: op[:name], style: op[:input_style], soap_action: op[:soap_action] } entry[:input_name] = op[:input_name] if op[:input_name] result << entry end result end |
#output(operation_name) ⇒ Array<Hash> #output(service_name, port_name, operation_name) ⇒ Array<Hash>
Returns a developer-friendly view of an operation's output body.
195 196 197 198 199 200 |
# File 'lib/wsdl/definition.rb', line 195 def output(*) op = resolve_operation(*) return [] unless op[:output] op[:output][:body].map { |el| project_element(el) } end |
#output_header(operation_name) ⇒ Array<Hash> #output_header(service_name, port_name, operation_name) ⇒ Array<Hash>
Returns a developer-friendly view of an operation's output headers.
207 208 209 210 211 212 |
# File 'lib/wsdl/definition.rb', line 207 def output_header(*) op = resolve_operation(*) return [] unless op[:output] op[:output][:header].map { |el| project_element(el) } end |
#port_type(service_name, port_name) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the SOAP type namespace URI for a port.
261 262 263 |
# File 'lib/wsdl/definition.rb', line 261 def port_type(service_name, port_name) @data[:services][service_name][:ports][port_name][:type] end |
#ports(service_name = nil) ⇒ Array<Hash>
Returns all ports. Pass a service name to filter.
138 139 140 141 142 |
# File 'lib/wsdl/definition.rb', line 138 def ports(service_name = nil) each_port(service_name).map do |svc_name, port_name, port_data| { service: svc_name, name: port_name, endpoint: port_data[:endpoint] } end end |
#resolve_service_and_port ⇒ Array(String, String)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Resolves the single service and port for auto-resolution.
rubocop:disable Metrics/AbcSize -- validation requires multiple checks
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/wsdl/definition.rb', line 271 def resolve_service_and_port svcs = @data[:services] if svcs.size != 1 names = svcs.keys.map(&:inspect).join(', ') raise ArgumentError, "Cannot auto-resolve service: expected 1, found #{svcs.size} (#{names}). " \ 'Pass explicit service and port names.' end svc_name = svcs.keys.first ports = svcs[svc_name][:ports] if ports.size != 1 names = ports.keys.map(&:inspect).join(', ') raise ArgumentError, "Cannot auto-resolve port for service #{svc_name.inspect}: " \ "expected 1, found #{ports.size} (#{names}). " \ 'Pass explicit service and port names.' end [svc_name, ports.keys.first] end |
#schema_version ⇒ Integer
Returns the schema version of this Definition's internal format.
45 46 47 |
# File 'lib/wsdl/definition.rb', line 45 def schema_version @data[:schema_version] end |
#service_name ⇒ String?
Returns the name of the primary service.
52 53 54 |
# File 'lib/wsdl/definition.rb', line 52 def service_name @data[:service_name] end |
#services ⇒ Array<Hash>
Returns all services. Arguments filter the results.
124 125 126 127 128 |
# File 'lib/wsdl/definition.rb', line 124 def services @data[:services].map do |name, data| { name:, ports: data[:ports].keys } end end |
#sources ⇒ Array<Hash{Symbol => Object}>
Returns source provenance for all documents fetched during parsing.
Each entry records the location, resolution status, content digest, and any error. Provides transparency into what was resolved and enables change detection.
79 80 81 |
# File 'lib/wsdl/definition.rb', line 79 def sources @data[:sources] end |
#to_dsl(operation_name) ⇒ String #to_dsl(service_name, port_name, operation_name) ⇒ String
Returns a pasteable DSL snippet for building a request.
Generates code for both header and body sections that can be
copy-pasted into an invoke or prepare block.
237 238 239 240 241 242 243 |
# File 'lib/wsdl/definition.rb', line 237 def to_dsl(*) op = resolve_operation(*) lines = [] append_dsl_section(lines, 'header', op[:input][:header]) append_dsl_section(lines, 'body', op[:input][:body]) lines.join("\n") end |
#to_h ⇒ Hash{String => Object}
298 299 300 |
# File 'lib/wsdl/definition.rb', line 298 def to_h serialize(@data) end |
#to_json ⇒ String
Serializes this Definition to a JSON string.
305 306 307 |
# File 'lib/wsdl/definition.rb', line 305 def to_json(*) JSON.generate(to_h, *) end |
#verify! ⇒ self
Raises if any build issues were recorded during construction.
Call this after WSDL.parse if you want strict behavior — failing on any operation that could not be fully resolved.
111 112 113 114 115 |
# File 'lib/wsdl/definition.rb', line 111 def verify! raise DefinitionError, build_issues if build_issues.any? self end |