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

handle arrays of refs in parameter schemas #205

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
24 changes: 12 additions & 12 deletions lib/phoenix_swagger/validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,17 @@ defmodule PhoenixSwagger.Validator do
# Let's go through requests parameters from swagger schema
# and collect it into json schema properties.
properties = Enum.reduce(parameters, %{}, fn(parameter, acc) ->
acc = if parameter["type"] == nil do
ref = String.split(parameter["schema"]["$ref"], "/") |> List.last
Map.merge(acc, schema["definitions"][ref])
else
acc
end
acc
if parameter["schema"] && parameter["schema"]["$ref"] do
ref = String.split(parameter["schema"]["$ref"], "/") |> List.last
Map.merge(acc, schema["definitions"][ref])
else
acc
end
end)
# collect request primitive parameters which do not refer to `definitions`
# these are mostly parameters from query string
properties = Enum.reduce(parameters, properties, fn(parameter, acc) ->
if parameter["type"] != nil do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can narrow it down to this line causing the test failures

if acc["properties"] |> is_map() && parameter["type"] != nil do
collect_properties(acc, parameter)
else
acc
Expand All @@ -143,11 +142,12 @@ defmodule PhoenixSwagger.Validator do
end

@doc false
defp collect_properties(properties, parameter) when properties == %{} do
Map.put(%{}, "properties", Map.put_new(%{}, parameter["name"], %{"type" => parameter["type"]}))
defp collect_properties(properties, %{"name" => param_name, "type" => param_type})
when properties == %{} do
%{"properties" => %{param_name => %{"type" => param_type}}}
end
defp collect_properties(properties, parameter) do
props = Map.put(properties["properties"], parameter["name"], %{"type" => parameter["type"]})
defp collect_properties(properties = %{"properties" => props}, %{"name" => param_name, "type" => param_type}) do
props = Map.put(props, param_name, %{"type" => param_type})
Map.put(properties, "properties", props)
end

Expand Down