make 2fa UI less awful
[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(opts \\ []) do
15 %OpenApi{
16 servers:
17 if opts[:server_specific] 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 API",
27 description: """
28 This is documentation for client Pleroma API. Most of the endpoints and entities come
29 from Mastodon API and have custom extensions on top.
30
31 While this document aims to be a complete guide to the client API Pleroma exposes,
32 the details are still being worked out. Some endpoints may have incomplete or poorly worded documentation.
33 You might want to check the following resources if something is not clear:
34 - [Legacy Pleroma-specific endpoint documentation](https://docs-develop.pleroma.social/backend/development/API/pleroma_api/)
35 - [Mastodon API documentation](https://docs.joinmastodon.org/client/intro/)
36 - [Differences in Mastodon API responses from vanilla Mastodon](https://docs-develop.pleroma.social/backend/development/API/differences_in_mastoapi_responses/)
37
38 Please report such occurences on our [issue tracker](https://git.pleroma.social/pleroma/pleroma/-/issues). Feel free to submit API questions or proposals there too!
39 """,
40 # Strip environment from the version
41 version: Application.spec(:pleroma, :vsn) |> to_string() |> String.replace(~r/\+.*$/, ""),
42 extensions: %{
43 # Logo path should be picked so that the path exists both on Pleroma instances and on api.pleroma.social
44 "x-logo": %{"url" => "/static/logo.svg", "altText" => "Pleroma logo"}
45 }
46 },
47 # populate the paths from a phoenix router
48 paths: OpenApiSpex.Paths.from_router(Router),
49 components: %OpenApiSpex.Components{
50 parameters: %{
51 "accountIdOrNickname" =>
52 Operation.parameter(:id, :path, :string, "Account ID or nickname",
53 example: "123",
54 required: true
55 )
56 },
57 securitySchemes: %{
58 "oAuth" => %OpenApiSpex.SecurityScheme{
59 type: "oauth2",
60 flows: %OpenApiSpex.OAuthFlows{
61 password: %OpenApiSpex.OAuthFlow{
62 authorizationUrl: "/oauth/authorize",
63 tokenUrl: "/oauth/token",
64 scopes: %{
65 # TODO: Document granular scopes
66 "read" => "Read everything",
67 "write" => "Write everything",
68 "follow" => "Manage relationships",
69 "push" => "Web Push API subscriptions"
70 }
71 }
72 }
73 }
74 }
75 },
76 extensions: %{
77 # Redoc-specific extension, every time a new tag is added it should be reflected here,
78 # otherwise it won't be shown.
79 "x-tagGroups": [
80 %{
81 "name" => "Accounts",
82 "tags" => ["Account actions", "Retrieve account information"]
83 },
84 %{
85 "name" => "Administration",
86 "tags" => [
87 "Emoji pack administration",
88 "Frontend managment",
89 "Instance configuration",
90 "Instance documents",
91 "Invites",
92 "MediaProxy cache",
93 "OAuth application managment",
94 "Relays",
95 "Report managment",
96 "Status administration",
97 "User administration"
98 ]
99 },
100 %{"name" => "Applications", "tags" => ["Applications", "Push subscriptions"]},
101 %{
102 "name" => "Current account",
103 "tags" => [
104 "Account credentials",
105 "Backups",
106 "Blocks and mutes",
107 "Data import",
108 "Domain blocks",
109 "Follow requests",
110 "Mascot",
111 "Markers",
112 "Notifications"
113 ]
114 },
115 %{"name" => "Instance", "tags" => ["Custom emojis"]},
116 %{
117 "name" => "Statuses",
118 "tags" => [
119 "Emoji reactions",
120 "Lists",
121 "Polls",
122 "Timelines",
123 "Retrieve status information",
124 "Scheduled statuses",
125 "Search",
126 "Status actions"
127 ]
128 },
129 %{"name" => "Miscellaneous", "tags" => ["Emoji packs", "Reports", "Suggestions"]}
130 ]
131 }
132 }
133 # discover request/response schemas from path specs
134 |> OpenApiSpex.resolve_schema_modules()
135 end
136 end