Move single used schemas to operation schema
This commit is contained in:
parent
2efc00b3cf
commit
dda65f7799
@ -7,18 +7,11 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||||||
alias OpenApiSpex.Reference
|
alias OpenApiSpex.Reference
|
||||||
alias OpenApiSpex.Schema
|
alias OpenApiSpex.Schema
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.Account
|
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.AccountRelationship
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse
|
alias Pleroma.Web.ApiSpec.Schemas.ActorType
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.AccountsResponse
|
alias Pleroma.Web.ApiSpec.Schemas.ApiError
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.AccountUpdateCredentialsRequest
|
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
|
alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.ListsResponse
|
alias Pleroma.Web.ApiSpec.Schemas.Status
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.StatusesResponse
|
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
|
alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
|
||||||
|
|
||||||
import Pleroma.Web.ApiSpec.Helpers
|
import Pleroma.Web.ApiSpec.Helpers
|
||||||
@ -37,9 +30,9 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||||||
description:
|
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.",
|
"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",
|
operationId: "AccountController.create",
|
||||||
requestBody: request_body("Parameters", AccountCreateRequest, required: true),
|
requestBody: request_body("Parameters", create_request(), required: true),
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Account", "application/json", AccountCreateResponse),
|
200 => Operation.response("Account", "application/json", create_response()),
|
||||||
400 => Operation.response("Error", "application/json", ApiError),
|
400 => Operation.response("Error", "application/json", ApiError),
|
||||||
403 => Operation.response("Error", "application/json", ApiError),
|
403 => Operation.response("Error", "application/json", ApiError),
|
||||||
429 => Operation.response("Error", "application/json", ApiError)
|
429 => Operation.response("Error", "application/json", ApiError)
|
||||||
@ -67,7 +60,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||||||
description: "Update the user's display and preferences.",
|
description: "Update the user's display and preferences.",
|
||||||
operationId: "AccountController.update_credentials",
|
operationId: "AccountController.update_credentials",
|
||||||
security: [%{"oAuth" => ["write:accounts"]}],
|
security: [%{"oAuth" => ["write:accounts"]}],
|
||||||
requestBody: request_body("Parameters", AccountUpdateCredentialsRequest, required: true),
|
requestBody: request_body("Parameters", update_creadentials_request(), required: true),
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Account", "application/json", Account),
|
200 => Operation.response("Account", "application/json", Account),
|
||||||
403 => Operation.response("Error", "application/json", ApiError)
|
403 => Operation.response("Error", "application/json", ApiError)
|
||||||
@ -94,7 +87,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Account", "application/json", AccountRelationshipsResponse)
|
200 => Operation.response("Account", "application/json", array_of_relationships())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@ -146,7 +139,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||||||
)
|
)
|
||||||
] ++ pagination_params(),
|
] ++ pagination_params(),
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Statuses", "application/json", StatusesResponse),
|
200 => Operation.response("Statuses", "application/json", array_of_statuses()),
|
||||||
404 => Operation.response("Error", "application/json", ApiError)
|
404 => Operation.response("Error", "application/json", ApiError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,7 +156,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||||||
parameters:
|
parameters:
|
||||||
[%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++ pagination_params(),
|
[%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++ pagination_params(),
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Accounts", "application/json", AccountsResponse)
|
200 => Operation.response("Accounts", "application/json", array_of_accounts())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@ -178,7 +171,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||||||
"Accounts which the given account is following, if network is not hidden by the account owner.",
|
"Accounts which the given account is following, if network is not hidden by the account owner.",
|
||||||
parameters:
|
parameters:
|
||||||
[%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++ pagination_params(),
|
[%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
|
end
|
||||||
|
|
||||||
@ -190,7 +183,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||||||
security: [%{"oAuth" => ["read:lists"]}],
|
security: [%{"oAuth" => ["read:lists"]}],
|
||||||
description: "User lists that you have added this account to.",
|
description: "User lists that you have added this account to.",
|
||||||
parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
|
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
|
end
|
||||||
|
|
||||||
@ -240,7 +233,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||||||
summary: "Mute",
|
summary: "Mute",
|
||||||
operationId: "AccountController.mute",
|
operationId: "AccountController.mute",
|
||||||
security: [%{"oAuth" => ["follow", "write:mutes"]}],
|
security: [%{"oAuth" => ["follow", "write:mutes"]}],
|
||||||
requestBody: request_body("Parameters", AccountMuteRequest),
|
requestBody: request_body("Parameters", mute_request()),
|
||||||
description:
|
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).",
|
"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: [
|
parameters: [
|
||||||
@ -307,7 +300,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||||||
summary: "Follows",
|
summary: "Follows",
|
||||||
operationId: "AccountController.follows",
|
operationId: "AccountController.follows",
|
||||||
security: [%{"oAuth" => ["follow", "write:follows"]}],
|
security: [%{"oAuth" => ["follow", "write:follows"]}],
|
||||||
requestBody: request_body("Parameters", AccountFollowsRequest, required: true),
|
requestBody: request_body("Parameters", follows_request(), required: true),
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Account", "application/json", AccountRelationship),
|
200 => Operation.response("Account", "application/json", AccountRelationship),
|
||||||
400 => Operation.response("Error", "application/json", ApiError),
|
400 => Operation.response("Error", "application/json", ApiError),
|
||||||
@ -324,7 +317,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||||||
description: "Accounts the user has muted.",
|
description: "Accounts the user has muted.",
|
||||||
security: [%{"oAuth" => ["follow", "read:mutes"]}],
|
security: [%{"oAuth" => ["follow", "read:mutes"]}],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Accounts", "application/json", AccountsResponse)
|
200 => Operation.response("Accounts", "application/json", array_of_accounts())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@ -337,7 +330,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||||||
description: "View your blocks. See also accounts/:id/{block,unblock}",
|
description: "View your blocks. See also accounts/:id/{block,unblock}",
|
||||||
security: [%{"oAuth" => ["read:blocks"]}],
|
security: [%{"oAuth" => ["read:blocks"]}],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Accounts", "application/json", AccountsResponse)
|
200 => Operation.response("Accounts", "application/json", array_of_accounts())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@ -366,4 +359,343 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
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
|
end
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
defmodule Pleroma.Web.ApiSpec.CustomEmojiOperation do
|
defmodule Pleroma.Web.ApiSpec.CustomEmojiOperation do
|
||||||
alias OpenApiSpex.Operation
|
alias OpenApiSpex.Operation
|
||||||
alias OpenApiSpex.Schema
|
alias OpenApiSpex.Schema
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.CustomEmoji
|
alias Pleroma.Web.ApiSpec.Schemas.Emoji
|
||||||
|
|
||||||
def open_api_operation(action) do
|
def open_api_operation(action) do
|
||||||
operation = String.to_existing_atom("#{action}_operation")
|
operation = String.to_existing_atom("#{action}_operation")
|
||||||
@ -19,17 +19,17 @@ defmodule Pleroma.Web.ApiSpec.CustomEmojiOperation do
|
|||||||
description: "Returns custom emojis that are available on the server.",
|
description: "Returns custom emojis that are available on the server.",
|
||||||
operationId: "CustomEmojiController.index",
|
operationId: "CustomEmojiController.index",
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Custom Emojis", "application/json", custom_emojis_resposnse())
|
200 => Operation.response("Custom Emojis", "application/json", resposnse())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp custom_emojis_resposnse do
|
defp resposnse do
|
||||||
%Schema{
|
%Schema{
|
||||||
title: "CustomEmojisResponse",
|
title: "CustomEmojisResponse",
|
||||||
description: "Response schema for custom emojis",
|
description: "Response schema for custom emojis",
|
||||||
type: :array,
|
type: :array,
|
||||||
items: CustomEmoji,
|
items: custom_emoji(),
|
||||||
example: [
|
example: [
|
||||||
%{
|
%{
|
||||||
"category" => "Fun",
|
"category" => "Fun",
|
||||||
@ -58,4 +58,31 @@ defmodule Pleroma.Web.ApiSpec.CustomEmojiOperation do
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
end
|
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
|
end
|
||||||
|
@ -4,10 +4,10 @@
|
|||||||
|
|
||||||
defmodule Pleroma.Web.ApiSpec.Schemas.Account do
|
defmodule Pleroma.Web.ApiSpec.Schemas.Account do
|
||||||
alias OpenApiSpex.Schema
|
alias OpenApiSpex.Schema
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.AccountEmoji
|
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.AccountField
|
alias Pleroma.Web.ApiSpec.Schemas.AccountField
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.AccountRelationship
|
alias Pleroma.Web.ApiSpec.Schemas.AccountRelationship
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.ActorType
|
alias Pleroma.Web.ApiSpec.Schemas.ActorType
|
||||||
|
alias Pleroma.Web.ApiSpec.Schemas.Emoji
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.FlakeID
|
alias Pleroma.Web.ApiSpec.Schemas.FlakeID
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
|
alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
|
|||||||
bot: %Schema{type: :boolean},
|
bot: %Schema{type: :boolean},
|
||||||
created_at: %Schema{type: :string, format: "date-time"},
|
created_at: %Schema{type: :string, format: "date-time"},
|
||||||
display_name: %Schema{type: :string},
|
display_name: %Schema{type: :string},
|
||||||
emojis: %Schema{type: :array, items: AccountEmoji},
|
emojis: %Schema{type: :array, items: Emoji},
|
||||||
fields: %Schema{type: :array, items: AccountField},
|
fields: %Schema{type: :array, items: AccountField},
|
||||||
follow_requests_count: %Schema{type: :integer},
|
follow_requests_count: %Schema{type: :integer},
|
||||||
followers_count: %Schema{type: :integer},
|
followers_count: %Schema{type: :integer},
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
# 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
|
|
@ -1,27 +0,0 @@
|
|||||||
# 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
|
|
@ -1,24 +0,0 @@
|
|||||||
# 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
|
|
@ -1,18 +0,0 @@
|
|||||||
# 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
|
|
@ -1,24 +0,0 @@
|
|||||||
# 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
|
|
@ -1,58 +0,0 @@
|
|||||||
# 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
|
|
@ -1,125 +0,0 @@
|
|||||||
# 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
|
|
@ -1,13 +0,0 @@
|
|||||||
# 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
|
|
@ -2,22 +2,18 @@
|
|||||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ApiSpec.Schemas.List do
|
defmodule Pleroma.Web.ApiSpec.Schemas.ApiError do
|
||||||
alias OpenApiSpex.Schema
|
alias OpenApiSpex.Schema
|
||||||
|
|
||||||
require OpenApiSpex
|
require OpenApiSpex
|
||||||
|
|
||||||
OpenApiSpex.schema(%{
|
OpenApiSpex.schema(%{
|
||||||
title: "List",
|
title: "ApiError",
|
||||||
description: "Response schema for a list",
|
description: "Response schema for API error",
|
||||||
type: :object,
|
type: :object,
|
||||||
properties: %{
|
properties: %{error: %Schema{type: :string}},
|
||||||
id: %Schema{type: :string},
|
|
||||||
title: %Schema{type: :string}
|
|
||||||
},
|
|
||||||
example: %{
|
example: %{
|
||||||
"id" => "123",
|
"error" => "Something went wrong"
|
||||||
"title" => "my list"
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
end
|
end
|
@ -1,30 +0,0 @@
|
|||||||
# 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
|
|
@ -2,14 +2,14 @@
|
|||||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ApiSpec.Schemas.AccountEmoji do
|
defmodule Pleroma.Web.ApiSpec.Schemas.Emoji do
|
||||||
alias OpenApiSpex.Schema
|
alias OpenApiSpex.Schema
|
||||||
|
|
||||||
require OpenApiSpex
|
require OpenApiSpex
|
||||||
|
|
||||||
OpenApiSpex.schema(%{
|
OpenApiSpex.schema(%{
|
||||||
title: "AccountEmoji",
|
title: "Emoji",
|
||||||
description: "Response schema for account custom fields",
|
description: "Response schema for an emoji",
|
||||||
type: :object,
|
type: :object,
|
||||||
properties: %{
|
properties: %{
|
||||||
shortcode: %Schema{type: :string},
|
shortcode: %Schema{type: :string},
|
@ -1,16 +0,0 @@
|
|||||||
# 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
|
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
defmodule Pleroma.Web.ApiSpec.Schemas.Poll do
|
defmodule Pleroma.Web.ApiSpec.Schemas.Poll do
|
||||||
alias OpenApiSpex.Schema
|
alias OpenApiSpex.Schema
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.AccountEmoji
|
alias Pleroma.Web.ApiSpec.Schemas.Emoji
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.FlakeID
|
alias Pleroma.Web.ApiSpec.Schemas.FlakeID
|
||||||
|
|
||||||
require OpenApiSpex
|
require OpenApiSpex
|
||||||
@ -20,7 +20,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Poll do
|
|||||||
multiple: %Schema{type: :boolean},
|
multiple: %Schema{type: :boolean},
|
||||||
votes_count: %Schema{type: :integer},
|
votes_count: %Schema{type: :integer},
|
||||||
voted: %Schema{type: :boolean},
|
voted: %Schema{type: :boolean},
|
||||||
emojis: %Schema{type: :array, items: AccountEmoji},
|
emojis: %Schema{type: :array, items: Emoji},
|
||||||
options: %Schema{
|
options: %Schema{
|
||||||
type: :array,
|
type: :array,
|
||||||
items: %Schema{
|
items: %Schema{
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
defmodule Pleroma.Web.ApiSpec.Schemas.Status do
|
defmodule Pleroma.Web.ApiSpec.Schemas.Status do
|
||||||
alias OpenApiSpex.Schema
|
alias OpenApiSpex.Schema
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.Account
|
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.FlakeID
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.Poll
|
alias Pleroma.Web.ApiSpec.Schemas.Poll
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
|
alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
|
||||||
@ -41,7 +41,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
|
|||||||
},
|
},
|
||||||
content: %Schema{type: :string, format: :html},
|
content: %Schema{type: :string, format: :html},
|
||||||
created_at: %Schema{type: :string, format: "date-time"},
|
created_at: %Schema{type: :string, format: "date-time"},
|
||||||
emojis: %Schema{type: :array, items: AccountEmoji},
|
emojis: %Schema{type: :array, items: Emoji},
|
||||||
favourited: %Schema{type: :boolean},
|
favourited: %Schema{type: :boolean},
|
||||||
favourites_count: %Schema{type: :integer},
|
favourites_count: %Schema{type: :integer},
|
||||||
id: FlakeID,
|
id: FlakeID,
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
# 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
|
|
@ -104,8 +104,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|||||||
:fullname
|
:fullname
|
||||||
])
|
])
|
||||||
|> Map.put(:nickname, params.username)
|
|> Map.put(:nickname, params.username)
|
||||||
|> Map.put(:fullname, params.fullname || params.username)
|
|> Map.put(:fullname, Map.get(params, :fullname, params.username))
|
||||||
|> Map.put(:bio, params.bio || "")
|
|
||||||
|> Map.put(:confirm, params.password)
|
|> Map.put(:confirm, params.password)
|
||||||
|> Map.put(:trusted_app, app.trusted)
|
|> Map.put(:trusted_app, app.trusted)
|
||||||
|
|
||||||
@ -158,7 +157,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|||||||
|
|
||||||
params =
|
params =
|
||||||
params
|
params
|
||||||
|> Map.from_struct()
|
|
||||||
|> Enum.filter(fn {_, value} -> not is_nil(value) end)
|
|> Enum.filter(fn {_, value} -> not is_nil(value) end)
|
||||||
|> Enum.into(%{})
|
|> Enum.into(%{})
|
||||||
|
|
||||||
@ -217,11 +215,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|||||||
Enum.map(fields, fn {_, v} -> v end)
|
Enum.map(fields, fn {_, v} -> v end)
|
||||||
else
|
else
|
||||||
Enum.map(fields, fn
|
Enum.map(fields, fn
|
||||||
%Pleroma.Web.ApiSpec.Schemas.AccountAttributeField{} = field ->
|
%{} = field -> %{"name" => field.name, "value" => field.value}
|
||||||
%{"name" => field.name, "value" => field.value}
|
field -> field
|
||||||
|
|
||||||
field ->
|
|
||||||
field
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,141 +0,0 @@
|
|||||||
# 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
|
|
@ -4,8 +4,6 @@
|
|||||||
|
|
||||||
defmodule Pleroma.Web.MastodonAPI.CustomEmojiControllerTest do
|
defmodule Pleroma.Web.MastodonAPI.CustomEmojiControllerTest do
|
||||||
use Pleroma.Web.ConnCase, async: true
|
use Pleroma.Web.ConnCase, async: true
|
||||||
alias Pleroma.Web.ApiSpec
|
|
||||||
import OpenApiSpex.TestAssertions
|
|
||||||
|
|
||||||
test "with tags", %{conn: conn} do
|
test "with tags", %{conn: conn} do
|
||||||
assert resp =
|
assert resp =
|
||||||
@ -21,6 +19,5 @@ defmodule Pleroma.Web.MastodonAPI.CustomEmojiControllerTest do
|
|||||||
assert Map.has_key?(emoji, "category")
|
assert Map.has_key?(emoji, "category")
|
||||||
assert Map.has_key?(emoji, "url")
|
assert Map.has_key?(emoji, "url")
|
||||||
assert Map.has_key?(emoji, "visible_in_picker")
|
assert Map.has_key?(emoji, "visible_in_picker")
|
||||||
assert_schema(emoji, "CustomEmoji", ApiSpec.spec())
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user