Skip to content

Commit

Permalink
(fix) #426 custom resolvers are incompatible with options.apiSpec set…
Browse files Browse the repository at this point in the history
… to path (#427)
  • Loading branch information
cdimascio committed Oct 27, 2020
2 parents 1ad3667 + 41a03e6 commit 97d7ad6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/openapi.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export class OpenApiValidator {
expressRoute.indexOf(baseUrl) === 0
? expressRoute.substring(baseUrl.length)
: expressRoute;
router[method.toLowerCase()](path, resolver(basePath, route, this.options.apiSpec));
router[method.toLowerCase()](path, resolver(basePath, route, context.apiDoc));
}
}
return router;
Expand Down
37 changes: 37 additions & 0 deletions test/operation.handler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import * as path from 'path';
import * as express from 'express';
import { expect } from 'chai';
import * as request from 'supertest';
import * as OpenApiValidator from '../src';
import * as resolvers from '../src/resolvers';
import { createApp } from './common/app';
import { OpenApiValidatorOpts } from '../src/framework/types';

describe('operation handler', () => {
let defaultNumberOfRoutes = null;
Expand Down Expand Up @@ -84,3 +87,37 @@ describe('operation handler', () => {
// expect(app._router.stack.length).to.be.greaterThan(defaultNumberOfRoutes);
});
});

describe('custom operation handler', () => {
let app = null;
let basePath = null;
const apiSpec = path.join(
__dirname,
'resources/eov-operations.modulepath.yaml',
);
const handler = {
basePath: path.join(__dirname, 'resources/routes'),
resolver: resolvers.modulePathResolver,
};
const eovConf: OpenApiValidatorOpts = {
apiSpec,
operationHandlers: handler,
};

before(async () => {
app = await createApp(eovConf, 3005);
basePath = app.basePath;
});

after(async () => app.server.close());

it('should recognize mapped operation', async () => {
return request(app)
.get(`${basePath}/ping`)
.expect(200)
.then((r) => {
expect(r.text).to.be.equal('pong');
});
});

});

0 comments on commit 97d7ad6

Please sign in to comment.