API / Swagger Interview questions
Describe the components section in OpenAPI 3.0?
The components object is where reusable pieces of an OpenAPI document live — schemas, parameters, responses, request bodies, security schemes, and examples — so they can be defined once and referenced from many places via $ref instead of duplicated.
components: schemas: User: type: object properties: id: { type: integer } email: { type: string } responses: NotFound: description: Resource not found securitySchemes: bearerAuth: type: http scheme: bearer
This was a structural improvement introduced in OpenAPI 3.0 over Swagger 2.0's flatter approach (which had separate top-level definitions, parameters, and responses sections); consolidating them under one components object made the document's reusable pieces easier to locate and organize consistently.
In practice, for any API beyond a trivial size, components are what keep a spec maintainable: a change to the User schema's shape only needs to happen in one place, and every operation referencing it via $ref picks up that change automatically the next time the document is processed.
More Related questions...