summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortusooa <tusooa@kazv.moe>2023-04-01 16:46:32 -0400
committertusooa <tusooa@kazv.moe>2023-10-15 17:20:26 -0400
commitf393a15dd1217a7f6aec9e9acc7b983e7b165a91 (patch)
tree379ca6959f3f644e5f0371c6bd9118f43a5adbe4
parent8829dcaee42b3ad1ee50f95b0586b22118771785 (diff)
Fix some specs about server-sent events in streaming
-rw-r--r--lib/pleroma/web/api_spec/operations/streaming_operation.ex49
1 files changed, 32 insertions, 17 deletions
diff --git a/lib/pleroma/web/api_spec/operations/streaming_operation.ex b/lib/pleroma/web/api_spec/operations/streaming_operation.ex
index 18674c9a1..fa48b9613 100644
--- a/lib/pleroma/web/api_spec/operations/streaming_operation.ex
+++ b/lib/pleroma/web/api_spec/operations/streaming_operation.ex
@@ -113,8 +113,8 @@ defmodule Pleroma.Web.ApiSpec.StreamingOperation do
defp get_schema(schema), do: schema.schema
defp server_sent_event_helper(name, description, type, payload, opts \\ []) do
- payload_type = opts[:payload_type] || :json
- has_stream = opts[:has_stream] || true
+ payload_type = Keyword.get(opts, :payload_type, :json)
+ has_stream = Keyword.get(opts, :has_stream, true)
stream_properties =
if has_stream do
@@ -127,6 +127,24 @@ defmodule Pleroma.Web.ApiSpec.StreamingOperation do
stream_required = if has_stream, do: [:stream], else: []
+ payload_schema =
+ if payload_type == :json do
+ %Schema{
+ title: "Event payload",
+ description: "JSON-encoded string of #{get_schema(payload).title}",
+ allOf: [payload]
+ }
+ else
+ payload
+ end
+
+ payload_example =
+ if payload_type == :json do
+ get_schema(payload).example |> Jason.encode!()
+ else
+ get_schema(payload).example
+ end
+
%Schema{
type: :object,
title: name,
@@ -141,22 +159,13 @@ defmodule Pleroma.Web.ApiSpec.StreamingOperation do
required: true,
enum: [type]
},
- payload:
- if payload_type == :json do
- %Schema{
- title: "Event payload",
- description: "JSON-encoded string of #{get_schema(payload).title}",
- allOf: [payload]
- }
- else
- payload
- end
+ payload: payload_schema
}
|> Map.merge(stream_properties),
example:
%{
"event" => type,
- "payload" => get_schema(payload).example |> Jason.encode!()
+ "payload" => payload_example
}
|> Map.merge(stream_example)
}
@@ -262,7 +271,8 @@ defmodule Pleroma.Web.ApiSpec.StreamingOperation do
allOf: [FlakeID],
example: "some-opaque-id"
},
- payload_type: :string
+ payload_type: :string,
+ has_stream: false
)
end
@@ -274,7 +284,7 @@ defmodule Pleroma.Web.ApiSpec.StreamingOperation do
%Schema{
type: :object,
title: "Results",
- required: [:result],
+ required: [:result, :type],
properties: %{
result: %Schema{
type: :string,
@@ -285,10 +295,15 @@ defmodule Pleroma.Web.ApiSpec.StreamingOperation do
type: :string,
title: "Error code",
description: "An error identifier. Only appears if `result` is `error`."
+ },
+ type: %Schema{
+ type: :string,
+ description: "Type of the request."
}
},
- example: %{"result" => "success"}
- }
+ example: %{"result" => "success", "type" => "pleroma:authenticate"}
+ },
+ has_stream: false
)
end