2020-04-01 19:00:59 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-04-01 19:00:59 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ApiSpec do
|
|
|
|
alias OpenApiSpex.OpenApi
|
2020-04-08 18:33:25 +00:00
|
|
|
alias OpenApiSpex.Operation
|
2020-04-01 19:00:59 +00:00
|
|
|
alias Pleroma.Web.Endpoint
|
|
|
|
alias Pleroma.Web.Router
|
|
|
|
|
|
|
|
@behaviour OpenApi
|
|
|
|
|
|
|
|
@impl OpenApi
|
2021-02-03 12:38:59 +00:00
|
|
|
def spec(opts \\ []) do
|
2020-04-01 19:00:59 +00:00
|
|
|
%OpenApi{
|
2020-09-18 21:50:38 +00:00
|
|
|
servers:
|
2021-02-03 12:38:59 +00:00
|
|
|
if opts[:server_specific] do
|
2020-09-18 21:50:38 +00:00
|
|
|
[
|
|
|
|
# Populate the Server info from a phoenix endpoint
|
|
|
|
OpenApiSpex.Server.from_endpoint(Endpoint)
|
|
|
|
]
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end,
|
2020-04-01 19:00:59 +00:00
|
|
|
info: %OpenApiSpex.Info{
|
2021-02-03 12:38:59 +00:00
|
|
|
title: "Pleroma API",
|
|
|
|
description: """
|
|
|
|
This is documentation for client Pleroma API. Most of the endpoints and entities come
|
|
|
|
from Mastodon API and have custom extensions on top.
|
|
|
|
|
|
|
|
While this document aims to be a complete guide to the client API Pleroma exposes,
|
|
|
|
the details are still being worked out. Some endpoints may have incomplete or poorly worded documentation.
|
|
|
|
You might want to check the following resources if something is not clear:
|
|
|
|
- [Legacy Pleroma-specific endpoint documentation](https://docs-develop.pleroma.social/backend/development/API/pleroma_api/)
|
|
|
|
- [Mastodon API documentation](https://docs.joinmastodon.org/client/intro/)
|
|
|
|
- [Differences in Mastodon API responses from vanilla Mastodon](https://docs-develop.pleroma.social/backend/development/API/differences_in_mastoapi_responses/)
|
|
|
|
|
|
|
|
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!
|
|
|
|
""",
|
2021-02-09 19:23:11 +00:00
|
|
|
# Strip environment from the version
|
|
|
|
version: Application.spec(:pleroma, :vsn) |> to_string() |> String.replace(~r/\+.*$/, ""),
|
2021-02-03 12:38:59 +00:00
|
|
|
extensions: %{
|
|
|
|
# Logo path should be picked so that the path exists both on Pleroma instances and on api.pleroma.social
|
|
|
|
"x-logo": %{"url" => "/static/logo.svg", "altText" => "Pleroma logo"}
|
|
|
|
}
|
2020-04-01 19:00:59 +00:00
|
|
|
},
|
|
|
|
# populate the paths from a phoenix router
|
2020-04-02 13:33:23 +00:00
|
|
|
paths: OpenApiSpex.Paths.from_router(Router),
|
|
|
|
components: %OpenApiSpex.Components{
|
2020-04-08 18:33:25 +00:00
|
|
|
parameters: %{
|
|
|
|
"accountIdOrNickname" =>
|
|
|
|
Operation.parameter(:id, :path, :string, "Account ID or nickname",
|
|
|
|
example: "123",
|
|
|
|
required: true
|
|
|
|
)
|
|
|
|
},
|
2020-04-02 13:33:23 +00:00
|
|
|
securitySchemes: %{
|
|
|
|
"oAuth" => %OpenApiSpex.SecurityScheme{
|
|
|
|
type: "oauth2",
|
|
|
|
flows: %OpenApiSpex.OAuthFlows{
|
|
|
|
password: %OpenApiSpex.OAuthFlow{
|
|
|
|
authorizationUrl: "/oauth/authorize",
|
|
|
|
tokenUrl: "/oauth/token",
|
2020-05-05 12:43:00 +00:00
|
|
|
scopes: %{
|
2021-02-03 12:38:59 +00:00
|
|
|
# TODO: Document granular scopes
|
|
|
|
"read" => "Read everything",
|
|
|
|
"write" => "Write everything",
|
|
|
|
"follow" => "Manage relationships",
|
|
|
|
"push" => "Web Push API subscriptions"
|
2020-05-05 12:43:00 +00:00
|
|
|
}
|
2020-04-02 13:33:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-03 12:38:59 +00:00
|
|
|
},
|
|
|
|
extensions: %{
|
|
|
|
# Redoc-specific extension, every time a new tag is added it should be reflected here,
|
|
|
|
# otherwise it won't be shown.
|
|
|
|
"x-tagGroups": [
|
|
|
|
%{
|
|
|
|
"name" => "Accounts",
|
|
|
|
"tags" => ["Account actions", "Retrieve account information", "Scrobbles"]
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"name" => "Administration",
|
|
|
|
"tags" => [
|
|
|
|
"Chat administration",
|
2021-02-17 17:56:13 +00:00
|
|
|
"Emoji pack administration",
|
2021-02-03 12:38:59 +00:00
|
|
|
"Frontend managment",
|
|
|
|
"Instance configuration",
|
|
|
|
"Instance documents",
|
|
|
|
"Invites",
|
|
|
|
"MediaProxy cache",
|
|
|
|
"OAuth application managment",
|
|
|
|
"Relays",
|
2021-03-04 17:13:53 +00:00
|
|
|
"Report managment",
|
|
|
|
"Status administration",
|
2023-01-15 23:31:37 +00:00
|
|
|
"User administration",
|
|
|
|
"Announcement management"
|
2021-02-03 12:38:59 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
%{"name" => "Applications", "tags" => ["Applications", "Push subscriptions"]},
|
|
|
|
%{
|
|
|
|
"name" => "Current account",
|
|
|
|
"tags" => [
|
|
|
|
"Account credentials",
|
|
|
|
"Backups",
|
|
|
|
"Blocks and mutes",
|
|
|
|
"Data import",
|
|
|
|
"Domain blocks",
|
|
|
|
"Follow requests",
|
|
|
|
"Mascot",
|
|
|
|
"Markers",
|
2023-01-15 23:31:37 +00:00
|
|
|
"Notifications",
|
|
|
|
"Filters",
|
|
|
|
"Settings"
|
2021-02-03 12:38:59 +00:00
|
|
|
]
|
|
|
|
},
|
2023-01-15 23:31:37 +00:00
|
|
|
%{"name" => "Instance", "tags" => ["Custom emojis", "Instance misc"]},
|
2021-02-03 12:38:59 +00:00
|
|
|
%{"name" => "Messaging", "tags" => ["Chats", "Conversations"]},
|
|
|
|
%{
|
|
|
|
"name" => "Statuses",
|
|
|
|
"tags" => [
|
|
|
|
"Emoji reactions",
|
|
|
|
"Lists",
|
|
|
|
"Polls",
|
|
|
|
"Timelines",
|
|
|
|
"Retrieve status information",
|
|
|
|
"Scheduled statuses",
|
|
|
|
"Search",
|
2023-01-15 23:31:37 +00:00
|
|
|
"Status actions",
|
|
|
|
"Media attachments"
|
2021-02-03 12:38:59 +00:00
|
|
|
]
|
|
|
|
},
|
2023-01-15 23:31:37 +00:00
|
|
|
%{
|
|
|
|
"name" => "Miscellaneous",
|
|
|
|
"tags" => [
|
|
|
|
"Emoji packs",
|
|
|
|
"Reports",
|
|
|
|
"Suggestions",
|
|
|
|
"Announcements",
|
|
|
|
"Remote interaction",
|
|
|
|
"Others"
|
|
|
|
]
|
|
|
|
}
|
2021-02-03 12:38:59 +00:00
|
|
|
]
|
2020-04-02 13:33:23 +00:00
|
|
|
}
|
2020-04-01 19:00:59 +00:00
|
|
|
}
|
|
|
|
# discover request/response schemas from path specs
|
|
|
|
|> OpenApiSpex.resolve_schema_modules()
|
|
|
|
end
|
|
|
|
end
|