Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
5.0KB

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