forked from mirrors/akkoma
Add Pleroma.Web.ApiSpec.Helpers
This commit is contained in:
parent
0aa24a150b
commit
03eebabe8e
2 changed files with 29 additions and 2 deletions
27
lib/pleroma/web/api_spec/helpers.ex
Normal file
27
lib/pleroma/web/api_spec/helpers.ex
Normal file
|
@ -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
|
|
@ -5,6 +5,7 @@
|
||||||
defmodule Pleroma.Web.ApiSpec.AppOperation do
|
defmodule Pleroma.Web.ApiSpec.AppOperation do
|
||||||
alias OpenApiSpex.Operation
|
alias OpenApiSpex.Operation
|
||||||
alias OpenApiSpex.Schema
|
alias OpenApiSpex.Schema
|
||||||
|
alias Pleroma.Web.ApiSpec.Helpers
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.AppCreateRequest
|
alias Pleroma.Web.ApiSpec.Schemas.AppCreateRequest
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.AppCreateResponse
|
alias Pleroma.Web.ApiSpec.Schemas.AppCreateResponse
|
||||||
|
|
||||||
|
@ -21,8 +22,7 @@ defmodule Pleroma.Web.ApiSpec.AppOperation do
|
||||||
summary: "Create an application",
|
summary: "Create an application",
|
||||||
description: "Create a new application to obtain OAuth2 credentials",
|
description: "Create a new application to obtain OAuth2 credentials",
|
||||||
operationId: "AppController.create",
|
operationId: "AppController.create",
|
||||||
requestBody:
|
requestBody: Helpers.request_body("Parameters", AppCreateRequest, required: true),
|
||||||
Operation.request_body("Parameters", "application/json", AppCreateRequest, required: true),
|
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("App", "application/json", AppCreateResponse),
|
200 => Operation.response("App", "application/json", AppCreateResponse),
|
||||||
422 =>
|
422 =>
|
||||||
|
|
Loading…
Reference in a new issue