logo

pleroma

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

account_operation.ex (33881B)


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