1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ApiSpec.Scopes.Compiler do
6 defmacro __before_compile__(_env) do
7 strings = __MODULE__.extract_all_scopes()
16 Pleroma.Web.Gettext.dgettext_noop(
28 def extract_all_scopes do
29 extract_all_scopes_from(Pleroma.Web.ApiSpec.spec())
32 def extract_all_scopes_from(specs) do
35 {_path, %{} = path_item}, acc ->
36 extract_routes(path_item)
37 |> Enum.flat_map(fn operation -> process_operation(operation) end)
46 defp extract_routes(path_item) do
49 |> Enum.map(fn {_method, path_item} -> path_item end)
51 %OpenApiSpex.Operation{} = _operation -> true
56 defp process_operation(operation) do
60 %{"oAuth" => scopes} -> process_scopes(scopes)
65 defp process_scopes(scopes) do
67 |> Enum.flat_map(fn scope ->
72 def process_scope(scope) do
73 hierarchy = String.split(scope, ":")
76 Enum.reduce(hierarchy, {"", []}, fn comp, {cur, list} ->
77 {cur <> comp <> ":", [cur <> comp | list]}