OpenAPI / Swagger interview questions

25 questions from the OpenAPI / Swagger course, each with the correct answer and an explanation. Try to answer before you open the answer.

OpenAPI Foundations

1. What is the relationship between Swagger 2.0 and OpenAPI?

  1. Swagger 2.0 was renamed OpenAPI 2.0 when donated to the OpenAPI Initiative
  2. They are unrelated formats
  3. OpenAPI is a Swagger UI plugin
  4. Swagger 2.0 is newer than OpenAPI 3.1
Show answer

Answer: Swagger 2.0 was renamed OpenAPI 2.0 when donated to the OpenAPI Initiative

The Swagger Specification became the OpenAPI Specification in 2015; Swagger now names a set of tools.

Lesson: What OpenAPI and Swagger Are

2. In an OpenAPI document, what does info.version describe?

  1. The OpenAPI Specification version
  2. The version of Swagger UI
  3. The HTTP version
  4. The version of the API being described
Show answer

Answer: The version of the API being described

The spec version goes in the top-level openapi field; info.version is your API's own version.

Lesson: Structure of an OpenAPI Document

3. What is a key benefit of design-first API development?

  1. The description is generated automatically from code
  2. No tests are needed
  3. Consumers can review the contract and build against mocks before implementation exists
  4. It avoids writing YAML
Show answer

Answer: Consumers can review the contract and build against mocks before implementation exists

Designing the contract first enables early feedback and parallel frontend and backend work.

Lesson: Design-First Versus Code-First

Paths, Parameters and Bodies

4. What is the operationId mainly used for?

  1. Choosing the HTTP method
  2. Setting the server URL
  3. Uniquely identifying an operation, for example as method names in generated code
  4. Defining security
Show answer

Answer: Uniquely identifying an operation, for example as method names in generated code

operationIds are unique identifiers that tools use for naming and linking.

Lesson: Paths and Operations

5. Which statement about path parameters in OpenAPI is true?

  1. They are optional by default
  2. They must be marked required: true and appear in the path template
  3. They are placed in the request body
  4. They cannot have a schema
Show answer

Answer: They must be marked required: true and appear in the path template

Path parameters are always required and must match a template variable in the path.

Lesson: Parameters: Path, Query, Header and Cookie

6. How are status codes written as keys in an OpenAPI responses object?

  1. As strings such as '200' or ranges such as '4XX', plus an optional default
  2. As unquoted numbers only
  3. As HTTP reason phrases
  4. They are not part of responses
Show answer

Answer: As strings such as '200' or ranges such as '4XX', plus an optional default

Response keys are status code strings, ranges like 4XX, or default.

Lesson: Request Bodies, Responses and Status Codes

Schemas and Data Modelling

7. Which keyword marks a property that appears in responses but should not be sent in requests?

  1. readOnly
  2. writeOnly
  3. required
  4. deprecated
Show answer

Answer: readOnly

readOnly properties such as server-generated ids belong only in responses.

Lesson: Schema Basics: Types, Formats and Constraints

9. How is a nullable string expressed in OpenAPI 3.1?

  1. nullable: true
  2. x-nullable: true
  3. type: [string, 'null']
  4. required: false
Show answer

Answer: type: [string, 'null']

3.1 follows JSON Schema, which expresses null as a type in a type array.

Lesson: OpenAPI 3.0 Versus 3.1

Security and Errors

10. What does `security: []` on an operation mean?

  1. The operation is forbidden
  2. All security schemes are required
  3. The operation requires no authentication, overriding the global default
  4. The document is invalid
Show answer

Answer: The operation requires no authentication, overriding the global default

An empty security array removes authentication requirements for that operation.

Lesson: Security Schemes and Requirements

11. Which OAuth flow suits a backend service calling another service with no user involved?

  1. Implicit
  2. Client credentials
  3. Authorization code with PKCE
  4. Password
Show answer

Answer: Client credentials

Client credentials is the machine-to-machine flow.

Lesson: OAuth 2.0 and OpenID Connect in OpenAPI

12. Which RFC defines Problem Details for HTTP APIs in its current version?

  1. RFC 9457
  2. RFC 2616
  3. RFC 6749
  4. RFC 7519
Show answer

Answer: RFC 9457

RFC 9457 is the current Problem Details standard, obsoleting RFC 7807.

Lesson: Describing Errors Consistently

API Design Patterns in OpenAPI

13. Why is cursor-based pagination often preferred for large collections?

  1. It stays fast and consistent as data changes, unlike large offsets
  2. It is easier to implement than every alternative
  3. It returns all items at once
  4. OpenAPI only supports cursors
Show answer

Answer: It stays fast and consistent as data changes, unlike large offsets

