From 74047479dc4ba09be0037f291d3e6bd01facbeaa Mon Sep 17 00:00:00 2001 From: Isaak Tsalicoglou Date: Wed, 8 Mar 2023 00:26:51 +0200 Subject: [PATCH] soap_version/0 now loads :version 1.1 by default In partial response to [issue 88](https://github.com/elixir-soap/soap/issues/88), I noticed that Soap fails completely if my application does not define `config :soap, :globals` in its `config/config.exs`, even though a) HTTPoison is the default client and b) version 1.1 is claimed in the documentation to be the default. Applications using a dependency that itself depends on Soap should not need to add anything to their `config/config.exs`, especially if what is expected to be defined therein has a sane default value (version 1.1, and HTTPoison), I redefined `soap_version/0` to first see if it can fetch its configuration; if not, it gracefully returns the (default, according to the docs) version 1.1. Note that the test suite of Soap still assumes that `config/config.exs` contains a configuration. Removing these lines from it makes tests fail. It might be a good idea to get rid of this caveat entirely, and follow the official recommendation to [avoid application configuration for libraries](https://hexdocs.pm/elixir/library-guidelines.html#avoid-application-configuration). --- lib/soap/response/parser.ex | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/soap/response/parser.ex b/lib/soap/response/parser.ex index 05d0b5c..12574b4 100644 --- a/lib/soap/response/parser.ex +++ b/lib/soap/response/parser.ex @@ -105,5 +105,17 @@ defmodule Soap.Response.Parser do defp apply_namespace_to_tag("", tag), do: tag defp apply_namespace_to_tag(env_namespace, tag), do: env_namespace <> ":" <> tag - defp soap_version, do: Application.fetch_env!(:soap, :globals)[:version] + defp soap_version do + case Application.fetch_env(:soap, :globals) do + :error -> + "1.1" + + {:ok, content} -> + if :version in Keyword.keys(content) do + content[:version] + else + "1.1" + end + end + end end