logo

pleroma

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

account_operation.ex (32583B)


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