0
0
Expressframework~20 mins

Swagger UI integration in Express - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Swagger UI Integration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output when accessing Swagger UI with this Express setup?

Given the following Express server code integrating Swagger UI, what will you see when you visit http://localhost:3000/api-docs in a browser?

Express
import express from 'express';
import swaggerUi from 'swagger-ui-express';
import swaggerDocument from './swagger.json' assert { type: 'json' };

const app = express();

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));

app.listen(3000, () => console.log('Server running on port 3000'));
AA web page showing interactive API documentation based on swagger.json
BA JSON file download of swagger.json
CA 404 Not Found error page
DA blank page with no content
Attempts:
2 left
💡 Hint

Swagger UI middleware serves a web interface for API docs.

📝 Syntax
intermediate
2:00remaining
Which option correctly imports and uses swagger-ui-express in ES modules?

Choose the correct way to import and use swagger-ui-express in an Express app using ES modules.

A
import swaggerUi from 'swagger-ui-express';
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
B
const swaggerUi = require('swagger-ui-express');
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
C
import { serve, setup } from 'swagger-ui-express';
app.use('/docs', serve, setup(swaggerDocument));
D
import swaggerUi from 'swagger-ui-express';
app.use('/docs', swaggerUi.setup(swaggerDocument), swaggerUi.serve);
Attempts:
2 left
💡 Hint

ES modules use import syntax and the middleware order matters.

🔧 Debug
advanced
3:00remaining
Why does Swagger UI show a blank page with no API details?

You integrated Swagger UI in Express but when visiting /api-docs, the page is blank with no API info. What is the most likely cause?

Express
import express from 'express';
import swaggerUi from 'swagger-ui-express';
import swaggerDocument from './swagger.json' assert { type: 'json' };

const app = express();

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup());

app.listen(3000);
AThe swagger.json file path is incorrect causing a runtime error
BThe swaggerDocument was not passed to swaggerUi.setup, so no API data is loaded
CThe middleware order is reversed; setup should come before serve
DExpress server is not listening on the correct port
Attempts:
2 left
💡 Hint

Check what argument is passed to swaggerUi.setup.

state_output
advanced
2:00remaining
What is the effect of calling swaggerUi.setup with custom options?

Consider this code snippet:

app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, { explorer: true }));

What does the explorer: true option do in the Swagger UI?

AChanges the UI theme to dark mode
BDisables the display of API endpoints in the UI
CAutomatically generates API documentation from code comments
DEnables a search bar to explore API endpoints interactively
Attempts:
2 left
💡 Hint

Look up Swagger UI options for explorer.

🧠 Conceptual
expert
3:00remaining
Which statement best describes the role of swagger-ui-express middleware in an Express app?

Choose the most accurate description of what swagger-ui-express middleware does in an Express application.

AIt converts Express routes into a Swagger spec file dynamically at runtime
BIt automatically validates all incoming API requests against the Swagger spec and rejects invalid ones
CIt serves a static HTML page that displays interactive API documentation generated from a Swagger/OpenAPI spec file
DIt replaces Express's routing system with Swagger-based routing
Attempts:
2 left
💡 Hint

Think about what Swagger UI actually provides to users.