-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add swagger event configuration * feat: add multiple instance configuration * feat: add tests * fix: swagger events method * docs: update readme * feat: add fix to the linter
- Loading branch information
1 parent
c275ab3
commit c5d3fc6
Showing
10 changed files
with
99 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
const swaggerEvents = options => ({ | ||
multiple: options.multiple !== undefined ? options.multiple : false, | ||
}); | ||
|
||
module.exports = swaggerEvents; |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* GET /api/admin/v1 | ||
* @summary This is the summary of the endpoint | ||
* @return {string} 200 - success response | ||
*/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* GET /api/client/v1 | ||
* @summary This is the summary of the endpoint | ||
* @return {string} 200 - success response | ||
*/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const express = require('express'); | ||
const expressJSDocSwagger = require('../../..'); | ||
|
||
const app = express(); | ||
|
||
const setupInstance = options => new Promise(resolve => { | ||
const instance = expressJSDocSwagger(app)(options); | ||
instance.on('finish', data => { | ||
resolve(data); | ||
}); | ||
}); | ||
|
||
module.exports = setupInstance; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const multipleInstance = require('.'); | ||
|
||
const instance1Options = { | ||
info: { | ||
version: '1.0.0', | ||
title: 'Admin API', | ||
description: 'Only admin accounts authorized to use this API', | ||
}, | ||
security: { | ||
BearerAuth: { | ||
type: 'http', | ||
scheme: 'bearer', | ||
bearerFormat: 'JWT', | ||
}, | ||
}, | ||
filesPattern: './admin-v1-docs.js', | ||
swaggerUIPath: '/api/v1/admin/docs', | ||
baseDir: __dirname, | ||
exposeSwaggerUI: true, | ||
exposeApiDocs: true, | ||
apiDocsPath: '/api/v1/admin/api-docs', | ||
}; | ||
|
||
const instance2Options = { | ||
info: { | ||
version: '1.0.0', | ||
title: 'Client API', | ||
description: 'For client', | ||
}, | ||
filesPattern: './client-v1-docs.js', | ||
swaggerUIPath: '/api/v1/client/docs', | ||
baseDir: __dirname, | ||
exposeSwaggerUI: true, | ||
exposeApiDocs: true, | ||
apiDocsPath: '/api/v1/client/api-docs', | ||
}; | ||
|
||
describe('multipleInstance test', () => { | ||
it('multipleInstance should be different when multiple option is "true"', async () => { | ||
const instance1Data = await multipleInstance({ | ||
...instance1Options, | ||
multiple: true, | ||
}); | ||
const instance2Data = await multipleInstance({ | ||
...instance2Options, | ||
multiple: true, | ||
}); | ||
expect(instance1Data).not.toEqual(instance2Data); | ||
}); | ||
}); |