Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F8613485
cast_parameters.ex
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
cast_parameters.ex
View Options
defmodule
OpenApiSpex.CastParameters
do
@moduledoc
false
alias
OpenApiSpex
.
{
Cast
,
Operation
,
Parameter
,
Schema
}
alias
OpenApiSpex.Cast
.
{
Error
,
Object
}
alias
Plug.Conn
@spec
cast
(
Plug.Conn
.
t
(),
Operation
.
t
(),
Schema
.
schemas
())
::
{
:error
,
[
Error
.
t
()]}
|
{
:ok
,
Conn
.
t
()}
def
cast
(
conn
,
operation
,
schemas
)
do
# Taken together as a set, operation parameters are similar to an object schema type.
# Convert parameters to an object schema, then delegate to `Cast.Object.cast/1`
properties
=
operation
.
parameters
|>
Enum
.
map
(
fn
parameter
->
{
parameter
.
name
,
Parameter
.
schema
(
parameter
)}
end
)
|>
Map
.
new
()
required
=
operation
.
parameters
|>
Enum
.
filter
(
&
&1
.
required
)
|>
Enum
.
map
(
&
&1
.
name
)
object_schema
=
%
Schema
{
type
:
:object
,
properties
:
properties
,
required
:
required
}
params
=
Map
.
merge
(
conn
.
path_params
,
conn
.
query_params
)
ctx
=
%
Cast
{
value
:
params
,
schema
:
object_schema
,
schemas
:
schemas
}
with
{
:ok
,
params
}
<-
Object
.
cast
(
ctx
)
do
{
:ok
,
%{
conn
|
params
:
params
}}
end
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Sat, Oct 25, 4:07 PM (2 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
553211
Default Alt Text
cast_parameters.ex (1 KB)
Attached To
Mode
R22 open_api_spex
Attached
Detach File
Event Timeline
Log In to Comment