logo

pleroma

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

helpers.ex (2470B)


  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.Helpers do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
  8. def request_body(description, schema_ref, opts \\ []) do
  9. media_types = ["application/json", "multipart/form-data", "application/x-www-form-urlencoded"]
  10. content =
  11. media_types
  12. |> Enum.map(fn type ->
  13. {type,
  14. %OpenApiSpex.MediaType{
  15. schema: schema_ref,
  16. example: opts[:example],
  17. examples: opts[:examples]
  18. }}
  19. end)
  20. |> Enum.into(%{})
  21. %OpenApiSpex.RequestBody{
  22. description: description,
  23. content: content,
  24. required: opts[:required] || false
  25. }
  26. end
  27. def admin_api_params do
  28. [Operation.parameter(:admin_token, :query, :string, "Allows authorization via admin token.")]
  29. end
  30. def pagination_params do
  31. [
  32. Operation.parameter(:max_id, :query, :string, "Return items older than this ID"),
  33. Operation.parameter(:min_id, :query, :string, "Return the oldest items newer than this ID"),
  34. Operation.parameter(
  35. :since_id,
  36. :query,
  37. :string,
  38. "Return the newest items newer than this ID"
  39. ),
  40. Operation.parameter(
  41. :offset,
  42. :query,
  43. %Schema{type: :integer, default: 0},
  44. "Return items past this number of items"
  45. ),
  46. Operation.parameter(
  47. :limit,
  48. :query,
  49. %Schema{type: :integer, default: 20},
  50. "Maximum number of items to return. Will be ignored if it's more than 40"
  51. )
  52. ]
  53. end
  54. def with_relationships_param do
  55. Operation.parameter(
  56. :with_relationships,
  57. :query,
  58. BooleanLike.schema(),
  59. "Embed relationships into accounts. **If this parameter is not set account's `pleroma.relationship` is going to be `null`.**"
  60. )
  61. end
  62. def empty_object_response do
  63. Operation.response("Empty object", "application/json", %Schema{type: :object, example: %{}})
  64. end
  65. def empty_array_response do
  66. Operation.response("Empty array", "application/json", %Schema{
  67. type: :array,
  68. items: %Schema{type: :object, example: %{}},
  69. example: []
  70. })
  71. end
  72. def no_content_response do
  73. Operation.response("No Content", "application/json", %Schema{type: :string, example: ""})
  74. end
  75. end