Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Swagger UI middleware.
Express
const swaggerUi = require('[1]');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'swagger-ui' which is the UI only, not the Express middleware.
Confusing with 'express-swagger-ui' which is a different package.
✗ Incorrect
The correct package to integrate Swagger UI with Express is swagger-ui-express.
2fill in blank
mediumComplete the code to serve Swagger UI at the '/api-docs' route.
Express
app.use('/api-docs', swaggerUi.[1](swaggerDocument));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'serve' which is a middleware but not the setup function.
Using 'init' which does not exist in this context.
✗ Incorrect
The method to set up Swagger UI middleware is setup.
3fill in blank
hardFix the error in the Swagger document import statement.
Express
const swaggerDocument = require('./[1].json');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'swaggerDocument' as file name which is a variable name, not a file.
Using 'swagger-ui' which is a package name, not a file.
✗ Incorrect
The Swagger JSON file is commonly named swagger.json.
4fill in blank
hardFill both blanks to correctly import Express and create an app instance.
Express
const [1] = require('express'); const app = [2]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'app' as the import variable name which is usually reserved for the app instance.
Using 'express()' as the import variable which is a function call, not a variable.
✗ Incorrect
You import Express as express and call it as a function to create the app instance.
5fill in blank
hardFill all three blanks to correctly set up Swagger UI middleware with options.
Express
app.use('/api-docs', swaggerUi.[1](swaggerDocument, [2])); const options = [3];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the options object inline instead of as a variable.
Using 'serve' instead of 'setup' for the method.
✗ Incorrect
The setup method is used with the Swagger document and options object. The options object can include settings like persistAuthorization.