diff --git a/src-javascript/config/expressConfig.js b/src-javascript/config/expressConfig.js index df597c8..ec16c8e 100644 --- a/src-javascript/config/expressConfig.js +++ b/src-javascript/config/expressConfig.js @@ -90,8 +90,11 @@ const server = async () => { // start swagger config SwaggerConfig.initSwagger({ - path: path.join(__dirname, '../../swagger.json'), - modify: false, + title: 'Node Swagger API', + description: 'Demonstrating how to describe a RESTful API with Swagger', + version: '1.0.0', + swaggerDocPath: path.join(__dirname, '../../swagger.json'), + modifySwaggerDoc: false, }); // end swagger config diff --git a/src-javascript/config/swaggerConfig.js b/src-javascript/config/swaggerConfig.js index b1d43ae..abf4d2e 100644 --- a/src-javascript/config/swaggerConfig.js +++ b/src-javascript/config/swaggerConfig.js @@ -16,11 +16,11 @@ class SwaggerConfig { static swaggerModify; static initSwagger(options) { - if (options) { - const { path, modify } = options; - this.swaggerPath = path; - this.swaggerModify = modify; - this.swaggerDocument = require(path); + const { title, description, version, swaggerDocPath, modifySwaggerDoc } = options; + if (swaggerDocPath) { + this.swaggerPath = swaggerDocPath; + this.swaggerModify = modifySwaggerDoc; + this.swaggerDocument = require(swaggerDocPath); this.swaggerDocument.paths = {}; if (this.swaggerModify) { this.modifySwaggerDocument(); @@ -29,9 +29,9 @@ class SwaggerConfig { this.swaggerDocument = { swagger: '2.0', info: { - version: '1.0.0', - title: 'Node Swagger API', - description: 'Demonstrating how to describe a RESTful API with Swagger', + title, + description, + version, }, schemes: ['http', 'https'], consumes: ['application/json'], diff --git a/src-typescript/config/expressConfig.ts b/src-typescript/config/expressConfig.ts index b9a32df..a111f1a 100644 --- a/src-typescript/config/expressConfig.ts +++ b/src-typescript/config/expressConfig.ts @@ -90,8 +90,11 @@ const server = async () => { }; // start swagger config SwaggerConfig.initSwagger({ - path: path.join(__dirname, '../../swagger.json'), - modify: false, + title: 'Node Swagger API', + description: 'Demonstrating how to describe a RESTful API with Swagger', + version: '1.0.0', + swaggerDocPath: path.join(__dirname, '../../swagger.json'), + modifySwaggerDoc: false, }); // end swagger config await loadRouters(path.join(__dirname, '../app/routes')); diff --git a/src-typescript/config/swaggerConfig.ts b/src-typescript/config/swaggerConfig.ts index 9f01be8..4c3ace9 100644 --- a/src-typescript/config/swaggerConfig.ts +++ b/src-typescript/config/swaggerConfig.ts @@ -83,22 +83,26 @@ interface SwaggerDocument { paths: Paths; } -interface SwaggerConfigOptions { - path: string; - modify?: boolean; +// exported because it is used in another repo express-master-controller which is connected through workflow +export interface SwaggerConfigOptions { + title: string; + description: string; + version: string; + swaggerDocPath?: string; + modifySwaggerDoc?: Boolean; } class SwaggerConfig { private static swaggerDocument: SwaggerDocument; private static swaggerPath: string; - private static swaggerModify: boolean | undefined; + private static swaggerModify: Boolean | undefined; - static initSwagger(options?: SwaggerConfigOptions) { - if (options) { - const { path, modify } = options; - this.swaggerPath = path; - this.swaggerModify = modify; - this.swaggerDocument = require(path); + static initSwagger(options: SwaggerConfigOptions) { + const { title, description, version, swaggerDocPath, modifySwaggerDoc } = options; + if (swaggerDocPath) { + this.swaggerPath = swaggerDocPath; + this.swaggerModify = modifySwaggerDoc; + this.swaggerDocument = require(swaggerDocPath); this.swaggerDocument.paths = {}; if (this.swaggerModify) { @@ -108,9 +112,9 @@ class SwaggerConfig { this.swaggerDocument = { swagger: '2.0', info: { - version: '1.0.0', - title: 'Node Swagger API', - description: 'Demonstrating how to describe a RESTful API with Swagger', + title, + description, + version, }, schemes: ['http', 'https'], consumes: ['application/json'],