Set Plug.Logger to log at `:debug` level
[akkoma] / lib / pleroma / docs / json.ex
index 38f01501761423ec8373cad2d36943444d120da3..f2a56d845e594752db66cd24d67483be0f9f6221 100644 (file)
@@ -1,14 +1,19 @@
 defmodule Pleroma.Docs.JSON do
-  @behaviour Pleroma.Docs.Formatter
+  @behaviour Pleroma.Docs.Generator
+
+  @spec process(keyword()) :: {:ok, String.t()}
   def process(descriptions) do
     config_path = "docs/generate_config.json"
-    {:ok, file} = File.open(config_path, [:write])
-    json = generate_json(descriptions)
-    IO.write(file, json)
-    :ok = File.close(file)
-    {:ok, config_path}
+
+    with {:ok, file} <- File.open(config_path, [:write, :utf8]),
+         json <- generate_json(descriptions),
+         :ok <- IO.write(file, json),
+         :ok <- File.close(file) do
+      {:ok, config_path}
+    end
   end
 
+  @spec generate_json([keyword()]) :: String.t()
   def generate_json(descriptions) do
     Jason.encode!(descriptions)
   end