liveBook · Manning

Input constraint

As explained in Secure APIs

An input constraint is a restriction on an input field's permitted type, size, values, or format.

An input constraint restricts what an API field may accept, such as its type, length, allowed values, format, or number of items. Schema linting checks strings, integers, and arrays for missing restrictions. section 12.2

Review input schemas for constraints such as:

API schema findings

Spectral flags components.schemas.RegisterStudent.properties.last_name because the string has no maxLength, enum, or const. It similarly flags courses.get parameters without minimum and maximum, and GetCourse.properties.lessons without maxItems. Review these findings especially for schemas that accept input; missing constraints are less problematic for read-only schemas whose output the API controls. section 12.2

npx spectral lint openapi.json --ruleset `pwd`/.spectral.yaml

Run Spectral against the OpenAPI specification to find missing string, integer, and array constraints. section 12.2

How Secure APIs covers it

How deep it goes
Identifies missing string, integer, and array limits but stops short of prescribing specific application values.
Examples
Uses email, last_name, courses parameters, and lessons arrays to demonstrate missing string, integer, and array restrictions.
What it assumes
Assumes familiarity with API endpoints and schemas while teaching constraint categories through concrete lint findings.
What you can do after
Diagnose missing field restrictions by running Spectral against an OpenAPI specification and reviewing each detection.
How it connects
Connects input constraints with OpenAPI schemas, Spectral, authentication and access controls, and API usability.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secure APIs. The section links point to the parts of the book it draws on.