alias OpenApiSpex.Reference
alias OpenApiSpex.Schema
alias Pleroma.Web.ApiSpec.Schemas.Account
- alias Pleroma.Web.ApiSpec.Schemas.ApiError
- alias Pleroma.Web.ApiSpec.Schemas.AccountCreateRequest
- alias Pleroma.Web.ApiSpec.Schemas.AccountCreateResponse
- alias Pleroma.Web.ApiSpec.Schemas.AccountFollowsRequest
- alias Pleroma.Web.ApiSpec.Schemas.AccountMuteRequest
alias Pleroma.Web.ApiSpec.Schemas.AccountRelationship
- alias Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse
- alias Pleroma.Web.ApiSpec.Schemas.AccountsResponse
- alias Pleroma.Web.ApiSpec.Schemas.AccountUpdateCredentialsRequest
+ alias Pleroma.Web.ApiSpec.Schemas.ActorType
+ alias Pleroma.Web.ApiSpec.Schemas.ApiError
alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
- alias Pleroma.Web.ApiSpec.Schemas.ListsResponse
- alias Pleroma.Web.ApiSpec.Schemas.StatusesResponse
+ alias Pleroma.Web.ApiSpec.Schemas.Status
alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
import Pleroma.Web.ApiSpec.Helpers
description:
"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.",
operationId: "AccountController.create",
- requestBody: request_body("Parameters", AccountCreateRequest, required: true),
+ requestBody: request_body("Parameters", create_request(), required: true),
responses: %{
- 200 => Operation.response("Account", "application/json", AccountCreateResponse),
+ 200 => Operation.response("Account", "application/json", create_response()),
400 => Operation.response("Error", "application/json", ApiError),
403 => Operation.response("Error", "application/json", ApiError),
429 => Operation.response("Error", "application/json", ApiError)
description: "Update the user's display and preferences.",
operationId: "AccountController.update_credentials",
security: [%{"oAuth" => ["write:accounts"]}],
- requestBody: request_body("Parameters", AccountUpdateCredentialsRequest, required: true),
+ requestBody: request_body("Parameters", update_creadentials_request(), required: true),
responses: %{
200 => Operation.response("Account", "application/json", Account),
403 => Operation.response("Error", "application/json", ApiError)
)
],
responses: %{
- 200 => Operation.response("Account", "application/json", AccountRelationshipsResponse)
+ 200 => Operation.response("Account", "application/json", array_of_relationships())
}
}
end
)
] ++ pagination_params(),
responses: %{
- 200 => Operation.response("Statuses", "application/json", StatusesResponse),
+ 200 => Operation.response("Statuses", "application/json", array_of_statuses()),
404 => Operation.response("Error", "application/json", ApiError)
}
}
parameters:
[%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++ pagination_params(),
responses: %{
- 200 => Operation.response("Accounts", "application/json", AccountsResponse)
+ 200 => Operation.response("Accounts", "application/json", array_of_accounts())
}
}
end
"Accounts which the given account is following, if network is not hidden by the account owner.",
parameters:
[%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++ pagination_params(),
- responses: %{200 => Operation.response("Accounts", "application/json", AccountsResponse)}
+ responses: %{200 => Operation.response("Accounts", "application/json", array_of_accounts())}
}
end
security: [%{"oAuth" => ["read:lists"]}],
description: "User lists that you have added this account to.",
parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
- responses: %{200 => Operation.response("Lists", "application/json", ListsResponse)}
+ responses: %{200 => Operation.response("Lists", "application/json", array_of_lists())}
}
end
summary: "Mute",
operationId: "AccountController.mute",
security: [%{"oAuth" => ["follow", "write:mutes"]}],
- requestBody: request_body("Parameters", AccountMuteRequest),
+ requestBody: request_body("Parameters", mute_request()),
description:
"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).",
parameters: [
summary: "Follows",
operationId: "AccountController.follows",
security: [%{"oAuth" => ["follow", "write:follows"]}],
- requestBody: request_body("Parameters", AccountFollowsRequest, required: true),
+ requestBody: request_body("Parameters", follows_request(), required: true),
responses: %{
200 => Operation.response("Account", "application/json", AccountRelationship),
400 => Operation.response("Error", "application/json", ApiError),
description: "Accounts the user has muted.",
security: [%{"oAuth" => ["follow", "read:mutes"]}],
responses: %{
- 200 => Operation.response("Accounts", "application/json", AccountsResponse)
+ 200 => Operation.response("Accounts", "application/json", array_of_accounts())
}
}
end
description: "View your blocks. See also accounts/:id/{block,unblock}",
security: [%{"oAuth" => ["read:blocks"]}],
responses: %{
- 200 => Operation.response("Accounts", "application/json", AccountsResponse)
+ 200 => Operation.response("Accounts", "application/json", array_of_accounts())
}
}
end
}
}
end
+
+ defp create_request do
+ %Schema{
+ title: "AccountCreateRequest",
+ description: "POST body for creating an account",
+ type: :object,
+ properties: %{
+ reason: %Schema{
+ type: :string,
+ description:
+ "Text that will be reviewed by moderators if registrations require manual approval"
+ },
+ username: %Schema{type: :string, description: "The desired username for the account"},
+ email: %Schema{
+ type: :string,
+ description:
+ "The email address to be used for login. Required when `account_activation_required` is enabled.",
+ format: :email
+ },
+ password: %Schema{
+ type: :string,
+ description: "The password to be used for login",
+ format: :password
+ },
+ agreement: %Schema{
+ type: :boolean,
+ description:
+ "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."
+ },
+ locale: %Schema{
+ type: :string,
+ description: "The language of the confirmation email that will be sent"
+ },
+ # Pleroma-specific properties:
+ fullname: %Schema{type: :string, description: "Full name"},
+ bio: %Schema{type: :string, description: "Bio", default: ""},
+ captcha_solution: %Schema{
+ type: :string,
+ description: "Provider-specific captcha solution"
+ },
+ captcha_token: %Schema{type: :string, description: "Provider-specific captcha token"},
+ captcha_answer_data: %Schema{type: :string, description: "Provider-specific captcha data"},
+ token: %Schema{
+ type: :string,
+ description: "Invite token required when the registrations aren't public"
+ }
+ },
+ required: [:username, :password, :agreement],
+ example: %{
+ "username" => "cofe",
+ "email" => "cofe@example.com",
+ "password" => "secret",
+ "agreement" => "true",
+ "bio" => "☕️"
+ }
+ }
+ end
+
+ defp create_response do
+ %Schema{
+ title: "AccountCreateResponse",
+ description: "Response schema for an account",
+ type: :object,
+ properties: %{
+ token_type: %Schema{type: :string},
+ access_token: %Schema{type: :string},
+ scope: %Schema{type: :array, items: %Schema{type: :string}},
+ created_at: %Schema{type: :integer, format: :"date-time"}
+ },
+ example: %{
+ "access_token" => "i9hAVVzGld86Pl5JtLtizKoXVvtTlSCJvwaugCxvZzk",
+ "created_at" => 1_585_918_714,
+ "scope" => ["read", "write", "follow", "push"],
+ "token_type" => "Bearer"
+ }
+ }
+ end
+
+ defp update_creadentials_request do
+ %Schema{
+ title: "AccountUpdateCredentialsRequest",
+ description: "POST body for creating an account",
+ type: :object,
+ properties: %{
+ bot: %Schema{
+ type: :boolean,
+ description: "Whether the account has a bot flag."
+ },
+ display_name: %Schema{
+ type: :string,
+ description: "The display name to use for the profile."
+ },
+ note: %Schema{type: :string, description: "The account bio."},
+ avatar: %Schema{
+ type: :string,
+ description: "Avatar image encoded using multipart/form-data",
+ format: :binary
+ },
+ header: %Schema{
+ type: :string,
+ description: "Header image encoded using multipart/form-data",
+ format: :binary
+ },
+ locked: %Schema{
+ type: :boolean,
+ description: "Whether manual approval of follow requests is required."
+ },
+ fields_attributes: %Schema{
+ oneOf: [
+ %Schema{type: :array, items: attribute_field()},
+ %Schema{type: :object, additionalProperties: %Schema{type: attribute_field()}}
+ ]
+ },
+ # NOTE: `source` field is not supported
+ #
+ # source: %Schema{
+ # type: :object,
+ # properties: %{
+ # privacy: %Schema{type: :string},
+ # sensitive: %Schema{type: :boolean},
+ # language: %Schema{type: :string}
+ # }
+ # },
+
+ # Pleroma-specific fields
+ no_rich_text: %Schema{
+ type: :boolean,
+ description: "html tags are stripped from all statuses requested from the API"
+ },
+ hide_followers: %Schema{type: :boolean, description: "user's followers will be hidden"},
+ hide_follows: %Schema{type: :boolean, description: "user's follows will be hidden"},
+ hide_followers_count: %Schema{
+ type: :boolean,
+ description: "user's follower count will be hidden"
+ },
+ hide_follows_count: %Schema{
+ type: :boolean,
+ description: "user's follow count will be hidden"
+ },
+ hide_favorites: %Schema{
+ type: :boolean,
+ description: "user's favorites timeline will be hidden"
+ },
+ show_role: %Schema{
+ type: :boolean,
+ description: "user's role (e.g admin, moderator) will be exposed to anyone in the
+ API"
+ },
+ default_scope: VisibilityScope,
+ pleroma_settings_store: %Schema{
+ type: :object,
+ description: "Opaque user settings to be saved on the backend."
+ },
+ skip_thread_containment: %Schema{
+ type: :boolean,
+ description: "Skip filtering out broken threads"
+ },
+ allow_following_move: %Schema{
+ type: :boolean,
+ description: "Allows automatically follow moved following accounts"
+ },
+ pleroma_background_image: %Schema{
+ type: :string,
+ description: "Sets the background image of the user.",
+ format: :binary
+ },
+ discoverable: %Schema{
+ type: :boolean,
+ description:
+ "Discovery of this account in search results and other services is allowed."
+ },
+ actor_type: ActorType
+ },
+ example: %{
+ bot: false,
+ display_name: "cofe",
+ note: "foobar",
+ fields_attributes: [%{name: "foo", value: "bar"}],
+ no_rich_text: false,
+ hide_followers: true,
+ hide_follows: false,
+ hide_followers_count: false,
+ hide_follows_count: false,
+ hide_favorites: false,
+ show_role: false,
+ default_scope: "private",
+ pleroma_settings_store: %{"pleroma-fe" => %{"key" => "val"}},
+ skip_thread_containment: false,
+ allow_following_move: false,
+ discoverable: false,
+ actor_type: "Person"
+ }
+ }
+ end
+
+ defp array_of_accounts do
+ %Schema{
+ title: "ArrayOfAccounts",
+ type: :array,
+ items: Account
+ }
+ end
+
+ defp array_of_relationships do
+ %Schema{
+ title: "ArrayOfRelationships",
+ description: "Response schema for account relationships",
+ type: :array,
+ items: AccountRelationship,
+ example: [
+ %{
+ "id" => "1",
+ "following" => true,
+ "showing_reblogs" => true,
+ "followed_by" => true,
+ "blocking" => false,
+ "blocked_by" => true,
+ "muting" => false,
+ "muting_notifications" => false,
+ "requested" => false,
+ "domain_blocking" => false,
+ "subscribing" => false,
+ "endorsed" => true
+ },
+ %{
+ "id" => "2",
+ "following" => true,
+ "showing_reblogs" => true,
+ "followed_by" => true,
+ "blocking" => false,
+ "blocked_by" => true,
+ "muting" => true,
+ "muting_notifications" => false,
+ "requested" => true,
+ "domain_blocking" => false,
+ "subscribing" => false,
+ "endorsed" => false
+ },
+ %{
+ "id" => "3",
+ "following" => true,
+ "showing_reblogs" => true,
+ "followed_by" => true,
+ "blocking" => true,
+ "blocked_by" => false,
+ "muting" => true,
+ "muting_notifications" => false,
+ "requested" => false,
+ "domain_blocking" => true,
+ "subscribing" => true,
+ "endorsed" => false
+ }
+ ]
+ }
+ end
+
+ defp follows_request do
+ %Schema{
+ title: "AccountFollowsRequest",
+ description: "POST body for muting an account",
+ type: :object,
+ properties: %{
+ uri: %Schema{type: :string, format: :uri}
+ },
+ required: [:uri]
+ }
+ end
+
+ defp mute_request do
+ %Schema{
+ title: "AccountMuteRequest",
+ description: "POST body for muting an account",
+ type: :object,
+ properties: %{
+ notifications: %Schema{
+ type: :boolean,
+ description: "Mute notifications in addition to statuses? Defaults to true.",
+ default: true
+ }
+ },
+ example: %{
+ "notifications" => true
+ }
+ }
+ end
+
+ defp list do
+ %Schema{
+ title: "List",
+ description: "Response schema for a list",
+ type: :object,
+ properties: %{
+ id: %Schema{type: :string},
+ title: %Schema{type: :string}
+ },
+ example: %{
+ "id" => "123",
+ "title" => "my list"
+ }
+ }
+ end
+
+ defp array_of_lists do
+ %Schema{
+ title: "ArrayOfLists",
+ description: "Response schema for lists",
+ type: :array,
+ items: list(),
+ example: [
+ %{"id" => "123", "title" => "my list"},
+ %{"id" => "1337", "title" => "anotehr list"}
+ ]
+ }
+ end
+
+ defp array_of_statuses do
+ %Schema{
+ title: "ArrayOfStatuses",
+ type: :array,
+ items: Status
+ }
+ end
+
+ defp attribute_field do
+ %Schema{
+ title: "AccountAttributeField",
+ description: "Request schema for account custom fields",
+ type: :object,
+ properties: %{
+ name: %Schema{type: :string},
+ value: %Schema{type: :string}
+ },
+ required: [:name, :value],
+ example: %{
+ "name" => "Website",
+ "value" => "https://pleroma.com"
+ }
+ }
+ end
end
defmodule Pleroma.Web.ApiSpec.CustomEmojiOperation do
alias OpenApiSpex.Operation
alias OpenApiSpex.Schema
- alias Pleroma.Web.ApiSpec.Schemas.CustomEmoji
+ alias Pleroma.Web.ApiSpec.Schemas.Emoji
def open_api_operation(action) do
operation = String.to_existing_atom("#{action}_operation")
description: "Returns custom emojis that are available on the server.",
operationId: "CustomEmojiController.index",
responses: %{
- 200 => Operation.response("Custom Emojis", "application/json", custom_emojis_resposnse())
+ 200 => Operation.response("Custom Emojis", "application/json", resposnse())
}
}
end
- defp custom_emojis_resposnse do
+ defp resposnse do
%Schema{
title: "CustomEmojisResponse",
description: "Response schema for custom emojis",
type: :array,
- items: CustomEmoji,
+ items: custom_emoji(),
example: [
%{
"category" => "Fun",
]
}
end
+
+ defp custom_emoji do
+ %Schema{
+ title: "CustomEmoji",
+ description: "Schema for a CustomEmoji",
+ allOf: [
+ Emoji,
+ %Schema{
+ type: :object,
+ properties: %{
+ category: %Schema{type: :string},
+ tags: %Schema{type: :array}
+ }
+ }
+ ],
+ example: %{
+ "category" => "Fun",
+ "shortcode" => "aaaa",
+ "url" =>
+ "https://files.mastodon.social/custom_emojis/images/000/007/118/original/aaaa.png",
+ "static_url" =>
+ "https://files.mastodon.social/custom_emojis/images/000/007/118/static/aaaa.png",
+ "visible_in_picker" => true,
+ "tags" => ["Gif", "Fun"]
+ }
+ }
+ end
end
defmodule Pleroma.Web.ApiSpec.Schemas.Account do
alias OpenApiSpex.Schema
- alias Pleroma.Web.ApiSpec.Schemas.AccountEmoji
alias Pleroma.Web.ApiSpec.Schemas.AccountField
alias Pleroma.Web.ApiSpec.Schemas.AccountRelationship
alias Pleroma.Web.ApiSpec.Schemas.ActorType
+ alias Pleroma.Web.ApiSpec.Schemas.Emoji
alias Pleroma.Web.ApiSpec.Schemas.FlakeID
alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
bot: %Schema{type: :boolean},
created_at: %Schema{type: :string, format: "date-time"},
display_name: %Schema{type: :string},
- emojis: %Schema{type: :array, items: AccountEmoji},
+ emojis: %Schema{type: :array, items: Emoji},
fields: %Schema{type: :array, items: AccountField},
follow_requests_count: %Schema{type: :integer},
followers_count: %Schema{type: :integer},
+++ /dev/null
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.ApiSpec.Schemas.AccountCreateRequest do
- alias OpenApiSpex.Schema
- require OpenApiSpex
-
- OpenApiSpex.schema(%{
- title: "AccountCreateRequest",
- description: "POST body for creating an account",
- type: :object,
- properties: %{
- reason: %Schema{
- type: :string,
- description:
- "Text that will be reviewed by moderators if registrations require manual approval"
- },
- username: %Schema{type: :string, description: "The desired username for the account"},
- email: %Schema{
- type: :string,
- description:
- "The email address to be used for login. Required when `account_activation_required` is enabled.",
- format: :email
- },
- password: %Schema{
- type: :string,
- description: "The password to be used for login",
- format: :password
- },
- agreement: %Schema{
- type: :boolean,
- description:
- "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."
- },
- locale: %Schema{
- type: :string,
- description: "The language of the confirmation email that will be sent"
- },
- # Pleroma-specific properties:
- fullname: %Schema{type: :string, description: "Full name"},
- bio: %Schema{type: :string, description: "Bio", default: ""},
- captcha_solution: %Schema{type: :string, description: "Provider-specific captcha solution"},
- captcha_token: %Schema{type: :string, description: "Provider-specific captcha token"},
- captcha_answer_data: %Schema{type: :string, description: "Provider-specific captcha data"},
- token: %Schema{
- type: :string,
- description: "Invite token required when the registrations aren't public"
- }
- },
- required: [:username, :password, :agreement],
- example: %{
- "username" => "cofe",
- "email" => "cofe@example.com",
- "password" => "secret",
- "agreement" => "true",
- "bio" => "☕️"
- }
- })
-end
+++ /dev/null
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.ApiSpec.Schemas.AccountCreateResponse do
- alias OpenApiSpex.Schema
-
- require OpenApiSpex
-
- OpenApiSpex.schema(%{
- title: "AccountCreateResponse",
- description: "Response schema for an account",
- type: :object,
- properties: %{
- token_type: %Schema{type: :string},
- access_token: %Schema{type: :string},
- scope: %Schema{type: :array, items: %Schema{type: :string}},
- created_at: %Schema{type: :integer, format: :"date-time"}
- },
- example: %{
- "access_token" => "i9hAVVzGld86Pl5JtLtizKoXVvtTlSCJvwaugCxvZzk",
- "created_at" => 1_585_918_714,
- "scope" => ["read", "write", "follow", "push"],
- "token_type" => "Bearer"
- }
- })
-end
+++ /dev/null
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.ApiSpec.Schemas.AccountAttributeField do
- alias OpenApiSpex.Schema
-
- require OpenApiSpex
-
- OpenApiSpex.schema(%{
- title: "AccountAttributeField",
- description: "Request schema for account custom fields",
- type: :object,
- properties: %{
- name: %Schema{type: :string},
- value: %Schema{type: :string}
- },
- required: [:name, :value],
- example: %{
- "name" => "Website",
- "value" => "https://pleroma.com"
- }
- })
-end
+++ /dev/null
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.ApiSpec.Schemas.AccountFollowsRequest do
- alias OpenApiSpex.Schema
- require OpenApiSpex
-
- OpenApiSpex.schema(%{
- title: "AccountFollowsRequest",
- description: "POST body for muting an account",
- type: :object,
- properties: %{
- uri: %Schema{type: :string, format: :uri}
- },
- required: [:uri]
- })
-end
+++ /dev/null
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.ApiSpec.Schemas.AccountMuteRequest do
- alias OpenApiSpex.Schema
- require OpenApiSpex
-
- OpenApiSpex.schema(%{
- title: "AccountMuteRequest",
- description: "POST body for muting an account",
- type: :object,
- properties: %{
- notifications: %Schema{
- type: :boolean,
- description: "Mute notifications in addition to statuses? Defaults to true.",
- default: true
- }
- },
- example: %{
- "notifications" => true
- }
- })
-end
+++ /dev/null
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse do
- require OpenApiSpex
-
- OpenApiSpex.schema(%{
- title: "AccountRelationshipsResponse",
- description: "Response schema for account relationships",
- type: :array,
- items: Pleroma.Web.ApiSpec.Schemas.AccountRelationship,
- example: [
- %{
- "id" => "1",
- "following" => true,
- "showing_reblogs" => true,
- "followed_by" => true,
- "blocking" => false,
- "blocked_by" => true,
- "muting" => false,
- "muting_notifications" => false,
- "requested" => false,
- "domain_blocking" => false,
- "subscribing" => false,
- "endorsed" => true
- },
- %{
- "id" => "2",
- "following" => true,
- "showing_reblogs" => true,
- "followed_by" => true,
- "blocking" => false,
- "blocked_by" => true,
- "muting" => true,
- "muting_notifications" => false,
- "requested" => true,
- "domain_blocking" => false,
- "subscribing" => false,
- "endorsed" => false
- },
- %{
- "id" => "3",
- "following" => true,
- "showing_reblogs" => true,
- "followed_by" => true,
- "blocking" => true,
- "blocked_by" => false,
- "muting" => true,
- "muting_notifications" => false,
- "requested" => false,
- "domain_blocking" => true,
- "subscribing" => true,
- "endorsed" => false
- }
- ]
- })
-end
+++ /dev/null
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.ApiSpec.Schemas.AccountUpdateCredentialsRequest do
- alias OpenApiSpex.Schema
- alias Pleroma.Web.ApiSpec.Schemas.AccountAttributeField
- alias Pleroma.Web.ApiSpec.Schemas.ActorType
- alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
- require OpenApiSpex
-
- OpenApiSpex.schema(%{
- title: "AccountUpdateCredentialsRequest",
- description: "POST body for creating an account",
- type: :object,
- properties: %{
- bot: %Schema{
- type: :boolean,
- description: "Whether the account has a bot flag."
- },
- display_name: %Schema{
- type: :string,
- description: "The display name to use for the profile."
- },
- note: %Schema{type: :string, description: "The account bio."},
- avatar: %Schema{
- type: :string,
- description: "Avatar image encoded using multipart/form-data",
- format: :binary
- },
- header: %Schema{
- type: :string,
- description: "Header image encoded using multipart/form-data",
- format: :binary
- },
- locked: %Schema{
- type: :boolean,
- description: "Whether manual approval of follow requests is required."
- },
- fields_attributes: %Schema{
- oneOf: [
- %Schema{type: :array, items: AccountAttributeField},
- %Schema{type: :object, additionalProperties: %Schema{type: AccountAttributeField}}
- ]
- },
- # NOTE: `source` field is not supported
- #
- # source: %Schema{
- # type: :object,
- # properties: %{
- # privacy: %Schema{type: :string},
- # sensitive: %Schema{type: :boolean},
- # language: %Schema{type: :string}
- # }
- # },
-
- # Pleroma-specific fields
- no_rich_text: %Schema{
- type: :boolean,
- description: "html tags are stripped from all statuses requested from the API"
- },
- hide_followers: %Schema{type: :boolean, description: "user's followers will be hidden"},
- hide_follows: %Schema{type: :boolean, description: "user's follows will be hidden"},
- hide_followers_count: %Schema{
- type: :boolean,
- description: "user's follower count will be hidden"
- },
- hide_follows_count: %Schema{
- type: :boolean,
- description: "user's follow count will be hidden"
- },
- hide_favorites: %Schema{
- type: :boolean,
- description: "user's favorites timeline will be hidden"
- },
- show_role: %Schema{
- type: :boolean,
- description: "user's role (e.g admin, moderator) will be exposed to anyone in the
- API"
- },
- default_scope: VisibilityScope,
- pleroma_settings_store: %Schema{
- type: :object,
- description: "Opaque user settings to be saved on the backend."
- },
- skip_thread_containment: %Schema{
- type: :boolean,
- description: "Skip filtering out broken threads"
- },
- allow_following_move: %Schema{
- type: :boolean,
- description: "Allows automatically follow moved following accounts"
- },
- pleroma_background_image: %Schema{
- type: :string,
- description: "Sets the background image of the user.",
- format: :binary
- },
- discoverable: %Schema{
- type: :boolean,
- description: "Discovery of this account in search results and other services is allowed."
- },
- actor_type: ActorType
- },
- example: %{
- bot: false,
- display_name: "cofe",
- note: "foobar",
- fields_attributes: [%{name: "foo", value: "bar"}],
- no_rich_text: false,
- hide_followers: true,
- hide_follows: false,
- hide_followers_count: false,
- hide_follows_count: false,
- hide_favorites: false,
- show_role: false,
- default_scope: "private",
- pleroma_settings_store: %{"pleroma-fe" => %{"key" => "val"}},
- skip_thread_containment: false,
- allow_following_move: false,
- discoverable: false,
- actor_type: "Person"
- }
- })
-end
+++ /dev/null
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.ApiSpec.Schemas.AccountsResponse do
- require OpenApiSpex
-
- OpenApiSpex.schema(%{
- title: "AccountsResponse",
- type: :array,
- items: Pleroma.Web.ApiSpec.Schemas.Account
- })
-end
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Web.ApiSpec.Schemas.List do
+defmodule Pleroma.Web.ApiSpec.Schemas.ApiError do
alias OpenApiSpex.Schema
require OpenApiSpex
OpenApiSpex.schema(%{
- title: "List",
- description: "Response schema for a list",
+ title: "ApiError",
+ description: "Response schema for API error",
type: :object,
- properties: %{
- id: %Schema{type: :string},
- title: %Schema{type: :string}
- },
+ properties: %{error: %Schema{type: :string}},
example: %{
- "id" => "123",
- "title" => "my list"
+ "error" => "Something went wrong"
}
})
end
+++ /dev/null
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.ApiSpec.Schemas.CustomEmoji do
- alias OpenApiSpex.Schema
-
- require OpenApiSpex
-
- OpenApiSpex.schema(%{
- title: "CustomEmoji",
- description: "Response schema for an CustomEmoji",
- type: :object,
- properties: %{
- shortcode: %Schema{type: :string},
- url: %Schema{type: :string},
- static_url: %Schema{type: :string},
- visible_in_picker: %Schema{type: :boolean},
- category: %Schema{type: :string},
- tags: %Schema{type: :array}
- },
- example: %{
- "shortcode" => "aaaa",
- "url" => "https://files.mastodon.social/custom_emojis/images/000/007/118/original/aaaa.png",
- "static_url" =>
- "https://files.mastodon.social/custom_emojis/images/000/007/118/static/aaaa.png",
- "visible_in_picker" => true
- }
- })
-end
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Web.ApiSpec.Schemas.AccountEmoji do
+defmodule Pleroma.Web.ApiSpec.Schemas.Emoji do
alias OpenApiSpex.Schema
require OpenApiSpex
OpenApiSpex.schema(%{
- title: "AccountEmoji",
- description: "Response schema for account custom fields",
+ title: "Emoji",
+ description: "Response schema for an emoji",
type: :object,
properties: %{
shortcode: %Schema{type: :string},
+++ /dev/null
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.ApiSpec.Schemas.ListsResponse do
- alias Pleroma.Web.ApiSpec.Schemas.List
-
- require OpenApiSpex
-
- OpenApiSpex.schema(%{
- title: "ListsResponse",
- description: "Response schema for lists",
- type: :array,
- items: List
- })
-end
defmodule Pleroma.Web.ApiSpec.Schemas.Poll do
alias OpenApiSpex.Schema
- alias Pleroma.Web.ApiSpec.Schemas.AccountEmoji
+ alias Pleroma.Web.ApiSpec.Schemas.Emoji
alias Pleroma.Web.ApiSpec.Schemas.FlakeID
require OpenApiSpex
multiple: %Schema{type: :boolean},
votes_count: %Schema{type: :integer},
voted: %Schema{type: :boolean},
- emojis: %Schema{type: :array, items: AccountEmoji},
+ emojis: %Schema{type: :array, items: Emoji},
options: %Schema{
type: :array,
items: %Schema{
defmodule Pleroma.Web.ApiSpec.Schemas.Status do
alias OpenApiSpex.Schema
alias Pleroma.Web.ApiSpec.Schemas.Account
- alias Pleroma.Web.ApiSpec.Schemas.AccountEmoji
+ alias Pleroma.Web.ApiSpec.Schemas.Emoji
alias Pleroma.Web.ApiSpec.Schemas.FlakeID
alias Pleroma.Web.ApiSpec.Schemas.Poll
alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
},
content: %Schema{type: :string, format: :html},
created_at: %Schema{type: :string, format: "date-time"},
- emojis: %Schema{type: :array, items: AccountEmoji},
+ emojis: %Schema{type: :array, items: Emoji},
favourited: %Schema{type: :boolean},
favourites_count: %Schema{type: :integer},
id: FlakeID,
+++ /dev/null
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.ApiSpec.Schemas.StatusesResponse do
- require OpenApiSpex
-
- OpenApiSpex.schema(%{
- title: "StatusesResponse",
- type: :array,
- items: Pleroma.Web.ApiSpec.Schemas.Status
- })
-end
:fullname
])
|> Map.put(:nickname, params.username)
- |> Map.put(:fullname, params.fullname || params.username)
- |> Map.put(:bio, params.bio || "")
+ |> Map.put(:fullname, Map.get(params, :fullname, params.username))
|> Map.put(:confirm, params.password)
|> Map.put(:trusted_app, app.trusted)
params =
params
- |> Map.from_struct()
|> Enum.filter(fn {_, value} -> not is_nil(value) end)
|> Enum.into(%{})
Enum.map(fields, fn {_, v} -> v end)
else
Enum.map(fields, fn
- %Pleroma.Web.ApiSpec.Schemas.AccountAttributeField{} = field ->
- %{"name" => field.name, "value" => field.value}
-
- field ->
- field
+ %{} = field -> %{"name" => field.name, "value" => field.value}
+ field -> field
end)
end
end
+++ /dev/null
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.ApiSpec.AccountOperationTest do
- use Pleroma.Web.ConnCase
-
- alias Pleroma.Web.ApiSpec
- alias Pleroma.Web.ApiSpec.Schemas.Account
- alias Pleroma.Web.ApiSpec.Schemas.AccountCreateRequest
- alias Pleroma.Web.ApiSpec.Schemas.AccountCreateResponse
- alias Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse
- alias Pleroma.Web.ApiSpec.Schemas.AccountUpdateCredentialsRequest
-
- import OpenApiSpex.TestAssertions
- import Pleroma.Factory
-
- test "Account example matches schema" do
- api_spec = ApiSpec.spec()
- schema = Account.schema()
- assert_schema(schema.example, "Account", api_spec)
- end
-
- test "AccountCreateRequest example matches schema" do
- api_spec = ApiSpec.spec()
- schema = AccountCreateRequest.schema()
- assert_schema(schema.example, "AccountCreateRequest", api_spec)
- end
-
- test "AccountCreateResponse example matches schema" do
- api_spec = ApiSpec.spec()
- schema = AccountCreateResponse.schema()
- assert_schema(schema.example, "AccountCreateResponse", api_spec)
- end
-
- test "AccountUpdateCredentialsRequest example matches schema" do
- api_spec = ApiSpec.spec()
- schema = AccountUpdateCredentialsRequest.schema()
- assert_schema(schema.example, "AccountUpdateCredentialsRequest", api_spec)
- end
-
- test "AccountController produces a AccountCreateResponse", %{conn: conn} do
- api_spec = ApiSpec.spec()
- app_token = insert(:oauth_token, user: nil)
-
- json =
- conn
- |> put_req_header("authorization", "Bearer " <> app_token.token)
- |> put_req_header("content-type", "application/json")
- |> post(
- "/api/v1/accounts",
- %{
- username: "foo",
- email: "bar@example.org",
- password: "qwerty",
- agreement: true
- }
- )
- |> json_response(200)
-
- assert_schema(json, "AccountCreateResponse", api_spec)
- end
-
- test "AccountUpdateCredentialsRequest produces an Account", %{conn: conn} do
- api_spec = ApiSpec.spec()
- token = insert(:oauth_token, scopes: ["read", "write"])
-
- json =
- conn
- |> put_req_header("authorization", "Bearer " <> token.token)
- |> put_req_header("content-type", "application/json")
- |> patch(
- "/api/v1/accounts/update_credentials",
- %{
- hide_followers_count: "true",
- hide_follows_count: "true",
- skip_thread_containment: "true",
- hide_follows: "true",
- pleroma_settings_store: %{"pleroma-fe" => %{"key" => "val"}},
- note: "foobar",
- fields_attributes: [%{name: "foo", value: "bar"}]
- }
- )
- |> json_response(200)
-
- assert_schema(json, "Account", api_spec)
- end
-
- test "AccountRelationshipsResponse example matches schema" do
- api_spec = ApiSpec.spec()
- schema = AccountRelationshipsResponse.schema()
- assert_schema(schema.example, "AccountRelationshipsResponse", api_spec)
- end
-
- test "/api/v1/accounts/relationships produces AccountRelationshipsResponse", %{
- conn: conn
- } do
- token = insert(:oauth_token, scopes: ["read", "write"])
- other_user = insert(:user)
- {:ok, _user} = Pleroma.User.follow(token.user, other_user)
- api_spec = ApiSpec.spec()
-
- assert [relationship] =
- conn
- |> put_req_header("authorization", "Bearer " <> token.token)
- |> get("/api/v1/accounts/relationships?id=#{other_user.id}")
- |> json_response(:ok)
-
- assert_schema([relationship], "AccountRelationshipsResponse", api_spec)
- end
-
- test "/api/v1/accounts/:id produces Account", %{
- conn: conn
- } do
- user = insert(:user)
- api_spec = ApiSpec.spec()
-
- assert resp =
- conn
- |> get("/api/v1/accounts/#{user.id}")
- |> json_response(:ok)
-
- assert_schema(resp, "Account", api_spec)
- end
-
- test "/api/v1/accounts/:id/statuses produces StatusesResponse", %{
- conn: conn
- } do
- user = insert(:user)
- Pleroma.Web.CommonAPI.post(user, %{"status" => "foobar"})
-
- api_spec = ApiSpec.spec()
-
- assert resp =
- conn
- |> get("/api/v1/accounts/#{user.id}/statuses")
- |> json_response(:ok)
-
- assert_schema(resp, "StatusesResponse", api_spec)
- end
-end
defmodule Pleroma.Web.MastodonAPI.CustomEmojiControllerTest do
use Pleroma.Web.ConnCase, async: true
- alias Pleroma.Web.ApiSpec
- import OpenApiSpex.TestAssertions
test "with tags", %{conn: conn} do
assert resp =
assert Map.has_key?(emoji, "category")
assert Map.has_key?(emoji, "url")
assert Map.has_key?(emoji, "visible_in_picker")
- assert_schema(emoji, "CustomEmoji", ApiSpec.spec())
end
end