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
endOptions
: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: trueDefault Schemas
create_checkout->Bazaar.Schemas.Shopping.CheckoutRespget_checkout->Bazaar.Schemas.Shopping.CheckoutRespupdate_checkout->Bazaar.Schemas.Shopping.CheckoutRespcomplete_checkout->Bazaar.Schemas.Shopping.CheckoutRespcancel_checkout->Bazaar.Schemas.Shopping.CheckoutRespget_order->Bazaar.Schemas.Shopping.OrderRespcancel_order->Bazaar.Schemas.Shopping.OrderResp