Openapi

A lightweight OpenAPI-first routing, validation and documentation layer for Elixir/Phoenix applications.

It parses OpenAPI (YAML/JSON) definitions, generates Phoenix routes, optionally validates requests using JSON Schema, and provides built-in Swagger UI integration for interactive API documentation.

Usage

defmodule MyAppWeb.Router do
use MyAppWeb, :router
import Openapi.Phoenix
pipeline :api do
plug :accepts, ["json"]
end
scope "/" do
pipe_through :api
openapi "priv/swagger.yaml"
swagger_docs "/api-docs"
end
end

The openapi macro is responsible for turning an OpenAPI definition into live Phoenix routes.

When used in a router, it performs the following steps at compile time:

At runtime, requests are dispatched based on the generated metadata:

Installation

If available in Hex, the package can be installed by adding openapi to your list of dependencies in mix.exs:

def deps do
[
{:openapi, "~> 0.1.0"}
]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/openapi.

TODO:

License

MIT