0
0
Expressframework~10 mins

swagger-jsdoc setup in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import swagger-jsdoc in an Express app.

Express
const swaggerJSDoc = require('[1]');
Drag options to blanks, or click blank then click option'
Aswagger-ui-express
Bexpress
Cswagger-jsdoc
Dbody-parser
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'express' instead of 'swagger-jsdoc'.
Using 'swagger-ui-express' which is for UI, not spec generation.
2fill in blank
medium

Complete the code to define the swagger-jsdoc options object.

Express
const options = {
  definition: {
    openapi: '[1]',
    info: {
      title: 'API Docs',
      version: '1.0.0'
    }
  },
  apis: ['./routes/*.js']
};
Drag options to blanks, or click blank then click option'
A2.0
B3.0.0
C1.0
Dlatest
Attempts:
3 left
💡 Hint
Common Mistakes
Using '2.0' which is an older Swagger version.
Using 'latest' which is not a valid version string.
3fill in blank
hard

Fix the error in creating the swaggerSpec variable.

Express
const swaggerSpec = swaggerJSDoc([1]);
Drag options to blanks, or click blank then click option'
Aoptions
BswaggerOptions
Cconfig
Doptions()
Attempts:
3 left
💡 Hint
Common Mistakes
Calling options as a function when it is an object.
Passing a wrong variable name.
4fill in blank
hard

Fill both blanks to set up swagger-ui-express middleware in Express.

Express
const swaggerUi = require('[1]');
app.use('/api-docs', swaggerUi.[2](swaggerSpec));
Drag options to blanks, or click blank then click option'
Aswagger-ui-express
Bswagger-jsdoc
Csetup
Dserve
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'swagger-jsdoc' instead of 'swagger-ui-express'.
Using 'serve' instead of 'setup' for the middleware that takes the spec.
5fill in blank
hard

Fill all three blanks to complete the swagger-jsdoc setup and serve docs at '/docs'.

Express
const swaggerUi = require('[1]');
const swaggerSpec = swaggerJSDoc([2]);
app.use('[3]', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
Drag options to blanks, or click blank then click option'
Aswagger-ui-express
Boptions
C/docs
Dswagger-jsdoc
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up package names.
Using wrong route path like '/api-docs'.