Bazaar.Plugs.ValidateResponse (Bazaar v0.3.0)

Copy Markdown View Source

Plug that validates outgoing UCP responses against schemas.

Uses Smelter-generated Ecto schemas to validate response bodies before they are sent to the client. Invalid responses are logged but still sent (in production) or can raise (in dev/test).

Usage

pipeline :bazaar_api do
  plug Bazaar.Plugs.ValidateResponse
end

Options

  • :schemas - Map of action atoms to schema modules (optional, uses defaults)
  • :enabled - Whether validation is enabled (default: true)
  • :strict - Raise on validation failure instead of logging (default: false)

Example

plug Bazaar.Plugs.ValidateResponse,
  strict: Application.compile_env(:my_app, :strict_validation, false)

# Or with custom schemas
plug Bazaar.Plugs.ValidateResponse,
  schemas: %{
    create_checkout: MyApp.Schemas.CustomCheckoutResp
  },
  strict: true

Default Schemas