Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F114949
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/open_api_spex/cast_parameters.ex b/lib/open_api_spex/cast_parameters.ex
index 41c8c34..f682b67 100644
--- a/lib/open_api_spex/cast_parameters.ex
+++ b/lib/open_api_spex/cast_parameters.ex
@@ -1,97 +1,97 @@
defmodule OpenApiSpex.CastParameters do
@moduledoc false
alias OpenApiSpex.{Cast, Operation, Parameter, Schema, Reference, Components}
alias OpenApiSpex.Cast.{Error, Object}
alias Plug.Conn
@spec cast(Plug.Conn.t(), Operation.t(), Components.t()) ::
{:error, [Error.t()]} | {:ok, Conn.t()}
def cast(conn, operation, components) do
# Convert parameters to an object schema for the set location
casted_params =
operation.parameters
|> Enum.reduce(%{}, fn param, acc ->
# Operation's parameters list may include references - resolving here
parameter =
case param do
%Reference{} -> Reference.resolve_parameter(param, components.parameters)
%Parameter{} -> param
end
location_schema =
acc
|> Map.get(parameter.in)
|> add_to_location_schema(parameter)
Map.put(acc, parameter.in, location_schema)
end)
# then delegate to `Cast.Object.cast/1`
|> Enum.map(fn {location, location_schema} ->
params = get_params_by_location(conn, location, Map.keys(location_schema.properties))
ctx = %Cast{
value: params,
schema: location_schema,
schemas: components.schemas
}
Object.cast(ctx)
end)
full_cast_result =
Enum.reduce_while(casted_params, {:ok, %{}}, fn
{:ok, entry}, {:ok, acc} -> {:cont, {:ok, Map.merge(acc, entry)}}
- cast_error, acc -> {:halt, cast_error}
+ cast_error, _ -> {:halt, cast_error}
end)
case full_cast_result do
{:ok, result} -> {:ok, %{conn | params: result}}
err -> err
end
end
defp get_params_by_location(conn, :query, _) do
conn.query_params
end
defp get_params_by_location(conn, :path, _) do
conn.path_params
end
defp get_params_by_location(conn, :cookie, _) do
conn.req_cookies
end
defp get_params_by_location(conn, :header, expected_names) do
conn.req_headers
- |> Enum.filter(fn {key, value} ->
+ |> Enum.filter(fn {key, _value} ->
Enum.member?(expected_names, String.downcase(key))
end)
|> Map.new()
end
defp add_to_location_schema(nil, parameter) do
# Since there is no Schema on the "parameter" level, we create one here
template_schema = %Schema{
type: :object,
additionalProperties: false,
properties: %{},
required: []
}
add_to_location_schema(template_schema, parameter)
end
defp add_to_location_schema(location_schema, parameter) do
# Put the operation parameter to the proper location schema for validation
required =
case parameter.required do
true -> [parameter.name | location_schema.required]
_ -> location_schema.required
end
properties = Map.put(location_schema.properties, parameter.name, Parameter.schema(parameter))
- location_schema = %{location_schema | properties: properties, required: required}
+ %{location_schema | properties: properties, required: required}
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Nov 26, 8:45 PM (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40476
Default Alt Text
(3 KB)
Attached To
Mode
R22 open_api_spex
Attached
Detach File
Event Timeline
Log In to Comment