1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
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
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, [])
18 @spec create_operation() :: Operation.t()
19 def create_operation do
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),
27 200 => Operation.response("App", "application/json", AppCreateResponse),
30 "Unprocessable Entity",
35 "If a required parameter is missing or improperly formatted, the request will fail.",
37 error: %Schema{type: :string}
40 "error" => "Validation failed: Redirect URI must be an absolute URI."
48 def verify_credentials_operation do
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"]}],
57 Operation.response("App", "application/json", %Schema{
60 "If the Authorization header was provided with a valid token, you should see your app returned as an Application entity.",
62 name: %Schema{type: :string},
63 vapid_key: %Schema{type: :string},
64 website: %Schema{type: :string, nullable: true}
69 "BCk-QqERU0q-CfYZjcuB6lnyyOYfJ2AifKqfeGIm7Z-HiTU5T9eTG5GxVA0_OH5mMlI4UkkDTpaZwozy0TzdZ2M=",
70 "website" => "https://myapp.com/"
80 "If the Authorization header contains an invalid token, is malformed, or is not present, an error will be returned indicating an authorization failure.",
82 error: %Schema{type: :string}
85 "error" => "The access token is invalid."