Schema Validation

스키마 검증

Validate input types, required fields, and ranges against a schema at the API boundary.

···
html
<div class="viz"><h3>REQUEST SCHEMA</h3><div class="row"><div class="box code" id="input">quantity: 2</div><span class="arrow">→</span><div class="box">quantity<br>number ≥ 1</div><span class="arrow">→</span><div class="box" id="out">PASS</div></div><div class="muted" id="why">valid field</div></div>
css
.viz{width:94%;height:88%;max-width:960px;padding:clamp(10px,2vmin,18px);border:1px solid var(--line);border-radius:14px;background:var(--surface);font:600 clamp(12px,1.35vw,16px)/1.35 var(--font-sans,system-ui,sans-serif);display:flex;flex-direction:column;gap:clamp(7px,1.8vmin,13px);overflow:hidden}.viz h3{margin:0;color:var(--accent);font:700 clamp(12px,1.35vw,16px)/1.2 var(--font-sans,system-ui,sans-serif);letter-spacing:.04em}.viz .row{display:flex;align-items:center;justify-content:center;gap:clamp(5px,1.4vmin,12px);flex:1;min-height:0}.viz .box{padding:clamp(5px,1.5vmin,12px);border:1px solid var(--line);border-radius:9px;background:var(--bg);text-align:center}.viz .muted{color:var(--muted)}.viz .accent{color:var(--accent)}.viz .code{font-family:ui-monospace,monospace}.viz .pill{padding:3px 7px;border:1px solid var(--line);border-radius:99px;white-space:nowrap}.viz .active{border-color:var(--accent);background:color-mix(in srgb,var(--accent) 12%,var(--surface))}.viz .arrow{color:var(--accent);font:700 18px ui-monospace,monospace}#out{min-width:18%;border-color:var(--accent)}#out.bad{border-color:var(--accent-3);color:var(--accent-3)}
js
let invalid=false;function draw(){invalid=!invalid;document.getElementById('input').textContent=invalid?'quantity: "two"':'quantity: 2';const out=document.getElementById('out');out.textContent=invalid?'ERROR':'PASS';out.classList.toggle('bad',invalid);document.getElementById('why').textContent=invalid?'quantity must be a number':'valid field'}draw();setInterval(draw,1600)

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.

Open as page ↗