|
@@ -13,7 +13,7 @@ import { InvalidMiddlewareException } from '../base/exceptions';
|
|
|
import { InvalidRouteException } from '../base/exceptions';
|
|
|
import { ServerNotInitializedException } from '../base/exceptions';
|
|
|
import { WebSocketHandler } from '../base/websocket';
|
|
|
-import swaggerJsDoc from 'swagger-jsdoc';
|
|
|
+import swaggerJsDoc, { OAS3Options, Options, SecurityRequirement } from 'swagger-jsdoc';
|
|
|
import swaggerUi from 'swagger-ui-express';
|
|
|
|
|
|
/** @sealed */
|
|
@@ -39,6 +39,8 @@ class Server {
|
|
|
private readonly viewsPath?: string;
|
|
|
private readonly options?: {[key: string]: any};
|
|
|
|
|
|
+ private readonly swaggerComponents? : object;
|
|
|
+ private readonly swaggerSecurity? : object;
|
|
|
private readonly swaggerDocsPath? : string;
|
|
|
private readonly swaggerTitle?: string;
|
|
|
private readonly swaggerDescription?: string;
|
|
@@ -69,6 +71,8 @@ class Server {
|
|
|
this.swaggerDescription = properties.swagger?.description || 'API Documentation';
|
|
|
this.swaggerApiVersion = properties.swagger?.version ||'1.0.0';
|
|
|
this.swaggerRoute = properties.swagger?.route || '/api-docs';
|
|
|
+ this.swaggerComponents = properties.swagger?.components;
|
|
|
+ this.swaggerSecurity = properties.swagger?.security;
|
|
|
}
|
|
|
this.initialized = false;
|
|
|
}
|
|
@@ -229,9 +233,9 @@ class Server {
|
|
|
if(!this.swaggerDocsPath)
|
|
|
return this;
|
|
|
|
|
|
- const swaggerOptions = {
|
|
|
+ const swaggerOptions : OAS3Options = {
|
|
|
swaggerDefinition: {
|
|
|
- openapi: '3.0.0',
|
|
|
+ openapi: '3.0.1',
|
|
|
info: {
|
|
|
title: this.swaggerTitle!,
|
|
|
version: this.swaggerApiVersion!,
|
|
@@ -244,7 +248,12 @@ class Server {
|
|
|
apis: [this.swaggerDocsPath],
|
|
|
};
|
|
|
|
|
|
- const swaggerDocs = swaggerJsDoc(swaggerOptions);
|
|
|
+ if(this.swaggerComponents)
|
|
|
+ swaggerOptions.swaggerDefinition!.components = this.swaggerComponents;
|
|
|
+ if(this.swaggerSecurity)
|
|
|
+ swaggerOptions.swaggerDefinition!.security = this.swaggerSecurity as SecurityRequirement[];
|
|
|
+
|
|
|
+ const swaggerDocs = swaggerJsDoc(swaggerOptions as Options);
|
|
|
|
|
|
this.instance.use(this.swaggerRoute!, swaggerUi.serve, swaggerUi.setup(swaggerDocs));
|
|
|
return this;
|