logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

api_spec.ex (5692B)


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