Schema validation compares a request body with declared shape and constraints. Missing required fields, wrong types, or out of range values are rejected before business logic runs. This catches client errors early and protects server assumptions.
The demo passes a numeric quantity and returns a field error for a string quantity. Error messages should help callers fix the input without exposing sensitive internal rules.
When to use
Use it at every API boundary that accepts external input.