mix selecto.gen.api (selecto_mix v0.4.6)

Generates a Selecto API endpoint and LiveView control panel.

The generator creates:

  • a domain-aware API module that maps JSON payloads to SelectoUpdato operations
  • Selecto-powered read/query handlers
  • a Phoenix controller for the API endpoint
  • a LiveView control panel for editing configuration and sending requests
  • choice-source picker hooks for write fields when the domain declares them

Usage

mix selecto.gen.api orders --domain MyApp.OrdersDomain

Options

  • --domain - Domain module used by generated API module (default: inferred)
  • --schema - Ecto schema module used for write operations (default: inferred)
  • --repo - Repo module used for execution (default: MyApp.Repo)
  • --api-path - Route path used in controller docs (default: /api/v1/updato/<name>)
  • --panel-path - Route path used for the control panel (default: /updato/<name>/control)
  • --panel-in-prod - Include control panel route in production snippets (default: false)
  • --force - Overwrite generated files

The task prints route snippets to add into your router.ex.

For choice-backed write fields, keep option and membership validation resolvers server-owned. Assign :choice_source_options_resolver, :choice_source_membership_resolver, and :choice_source_scope from the generated LiveView using socket/session data rather than browser parameters. For HTTP writes, customize the generated controller's api_config/1 hook with the same server-owned resolver and scope. For security-sensitive Domain-of-Interest filters, declare constraint_policy: %{domain_of_interest: :fail_closed} on the choice source in the domain overlay and have the resolver return a closed result when a trusted filter cannot be enforced.

For domain-authored actions with capabilities, assign :capability_resolver in api_config/1 and write_api_config/1. Set :require_capability_resolver to true when capability-declared action preview/apply and generated query endpoints should fail closed without a resolver. Query capability enforcement uses SelectoComponents.QueryContract when that dependency is available in the generated host app.