Skip to content

Commit

Permalink
added some extra swagger config options
Browse files Browse the repository at this point in the history
Signed-off-by: Ijlal Ahmad <[email protected]>
  • Loading branch information
Thre4dripper committed Jul 10, 2024
1 parent ce3b42e commit fa3b5f4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
7 changes: 5 additions & 2 deletions src-javascript/config/expressConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions src-javascript/config/swaggerConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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'],
Expand Down
7 changes: 5 additions & 2 deletions src-typescript/config/expressConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
30 changes: 17 additions & 13 deletions src-typescript/config/swaggerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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'],
Expand Down

0 comments on commit fa3b5f4

Please sign in to comment.