Cursors avoid slow deep offsets and skipped or duplicated items when rows are inserted.

Lesson: Pagination, Filtering and Naming Conventions

14. Which change to a public API is usually breaking?

  1. Adding a new optional query parameter
  2. Adding a new endpoint
  3. Adding a new field to a response
  4. Making a previously optional request field required
Show answer

Answer: Making a previously optional request field required

Existing clients that do not send the field would suddenly be rejected.

Lesson: Versioning, Evolution and Breaking Changes

15. In OpenAPI 3.1, where are events that your API sends to registered consumer URLs described?

  1. In the servers section
  2. In securitySchemes
  3. In the top-level webhooks section
  4. They cannot be described
Show answer

Answer: In the top-level webhooks section

OpenAPI 3.1 added a top-level webhooks object for outgoing event requests.

Lesson: Webhooks, Callbacks, Links and File Uploads

Documentation, Linting and Mocking

16. Which feature is Swagger UI best known for?

  1. Generating database schemas
  2. Running load tests
  3. Interactive "Try it out" requests from the documentation
  4. Compiling Java code
Show answer

Answer: Interactive "Try it out" requests from the documentation

Swagger UI lets readers send real requests directly from the rendered docs.

Lesson: Interactive Documentation: Swagger UI, Redoc and Scalar

17. What does linting an OpenAPI document check beyond spec validation?

  1. Whether the server is running
  2. Style and quality rules such as naming conventions, required descriptions and documented errors
  3. Database indexes
  4. Network latency
Show answer

Answer: Style and quality rules such as naming conventions, required descriptions and documented errors

Linters enforce organisation-specific conventions on top of structural validity.

Lesson: Validating and Linting OpenAPI Documents

18. What does Schemathesis do with an OpenAPI document?

  1. Generates many test requests from the schema and checks the running API's responses against the contract
  2. Generates documentation websites
  3. Converts YAML to JSON only
  4. Deploys the API
Show answer

Answer: Generates many test requests from the schema and checks the running API's responses against the contract

It is a property-based testing tool that finds crashes and contract violations.

Lesson: Mock Servers and Contract Testing

Code Generation and Frameworks

19. Why should generated code not be edited by hand?

  1. Edits are lost the next time code is regenerated from the contract
  2. It is read-only on disk
  3. Editing breaks the OpenAPI document
  4. Generators encrypt the code
Show answer

Answer: Edits are lost the next time code is regenerated from the contract

Generated code should be reproducible from the contract; customise via configuration or templates.

Lesson: Generating Clients and Server Stubs

20. Where does springdoc-openapi serve the generated OpenAPI JSON by default?

  1. /openapi.yaml
  2. /swagger.json
  3. /api/spec
  4. /v3/api-docs
Show answer

Answer: /v3/api-docs

springdoc serves the document at /v3/api-docs and Swagger UI at /swagger-ui.html by default.

Lesson: Code-First with springdoc-openapi in Spring Boot

21. In FastAPI, where is the interactive Swagger UI served by default?

  1. /swagger
  2. /api-docs
  3. /docs
  4. /ui
Show answer

Answer: /docs

FastAPI serves Swagger UI at /docs and Redoc at /redoc by default.

Lesson: OpenAPI in Other Frameworks

API Workflow, Governance and Revision

22. In an API-first pipeline, what does a breaking-change check compare?

  1. Two database schemas
  2. Swagger UI themes
  3. The new OpenAPI document against the previous published version
  4. Server CPU usage
Show answer

Answer: The new OpenAPI document against the previous published version

It diffs contracts to detect changes that would break existing clients.

Lesson: An API-First Workflow in CI/CD

23. Which specification describes event-driven, message-based APIs in the way OpenAPI describes HTTP APIs?

  1. GraphQL SDL
  2. AsyncAPI
  3. WSDL
  4. JSON:API
Show answer

Answer: AsyncAPI

AsyncAPI describes channels and messages for brokers and other asynchronous protocols.

Lesson: API Governance, Catalogues and AsyncAPI

24. In the case study, how can the mobile team start work before the backend is implemented?

  1. They build against a Prism mock server generated from the OpenAPI document
  2. They wait for the release
  3. They read the database schema
  4. They use the production API
Show answer

Answer: They build against a Prism mock server generated from the OpenAPI document

Mock servers driven by the contract allow parallel development.

Lesson: Case Study: Designing an Orders API Contract

25. Which top-level field holds reusable schemas, parameters, responses and security schemes?

  1. paths
  2. info
  3. servers
  4. components
Show answer

Answer: components

components is the container for reusable definitions referenced with $ref.

Lesson: Revision and Interview Questions

← Back to the course