Skip to content

Commit

Permalink
Merge pull request #45 from haimkastner/pass-express-app-feature
Browse files Browse the repository at this point in the history
Let pass express app instead of creating a new instance within.
  • Loading branch information
HugoMario authored Jan 6, 2022
2 parents 443c632 + 669cd14 commit bf111dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/middleware/express.app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ export class ExpressAppConfig {
this.definitionPath = definitionPath;
this.routingOptions = appOptions.routing;
this.setOpenApiValidatorOptions(definitionPath, appOptions);
this.app = express();
this.app.use(cors(appOptions.cors));

// Create new express app only if not passed by options
this.app = appOptions.app || express();

this.app.use(cors(appOptions.cors));

const spec = fs.readFileSync(definitionPath, 'utf8');
const swaggerDoc = jsyaml.safeLoad(spec);
Expand Down
10 changes: 7 additions & 3 deletions src/middleware/oas3.options.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import { OpenApiValidatorOpts } from 'express-openapi-validator/dist/framework/types';
import { LoggingOptions } from './logging.options'
import { SwaggerUiOptions } from './swagger.ui.options';
import * as express from 'express';

export class Oas3AppOptions {
public routing: any;
public openApiValidator: OpenApiValidatorOpts;
public logging: LoggingOptions;
public swaggerUI: SwaggerUiOptions;
public cors: any;
public app: express.Application;
public cors: any;

constructor(routingOpts: any, openApiValidatorOpts: OpenApiValidatorOpts, logging: LoggingOptions, swaggerUI: SwaggerUiOptions, app: express.Application, cors: any) {

constructor(routingOpts: any, openApiValidatorOpts: OpenApiValidatorOpts, logging: LoggingOptions, swaggerUI: SwaggerUiOptions, cors: any) {
this.routing = routingOpts;
this.openApiValidator = openApiValidatorOpts;
this.swaggerUI = swaggerUI;
if (!logging)
logging = new LoggingOptions(null, null);
this.logging = logging;
this.cors = cors;
this.app = app;
this.cors = cors;
}
}

0 comments on commit bf111dc

Please sign in to comment.