OpenAPI and Swagger REST API Documentation Fundamentals Quiz Quiz

Explore your understanding of REST API documentation using the OpenAPI Specification and Swagger with this beginner-friendly quiz. Assess core concepts, terms, and best practices relevant to clear and effective API documentation for developers and teams.

  1. Purpose of OpenAPI

    What is the primary purpose of the OpenAPI Specification in REST API documentation?

    1. To generate passwords for API users
    2. To deploy APIs to cloud platforms
    3. To store endpoint data securely
    4. To provide a standardized, machine-readable format for describing RESTful APIs

    Explanation: The main goal of OpenAPI is to define a clear, structured, and machine-readable description of a REST API. This helps both people and tools to understand and interact with APIs consistently. Storing data securely and deploying APIs are not the functions of OpenAPI. Generating passwords is unrelated to API documentation.

  2. Swagger UI's Function

    Which feature does Swagger UI offer to help users interact with REST APIs based on documentation?

    1. Real-time error correction in database queries
    2. Compression of HTTP responses
    3. An interactive web interface to try API endpoints
    4. Automatic server scaling

    Explanation: Swagger UI provides an interactive visual interface where users can view and test API endpoints directly from the browser. Automatic server scaling, error correction in queries, and response compression are not provided by Swagger UI, as those are related to infrastructure or performance rather than interactive documentation.

  3. OpenAPI Document Format

    In which formats can an OpenAPI document be written for defining a REST API specification?

    1. CSV or TSV
    2. DOCX or PDF
    3. YAML or JSON
    4. XML or HTML

    Explanation: OpenAPI documents can be written in either YAML or JSON formats, both of which are supported and widely used for configuration and data interchange. CSV and TSV are tabular data formats unsuitable for hierarchical specifications. XML and HTML are markup languages, while DOCX and PDF are document formats not intended for API specifications.

  4. Use of 'paths' Key

    What does the 'paths' key in an OpenAPI document represent?

    1. A list of resource images
    2. A list of authentication providers
    3. A list of available endpoints and their operations
    4. A list of server hardware requirements

    Explanation: The 'paths' key defines all available endpoints (paths) for the API, along with their supported HTTP operations like GET, POST, PUT, and DELETE. It does not specify server hardware, authentication providers, or resource images; those are defined elsewhere or not at all within the OpenAPI structure.

  5. Supported HTTP Methods

    Which HTTP methods can be documented in the OpenAPI specification for an API endpoint?

    1. PUSH, PULL, FETCH, UPDATE
    2. GET, POST, PUT, DELETE, PATCH
    3. LOGIN, REGISTER, SUBSCRIBE, UNSUBSCRIBE
    4. REQUEST, RESPONSE, REDIRECT, CONNECT

    Explanation: The OpenAPI specification can document standard HTTP methods such as GET, POST, PUT, DELETE, and PATCH, which define actions on resources. LOGIN and related terms are not HTTP methods but rather endpoint purposes. REQUEST, RESPONSE, and similar terms are not HTTP methods but refer instead to general concepts. PUSH and related terms are not standard HTTP methods.

  6. OpenAPI 'components' Section

    What is typically included in the 'components' section of an OpenAPI document?

    1. API usage reports
    2. Database backup files
    3. Application performance logs
    4. Reusable schemas, parameters, and security definitions

    Explanation: The 'components' section stores reusable parts such as schemas (data models), parameters, and security schemes to avoid repetition in the main document. Application logs, usage reports, and backup files are unrelated to API specification; they pertain to monitoring or data management.

  7. Describing Responses

    How does the OpenAPI specification allow documentation of the response for an endpoint?

    1. By listing user permissions
    2. By writing endpoint URLs only
    3. By storing JWT access tokens
    4. By specifying status codes, response descriptions, and optional schemas under the 'responses' object

    Explanation: The 'responses' object under each endpoint details expected status codes, text descriptions, and optionally response body structure using schemas. Merely listing URLs does not describe responses. JWT tokens are for authentication, and user permissions are part of security, not basic response documentation.

  8. API Parameter Locations

    Which locations can be specified for parameters in an OpenAPI document?

    1. Path, query, header, and cookie
    2. Module, package, class, and method
    3. Front, center, left, and right
    4. Table, view, field, and row

    Explanation: Parameters in OpenAPI can be located in the path, query string, HTTP headers, and cookies, as defined in the specification. Table-related and software structure terms are unrelated and do not fit parameter locations, while front, center, left, and right have no connection to API parameter structures.

  9. API Security Schemes

    Which example best illustrates a security scheme you might document in OpenAPI?

    1. Media file compression
    2. URL routing rules
    3. HTTP Basic Authentication
    4. Daily API traffic logs

    Explanation: HTTP Basic Authentication is a standard security scheme type described in OpenAPI and used to protect endpoints. API traffic logs, media compression, and URL routing are not security schemes and are therefore not appropriate for this documentation section.

  10. Meaning of 'deprecated' Field

    When an API operation is marked as 'deprecated' in OpenAPI documentation, what does this indicate?

    1. The operation has the highest security level
    2. The operation should not be used and may be removed in the future
    3. The operation is read-only and cannot modify data
    4. The operation is required in all future API versions

    Explanation: Marking an operation as 'deprecated' communicates to users that it will likely be removed in a future release and should be avoided when possible. It does not say anything about the operation's security, whether it is read-only, or its requirement in future versions; these statements would require different fields or documentation.