logo

pleroma

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

account_operation.ex (35943B)


  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.AccountOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Reference
  7. alias OpenApiSpex.Schema
  8. alias Pleroma.Web.ApiSpec.Schemas.Account
  9. alias Pleroma.Web.ApiSpec.Schemas.AccountRelationship
  10. alias Pleroma.Web.ApiSpec.Schemas.ActorType
  11. alias Pleroma.Web.ApiSpec.Schemas.ApiError
  12. alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
  13. alias Pleroma.Web.ApiSpec.Schemas.FlakeID
  14. alias Pleroma.Web.ApiSpec.Schemas.List
  15. alias Pleroma.Web.ApiSpec.Schemas.Status
  16. alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
  17. import Pleroma.Web.ApiSpec.Helpers
  18. @spec open_api_operation(atom) :: Operation.t()
  19. def open_api_operation(action) do
  20. operation = String.to_existing_atom("#{action}_operation")
  21. apply(__MODULE__, operation, [])
  22. end
  23. @spec create_operation() :: Operation.t()
  24. def create_operation do
  25. %Operation{
  26. tags: ["Account credentials"],
  27. summary: "Register an account",
  28. description:
  29. "Creates a user and account records. Returns an account access token for the app that initiated the request. The app should save this token for later, and should wait for the user to confirm their account by clicking a link in their email inbox.",
  30. operationId: "AccountController.create",
  31. requestBody: request_body("Parameters", create_request(), required: true),
  32. responses: %{
  33. 200 => Operation.response("Account", "application/json", create_response()),
  34. 400 => Operation.response("Error", "application/json", ApiError),
  35. 403 => Operation.response("Error", "application/json", ApiError),
  36. 429 => Operation.response("Error", "application/json", ApiError)
  37. }
  38. }
  39. end
  40. def verify_credentials_operation do
  41. %Operation{
  42. tags: ["Account credentials"],
  43. description: "Test to make sure that the user token works.",
  44. summary: "Verify account credentials",
  45. operationId: "AccountController.verify_credentials",
  46. security: [%{"oAuth" => ["read:accounts"]}],
  47. responses: %{
  48. 200 => Operation.response("Account", "application/json", Account)
  49. }
  50. }
  51. end
  52. def update_credentials_operation do
  53. %Operation{
  54. tags: ["Account credentials"],
  55. summary: "Update account credentials",
  56. description: "Update the user's display and preferences.",
  57. operationId: "AccountController.update_credentials",
  58. security: [%{"oAuth" => ["write:accounts"]}],
  59. requestBody: request_body("Parameters", update_credentials_request(), required: true),
  60. responses: %{
  61. 200 => Operation.response("Account", "application/json", Account),
  62. 403 => Operation.response("Error", "application/json", ApiError),
  63. 413 => Operation.response("Error", "application/json", ApiError)
  64. }
  65. }
  66. end
  67. def relationships_operation do
  68. %Operation{
  69. tags: ["Retrieve account information"],
  70. summary: "Relationship with current account",
  71. operationId: "AccountController.relationships",
  72. description: "Find out whether a given account is followed, blocked, muted, etc.",
  73. security: [%{"oAuth" => ["read:follows"]}],
  74. parameters: [
  75. Operation.parameter(
  76. :id,
  77. :query,
  78. %Schema{
  79. oneOf: [%Schema{type: :array, items: %Schema{type: :string}}, %Schema{type: :string}]
  80. },
  81. "Account IDs",
  82. example: "123"
  83. )
  84. ],
  85. responses: %{
  86. 200 => Operation.response("Account", "application/json", array_of_relationships())
  87. }
  88. }
  89. end
  90. def show_operation do
  91. %Operation{
  92. tags: ["Retrieve account information"],
  93. summary: "Account",
  94. operationId: "AccountController.show",
  95. description: "View information about a profile.",
  96. parameters: [
  97. %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
  98. with_relationships_param()
  99. ],
  100. responses: %{
  101. 200 => Operation.response("Account", "application/json", Account),
  102. 401 => Operation.response("Error", "application/json", ApiError),
  103. 404 => Operation.response("Error", "application/json", ApiError)
  104. }
  105. }
  106. end
  107. def statuses_operation do
  108. %Operation{
  109. summary: "Statuses",
  110. tags: ["Retrieve account information"],
  111. operationId: "AccountController.statuses",
  112. description:
  113. "Statuses posted to the given account. Public (for public statuses only), or user token + `read:statuses` (for private statuses the user is authorized to see)",
  114. parameters:
  115. [
  116. %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
  117. Operation.parameter(
  118. :pinned,
  119. :query,
  120. BooleanLike.schema(),
  121. "Include only pinned statuses"
  122. ),
  123. Operation.parameter(:tagged, :query, :string, "With tag"),
  124. Operation.parameter(
  125. :only_media,
  126. :query,
  127. BooleanLike.schema(),
  128. "Include only statuses with media attached"
  129. ),
  130. Operation.parameter(
  131. :with_muted,
  132. :query,
  133. BooleanLike.schema(),
  134. "Include statuses from muted accounts."
  135. ),
  136. Operation.parameter(:exclude_reblogs, :query, BooleanLike.schema(), "Exclude reblogs"),
  137. Operation.parameter(
  138. :only_reblogs,
  139. :query,
  140. BooleanLike.schema(),
  141. "Include only reblogs"
  142. ),
  143. Operation.parameter(:exclude_replies, :query, BooleanLike.schema(), "Exclude replies"),
  144. Operation.parameter(
  145. :exclude_visibilities,
  146. :query,
  147. %Schema{type: :array, items: VisibilityScope},
  148. "Exclude visibilities"
  149. ),
  150. Operation.parameter(
  151. :with_muted,
  152. :query,
  153. BooleanLike.schema(),
  154. "Include reactions from muted accounts."
  155. )
  156. ] ++ pagination_params(),
  157. responses: %{
  158. 200 => Operation.response("Statuses", "application/json", array_of_statuses()),
  159. 401 => Operation.response("Error", "application/json", ApiError),
  160. 404 => Operation.response("Error", "application/json", ApiError)
  161. }
  162. }
  163. end
  164. def followers_operation do
  165. %Operation{
  166. tags: ["Retrieve account information"],
  167. summary: "Followers",
  168. operationId: "AccountController.followers",
  169. security: [%{"oAuth" => ["read:accounts"]}],
  170. description:
  171. "Accounts which follow the given account, if network is not hidden by the account owner.",
  172. parameters: [
  173. %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
  174. Operation.parameter(:id, :query, :string, "ID of the resource owner"),
  175. with_relationships_param() | pagination_params()
  176. ],
  177. responses: %{
  178. 200 => Operation.response("Accounts", "application/json", array_of_accounts())
  179. }
  180. }
  181. end
  182. def following_operation do
  183. %Operation{
  184. tags: ["Retrieve account information"],
  185. summary: "Following",
  186. operationId: "AccountController.following",
  187. security: [%{"oAuth" => ["read:accounts"]}],
  188. description:
  189. "Accounts which the given account is following, if network is not hidden by the account owner.",
  190. parameters: [
  191. %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
  192. Operation.parameter(:id, :query, :string, "ID of the resource owner"),
  193. with_relationships_param() | pagination_params()
  194. ],
  195. responses: %{200 => Operation.response("Accounts", "application/json", array_of_accounts())}
  196. }
  197. end
  198. def lists_operation do
  199. %Operation{
  200. tags: ["Retrieve account information"],
  201. summary: "Lists containing this account",
  202. operationId: "AccountController.lists",
  203. security: [%{"oAuth" => ["read:lists"]}],
  204. description: "User lists that you have added this account to.",
  205. parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
  206. responses: %{200 => Operation.response("Lists", "application/json", array_of_lists())}
  207. }
  208. end
  209. def follow_operation do
  210. %Operation{
  211. tags: ["Account actions"],
  212. summary: "Follow",
  213. operationId: "AccountController.follow",
  214. security: [%{"oAuth" => ["follow", "write:follows"]}],
  215. description: "Follow the given account",
  216. parameters: [
  217. %Reference{"$ref": "#/components/parameters/accountIdOrNickname"}
  218. ],
  219. requestBody:
  220. request_body(
  221. "Parameters",
  222. %Schema{
  223. type: :object,
  224. properties: %{
  225. reblogs: %Schema{
  226. allOf: [BooleanLike],
  227. description: "Receive this account's reblogs in home timeline? Defaults to true.",
  228. default: true
  229. },
  230. notify: %Schema{
  231. allOf: [BooleanLike],
  232. description:
  233. "Receive notifications for all statuses posted by the account? Defaults to false.",
  234. default: false
  235. }
  236. }
  237. },
  238. required: false
  239. ),
  240. responses: %{
  241. 200 => Operation.response("Relationship", "application/json", AccountRelationship),
  242. 400 => Operation.response("Error", "application/json", ApiError),
  243. 404 => Operation.response("Error", "application/json", ApiError)
  244. }
  245. }
  246. end
  247. def unfollow_operation do
  248. %Operation{
  249. tags: ["Account actions"],
  250. summary: "Unfollow",
  251. operationId: "AccountController.unfollow",
  252. security: [%{"oAuth" => ["follow", "write:follows"]}],
  253. description: "Unfollow the given account",
  254. parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
  255. responses: %{
  256. 200 => Operation.response("Relationship", "application/json", AccountRelationship),
  257. 400 => Operation.response("Error", "application/json", ApiError),
  258. 404 => Operation.response("Error", "application/json", ApiError)
  259. }
  260. }
  261. end
  262. def mute_operation do
  263. %Operation{
  264. tags: ["Account actions"],
  265. summary: "Mute",
  266. operationId: "AccountController.mute",
  267. security: [%{"oAuth" => ["follow", "write:mutes"]}],
  268. requestBody: request_body("Parameters", mute_request()),
  269. description:
  270. "Mute the given account. Clients should filter statuses and notifications from this account, if received (e.g. due to a boost in the Home timeline).",
  271. parameters: [
  272. %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
  273. Operation.parameter(
  274. :notifications,
  275. :query,
  276. %Schema{allOf: [BooleanLike], default: true},
  277. "Mute notifications in addition to statuses? Defaults to `true`."
  278. )
  279. ],
  280. responses: %{
  281. 200 => Operation.response("Relationship", "application/json", AccountRelationship)
  282. }
  283. }
  284. end
  285. def unmute_operation do
  286. %Operation{
  287. tags: ["Account actions"],
  288. summary: "Unmute",
  289. operationId: "AccountController.unmute",
  290. security: [%{"oAuth" => ["follow", "write:mutes"]}],
  291. description: "Unmute the given account.",
  292. parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
  293. responses: %{
  294. 200 => Operation.response("Relationship", "application/json", AccountRelationship)
  295. }
  296. }
  297. end
  298. def block_operation do
  299. %Operation{
  300. tags: ["Account actions"],
  301. summary: "Block",
  302. operationId: "AccountController.block",
  303. requestBody: request_body("Parameters", block_request()),
  304. security: [%{"oAuth" => ["follow", "write:blocks"]}],
  305. description:
  306. "Block the given account. Clients should filter statuses from this account if received (e.g. due to a boost in the Home timeline)",
  307. parameters: [
  308. %Reference{"$ref": "#/components/parameters/accountIdOrNickname"}
  309. ],
  310. responses: %{
  311. 200 => Operation.response("Relationship", "application/json", AccountRelationship)
  312. }
  313. }
  314. end
  315. defp block_request do
  316. %Schema{
  317. title: "AccountBlockRequest",
  318. description: "POST body for blocking an account",
  319. type: :object,
  320. properties: %{
  321. duration: %Schema{
  322. type: :integer,
  323. nullable: true,
  324. description: "Expire the mute in `duration` seconds. Default 0 for infinity"
  325. }
  326. },
  327. example: %{
  328. "duration" => 86_400
  329. }
  330. }
  331. end
  332. def unblock_operation do
  333. %Operation{
  334. tags: ["Account actions"],
  335. summary: "Unblock",
  336. operationId: "AccountController.unblock",
  337. security: [%{"oAuth" => ["follow", "write:blocks"]}],
  338. description: "Unblock the given account.",
  339. parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
  340. responses: %{
  341. 200 => Operation.response("Relationship", "application/json", AccountRelationship)
  342. }
  343. }
  344. end
  345. def endorse_operation do
  346. %Operation{
  347. tags: ["Account actions"],
  348. summary: "Endorse",
  349. operationId: "AccountController.endorse",
  350. security: [%{"oAuth" => ["follow", "write:accounts"]}],
  351. description: "Adds the given account to endorsed accounts list.",
  352. parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
  353. responses: %{
  354. 200 => Operation.response("Relationship", "application/json", AccountRelationship),
  355. 400 =>
  356. Operation.response("Bad Request", "application/json", %Schema{
  357. allOf: [ApiError],
  358. title: "Unprocessable Entity",
  359. example: %{
  360. "error" => "You have already pinned the maximum number of users"
  361. }
  362. })
  363. }
  364. }
  365. end
  366. def unendorse_operation do
  367. %Operation{
  368. tags: ["Account actions"],
  369. summary: "Unendorse",
  370. operationId: "AccountController.unendorse",
  371. security: [%{"oAuth" => ["follow", "write:accounts"]}],
  372. description: "Removes the given account from endorsed accounts list.",
  373. parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
  374. responses: %{
  375. 200 => Operation.response("Relationship", "application/json", AccountRelationship)
  376. }
  377. }
  378. end
  379. def endorsements_operation do
  380. %Operation{
  381. tags: ["Retrieve account information"],
  382. summary: "Endorsements",
  383. description: "Returns endorsed accounts",
  384. operationId: "AccountController.endorsements",
  385. parameters: [
  386. with_relationships_param(),
  387. %Reference{"$ref": "#/components/parameters/accountIdOrNickname"}
  388. ],
  389. responses: %{
  390. 200 =>
  391. Operation.response(
  392. "Array of Accounts",
  393. "application/json",
  394. array_of_accounts()
  395. ),
  396. 404 => Operation.response("Not Found", "application/json", ApiError)
  397. }
  398. }
  399. end
  400. def remove_from_followers_operation do
  401. %Operation{
  402. tags: ["Account actions"],
  403. summary: "Remove from followers",
  404. operationId: "AccountController.remove_from_followers",
  405. security: [%{"oAuth" => ["follow", "write:follows"]}],
  406. description: "Remove the given account from followers",
  407. parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
  408. responses: %{
  409. 200 => Operation.response("Relationship", "application/json", AccountRelationship),
  410. 400 => Operation.response("Error", "application/json", ApiError),
  411. 404 => Operation.response("Error", "application/json", ApiError)
  412. }
  413. }
  414. end
  415. def note_operation do
  416. %Operation{
  417. tags: ["Account actions"],
  418. summary: "Set a private note about a user.",
  419. operationId: "AccountController.note",
  420. security: [%{"oAuth" => ["follow", "write:accounts"]}],
  421. requestBody: request_body("Parameters", note_request()),
  422. description: "Create a note for the given account.",
  423. parameters: [
  424. %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
  425. Operation.parameter(
  426. :comment,
  427. :query,
  428. %Schema{type: :string},
  429. "Account note body"
  430. )
  431. ],
  432. responses: %{
  433. 200 => Operation.response("Relationship", "application/json", AccountRelationship)
  434. }
  435. }
  436. end
  437. def follow_by_uri_operation do
  438. %Operation{
  439. tags: ["Account actions"],
  440. summary: "Follow by URI",
  441. operationId: "AccountController.follows",
  442. security: [%{"oAuth" => ["follow", "write:follows"]}],
  443. requestBody: request_body("Parameters", follow_by_uri_request(), required: true),
  444. responses: %{
  445. 200 => Operation.response("Account", "application/json", AccountRelationship),
  446. 400 => Operation.response("Error", "application/json", ApiError),
  447. 404 => Operation.response("Error", "application/json", ApiError)
  448. }
  449. }
  450. end
  451. def mutes_operation do
  452. %Operation{
  453. tags: ["Blocks and mutes"],
  454. summary: "Retrieve list of mutes",
  455. operationId: "AccountController.mutes",
  456. description: "Accounts the user has muted.",
  457. security: [%{"oAuth" => ["follow", "read:mutes"]}],
  458. parameters: [with_relationships_param() | pagination_params()],
  459. responses: %{
  460. 200 => Operation.response("Accounts", "application/json", array_of_muted_accounts())
  461. }
  462. }
  463. end
  464. def blocks_operation do
  465. %Operation{
  466. tags: ["Blocks and mutes"],
  467. summary: "Retrieve list of blocks",
  468. operationId: "AccountController.blocks",
  469. description: "View your blocks. See also accounts/:id/{block,unblock}",
  470. security: [%{"oAuth" => ["read:blocks"]}],
  471. parameters: [with_relationships_param() | pagination_params()],
  472. responses: %{
  473. 200 => Operation.response("Accounts", "application/json", array_of_blocked_accounts())
  474. }
  475. }
  476. end
  477. def lookup_operation do
  478. %Operation{
  479. tags: ["Retrieve account information"],
  480. summary: "Find a user by nickname",
  481. operationId: "AccountController.lookup",
  482. parameters: [
  483. Operation.parameter(
  484. :acct,
  485. :query,
  486. :string,
  487. "User nickname"
  488. )
  489. ],
  490. responses: %{
  491. 200 => Operation.response("Account", "application/json", Account),
  492. 401 => Operation.response("Error", "application/json", ApiError),
  493. 404 => Operation.response("Error", "application/json", ApiError)
  494. }
  495. }
  496. end
  497. def own_endorsements_operation do
  498. %Operation{
  499. tags: ["Retrieve account information"],
  500. summary: "Endorsements",
  501. operationId: "AccountController.own_endorsements",
  502. description: "Returns endorsed accounts",
  503. security: [%{"oAuth" => ["read:accounts"]}],
  504. responses: %{
  505. 200 => Operation.response("Array of Accounts", "application/json", array_of_accounts())
  506. }
  507. }
  508. end
  509. def familiar_followers_operation do
  510. %Operation{
  511. tags: ["Retrieve account information"],
  512. summary: "Followers that you follow",
  513. operationId: "AccountController.familiar_followers",
  514. description:
  515. "Obtain a list of all accounts that follow a given account, filtered for accounts you follow.",
  516. security: [%{"oAuth" => ["read:follows"]}],
  517. parameters: [
  518. Operation.parameter(
  519. :id,
  520. :query,
  521. %Schema{
  522. oneOf: [%Schema{type: :array, items: %Schema{type: :string}}, %Schema{type: :string}]
  523. },
  524. "Account IDs",
  525. example: "123"
  526. )
  527. ],
  528. responses: %{
  529. 200 =>
  530. Operation.response("Accounts", "application/json", %Schema{
  531. title: "ArrayOfAccounts",
  532. type: :array,
  533. items: %Schema{
  534. title: "Account",
  535. type: :object,
  536. properties: %{
  537. id: FlakeID,
  538. accounts: %Schema{
  539. title: "ArrayOfAccounts",
  540. type: :array,
  541. items: Account,
  542. example: [Account.schema().example]
  543. }
  544. }
  545. }
  546. })
  547. }
  548. }
  549. end
  550. defp create_request do
  551. %Schema{
  552. title: "AccountCreateRequest",
  553. description: "POST body for creating an account",
  554. type: :object,
  555. required: [:username, :password, :agreement],
  556. properties: %{
  557. reason: %Schema{
  558. type: :string,
  559. nullable: true,
  560. description:
  561. "Text that will be reviewed by moderators if registrations require manual approval"
  562. },
  563. username: %Schema{type: :string, description: "The desired username for the account"},
  564. email: %Schema{
  565. type: :string,
  566. nullable: true,
  567. description:
  568. "The email address to be used for login. Required when `account_activation_required` is enabled.",
  569. format: :email
  570. },
  571. password: %Schema{
  572. type: :string,
  573. description: "The password to be used for login",
  574. format: :password
  575. },
  576. agreement: %Schema{
  577. allOf: [BooleanLike],
  578. description:
  579. "Whether the user agrees to the local rules, terms, and policies. These should be presented to the user in order to allow them to consent before setting this parameter to TRUE."
  580. },
  581. locale: %Schema{
  582. type: :string,
  583. nullable: true,
  584. description: "The language of the confirmation email that will be sent"
  585. },
  586. # Pleroma-specific properties:
  587. fullname: %Schema{type: :string, nullable: true, description: "Full name"},
  588. bio: %Schema{type: :string, description: "Bio", nullable: true, default: ""},
  589. captcha_solution: %Schema{
  590. type: :string,
  591. nullable: true,
  592. description: "Provider-specific captcha solution"
  593. },
  594. captcha_token: %Schema{
  595. type: :string,
  596. nullable: true,
  597. description: "Provider-specific captcha token"
  598. },
  599. captcha_answer_data: %Schema{
  600. type: :string,
  601. nullable: true,
  602. description: "Provider-specific captcha data"
  603. },
  604. token: %Schema{
  605. type: :string,
  606. nullable: true,
  607. description: "Invite token required when the registrations aren't public"
  608. },
  609. birthday: %Schema{
  610. nullable: true,
  611. description: "User's birthday",
  612. anyOf: [
  613. %Schema{
  614. type: :string,
  615. format: :date
  616. },
  617. %Schema{
  618. type: :string,
  619. maxLength: 0
  620. }
  621. ]
  622. },
  623. language: %Schema{
  624. type: :string,
  625. nullable: true,
  626. description: "User's preferred language for emails"
  627. }
  628. },
  629. example: %{
  630. "username" => "cofe",
  631. "email" => "cofe@example.com",
  632. "password" => "secret",
  633. "agreement" => "true",
  634. "bio" => "☕️"
  635. }
  636. }
  637. end
  638. # Note: this is a token response (if login succeeds!), but there's no oauth operation file yet.
  639. defp create_response do
  640. %Schema{
  641. title: "AccountCreateResponse",
  642. description: "Response schema for an account",
  643. type: :object,
  644. properties: %{
  645. # The response when auto-login on create succeeds (token is issued):
  646. token_type: %Schema{type: :string},
  647. access_token: %Schema{type: :string},
  648. refresh_token: %Schema{type: :string},
  649. scope: %Schema{type: :string},
  650. created_at: %Schema{type: :integer, format: :"date-time"},
  651. me: %Schema{type: :string},
  652. expires_in: %Schema{type: :integer},
  653. #
  654. # The response when registration succeeds but auto-login fails (no token):
  655. identifier: %Schema{type: :string},
  656. message: %Schema{type: :string}
  657. },
  658. # Note: example of successful registration with failed login response:
  659. # example: %{
  660. # "identifier" => "missing_confirmed_email",
  661. # "message" => "You have been registered. Please check your email for further instructions."
  662. # },
  663. example: %{
  664. "token_type" => "Bearer",
  665. "access_token" => "i9hAVVzGld86Pl5JtLtizKoXVvtTlSCJvwaugCxvZzk",
  666. "refresh_token" => "i9hAVVzGld86Pl5JtLtizKoXVvtTlSCJvwaugCxvZzz",
  667. "created_at" => 1_585_918_714,
  668. "expires_in" => 600,
  669. "scope" => "read write follow push",
  670. "me" => "https://gensokyo.2hu/users/raymoo"
  671. }
  672. }
  673. end
  674. defp update_credentials_request do
  675. %Schema{
  676. title: "AccountUpdateCredentialsRequest",
  677. description: "POST body for creating an account",
  678. type: :object,
  679. properties: %{
  680. bot: %Schema{
  681. allOf: [BooleanLike],
  682. nullable: true,
  683. description: "Whether the account has a bot flag."
  684. },
  685. display_name: %Schema{
  686. type: :string,
  687. nullable: true,
  688. description: "The display name to use for the profile."
  689. },
  690. note: %Schema{type: :string, description: "The account bio."},
  691. avatar: %Schema{
  692. type: :string,
  693. nullable: true,
  694. description: "Avatar image encoded using multipart/form-data",
  695. format: :binary
  696. },
  697. header: %Schema{
  698. type: :string,
  699. nullable: true,
  700. description: "Header image encoded using multipart/form-data",
  701. format: :binary
  702. },
  703. locked: %Schema{
  704. allOf: [BooleanLike],
  705. nullable: true,
  706. description: "Whether manual approval of follow requests is required."
  707. },
  708. accepts_chat_messages: %Schema{
  709. allOf: [BooleanLike],
  710. nullable: true,
  711. description: "Whether the user accepts receiving chat messages."
  712. },
  713. fields_attributes: %Schema{
  714. nullable: true,
  715. oneOf: [
  716. %Schema{type: :array, items: attribute_field()},
  717. %Schema{type: :object, additionalProperties: attribute_field()}
  718. ]
  719. },
  720. # NOTE: `source` field is not supported
  721. #
  722. # source: %Schema{
  723. # type: :object,
  724. # properties: %{
  725. # privacy: %Schema{type: :string},
  726. # sensitive: %Schema{type: :boolean},
  727. # language: %Schema{type: :string}
  728. # }
  729. # },
  730. # Pleroma-specific fields
  731. no_rich_text: %Schema{
  732. allOf: [BooleanLike],
  733. nullable: true,
  734. description: "html tags are stripped from all statuses requested from the API"
  735. },
  736. hide_followers: %Schema{
  737. allOf: [BooleanLike],
  738. nullable: true,
  739. description: "user's followers will be hidden"
  740. },
  741. hide_follows: %Schema{
  742. allOf: [BooleanLike],
  743. nullable: true,
  744. description: "user's follows will be hidden"
  745. },
  746. hide_followers_count: %Schema{
  747. allOf: [BooleanLike],
  748. nullable: true,
  749. description: "user's follower count will be hidden"
  750. },
  751. hide_follows_count: %Schema{
  752. allOf: [BooleanLike],
  753. nullable: true,
  754. description: "user's follow count will be hidden"
  755. },
  756. hide_favorites: %Schema{
  757. allOf: [BooleanLike],
  758. nullable: true,
  759. description: "user's favorites timeline will be hidden"
  760. },
  761. show_role: %Schema{
  762. allOf: [BooleanLike],
  763. nullable: true,
  764. description: "user's role (e.g admin, moderator) will be exposed to anyone in the
  765. API"
  766. },
  767. default_scope: VisibilityScope,
  768. pleroma_settings_store: %Schema{
  769. type: :object,
  770. nullable: true,
  771. description: "Opaque user settings to be saved on the backend."
  772. },
  773. skip_thread_containment: %Schema{
  774. allOf: [BooleanLike],
  775. nullable: true,
  776. description: "Skip filtering out broken threads"
  777. },
  778. allow_following_move: %Schema{
  779. allOf: [BooleanLike],
  780. nullable: true,
  781. description: "Allows automatically follow moved following accounts"
  782. },
  783. also_known_as: %Schema{
  784. type: :array,
  785. items: %Schema{type: :string},
  786. nullable: true,
  787. description: "List of alternate ActivityPub IDs"
  788. },
  789. pleroma_background_image: %Schema{
  790. type: :string,
  791. nullable: true,
  792. description: "Sets the background image of the user.",
  793. format: :binary
  794. },
  795. discoverable: %Schema{
  796. allOf: [BooleanLike],
  797. nullable: true,
  798. description:
  799. "Discovery (listing, indexing) of this account by external services (search bots etc.) is allowed."
  800. },
  801. actor_type: ActorType,
  802. birthday: %Schema{
  803. nullable: true,
  804. description: "User's birthday",
  805. anyOf: [
  806. %Schema{
  807. type: :string,
  808. format: :date
  809. },
  810. %Schema{
  811. type: :string,
  812. maxLength: 0
  813. }
  814. ]
  815. },
  816. show_birthday: %Schema{
  817. allOf: [BooleanLike],
  818. nullable: true,
  819. description: "User's birthday will be visible"
  820. },
  821. avatar_description: %Schema{
  822. type: :string,
  823. nullable: true,
  824. description: "Avatar image description."
  825. },
  826. header_description: %Schema{
  827. type: :string,
  828. nullable: true,
  829. description: "Header image description."
  830. }
  831. },
  832. example: %{
  833. bot: false,
  834. display_name: "cofe",
  835. note: "foobar",
  836. fields_attributes: [%{name: "foo", value: "bar"}],
  837. no_rich_text: false,
  838. hide_followers: true,
  839. hide_follows: false,
  840. hide_followers_count: false,
  841. hide_follows_count: false,
  842. hide_favorites: false,
  843. show_role: false,
  844. default_scope: "private",
  845. pleroma_settings_store: %{"pleroma-fe" => %{"key" => "val"}},
  846. skip_thread_containment: false,
  847. allow_following_move: false,
  848. also_known_as: ["https://foo.bar/users/foo"],
  849. discoverable: false,
  850. actor_type: "Person",
  851. show_birthday: false,
  852. birthday: "2001-02-12"
  853. }
  854. }
  855. end
  856. def array_of_accounts do
  857. %Schema{
  858. title: "ArrayOfAccounts",
  859. type: :array,
  860. items: Account,
  861. example: [Account.schema().example]
  862. }
  863. end
  864. def array_of_muted_accounts do
  865. %Schema{
  866. title: "ArrayOfMutedAccounts",
  867. type: :array,
  868. items: %Schema{
  869. title: "MutedAccount",
  870. description: "Response schema for a muted account",
  871. allOf: [
  872. Account,
  873. %Schema{
  874. type: :object,
  875. properties: %{
  876. mute_expires_at: %Schema{type: :string, format: "date-time", nullable: true}
  877. }
  878. }
  879. ]
  880. },
  881. example: [
  882. Account.schema().example
  883. |> Map.put("mute_expires_at", "2025-11-29T16:23:13Z")
  884. ]
  885. }
  886. end
  887. def array_of_blocked_accounts do
  888. %Schema{
  889. title: "ArrayOfBlockedAccounts",
  890. type: :array,
  891. items: %Schema{
  892. title: "BlockedAccount",
  893. description: "Response schema for a blocked account",
  894. allOf: [
  895. Account,
  896. %Schema{
  897. type: :object,
  898. properties: %{
  899. block_expires_at: %Schema{type: :string, format: "date-time", nullable: true}
  900. }
  901. }
  902. ]
  903. },
  904. example: [
  905. Account.schema().example
  906. |> Map.put("block_expires_at", "2025-11-29T16:23:13Z")
  907. ]
  908. }
  909. end
  910. defp array_of_relationships do
  911. %Schema{
  912. title: "ArrayOfRelationships",
  913. description: "Response schema for account relationships",
  914. type: :array,
  915. items: AccountRelationship,
  916. example: [
  917. %{
  918. "id" => "1",
  919. "following" => true,
  920. "showing_reblogs" => true,
  921. "followed_by" => true,
  922. "blocking" => false,
  923. "blocked_by" => true,
  924. "muting" => false,
  925. "muting_notifications" => false,
  926. "note" => "",
  927. "requested" => false,
  928. "domain_blocking" => false,
  929. "subscribing" => false,
  930. "notifying" => false,
  931. "endorsed" => true
  932. },
  933. %{
  934. "id" => "2",
  935. "following" => true,
  936. "showing_reblogs" => true,
  937. "followed_by" => true,
  938. "blocking" => false,
  939. "blocked_by" => true,
  940. "muting" => true,
  941. "muting_notifications" => false,
  942. "note" => "",
  943. "requested" => true,
  944. "domain_blocking" => false,
  945. "subscribing" => false,
  946. "notifying" => false,
  947. "endorsed" => false
  948. },
  949. %{
  950. "id" => "3",
  951. "following" => true,
  952. "showing_reblogs" => true,
  953. "followed_by" => true,
  954. "blocking" => true,
  955. "blocked_by" => false,
  956. "muting" => true,
  957. "muting_notifications" => false,
  958. "note" => "",
  959. "requested" => false,
  960. "domain_blocking" => true,
  961. "subscribing" => true,
  962. "notifying" => true,
  963. "endorsed" => false
  964. }
  965. ]
  966. }
  967. end
  968. defp follow_by_uri_request do
  969. %Schema{
  970. title: "AccountFollowsRequest",
  971. description: "POST body for muting an account",
  972. type: :object,
  973. properties: %{
  974. uri: %Schema{type: :string, nullable: true, format: :uri}
  975. },
  976. required: [:uri]
  977. }
  978. end
  979. defp mute_request do
  980. %Schema{
  981. title: "AccountMuteRequest",
  982. description: "POST body for muting an account",
  983. type: :object,
  984. properties: %{
  985. notifications: %Schema{
  986. allOf: [BooleanLike],
  987. nullable: true,
  988. description: "Mute notifications in addition to statuses? Defaults to true.",
  989. default: true
  990. },
  991. duration: %Schema{
  992. type: :integer,
  993. nullable: true,
  994. description: "Expire the mute in `expires_in` seconds. Default 0 for infinity"
  995. },
  996. expires_in: %Schema{
  997. type: :integer,
  998. nullable: true,
  999. description: "Deprecated, use `duration` instead",
  1000. default: 0
  1001. }
  1002. },
  1003. example: %{
  1004. "notifications" => true,
  1005. "expires_in" => 86_400
  1006. }
  1007. }
  1008. end
  1009. defp note_request do
  1010. %Schema{
  1011. title: "AccountNoteRequest",
  1012. description: "POST body for adding a note for an account",
  1013. type: :object,
  1014. properties: %{
  1015. comment: %Schema{
  1016. type: :string,
  1017. description: "Account note body"
  1018. }
  1019. },
  1020. example: %{
  1021. "comment" => "Example note"
  1022. }
  1023. }
  1024. end
  1025. defp array_of_lists do
  1026. %Schema{
  1027. title: "ArrayOfLists",
  1028. description: "Response schema for lists",
  1029. type: :array,
  1030. items: List,
  1031. example: [
  1032. %{"id" => "123", "title" => "my list"},
  1033. %{"id" => "1337", "title" => "anotehr list"}
  1034. ]
  1035. }
  1036. end
  1037. defp array_of_statuses do
  1038. %Schema{
  1039. title: "ArrayOfStatuses",
  1040. type: :array,
  1041. items: Status
  1042. }
  1043. end
  1044. defp attribute_field do
  1045. %Schema{
  1046. title: "AccountAttributeField",
  1047. description: "Request schema for account custom fields",
  1048. type: :object,
  1049. properties: %{
  1050. name: %Schema{type: :string},
  1051. value: %Schema{type: :string}
  1052. },
  1053. required: [:name, :value],
  1054. example: %{
  1055. "name" => "Website",
  1056. "value" => "https://pleroma.com"
  1057. }
  1058. }
  1059. end
  1060. end