API / Swagger Interview questions
What is the difference between OpenAPI 2.0 (Swagger) and OpenAPI 3.0?
OpenAPI 3.0 was a significant restructuring of the specification compared to its predecessor, Swagger 2.0, introducing several structural changes aimed at improving flexibility and reducing duplication.
| Swagger 2.0 | OpenAPI 3.0 |
| Single host/basePath/schemes fields for server info. | A servers array, supporting multiple environments and variables. |
| Separate top-level definitions, parameters, responses sections. | Unified under one components object. |
| Request body described awkwardly via a body-type parameter. | Dedicated requestBody object, decoupled from parameters. |
| One content type assumed per operation via produces/consumes. | Explicit content map supporting multiple media types per response. |
The requestBody change is one of the most practically significant: in Swagger 2.0, a JSON request body had to be shoehorned into the same parameters array as query and path parameters using in: body, which was conceptually awkward; OpenAPI 3.0's dedicated requestBody object is a cleaner, more intuitive fit for how request payloads actually work.
More Related questions...