diff --git a/README.md b/README.md index 398316b..728afa3 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/lib/soap/wsdl.ex b/lib/soap/wsdl.ex index b64ea04..899d829 100644 --- a/lib/soap/wsdl.ex +++ b/lib/soap/wsdl.ex @@ -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() @@ -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 @@ -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