API / Swagger Interview questions
What is the difference between Swagger 2.0's definitions and OpenAPI 3.0's components/schemas?
Both serve the same fundamental purpose — a place to define reusable data shapes referenced elsewhere via $ref — but OpenAPI 3.0 relocated and reorganized this concept as part of its broader restructuring into the unified components object.
# Swagger 2.0 definitions: User: type: object properties: id: { type: integer } # OpenAPI 3.0 components: schemas: User: type: object properties: id: { type: integer }
Functionally, referencing a schema changes correspondingly: a Swagger 2.0 $ref pointing at a definition looks like #/definitions/User, while the OpenAPI 3.0 equivalent looks like #/components/schemas/User — a mechanical but breaking change that any tooling or migration script converting between the two versions has to account for.
Beyond the path change, OpenAPI 3.0's components also unified what were separate top-level sections in Swagger 2.0 (definitions, parameters, responses, securityDefinitions) into one consistently-structured object with matching sub-keys (schemas, parameters, responses, securitySchemes), which is a broader organizational shift beyond just renaming definitions to schemas.
More Related questions...