Bird
Raised Fist0
Rest APIprogramming~20 mins

OpenAPI Specification (Swagger) in Rest API - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
OpenAPI Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
1:30remaining
What is the output of this OpenAPI snippet?
Given this OpenAPI YAML snippet describing a GET endpoint, what is the value of the summary field for the /pets path?
Rest API
paths:
  /pets:
    get:
      summary: List all pets
      responses:
        '200':
          description: A paged array of pets
AFetch all animals
BRetrieve pets list
CList all pets
DGet pets data
Attempts:
2 left
💡 Hint
Look for the summary field under the get method.
🧠 Conceptual
intermediate
1:00remaining
Which HTTP status code is used for a successful resource creation in OpenAPI?
In OpenAPI specifications, which HTTP status code should be used to indicate that a resource was successfully created?
A201
B200
C204
D400
Attempts:
2 left
💡 Hint
Think about the standard HTTP codes for resource creation.
🔧 Debug
advanced
2:00remaining
Identify the error in this OpenAPI parameter definition
What error will this OpenAPI parameter definition cause when validating the spec?
Rest API
parameters:
  - name: userId
    in: query
    required: true
    schema:
      type: integer
      format: uuid
AParameter 'in' must be 'path' for required parameters
BFormat 'uuid' is invalid for type 'integer'
CMissing 'description' field
DSchema type must be 'string' for query parameters
Attempts:
2 left
💡 Hint
Check if the format matches the type.
📝 Syntax
advanced
2:30remaining
Which option correctly defines a request body in OpenAPI 3.0?
Select the correct YAML snippet that defines a JSON request body with a required 'name' string property.
A
requestBody:
  schema:
    type: object
    properties:
      name:
        type: string
    required: [name]
B
requestBody:
  content:
    application/json:
      schema:
        properties:
          name:
            type: string
        required: name
C
requestBody:
  content:
    application/json:
      properties:
        name:
          type: string
      required: [name]
D
requestBody:
  content:
    application/json:
      schema:
        type: object
        properties:
          name:
            type: string
        required: [name]
Attempts:
2 left
💡 Hint
Remember the correct nesting of 'content' and 'schema' in requestBody.
🚀 Application
expert
2:00remaining
How many endpoints are defined in this OpenAPI snippet?
Count the total number of unique HTTP methods defined under the 'paths' object.
Rest API
paths:
  /users:
    get:
      summary: Get users
    post:
      summary: Create user
  /users/{id}:
    get:
      summary: Get user by ID
    put:
      summary: Update user
    delete:
      summary: Delete user
  /status:
    get:
      summary: Get status
A6
B7
C5
D8
Attempts:
2 left
💡 Hint
Count each HTTP method under each path separately.

Practice

(1/5)
1. What is the main purpose of the OpenAPI Specification in REST APIs?
easy
A. To store user data securely
B. To execute API requests automatically
C. To replace the need for API servers
D. To describe the API endpoints, methods, and data formats in a standard way

Solution

  1. Step 1: Understand OpenAPI's role

    OpenAPI Specification is designed to describe APIs clearly and consistently.
  2. Step 2: Identify the correct purpose

    It documents endpoints, HTTP methods, parameters, and data formats for APIs.
  3. Final Answer:

    To describe the API endpoints, methods, and data formats in a standard way -> Option D
  4. Quick Check:

    OpenAPI = API description standard [OK]
Hint: OpenAPI is for describing APIs, not running or storing data [OK]
Common Mistakes:
  • Confusing OpenAPI with API execution tools
  • Thinking OpenAPI stores user data
  • Believing OpenAPI replaces servers
2. Which of the following is the correct way to define an HTTP GET method for the path /users in OpenAPI YAML?
easy
A. paths: get: /users: summary: Get all users
B. paths: /users: get: summary: Get all users
C. get: paths: /users: summary: Get all users
D. paths: /users: post: summary: Get all users

Solution

  1. Step 1: Check OpenAPI path structure

    Paths are keys under paths, then HTTP methods like get are nested under each path.
  2. Step 2: Validate correct nesting and method

    paths: /users: get: summary: Get all users correctly places /users under paths and get under /users.
  3. Final Answer:

    paths: /users: get: summary: Get all users -> Option B
  4. Quick Check:

    Paths > /users > get [OK]
Hint: Remember: paths > endpoint > method > details [OK]
Common Mistakes:
  • Swapping method and path levels
  • Using wrong HTTP method for GET
  • Incorrect YAML indentation
3. Given this OpenAPI snippet, what is the response code defined for a successful GET request to /items?
paths:
  /items:
    get:
      responses:
        '200':
          description: Successful response
        '404':
          description: Not found
medium
A. 200
B. 201
C. 500
D. 404

Solution

  1. Step 1: Locate response codes under GET method

    The snippet shows responses under get for /items.
  2. Step 2: Identify success response code

    Code 200 is labeled as "Successful response", indicating success.
  3. Final Answer:

    200 -> Option A
  4. Quick Check:

    Success = 200 HTTP code [OK]
Hint: Success responses usually use 200 code [OK]
Common Mistakes:
  • Choosing 404 as success code
  • Confusing 201 (created) with 200
  • Ignoring response codes listed
4. Identify the error in this OpenAPI YAML snippet:
paths:
  /login:
    post:
      summary: User login
      responses:
        200:
          description: Login successful
medium
A. Summary field is not allowed under POST
B. Missing requestBody for POST method
C. Response code 200 should be a string '200', not a number
D. Path should start with a capital letter

Solution

  1. Step 1: Check response code format

    OpenAPI requires response codes as strings, e.g., '200', not numbers.
  2. Step 2: Verify other fields

    Summary is allowed; requestBody is optional; path case is flexible.
  3. Final Answer:

    Response code 200 should be a string '200', not a number -> Option C
  4. Quick Check:

    Response codes must be strings [OK]
Hint: Always quote response codes as strings in YAML [OK]
Common Mistakes:
  • Using numeric response codes
  • Assuming requestBody is mandatory
  • Thinking summary is invalid
5. You want to document an API that returns a list of products with optional filtering by category. Which OpenAPI feature helps you define the optional category filter parameter for the GET /products endpoint?
hard
A. Use a query parameter with required: false under the GET method
B. Add a path parameter named category in the URL
C. Include category in the requestBody schema
D. Define category as a header parameter

Solution

  1. Step 1: Understand parameter types

    Optional filters are usually query parameters, not path or header parameters.
  2. Step 2: Define optional query parameter

    Set required: false for the category query parameter under GET.
  3. Final Answer:

    Use a query parameter with required: false under the GET method -> Option A
  4. Quick Check:

    Optional filters = query params with required false [OK]
Hint: Filters usually go as optional query parameters [OK]
Common Mistakes:
  • Using path parameters for optional filters
  • Putting filters in requestBody for GET
  • Defining filters as headers
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard