This repository was archived by the owner on Mar 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 193
Expand file tree
/
Copy pathsample1.js
More file actions
34 lines (29 loc) · 1.27 KB
/
sample1.js
File metadata and controls
34 lines (29 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**************************************************************************************************
* This sample demonstrates the most simplistic usage of Swagger Express Middleware.
* It simply creates a new Express Application and adds all of the Swagger middleware
* without changing any options, and without adding any custom middleware.
**************************************************************************************************/
'use strict';
const createMiddleware = require('@apidevtools/swagger-express-middleware');
const path = require('path');
const express = require('express');
// Create an Express app
const app = express();
// Initialize Swagger Express Middleware with our Swagger file
let swaggerFile = path.join(__dirname, 'PetStore.yaml');
createMiddleware(swaggerFile, app, (err, middleware) => {
// Add all the Swagger Express Middleware, or just the ones you need.
// NOTE: Some of these accept optional options (omitted here for brevity)
app.use(
middleware.metadata(),
middleware.CORS(),
middleware.files(),
middleware.parseRequest(),
middleware.validateRequest(),
middleware.mock()
);
// Start the app
app.listen(8000, () => {
console.log('The Swagger Pet Store is now running at http://localhost:8000');
});
});