Challenge - 5 Problems
Express Swagger Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediateWhat 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']); });
Attempts:
2 left
💡 Hint
Look at the @swagger comment block and the HTTP method used.
✗ Incorrect
The Swagger comment documents a GET /users endpoint with a 200 response returning an array of strings. This matches option A.
📝 Syntax
intermediateWhich 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?
Attempts:
2 left
💡 Hint
POST endpoints with JSON bodies use requestBody with application/json content type.
✗ Incorrect
Option C correctly uses requestBody with application/json and defines username and password as string properties. Other options use wrong HTTP methods, wrong parameter locations, or wrong content types.
🔧 Debug
advancedWhy 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' }]); });
Attempts:
2 left
💡 Hint
Check if the Swagger comment syntax matches the standard and if the UI setup might affect display.
✗ Incorrect
The Swagger comment block is correctly formatted with proper indentation and schema. The array type is valid. Missing example fields do not prevent display. The issue is likely in the Swagger UI setup or loading.
❓ state_output
advancedWhat 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(); });
Attempts:
2 left
💡 Hint
Look at the responses section in the Swagger comment.
✗ Incorrect
The documented successful response status code is 204, which means no content but success. 400 is for invalid input but not the main success code.
🧠 Conceptual
expertWhich statement about documenting Express endpoints with Swagger is true?
Select the one true statement about documenting Express endpoints using Swagger comments.
Attempts:
2 left
💡 Hint
Think about how Swagger matches comments to routes.
✗ Incorrect
Swagger uses the HTTP method in comments to match the Express route method. They must match exactly (e.g., get, post). Comments outside route handlers are fine. Swagger does not auto-generate docs without comments. Response schemas improve docs but are optional.
