add seperate source and dest entries in language listing (#193)
[akkoma] / lib / pleroma / web / api_spec / operations / translate_operation.ex
1 defmodule Pleroma.Web.ApiSpec.TranslationOperation do
2 alias OpenApiSpex.Operation
3 alias OpenApiSpex.Schema
4
5 @spec open_api_operation(atom) :: Operation.t()
6 def open_api_operation(action) do
7 operation = String.to_existing_atom("#{action}_operation")
8 apply(__MODULE__, operation, [])
9 end
10
11 @spec languages_operation() :: Operation.t()
12 def languages_operation() do
13 %Operation{
14 tags: ["Retrieve status translation"],
15 summary: "Translate status",
16 description: "View the translation of a given status",
17 operationId: "AkkomaAPI.TranslationController.languages",
18 security: [%{"oAuth" => ["read:statuses"]}],
19 responses: %{
20 200 =>
21 Operation.response("Translation", "application/json", source_dest_languages_schema())
22 }
23 }
24 end
25
26 defp source_dest_languages_schema do
27 %Schema{
28 type: :object,
29 required: [:source, :target],
30 properties: %{
31 source: languages_schema(),
32 target: languages_schema()
33 }
34 }
35 end
36
37 defp languages_schema do
38 %Schema{
39 type: :array,
40 items: %Schema{
41 type: :object,
42 properties: %{
43 code: %Schema{
44 type: :string
45 },
46 name: %Schema{
47 type: :string
48 }
49 }
50 }
51 }
52 end
53 end