Openapi.Phoenix (Openapi v0.3.1)

Copy Markdown View Source

Basic Phoenix integration helpers for OpenAPI support.

This module provides macros that help integrate OpenAPI definition tracking into Phoenix routers and applications.

It enables routers to declare OpenAPI files and participate in automatic discovery and aggregation of API definitions across the system.

Summary

Functions

Injects OpenAPI router functionality into a module.

Register an OpenAPI spec and its routes with the application.

Register swagger-ui to a given path.

Functions

__using__(_)

(macro)

Injects OpenAPI router functionality into a module.

When used, the module:

  • Registers itself in :persistent_term as an OpenAPI router on load
  • Enables accumulation of @openapi_files module attributes
  • Exposes __openapi_files__/0 for retrieving declared OpenAPI files
  • Imports Openapi.Phoenix helpers

This allows the module to participate automatically in OpenAPI definition discovery and generation.

openapi(path, options \\ [])

(macro)

Register an OpenAPI spec and its routes with the application.

Options:

  • handler: Default handler of the routes can be overwritten with x-handler
  • strict (Default true): Validates routes at compile time.
  • server: The server/namespace for this spec. Auto-detected from router module if not provided.
  • prefix: Explicit route prefix applied to all generated OpenAPI paths.

swagger_docs(path, options \\ [])

(macro)

Register swagger-ui to a given path.

Options:

  • server: The server/namespace whose spec will be served on swagger-ui.
  • prefix: Explicit route prefix applied to the path.