Add Pleroma.Web.ApiSpec.Helpers
authorEgor Kislitsyn <egor@kislitsyn.com>
Fri, 3 Apr 2020 18:52:25 +0000 (22:52 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Mon, 6 Apr 2020 13:11:00 +0000 (17:11 +0400)
lib/pleroma/web/api_spec/helpers.ex [new file with mode: 0644]
lib/pleroma/web/api_spec/operations/app_operation.ex

diff --git a/lib/pleroma/web/api_spec/helpers.ex b/lib/pleroma/web/api_spec/helpers.ex
new file mode 100644 (file)
index 0000000..35cf4c0
--- /dev/null
@@ -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.Helpers do
+  def request_body(description, schema_ref, opts \\ []) do
+    media_types = ["application/json", "multipart/form-data"]
+
+    content =
+      media_types
+      |> Enum.map(fn type ->
+        {type,
+         %OpenApiSpex.MediaType{
+           schema: schema_ref,
+           example: opts[:example],
+           examples: opts[:examples]
+         }}
+      end)
+      |> Enum.into(%{})
+
+    %OpenApiSpex.RequestBody{
+      description: description,
+      content: content,
+      required: opts[:required] || false
+    }
+  end
+end
index 41d56693ac1be1485fcd08f15e010716a1fbbd37..26d8dbd421a7331367ad73fca00587971ee44923 100644 (file)
@@ -5,6 +5,7 @@
 defmodule Pleroma.Web.ApiSpec.AppOperation do
   alias OpenApiSpex.Operation
   alias OpenApiSpex.Schema
+  alias Pleroma.Web.ApiSpec.Helpers
   alias Pleroma.Web.ApiSpec.Schemas.AppCreateRequest
   alias Pleroma.Web.ApiSpec.Schemas.AppCreateResponse
 
@@ -21,8 +22,7 @@ defmodule Pleroma.Web.ApiSpec.AppOperation do
       summary: "Create an application",
       description: "Create a new application to obtain OAuth2 credentials",
       operationId: "AppController.create",
-      requestBody:
-        Operation.request_body("Parameters", "application/json", AppCreateRequest, required: true),
+      requestBody: Helpers.request_body("Parameters", AppCreateRequest, required: true),
       responses: %{
         200 => Operation.response("App", "application/json", AppCreateResponse),
         422 =>