logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

boolean_like.ex (904B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ApiSpec.Schemas.BooleanLike do
  5. alias OpenApiSpex.Cast
  6. alias OpenApiSpex.Schema
  7. require OpenApiSpex
  8. OpenApiSpex.schema(%{
  9. title: "BooleanLike",
  10. description: """
  11. The following values will be treated as `false`:
  12. - false
  13. - 0
  14. - "0",
  15. - "f",
  16. - "F",
  17. - "false",
  18. - "FALSE",
  19. - "off",
  20. - "OFF"
  21. All other non-null values will be treated as `true`
  22. """,
  23. anyOf: [
  24. %Schema{type: :boolean},
  25. %Schema{type: :string},
  26. %Schema{type: :integer}
  27. ],
  28. "x-validate": __MODULE__
  29. })
  30. def cast(%Cast{value: value} = context) do
  31. context
  32. |> Map.put(:value, Pleroma.Web.Utils.Params.truthy_param?(value))
  33. |> Cast.ok()
  34. end
  35. end