summaryrefslogtreecommitdiff
path: root/lib/pleroma/web/api_spec/schemas/boolean_like.ex
blob: eb001c5bb35e2d31af499f05792734f91470c35f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.ApiSpec.Schemas.BooleanLike do
  alias OpenApiSpex.Schema

  require OpenApiSpex

  OpenApiSpex.schema(%{
    title: "BooleanLike",
    description: """
    The following values will be treated as `false`:
      - false
      - 0
      - "0",
      - "f",
      - "F",
      - "false",
      - "FALSE",
      - "off",
      - "OFF"

    All other non-null values will be treated as `true`
    """,
    anyOf: [
      %Schema{type: :boolean},
      %Schema{type: :string},
      %Schema{type: :integer}
    ]
  })

  def after_cast(value, _schmea) do
    {:ok, Pleroma.Web.ControllerHelper.truthy_param?(value)}
  end
end