Packages

Elixir library for generating HTTP clients from OpenAPI V3 json specifications

Current section

Files

Jump to
ex_oapi priv templates app_mode main.eex
Raw

priv/templates/app_mode/main.eex

defmodule <%= @title %> do
@moduledoc """
The SDK for <%= @title %>.
Endpoint modules and the schemas generated from the OpenAPI spec can be found under
the `./sdk` directory.
One usecase for this module is to wrap the SDK Client struct instantiation,
for instance, setting base url for the API calls, adding authorization headers,
middleware, default parameters, etc, and returning the prepared `ExOAPI.Client.t()`
struct to the caller so they can use it in subsequent calls.
"""
@doc """
Sample function for returning a properly usable client.
"""
@spec new(String.t(), String.t()) :: ExOAPI.Client.t()
def new(api_base_url, auth_bearer_key) do
%ExOAPI.Client{}
|> ExOAPI.Client.add_base_url(api_base_url)
|> ExOAPI.Client.add_middleware(Tesla.Middleware.JSON)
|> ExOAPI.Client.add_header("Authorization", "Bearer #{auth_bearer_key}")
end
end