Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
feat: add apiCooker option to handle api before register route
Browse files Browse the repository at this point in the history
  • Loading branch information
amazing-gao committed Mar 3, 2018
1 parent 04d5a27 commit 0815235
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/router.js
Expand Up @@ -18,17 +18,19 @@ class OAIRouter extends Router {
const {
apiDoc,
apiExplorerVisible = true,
apiCooker = (api) => { return api; },
options = {},
} = opts;
assert(util.isString(apiDoc), 'apiDoc must be string.');
assert(util.isFunction(apiCooker), 'apiCooker must be function.');

this.apiDoc = apiDoc;
this.apiExplorerVisible = apiExplorerVisible;
this.apiCooker = apiCooker;
this.options = options;

this.api = null;
this.pluginRegister = new PluginRegister(this.options);

this.apiDoc = apiDoc;
}

/**
Expand All @@ -39,7 +41,7 @@ class OAIRouter extends Router {
routes() {
spec(this.apiDoc)
.then(async (api) => {
this.api = api;
this.api = await this.apiCooker(api);

await this.registerRoutes();
await this.registerApiExplorer();
Expand Down

0 comments on commit 0815235

Please sign in to comment.