federation_status: Add ApiSpec
This commit is contained in:
parent
3b5a7a6b14
commit
aafdc975bd
|
@ -0,0 +1,40 @@
|
||||||
|
# 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.PleromaInstancesOperation do
|
||||||
|
alias OpenApiSpex.Operation
|
||||||
|
alias OpenApiSpex.Schema
|
||||||
|
|
||||||
|
def open_api_operation(action) do
|
||||||
|
operation = String.to_existing_atom("#{action}_operation")
|
||||||
|
apply(__MODULE__, operation, [])
|
||||||
|
end
|
||||||
|
|
||||||
|
def show_operation do
|
||||||
|
%Operation{
|
||||||
|
tags: ["PleromaInstances"],
|
||||||
|
summary: "Instances federation status",
|
||||||
|
description: "Information about instances deemed unreachable by the server",
|
||||||
|
operationId: "PleromaInstances.show",
|
||||||
|
responses: %{
|
||||||
|
200 => Operation.response("PleromaInstances", "application/json", pleroma_instances())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def pleroma_instances do
|
||||||
|
%Schema{
|
||||||
|
type: :object,
|
||||||
|
properties: %{
|
||||||
|
unreachable: %Schema{
|
||||||
|
type: :object,
|
||||||
|
properties: %{hostname: %Schema{type: :string, format: :"date-time"}}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
example: %{
|
||||||
|
"unreachable" => %{"consistently-unreachable.name" => "2020-10-14 22:07:58.216473"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
|
@ -7,7 +7,9 @@ defmodule Pleroma.Web.PleromaAPI.InstancesController do
|
||||||
|
|
||||||
alias Pleroma.Instances
|
alias Pleroma.Instances
|
||||||
|
|
||||||
# defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaInstancesController
|
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
||||||
|
|
||||||
|
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaInstancesOperation
|
||||||
|
|
||||||
def show(conn, _params) do
|
def show(conn, _params) do
|
||||||
unreachable =
|
unreachable =
|
||||||
|
|
|
@ -31,10 +31,8 @@ test "GET /api/v1/pleroma/federation_status", %{
|
||||||
assert conn
|
assert conn
|
||||||
|> put_req_header("content-type", "application/json")
|
|> put_req_header("content-type", "application/json")
|
||||||
|> get("/api/v1/pleroma/federation_status")
|
|> get("/api/v1/pleroma/federation_status")
|
||||||
|> json_response(200) == %{
|
|> json_response_and_validate_schema(200) == %{
|
||||||
"unreachable" => %{constant_host => to_string(constant_unreachable)}
|
"unreachable" => %{constant_host => to_string(constant_unreachable)}
|
||||||
}
|
}
|
||||||
|
|
||||||
# |> json_response_and_validate_schema(200)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue