API / Swagger Interview questions
What is a response object in OpenAPI?
A response object describes what an operation returns for a specific HTTP status code — its description, headers, and the schema of its body content — and every operation's responses field maps possible status codes to these descriptions.
responses: '200': description: Successful retrieval content: application/json: schema: $ref: '#/components/schemas/User' '404': description: User not found
Documenting error responses (like the 404 above) alongside success responses is just as important as the success case: a well-documented API tells consumers exactly what error shape to expect for common failure conditions, rather than leaving them to discover it through trial and error against a live server.
A special key, default, can also be used to describe the response for any status code not explicitly listed, which is a convenient way to document a general error response shape without enumerating every possible HTTP status code individually.
More Related questions...