Skip to content

Commit

Permalink
cleanup types
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed Mar 26, 2019
1 parent 9a55c78 commit 4b96f66
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
5 changes: 5 additions & 0 deletions src/framework/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// import { IOpenAPIRequestCoercer } from 'openapi-request-coercer';
// import { IOpenAPIRequestValidator } from 'openapi-request-validator';
// import { IOpenAPIResponseValidator } from 'openapi-response-validator';
import { Request } from 'express';
import {
// IOpenAPISecurityHandler,
SecurityHandlers,
Expand Down Expand Up @@ -135,3 +136,7 @@ export interface OpenAPIFrameworkVisitor {
visitPath?(context: OpenAPIFrameworkPathContext): void;
// visitOperation?(context: OpenAPIFrameworkOperationContext): void;
}

export interface OpenApiRequest extends Request {
openapi;
}
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as _ from 'lodash';
import { ExpressApp } from 'express';
import { Application, Response, NextFunction } from 'express';
import { OpenAPIFrameworkArgs } from './framework';
import { OpenApiContext } from './openapi.context';
import * as middlewares from './middlewares';
import ono from 'ono';
import { OpenApiRequest } from './framework/types';

const loggingKey = 'express-openapi-validator';

Expand All @@ -24,7 +25,7 @@ export function OpenApiValidator(options: OpenApiValidatorOpts) {
this.context = openApiContext;
}

OpenApiValidator.prototype.install = function(app: ExpressApp) {
OpenApiValidator.prototype.install = function(app: Application) {
const pathParams = [];
for (const route of this.context.routes) {
if (route.pathParams.length > 0) {
Expand All @@ -34,7 +35,7 @@ OpenApiValidator.prototype.install = function(app: ExpressApp) {

// install param on routes with paths
for (const p of _.uniq(pathParams)) {
app.param(p, (req, res, next, value, name) => {
app.param(p, (req: OpenApiRequest, res, next, value, name) => {
if (req.openapi.pathParams) {
// override path params
req.params[name] = req.openapi.pathParams[name] || req.params[name];
Expand Down
8 changes: 4 additions & 4 deletions test/app.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ export function routes(app) {
.Router()
.post('/', function(req, res, next) {
res.json({
name: `${req.metnod}: /router_1`,
name: `${req.method}: /router_1`,
});
})
.get('/', function(req, res, next) {
res.json({
name: `${req.metnod}: /router_1`,
name: `${req.method}: /router_1`,
});
})
.get('/:id', function(req, res, next) {
res.json({
name: `${req.metnod}: /router_1/${req.params.id}`,
name: `${req.method}: /router_1/${req.params.id}`,
});
})
.get('/:id/best/:bid', function(req, res, next) {
res.json({
name: `${req.metnod}: /router_1/${req.params.id}/best/${
name: `${req.method}: /router_1/${req.params.id}/best/${
req.params.bid
}`,
});
Expand Down
4 changes: 2 additions & 2 deletions test/headers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import * as request from 'supertest';
import app from './app';

const packageJson = require('../package.json');
const basePath = app.basePath;
const basePath = (<any>app).basePath;

describe(packageJson.name, () => {
after(() => {
app.server.close();
(<any>app).server.close();
});

it('should throw 400 if required header is missing', async () =>
Expand Down
4 changes: 2 additions & 2 deletions test/routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import * as request from 'supertest';
import app from './app';

const packageJson = require('../package.json');
const basePath = app.basePath;
const basePath = (<any>app).basePath;

describe(packageJson.name, () => {
after(() => {
app.server.close();
(<any>app).server.close();
});
it(`should test something`, () => {
expect('a').to.equal('a');
Expand Down

0 comments on commit 4b96f66

Please sign in to comment.