logo

pleroma

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

instance_document_operation.ex (3728B)


  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.Admin.InstanceDocumentOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. alias Pleroma.Web.ApiSpec.Helpers
  8. alias Pleroma.Web.ApiSpec.Schemas.ApiError
  9. def open_api_operation(action) do
  10. operation = String.to_existing_atom("#{action}_operation")
  11. apply(__MODULE__, operation, [])
  12. end
  13. def show_operation do
  14. %Operation{
  15. tags: ["Instance documents"],
  16. summary: "Retrieve an instance document",
  17. operationId: "AdminAPI.InstanceDocumentController.show",
  18. security: [%{"oAuth" => ["admin:read"]}],
  19. parameters: [
  20. Operation.parameter(:name, :path, %Schema{type: :string}, "The document name",
  21. required: true
  22. )
  23. | Helpers.admin_api_params()
  24. ],
  25. responses: %{
  26. 200 => document_content(),
  27. 400 => Operation.response("Bad Request", "application/json", ApiError),
  28. 403 => Operation.response("Forbidden", "application/json", ApiError),
  29. 404 => Operation.response("Not Found", "application/json", ApiError)
  30. }
  31. }
  32. end
  33. def update_operation do
  34. %Operation{
  35. tags: ["Instance documents"],
  36. summary: "Update an instance document",
  37. operationId: "AdminAPI.InstanceDocumentController.update",
  38. security: [%{"oAuth" => ["admin:write"]}],
  39. requestBody: Helpers.request_body("Parameters", update_request()),
  40. parameters: [
  41. Operation.parameter(:name, :path, %Schema{type: :string}, "The document name",
  42. required: true
  43. )
  44. | Helpers.admin_api_params()
  45. ],
  46. responses: %{
  47. 200 => Operation.response("InstanceDocument", "application/json", instance_document()),
  48. 400 => Operation.response("Bad Request", "application/json", ApiError),
  49. 403 => Operation.response("Forbidden", "application/json", ApiError),
  50. 404 => Operation.response("Not Found", "application/json", ApiError)
  51. }
  52. }
  53. end
  54. defp update_request do
  55. %Schema{
  56. title: "UpdateRequest",
  57. description: "POST body for uploading the file",
  58. type: :object,
  59. required: [:file],
  60. properties: %{
  61. file: %Schema{
  62. type: :string,
  63. format: :binary,
  64. description: "The file to be uploaded, using multipart form data."
  65. }
  66. }
  67. }
  68. end
  69. def delete_operation do
  70. %Operation{
  71. tags: ["Instance documents"],
  72. summary: "Delete an instance document",
  73. operationId: "AdminAPI.InstanceDocumentController.delete",
  74. security: [%{"oAuth" => ["admin:write"]}],
  75. parameters: [
  76. Operation.parameter(:name, :path, %Schema{type: :string}, "The document name",
  77. required: true
  78. )
  79. | Helpers.admin_api_params()
  80. ],
  81. responses: %{
  82. 200 => Operation.response("InstanceDocument", "application/json", instance_document()),
  83. 400 => Operation.response("Bad Request", "application/json", ApiError),
  84. 403 => Operation.response("Forbidden", "application/json", ApiError),
  85. 404 => Operation.response("Not Found", "application/json", ApiError)
  86. }
  87. }
  88. end
  89. defp instance_document do
  90. %Schema{
  91. title: "InstanceDocument",
  92. type: :object,
  93. properties: %{
  94. url: %Schema{type: :string}
  95. },
  96. example: %{
  97. "url" => "https://example.com/static/terms-of-service.html"
  98. }
  99. }
  100. end
  101. defp document_content do
  102. Operation.response("InstanceDocumentContent", "text/html", %Schema{
  103. type: :string,
  104. example: "<h1>Instance panel</h1>"
  105. })
  106. end
  107. end