Home / Knowledge hub / API schema validation
Knowledge hub
API schema validation
Rejecting requests that do not match the format the API says it accepts.
What it means
API schema validation means checking each request against a formal description of what the endpoint accepts: which fields exist, what type each one is, how long it may be, and which values are allowed. Anything that does not fit is refused before your code acts on it.
The description is usually an OpenAPI document or a JSON Schema. Think of it as a customs form for data. If a field is not on the form, or is the wrong kind of thing, it does not get through the door.
Why it matters
Without it, each handler decides for itself what to trust, and some will trust too much. A text field arrives where a number was expected. A list shows up with a million entries. An extra field such as role is quietly saved because nothing said it was not allowed.
A schema turns those surprises into a clean error. It is a cheap way to narrow input validation and to stop mass assignment, because unknown fields are refused rather than copied into a record. Teams often add it once and then forget it, so it keeps working quietly in the background.
How it shows up
You meet it in an API gateway, in a framework that reads the OpenAPI file, or in validation code at the top of each handler. The usual gaps are schemas that allow additional properties by default, strings with no maximum length, and documents that drifted from what the code really accepts.
Also check what happens on failure. A good API answers with a plain 400 or 422 and no stack trace. Check that the schema covers every method and version, including old ones nobody remembers. A schema checks shape, not permission, so it never replaces an ownership check.
Questions people ask
API schema validation, answered
Is schema validation the same as input validation?
No, it is one part of it. Schema validation checks structure: names, types, sizes and allowed values. Input validation also covers meaning, such as whether this coupon is still valid or this date is in the past.
You need both. The schema is the first, cheap filter.
Does schema validation stop injection?
Not by itself. A string can match the schema and still contain a hostile payload. Constraints such as a strict pattern or a short enum help a lot, but the fix for injection is still parameterised queries and correct output encoding.
Should we validate responses too?
It is worth doing, at least in testing. Checking responses against the schema catches fields that should never leave the server, such as an internal flag or another person's email address.
It also tells you when the documentation and the code have drifted apart.
What does additionalProperties do?
In JSON Schema, setting additionalProperties to false refuses any field the schema does not list. By default unknown fields are allowed.
That default is why many APIs accept fields they never meant to.
How do we test our schema checks?
Send requests that break the schema on purpose: wrong types, missing fields, oversized strings, extra fields, and nested objects. Each should fail the same clean way.
Then repeat on every method and every API version, since coverage is often uneven.
Sources
Where this comes from
Related
Terms that sit next to this one
Input validation
Checking that what arrives is the shape and range you expected.
Mass assignment
When the fields in a request get written straight onto a record.
OpenAPI specification
A file that describes an API's endpoints so tools and people can read it.
Allowlist
A list of what you permit, with everything else refused by default.
Untrusted input
Anything that arrived from outside your own code, and is therefore suspect.
Does your API refuse what it should?
Extra fields, wrong types and oversized values are the kind of input we try against your endpoints. Each finding comes with the exact request and response. Book a pilot on one app.
Or start with a $199 pilot on one application: thirty days, success criteria agreed before day one, credited against the annual if you convert.