Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F7892357
api_spec_helpers.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
api_spec_helpers.ex
View Options
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma.Tests.ApiSpecHelpers
do
@moduledoc
"""
OpenAPI spec test helpers
"""
import
ExUnit.Assertions
alias
OpenApiSpex.Cast.Error
alias
OpenApiSpex.Reference
alias
OpenApiSpex.Schema
def
assert_schema
(
value
,
schema
)
do
api_spec
=
Pleroma.Web.ApiSpec
.
spec
()
case
OpenApiSpex
.
cast_value
(
value
,
schema
,
api_spec
)
do
{
:ok
,
data
}
->
data
{
:error
,
errors
}
->
errors
=
Enum
.
map
(
errors
,
fn
error
->
message
=
Error
.
message
(
error
)
path
=
Error
.
path_to_string
(
error
)
"
#{
message
}
at
#{
path
}
"
end
)
flunk
(
"Value does not conform to schema
#{
schema
.
title
}
:
#{
Enum
.
join
(
errors
,
"
\n
"
)
}
\n
#{
inspect
(
value
)
}
"
)
end
end
def
resolve_schema
(%
Schema
{}
=
schema
),
do
:
schema
def
resolve_schema
(%
Reference
{}
=
ref
)
do
schemas
=
Pleroma.Web.ApiSpec
.
spec
()
.
components
.
schemas
Reference
.
resolve_schema
(
ref
,
schemas
)
end
def
api_operations
do
paths
=
Pleroma.Web.ApiSpec
.
spec
()
.
paths
Enum
.
flat_map
(
paths
,
fn
{
_
,
path_item
}
->
path_item
|>
Map
.
take
([
:delete
,
:get
,
:head
,
:options
,
:patch
,
:post
,
:put
,
:trace
])
|>
Map
.
values
()
|>
Enum
.
reject
(
&
is_nil
/
1
)
end
)
|>
Enum
.
uniq
()
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Thu, Oct 2, 4:22 AM (15 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
487252
Default Alt Text
api_spec_helpers.ex (1 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment