Merge branch 'develop' into openapi/account
[akkoma] / lib / pleroma / web / api_spec / schemas / boolean_like.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.Schemas.BooleanLike do
6 alias OpenApiSpex.Schema
7
8 require OpenApiSpex
9
10 OpenApiSpex.schema(%{
11 title: "BooleanLike",
12 description: """
13 The following values will be treated as `false`:
14 - false
15 - 0
16 - "0",
17 - "f",
18 - "F",
19 - "false",
20 - "FALSE",
21 - "off",
22 - "OFF"
23
24 All other non-null values will be treated as `true`
25 """,
26 anyOf: [
27 %Schema{type: :boolean},
28 %Schema{type: :string},
29 %Schema{type: :integer}
30 ]
31 })
32
33 def after_cast(value, _schmea) do
34 {:ok, Pleroma.Web.ControllerHelper.truthy_param?(value)}
35 end
36 end