1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ApiSpec.Admin.InstanceDocumentOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Helpers
9 alias Pleroma.Web.ApiSpec.Schemas.ApiError
11 def open_api_operation(action) do
12 operation = String.to_existing_atom("#{action}_operation")
13 apply(__MODULE__, operation, [])
18 tags: ["Instance documents"],
19 summary: "Retrieve an instance document",
20 operationId: "AdminAPI.InstanceDocumentController.show",
21 security: [%{"oAuth" => ["admin:read"]}],
23 Operation.parameter(:name, :path, %Schema{type: :string}, "The document name",
26 | Helpers.admin_api_params()
29 200 => document_content(),
30 400 => Operation.response("Bad Request", "application/json", ApiError),
31 403 => Operation.response("Forbidden", "application/json", ApiError),
32 404 => Operation.response("Not Found", "application/json", ApiError)
37 def update_operation do
39 tags: ["Instance documents"],
40 summary: "Update an instance document",
41 operationId: "AdminAPI.InstanceDocumentController.update",
42 security: [%{"oAuth" => ["admin:write"]}],
43 requestBody: Helpers.request_body("Parameters", update_request()),
45 Operation.parameter(:name, :path, %Schema{type: :string}, "The document name",
48 | Helpers.admin_api_params()
51 200 => Operation.response("InstanceDocument", "application/json", instance_document()),
52 400 => Operation.response("Bad Request", "application/json", ApiError),
53 403 => Operation.response("Forbidden", "application/json", ApiError),
54 404 => Operation.response("Not Found", "application/json", ApiError)
59 defp update_request do
61 title: "UpdateRequest",
62 description: "POST body for uploading the file",
69 description: "The file to be uploaded, using multipart form data."
75 def delete_operation do
77 tags: ["Instance documents"],
78 summary: "Delete an instance document",
79 operationId: "AdminAPI.InstanceDocumentController.delete",
80 security: [%{"oAuth" => ["admin:write"]}],
82 Operation.parameter(:name, :path, %Schema{type: :string}, "The document name",
85 | Helpers.admin_api_params()
88 200 => Operation.response("InstanceDocument", "application/json", instance_document()),
89 400 => Operation.response("Bad Request", "application/json", ApiError),
90 403 => Operation.response("Forbidden", "application/json", ApiError),
91 404 => Operation.response("Not Found", "application/json", ApiError)
96 defp instance_document do
98 title: "InstanceDocument",
101 url: %Schema{type: :string}
104 "url" => "https://example.com/static/terms-of-service.html"
109 defp document_content do
110 Operation.response("InstanceDocumentContent", "text/html", %Schema{
112 example: "<h1>Instance panel</h1>"