Skip to content

Commit

Permalink
Introduce apiDoc as a param for operation resolver
Browse files Browse the repository at this point in the history
* Make apiDoc accessible to operation resolver
* Use context.apiDoc
  • Loading branch information
michaelmelody91 committed Sep 11, 2020
1 parent 31dfb96 commit 3074a1d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export class OpenApiValidator {
*/
if (this.isOperationHandlerOptions(this.options.operationHandlers)) {
const { basePath, resolver } = this.options.operationHandlers;
app[method.toLowerCase()](expressRoute, resolver(basePath, route));
app[method.toLowerCase()](expressRoute, resolver(basePath, route, context.apiDoc));
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as path from 'path';
import { RequestHandler } from "express";
import { RouteMetadata } from "./framework/openapi.spec.loader";
import { OpenAPIV3 } from "./framework/types"

export function defaultResolver(handlersPath: string, route: RouteMetadata): RequestHandler {
export function defaultResolver(handlersPath: string, route: RouteMetadata, apiDoc: OpenAPIV3.Document): RequestHandler {
const tmpModules = {};
const { expressRoute, method, schema } = route;
const oId = schema['x-eov-operation-id'] || schema['operationId'];
Expand Down Expand Up @@ -39,7 +40,7 @@ export function defaultResolver(handlersPath: string, route: RouteMetadata): Req
}
}

export function modulePathResolver(handlersPath: string, route: RouteMetadata): RequestHandler {
export function modulePathResolver(handlersPath: string, route: RouteMetadata, apiDoc: OpenAPIV3.Document): RequestHandler {
const [controller, method] = route.schema['operationId'].split('.')

const modulePath = path.join(handlersPath, controller);
Expand Down

0 comments on commit 3074a1d

Please sign in to comment.