Framework.VerifiedRoutes (Framework v0.5.0)

View Source

VerifiedRoutes provides type-safe route generation and parameter validation.

Generated from AppSpec definitions, these helpers ensure:

  • All navigation goes through verified routes
  • Parameters are validated at runtime
  • Deep links are properly handled
  • Navigation intents are properly typed

Usage

Instead of raw Phoenix routes or string URLs:

# BAD - forbidden by Credo rules
~p"/dashboard"
Routes.dashboard_path(conn, :show)

# GOOD - verified routes
routes().dashboard_path()
routes().project_show_path(org_id: org.id, project_id: project.id)

Summary

Functions

Extracts path from page AST.

Generates route path with parameter validation.

Generates route URL with parameter validation.

Gets all route patterns from registered AppSpec modules.

Gets the base URL from configuration.

Gets all registered AppSpec modules (same logic as MessageSecurity).

Gets a route helper function for a specific page from registered AppSpec modules.

Matches parameterized patterns like "/users/:user_id/profile".

Matches a path against a route pattern and extracts parameters.

Parses query parameters from query string.

Validates parameters and builds path.

Validates deep links against known routes.

Functions

extract_path_from_ast(arg1)

Extracts path from page AST.

generate_path(page_name, params \\ %{})

Generates route path with parameter validation.

Returns validated path string or raises on invalid parameters.

generate_url(page_name, params \\ %{})

Generates route URL with parameter validation.

Similar to generate_path but returns full URL.

get_all_route_patterns()

Gets all route patterns from registered AppSpec modules.

get_base_url()

Gets the base URL from configuration.

get_registered_appspecs()

Gets all registered AppSpec modules (same logic as MessageSecurity).

get_route_helper(page_name)

Gets a route helper function for a specific page from registered AppSpec modules.

match_parameterized_pattern(path, pattern, query_params)

Matches parameterized patterns like "/users/:user_id/profile".

match_path_pattern(path, pattern)

Matches a path against a route pattern and extracts parameters.

parse_query_params(query_string)

Parses query parameters from query string.

validate_and_build_path(page_name, params)

Validates parameters and builds path.

Returns {:ok, path} or {:error, reason}.

validate_deep_link(path)

Validates deep links against known routes.

Returns {:ok, {page_name, params}} for valid links, {:error, :url_invalid} for invalid ones.