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

Allow empty soap actions #77

Closed
Closed
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ Configure version of SOAP protocol. Supported versions `1.1`(default) and `1.2`.
config :soap, :globals, version: "1.1"
```

Allow empty `soapAction` attribute in operation definition
```elixir
config :soap, :globals, allow_empty_soap_action: true
```

In case of `schema_namespace` is not present in types definitions
```elixir
config :soap, :globals, absent_schema_namespace: true
```

## Usage

The documentation is available on [HexDocs](https://hexdocs.pm/soap/api-reference.html).
Expand Down
23 changes: 16 additions & 7 deletions lib/soap/wsdl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,17 @@ defmodule Soap.Wsdl do

@spec get_schema_namespace(String.t()) :: String.t()
defp get_schema_namespace(wsdl) do
{_, _, _, schema_namespace, _} =
wsdl
|> xpath(~x"//namespace::*"l)
|> Enum.find(fn {_, _, _, _, x} -> x == :"http://www.w3.org/2001/XMLSchema" end)

schema_namespace
case Application.fetch_env!(:soap, :globals)[:absent_schema_namespace] do
true ->
[]
_ ->
{_, _, _, schema_namespace, _} =
wsdl
|> xpath(~x"//namespace::*"l)
|> Enum.find(fn {_, _, _, _, x} -> x == :"http://www.w3.org/2001/XMLSchema" end)

schema_namespace
end
end

@spec get_namespaces(String.t(), String.t(), String.t()) :: map()
Expand Down Expand Up @@ -153,7 +158,7 @@ defmodule Soap.Wsdl do
|> xpath(~x".", name: ~x"./@name"s, soap_action: ~x"./#{ns("operation", soap_ns)}/@soapAction"s)
|> Map.put(:input, get_operation_input(node, protocol_ns, soap_ns))
end)
|> Enum.reject(fn x -> x[:soap_action] == "" end)
|> Enum.reject(fn x -> x[:soap_action] == "" && !allow_empty_soap_action() end)
end

defp get_operation_input(element, protocol_ns, soap_ns) do
Expand Down Expand Up @@ -218,6 +223,10 @@ defmodule Soap.Wsdl do
defp soap_version, do: Application.fetch_env!(:soap, :globals)[:version]
defp soap_version(opts) when is_list(opts), do: Keyword.get(opts, :soap_version, soap_version())

defp allow_empty_soap_action do
Application.fetch_env!(:soap, :globals)[:allow_empty_soap_action] || false
end

defp ns(name, []), do: "#{name}"
defp ns(name, namespace), do: "#{namespace}:#{name}"
end