File size: 1,336 Bytes
88211d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
defmodule PlausibleWeb.Plugins.API.Spec do
  @moduledoc """
  OpenAPI specification for the Plugins API
  """
  alias OpenApiSpex.{Components, Info, OpenApi, Paths, Server}
  alias PlausibleWeb.Router
  @behaviour OpenApi

  @impl OpenApi
  def spec do
    %OpenApi{
      servers: [
        %Server{
          description: "This server",
          url: PlausibleWeb.Endpoint.url(),
          variables: %{}
        }
      ],
      info: %Info{
        title: "Plausible Plugins API",
        version: "1.0-rc"
      },
      # Populate the paths from a phoenix router
      paths: Paths.from_router(Router),
      components: %Components{
        securitySchemes: %{
          "basic_auth" => %OpenApiSpex.SecurityScheme{
            type: "http",
            scheme: "basic",
            description: """
            HTTP basic access authentication using your Site Domain as the
            username and the Plugin Token contents as the password.
            Note that Site Domain is optional, a password alone suffices.

            For more information see
            https://en.wikipedia.org/wiki/Basic_access_authentication
            """
          }
        }
      },
      security: [%{"basic_auth" => []}]
    }
    # Discover request/response schemas from path specs
    |> OpenApiSpex.resolve_schema_modules()
  end
end