PhoenixSpec.ViewExtractor (PhoenixSpec v0.1.1)

View Source

Extracts response shapes from Phoenix JSON view modules by analyzing their AST.

Detects:

  • Map literals returned by data/1 and action functions
  • Ecto schema pattern matches to resolve field types
  • Calls to other *JSON.data/1 for nested schemas
  • Wrapping patterns like %{data: ...}
  • Optional fields via @optional attribute or inline conditionals

Summary

Functions

Extracts view information from a JSON view module's source file.

Derives an OpenAPI schema name from a JSON view module name.

Functions

extract(module)

@spec extract(module()) :: struct() | nil

Extracts view information from a JSON view module's source file.

view_module_to_schema_name(module)

@spec view_module_to_schema_name(module()) :: String.t()

Derives an OpenAPI schema name from a JSON view module name.

Examples

iex> PhoenixSpec.ViewExtractor.view_module_to_schema_name(TestAppWeb.PostJSON)
"Post"

iex> PhoenixSpec.ViewExtractor.view_module_to_schema_name(TestAppWeb.UserJSON)
"User"