diff --git a/src/controllers/tests/generator.controller.test.ts b/src/controllers/tests/generator.controller.test.ts index 938bb81e..2214fc4a 100644 --- a/src/controllers/tests/generator.controller.test.ts +++ b/src/controllers/tests/generator.controller.test.ts @@ -11,7 +11,7 @@ describe('GeneratorController', () => { const app = new App([new GenerateController()]); return await request(app.getServer()) - .post('/generate') + .post('/v1/generate') .send({ asyncapi: { asyncapi: '2.2.0', @@ -33,7 +33,7 @@ describe('GeneratorController', () => { const app = new App([new GenerateController()]); return await request(app.getServer()) - .post('/generate') + .post('/v1/generate') .send({ asyncapi: { asyncapi: '2.2.0', @@ -52,7 +52,7 @@ describe('GeneratorController', () => { const app = new App([new GenerateController()]); return await request(app.getServer()) - .post('/generate') + .post('/v1/generate') .send({ asyncapi: { asyncapi: '2.2.0', diff --git a/src/middlewares/request-body-validation.middleware.ts b/src/middlewares/request-body-validation.middleware.ts index 71fd4f30..30719c36 100644 --- a/src/middlewares/request-body-validation.middleware.ts +++ b/src/middlewares/request-body-validation.middleware.ts @@ -15,7 +15,9 @@ const ajv = new Ajv({ * Retrieve proper AJV's validator function, create or reuse it. */ async function getValidator(req: Request) { - const { path: reqPath, method } = req; + const method = req.method; + let reqPath = req.path; + reqPath = reqPath.startsWith('/v1') ? reqPath.replace('/v1', '') : reqPath; const schemaName = `${reqPath}->${method}`; const validate = ajv.getSchema(schemaName); diff --git a/src/middlewares/tests/document-validation.middleware.test.ts b/src/middlewares/tests/document-validation.middleware.test.ts index 46b7ee0e..d3e7d89e 100644 --- a/src/middlewares/tests/document-validation.middleware.test.ts +++ b/src/middlewares/tests/document-validation.middleware.test.ts @@ -21,7 +21,7 @@ describe('documentValidationMiddleware', () => { const app = new App([new TestController()]); return await request(app.getServer()) - .post('/test') + .post('/v1/test') .send({}) .expect(200, { success: true, @@ -40,7 +40,7 @@ describe('documentValidationMiddleware', () => { const app = new App([new TestController()]); return await request(app.getServer()) - .post('/test') + .post('/v1/test') .send({ asyncapi: { asyncapi: '2.2.0', @@ -97,7 +97,7 @@ describe('documentValidationMiddleware', () => { const app = new App([new TestController()]); return await request(app.getServer()) - .post('/test') + .post('/v1/test') .send({ // without title, version and channels asyncapi: { diff --git a/src/middlewares/tests/problem.middleware.test.ts b/src/middlewares/tests/problem.middleware.test.ts index 89f3d990..ac943ce9 100644 --- a/src/middlewares/tests/problem.middleware.test.ts +++ b/src/middlewares/tests/problem.middleware.test.ts @@ -23,7 +23,7 @@ describe('problemMiddleware', () => { const app = new App([new TestController()]); return await request(app.getServer()) - .post('/test') + .post('/v1/test') .send({}) .expect(422, { type: ProblemException.createType('custom-problem'), @@ -43,7 +43,7 @@ describe('problemMiddleware', () => { const app = new App([new TestController()]); return await request(app.getServer()) - .post('/test') + .post('/v1/test') .send({}) .expect(200, { success: true, diff --git a/src/middlewares/tests/request-body-validation.middleware.test.ts b/src/middlewares/tests/request-body-validation.middleware.test.ts index 2df81d31..b479ebc9 100644 --- a/src/middlewares/tests/request-body-validation.middleware.test.ts +++ b/src/middlewares/tests/request-body-validation.middleware.test.ts @@ -20,7 +20,7 @@ describe('requestBodyValidationMiddleware', () => { const app = new App([new TestController()]); return await request(app.getServer()) - .post('/generate') + .post('/v1/generate') .send({ asyncapi: { asyncapi: '2.2.0', @@ -39,7 +39,7 @@ describe('requestBodyValidationMiddleware', () => { it('should throw error when request body is invalid', async () => { const TestController = createTestController({ - path: '/test', + path: '/generate', method: 'post', callback: (_, res) => { res.status(200).send({ success: true }); @@ -48,7 +48,7 @@ describe('requestBodyValidationMiddleware', () => { const app = new App([new TestController()]); return await request(app.getServer()) - .post('/generate') + .post('/v1/generate') .send({ asyncapi: { asyncapi: '2.2.0',