Add spec for AccountController.unfollow
[akkoma] / lib / pleroma / web / api_spec / operations / app_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.AppOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Helpers
9 alias Pleroma.Web.ApiSpec.Schemas.AppCreateRequest
10 alias Pleroma.Web.ApiSpec.Schemas.AppCreateResponse
11
12 @spec open_api_operation(atom) :: Operation.t()
13 def open_api_operation(action) do
14 operation = String.to_existing_atom("#{action}_operation")
15 apply(__MODULE__, operation, [])
16 end
17
18 @spec create_operation() :: Operation.t()
19 def create_operation do
20 %Operation{
21 tags: ["apps"],
22 summary: "Create an application",
23 description: "Create a new application to obtain OAuth2 credentials",
24 operationId: "AppController.create",
25 requestBody: Helpers.request_body("Parameters", AppCreateRequest, required: true),
26 responses: %{
27 200 => Operation.response("App", "application/json", AppCreateResponse),
28 422 =>
29 Operation.response(
30 "Unprocessable Entity",
31 "application/json",
32 %Schema{
33 type: :object,
34 description:
35 "If a required parameter is missing or improperly formatted, the request will fail.",
36 properties: %{
37 error: %Schema{type: :string}
38 },
39 example: %{
40 "error" => "Validation failed: Redirect URI must be an absolute URI."
41 }
42 }
43 )
44 }
45 }
46 end
47
48 def verify_credentials_operation do
49 %Operation{
50 tags: ["apps"],
51 summary: "Verify your app works",
52 description: "Confirm that the app's OAuth2 credentials work.",
53 operationId: "AppController.verify_credentials",
54 security: [%{"oAuth" => ["read"]}],
55 responses: %{
56 200 =>
57 Operation.response("App", "application/json", %Schema{
58 type: :object,
59 description:
60 "If the Authorization header was provided with a valid token, you should see your app returned as an Application entity.",
61 properties: %{
62 name: %Schema{type: :string},
63 vapid_key: %Schema{type: :string},
64 website: %Schema{type: :string, nullable: true}
65 },
66 example: %{
67 "name" => "My App",
68 "vapid_key" =>
69 "BCk-QqERU0q-CfYZjcuB6lnyyOYfJ2AifKqfeGIm7Z-HiTU5T9eTG5GxVA0_OH5mMlI4UkkDTpaZwozy0TzdZ2M=",
70 "website" => "https://myapp.com/"
71 }
72 }),
73 422 =>
74 Operation.response(
75 "Unauthorized",
76 "application/json",
77 %Schema{
78 type: :object,
79 description:
80 "If the Authorization header contains an invalid token, is malformed, or is not present, an error will be returned indicating an authorization failure.",
81 properties: %{
82 error: %Schema{type: :string}
83 },
84 example: %{
85 "error" => "The access token is invalid."
86 }
87 }
88 )
89 }
90 }
91 end
92 end