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

#add-nested-types Nested types has been added #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
29 changes: 18 additions & 11 deletions lib/soap/request/params.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ defmodule Soap.Request.Params do
errors =
params
|> Enum.map(&validate_param(&1, wsdl, operation))
|> List.flatten()

case Enum.any?(errors) do
true ->
Expand All @@ -60,21 +61,27 @@ defmodule Soap.Request.Params do
nil

_ ->
if Map.has_key?(val_map, k) do
validate_param_attributes(val_map, k, v)
else
"Invalid SOAP message:Invalid content was found starting with element '#{k}'. One of {#{
Enum.join(Map.keys(val_map), ", ")
}} is expected."
case Map.get(val_map, k, nil) do
%{type: attribute_type} ->
[_, type] = String.split(attribute_type, ":")

if is_list(v) do
Enum.map(v, &validate_param(&1, wsdl, type))
else
validate_param_attributes(k, v, type)
end

nil ->
"Invalid SOAP message:Invalid content was found starting with element '#{k}'. One of {#{
Enum.join(Map.keys(val_map), ", ")
}} is expected."
end
end
end

@spec validate_param_attributes(val_map :: map(), k :: String.t(), v :: String.t()) :: String.t() | nil
defp validate_param_attributes(val_map, k, v) do
attributes = val_map[k]
[_, type] = String.split(attributes.type, ":")

@spec validate_param_attributes(k :: String.t(), v :: String.t(), type :: String.t()) ::
String.t() | nil
defp validate_param_attributes(k, v, type) do
case Integer.parse(v) do
{number, ""} -> validate_type(k, number, type)
_ -> validate_type(k, v, type)
Expand Down