Bump Copyright to 2021
[akkoma] / lib / pleroma / web / api_spec.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec do
6 alias OpenApiSpex.OpenApi
7 alias OpenApiSpex.Operation
8 alias Pleroma.Web.Endpoint
9 alias Pleroma.Web.Router
10
11 @behaviour OpenApi
12
13 @impl OpenApi
14 def spec do
15 %OpenApi{
16 servers:
17 if Phoenix.Endpoint.server?(:pleroma, Endpoint) do
18 [
19 # Populate the Server info from a phoenix endpoint
20 OpenApiSpex.Server.from_endpoint(Endpoint)
21 ]
22 else
23 []
24 end,
25 info: %OpenApiSpex.Info{
26 title: "Pleroma",
27 description: Application.spec(:pleroma, :description) |> to_string(),
28 version: Application.spec(:pleroma, :vsn) |> to_string()
29 },
30 # populate the paths from a phoenix router
31 paths: OpenApiSpex.Paths.from_router(Router),
32 components: %OpenApiSpex.Components{
33 parameters: %{
34 "accountIdOrNickname" =>
35 Operation.parameter(:id, :path, :string, "Account ID or nickname",
36 example: "123",
37 required: true
38 )
39 },
40 securitySchemes: %{
41 "oAuth" => %OpenApiSpex.SecurityScheme{
42 type: "oauth2",
43 flows: %OpenApiSpex.OAuthFlows{
44 password: %OpenApiSpex.OAuthFlow{
45 authorizationUrl: "/oauth/authorize",
46 tokenUrl: "/oauth/token",
47 scopes: %{
48 "read" => "read",
49 "write" => "write",
50 "follow" => "follow",
51 "push" => "push"
52 }
53 }
54 }
55 }
56 }
57 }
58 }
59 # discover request/response schemas from path specs
60 |> OpenApiSpex.resolve_schema_modules()
61 end
62 end