0
0
Expressframework~20 mins

Documenting endpoints in Express - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Express Swagger Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Express endpoint documentation?
Consider this Express route documented with Swagger comments. What will the generated Swagger UI show for the GET /users endpoint?
Express
const express = require('express');
const app = express();

/**
 * @swagger
 * /users:
 *   get:
 *     summary: Retrieve a list of users
 *     responses:
 *       200:
 *         description: A list of users.
 *         content:
 *           application/json:
 *             schema:
 *               type: array
 *               items:
 *                 type: string
 */
app.get('/users', (req, res) => {
  res.json(['Alice', 'Bob']);
});
AThe Swagger UI shows a GET /users endpoint with a 200 response returning an array of strings.
BThe Swagger UI shows a POST /users endpoint with no response documented.
CThe Swagger UI shows a GET /users endpoint but no response schema is shown.
DThe Swagger UI shows a GET /users endpoint with a 404 response documented.
Attempts:
2 left
💡 Hint
Look at the @swagger comment block and the HTTP method used.
📝 Syntax
intermediate
2:00remaining
Which option correctly documents a POST /login endpoint with a JSON body?
You want to document a POST /login endpoint that accepts a JSON body with username and password fields. Which Swagger comment block is correct?
A
/**
 * @swagger
 * /login:
 *   post:
 *     requestBody:
 *       content:
 *         application/xml:
 *           schema:
 *             type: object
 *             properties:
 *               username:
 *                 type: string
 *               password:
 *                 type: string
 *     responses:
 *       200:
 *         description: Login successful
 */
B
/**
 * @swagger
 * /login:
 *   get:
 *     parameters:
 *       - in: body
 *         name: user
 *         schema:
 *           type: object
 *           properties:
 *             username:
 *               type: string
 *             password:
 *               type: string
 *     responses:
 *       200:
 *         description: Login successful
 */
C
/**
 * @swagger
 * /login:
 *   post:
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               username:
 *                 type: string
 *               password:
 *                 type: string
 *     responses:
 *       200:
 *         description: Login successful
 */
D
/**
 * @swagger
 * /login:
 *   post:
 *     parameters:
 *       - in: query
 *         name: username
 *         schema:
 *           type: string
 *       - in: query
 *         name: password
 *         schema:
 *           type: string
 *     responses:
 *       200:
 *         description: Login successful
 */
Attempts:
2 left
💡 Hint
POST endpoints with JSON bodies use requestBody with application/json content type.
🔧 Debug
advanced
2:00remaining
Why does this Swagger documentation not show the response schema?
This Express endpoint has Swagger comments but the response schema does not appear in the generated docs. What is the issue?
Express
/**
 * @swagger
 * /items:
 *   get:
 *     summary: Get items
 *     responses:
 *       200:
 *         description: List of items
 *         content:
 *           application/json:
 *             schema:
 *               type: array
 *               items:
 *                 type: object
 *                 properties:
 *                   id:
 *                     type: integer
 *                   name:
 *                     type: string
 */
app.get('/items', (req, res) => {
  res.json([{ id: 1, name: 'Item1' }]);
});
AThe Swagger comment block is correct; the issue is likely in the Swagger UI configuration, not the code.
BThe indentation of the Swagger comment is incorrect, so the parser ignores the schema.
CThe Swagger parser requires the 'type' field to be 'object' at the root, so array is invalid here.
DThe response schema is missing a required 'example' field, so it does not show.
Attempts:
2 left
💡 Hint
Check if the Swagger comment syntax matches the standard and if the UI setup might affect display.
state_output
advanced
2:00remaining
What is the documented response status code for this Express endpoint?
Given this Swagger comment for an Express endpoint, what status code is documented for the response?
Express
/**
 * @swagger
 * /profile:
 *   put:
 *     summary: Update user profile
 *     responses:
 *       204:
 *         description: Profile updated successfully
 *       400:
 *         description: Invalid input
 */
app.put('/profile', (req, res) => {
  if (!req.body.name) {
    return res.status(400).send('Name required');
  }
  res.status(204).send();
});
A200
B204
C400
D404
Attempts:
2 left
💡 Hint
Look at the responses section in the Swagger comment.
🧠 Conceptual
expert
2:00remaining
Which statement about documenting Express endpoints with Swagger is true?
Select the one true statement about documenting Express endpoints using Swagger comments.
ASwagger comments must be placed inside the route handler function to be recognized.
BSwagger automatically generates endpoint documentation without any comments if Express routes exist.
CResponse schemas in Swagger comments are optional and do not affect the generated documentation.
DThe HTTP method in Swagger comments must match the Express route method exactly for correct documentation.
Attempts:
2 left
💡 Hint
Think about how Swagger matches comments to routes.