2020-04-08 18:33:25 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-04-08 18:33:25 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ApiSpec.Schemas.BooleanLike do
|
2021-03-05 11:51:29 +00:00
|
|
|
alias OpenApiSpex.Cast
|
2020-04-08 18:33:25 +00:00
|
|
|
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}
|
2021-03-05 11:51:29 +00:00
|
|
|
],
|
|
|
|
"x-validate": __MODULE__
|
2020-04-08 18:33:25 +00:00
|
|
|
})
|
|
|
|
|
2021-03-05 11:51:29 +00:00
|
|
|
def cast(%Cast{value: value} = context) do
|
|
|
|
context
|
|
|
|
|> Map.put(:value, Pleroma.Web.ControllerHelper.truthy_param?(value))
|
|
|
|
|> Cast.ok()
|
2020-04-08 18:33:25 +00:00
|
|
|
end
|
|
|
|
end
|