API / Swagger Interview questions
What is a schema in OpenAPI?
A schema is a description of the shape and constraints of a piece of JSON (or other media type) data — the fields an object has, their types, which are required, and validation rules like string formats or numeric ranges — used throughout an OpenAPI document to describe request bodies, response bodies, and individual parameters.
User: type: object required: [id, email] properties: id: type: integer email: type: string format: email nickname: type: string
OpenAPI's schema syntax is based on JSON Schema, though earlier OpenAPI versions supported only a subset of full JSON Schema's capabilities; OpenAPI 3.1 aligned much more closely with JSON Schema itself, closing most of those historical gaps.
Schemas are commonly defined once in a reusable components/schemas section and referenced from multiple places via $ref, so a User schema used in both a create-user request body and a get-user response doesn't need to be duplicated and kept in sync by hand in two places.
More Related questions...