Merge remote-tracking branch 'pleroma/develop' into optional-config
[akkoma] / lib / pleroma / web / api_spec / schemas / boolean_like.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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.Cast
7 alias OpenApiSpex.Schema
8
9 require OpenApiSpex
10
11 OpenApiSpex.schema(%{
12 title: "BooleanLike",
13 description: """
14 The following values will be treated as `false`:
15 - false
16 - 0
17 - "0",
18 - "f",
19 - "F",
20 - "false",
21 - "FALSE",
22 - "off",
23 - "OFF"
24
25 All other non-null values will be treated as `true`
26 """,
27 anyOf: [
28 %Schema{type: :boolean},
29 %Schema{type: :string},
30 %Schema{type: :integer}
31 ],
32 "x-validate": __MODULE__
33 })
34
35 def cast(%Cast{value: value} = context) do
36 context
37 |> Map.put(:value, Pleroma.Web.ControllerHelper.truthy_param?(value))
38 |> Cast.ok()
39 end
40 end