Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into chat-federation...
[akkoma] / lib / pleroma / web / api_spec.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 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 # Populate the Server info from a phoenix endpoint
18 OpenApiSpex.Server.from_endpoint(Endpoint)
19 ],
20 info: %OpenApiSpex.Info{
21 title: "Pleroma",
22 description: Application.spec(:pleroma, :description) |> to_string(),
23 version: Application.spec(:pleroma, :vsn) |> to_string()
24 },
25 # populate the paths from a phoenix router
26 paths: OpenApiSpex.Paths.from_router(Router),
27 components: %OpenApiSpex.Components{
28 parameters: %{
29 "accountIdOrNickname" =>
30 Operation.parameter(:id, :path, :string, "Account ID or nickname",
31 example: "123",
32 required: true
33 )
34 },
35 securitySchemes: %{
36 "oAuth" => %OpenApiSpex.SecurityScheme{
37 type: "oauth2",
38 flows: %OpenApiSpex.OAuthFlows{
39 password: %OpenApiSpex.OAuthFlow{
40 authorizationUrl: "/oauth/authorize",
41 tokenUrl: "/oauth/token",
42 scopes: %{
43 "read" => "read",
44 "write" => "write",
45 "follow" => "follow",
46 "push" => "push"
47 }
48 }
49 }
50 }
51 }
52 }
53 }
54 # discover request/response schemas from path specs
55 |> OpenApiSpex.resolve_schema_modules()
56 end
57 end