Created
February 15, 2020 19:32
-
-
Save rocioDEV/dcd21717a2e51aba46d358bde6e44d06 to your computer and use it in GitHub Desktop.
Express live documentation with swagger-jsdoc & swagger-ui-express
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... non relevant require statements are omitted | |
const swaggerJsdoc = require('swagger-jsdoc') | |
const swaggerUi = require('swagger-ui-express') | |
const packageJson = require('../package.json') | |
const appVersion = packageJson.version | |
const appName = packageJson.name | |
const API_DOCS_PATH = path.resolve(__dirname, '../api.yaml') | |
const app = express() | |
// Create specs object with swagger-jsdoc, it will read | |
// your yaml files / comments and parse them | |
const specs = swaggerJsdoc({ | |
definition: { | |
openapi: '3.0.1', | |
info: { | |
title: appName, | |
version: appVersion, | |
description: 'Autogenerated OpenAPI 3.0.1 doc', | |
}, | |
}, | |
apis: [path.resolve(__dirname, '../api.yaml')], | |
}) | |
// Pass parsed object to swagger-ui-express to expose | |
// this information thourgh and express endpoint | |
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment