WardrikRest.Reader behaviour (wardrik_rest v0.1.0-rc.1)

Copy Markdown

Reads an API's description into a WardrikRest.Spec.

A source is {module, opts}: a module with this behaviour, and what it reads. WardrikRest.Discovery reads Google Discovery documents. Write one for another format to load its APIs the same way:

defmodule MyApp.Described do
  @behaviour WardrikRest.Reader

  @impl true
  def read(opts), do: {:ok, %WardrikRest.Spec{...}}
end

WardrikRest.API.load({MyApp.Described, path: "priv/api.json"}, name: "my_api", ...)

The spec's schemas are JSON Schema, and refer to its types as %{"$ref" => name}; each tool's schema is fitted from them. See WardrikRest.Spec.

Summary

Types

t()

A reader and its options.

Callbacks

Returns the spec, or why the description can't be read.

Functions

Reads source with its reader.

Types

t()

@type t() :: {module(), keyword()}

A reader and its options.

Callbacks

read(opts)

@callback read(opts :: keyword()) :: {:ok, WardrikRest.Spec.t()} | {:error, String.t()}

Returns the spec, or why the description can't be read.

Functions

read(arg)

@spec read(t()) :: {:ok, WardrikRest.Spec.t()} | {:error, String.t()}

Reads source with its reader.