aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/api_spec
diff options
context:
space:
mode:
authorEgor Kislitsyn <egor@kislitsyn.com>2020-04-03 22:45:08 +0400
committerEgor Kislitsyn <egor@kislitsyn.com>2020-04-13 17:38:59 +0400
commitb08ded6c2f5ee29c6efc8c67cfc2ce0a679f0c77 (patch)
treed8369c5b90fe41d5b955dba996c41f3f338c5efe /lib/pleroma/web/api_spec
parentef37774403ff5af69a637875240eec205b6f55a5 (diff)
downloadpleroma-b08ded6c2f5ee29c6efc8c67cfc2ce0a679f0c77.tar.gz
Add spec for AccountController.create
Diffstat (limited to 'lib/pleroma/web/api_spec')
-rw-r--r--lib/pleroma/web/api_spec/operations/account_operation.ex68
-rw-r--r--lib/pleroma/web/api_spec/render_error.ex27
-rw-r--r--lib/pleroma/web/api_spec/schemas/account_create_request.ex56
-rw-r--r--lib/pleroma/web/api_spec/schemas/account_create_response.ex29
4 files changed, 180 insertions, 0 deletions
diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex
new file mode 100644
index 000000000..9085f1af1
--- /dev/null
+++ b/lib/pleroma/web/api_spec/operations/account_operation.ex
@@ -0,0 +1,68 @@
+# 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.AccountOperation do
+ alias OpenApiSpex.Operation
+ alias Pleroma.Web.ApiSpec.Schemas.AccountCreateRequest
+ alias Pleroma.Web.ApiSpec.Schemas.AccountCreateResponse
+ alias Pleroma.Web.ApiSpec.Helpers
+
+ @spec open_api_operation(atom) :: Operation.t()
+ def open_api_operation(action) do
+ operation = String.to_existing_atom("#{action}_operation")
+ apply(__MODULE__, operation, [])
+ end
+
+ @spec create_operation() :: Operation.t()
+ def create_operation do
+ %Operation{
+ tags: ["accounts"],
+ summary: "Register an account",
+ 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: Helpers.request_body("Parameters", AccountCreateRequest, required: true),
+ responses: %{
+ 200 => Operation.response("Account", "application/json", AccountCreateResponse)
+ }
+ }
+ end
+
+ def verify_credentials_operation do
+ :ok
+ end
+
+ def update_credentials_operation do
+ :ok
+ end
+
+ def relationships_operation do
+ :ok
+ end
+
+ def show_operation do
+ :ok
+ end
+
+ def statuses_operation do
+ :ok
+ end
+
+ def followers_operation do
+ :ok
+ end
+
+ def following_operation, do: :ok
+ def lists_operation, do: :ok
+ def follow_operation, do: :ok
+ def unfollow_operation, do: :ok
+ def mute_operation, do: :ok
+ def unmute_operation, do: :ok
+ def block_operation, do: :ok
+ def unblock_operation, do: :ok
+ def follows_operation, do: :ok
+ def mutes_operation, do: :ok
+ def blocks_operation, do: :ok
+ def endorsements_operation, do: :ok
+end
diff --git a/lib/pleroma/web/api_spec/render_error.ex b/lib/pleroma/web/api_spec/render_error.ex
new file mode 100644
index 000000000..e063d115b
--- /dev/null
+++ b/lib/pleroma/web/api_spec/render_error.ex
@@ -0,0 +1,27 @@
+# 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.RenderError do
+ @behaviour Plug
+
+ alias Plug.Conn
+ alias OpenApiSpex.Plug.JsonRenderError
+
+ @impl Plug
+ def init(opts), do: opts
+
+ @impl Plug
+
+ def call(%{private: %{open_api_spex: %{operation_id: "AccountController.create"}}} = conn, _) do
+ conn
+ |> Conn.put_status(:bad_request)
+ |> Phoenix.Controller.json(%{"error" => "Missing parameters"})
+ end
+
+ def call(conn, reason) do
+ opts = JsonRenderError.init(reason)
+
+ JsonRenderError.call(conn, opts)
+ end
+end
diff --git a/lib/pleroma/web/api_spec/schemas/account_create_request.ex b/lib/pleroma/web/api_spec/schemas/account_create_request.ex
new file mode 100644
index 000000000..398e2d613
--- /dev/null
+++ b/lib/pleroma/web/api_spec/schemas/account_create_request.ex
@@ -0,0 +1,56 @@
+# 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"},
+ 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
diff --git a/lib/pleroma/web/api_spec/schemas/account_create_response.ex b/lib/pleroma/web/api_spec/schemas/account_create_response.ex
new file mode 100644
index 000000000..f41a034c0
--- /dev/null
+++ b/lib/pleroma/web/api_spec/schemas/account_create_response.ex
@@ -0,0 +1,29 @@
+# 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}
+ },
+ example: %{
+ "JSON" => %{
+ "access_token" => "i9hAVVzGld86Pl5JtLtizKoXVvtTlSCJvwaugCxvZzk",
+ "created_at" => 1_585_918_714,
+ "scope" => ["read", "write", "follow", "push"],
+ "token_type" => "Bearer"
+ }
+ }
+ })
+end