UNPKG

express-oas-generator

Version:

Module to automatically generate OpenAPI (Swagger) specification for existing ExpressJS 4.x REST API applications

1,409 lines (403 loc) 18.7 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Global - Documentation</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc.css"> <script src="scripts/nav.js" defer></script> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav > <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#handleRequests">handleRequests</a></li><li><a href="global.html#handleResponses">handleResponses</a></li><li><a href="global.html#init">init</a></li><li><a href="global.html#predefinedSpec">predefinedSpec</a></li><li><a href="global.html#responseMiddlewareHasBeenApplied">responseMiddlewareHasBeenApplied</a></li><li><a href="global.html#serveApiDocs">serveApiDocs</a></li></ul> </nav> <div id="main"> <h1 class="page-title">Global</h1> <section> <header> <h2> </h2> </header> <article> <div class="container-overview"> <dl class="details"> </dl> </div> <h3 class="subsection-title">Members</h3> <h4 class="name" id="predefinedSpec"><span class="type-signature"></span>predefinedSpec<span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line38">line 38</a> </li></ul></dd> </dl> <h4 class="name" id="responseMiddlewareHasBeenApplied"><span class="type-signature"></span>responseMiddlewareHasBeenApplied<span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line56">line 56</a> </li></ul></dd> </dl> <div class="description"> used make sure the *order* of which the middlewares are applied is correct The `response` middleware MUST be applied FIRST, before the `request` middleware is applied. We'll use this to make sure the order is correct. If not - we'll throw an informative error. </div> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="handleRequests"><span class="type-signature"></span>handleRequests<span class="signature">(options)</span><span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line284">line 284</a> </li></ul></dd> </dl> <div class="description"> apply the `request` middleware Applies to the `app` you provided in `handleResponses` Also, since this is the last function you'll need to invoke, it also initializes the specification and serves the api documentation. The options are for these tasks. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"> <h6>Properties</h6> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>path</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>api-docs</code> </td> <td class="description last">where to serve the openAPI docs. Defaults to `api-docs`</td> </tr> <tr> <td class="name"><code>predefinedSpec</code></td> <td class="type"> <span class="param-type">*</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>{}</code> </td> <td class="description last"></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> void </div> <h4 class="name" id="handleResponses"><span class="type-signature"></span>handleResponses<span class="signature">(expressApp, options<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line218">line 218</a> </li></ul></dd> </dl> <div class="description"> apply the `response` middleware. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>expressApp</code></td> <td class="type"> <span class="param-type">Express</span> </td> <td class="attributes"> </td> <td class="description last">the express app</td> </tr> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">optional configuration options <h6>Properties</h6> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>pathToOutputFile</code></td> <td class="type"> <span class="param-type">string</span> | <span class="param-type">undefined</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> </td> <td class="description last">where to write the openAPI specification to. Specify this to create the openAPI specification file.</td> </tr> <tr> <td class="name"><code>writeIntervalMs</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>10000</code> </td> <td class="description last">how often to write the openAPI specification to file</td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> void </div> <h4 class="name" id="init"><span class="type-signature"></span>init<span class="signature">(aApp, aPredefinedSpec<span class="signature-attributes">opt</span>, aPath<span class="signature-attributes">opt</span>, aWriteInterval<span class="signature-attributes">opt</span>, aApiDocsPath<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line353">line 353</a> </li></ul></dd> </dl> <div class="description"> initialize the `express-oas-generator`. This will apply both `handleResponses` and `handleRequests` and also will call `serveApiDocs`. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>aApp</code></td> <td class="type"> <span class="param-type">Express</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last">the express app</td> </tr> <tr> <td class="name"><code>aPredefinedSpec</code></td> <td class="type"> <span class="param-type">*</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>{}</code> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>aPath</code></td> <td class="type"> <span class="param-type">string</span> | <span class="param-type">undefined</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> </td> <td class="description last">where to write the openAPI specification to. Specify this to create the openAPI specification file.</td> </tr> <tr> <td class="name"><code>aWriteInterval</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>10000</code> </td> <td class="description last">how often to write the openAPI specification to file</td> </tr> <tr> <td class="name"><code>aApiDocsPath</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>api-docs</code> </td> <td class="description last">where to serve the openAPI docs. Defaults to `api-docs`</td> </tr> </tbody> </table> <h4 class="name" id="serveApiDocs"><span class="type-signature"></span>serveApiDocs<span class="signature">(options)</span><span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line97">line 97</a> </li></ul></dd> </dl> <div class="description"> serve the openAPI docs with swagger at a specified path / url </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"> <h6>Properties</h6> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>path</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>api-docs</code> </td> <td class="description last">where to serve the openAPI docs. Defaults to `api-docs`</td> </tr> <tr> <td class="name"><code>predefinedSpec</code></td> <td class="type"> <span class="param-type">*</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> <code>{}</code> </td> <td class="description last"></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> void </div> </article> </section> </div> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Tue Nov 12 2019 09:46:05 GMT+0200 (Eastern European Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. </footer> <script>prettyPrint();</script> <script src="scripts/polyfill.js"></script> <script src="scripts/linenumber.js"></script> </body> </html>