diff --git a/lib/routes.js b/lib/routes.js index ba65144..3e5ae45 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -169,7 +169,7 @@ function fastifySwagger (fastify, opts, done) { reply.send(transformSpecification(rfdc(fastify.swagger()), req, reply)) } : function (req, reply) { - reply.send(transformSpecification(fastify.swagger()), req, reply) + reply.send(transformSpecification(fastify.swagger(), req, reply)) } : function (req, reply) { reply.send(fastify.swagger()) @@ -191,7 +191,7 @@ function fastifySwagger (fastify, opts, done) { : function (req, reply) { reply .type('application/x-yaml') - .send(yaml.stringify(transformSpecification(fastify.swagger()), req, reply)) + .send(yaml.stringify(transformSpecification(fastify.swagger(), req, reply))) } : function (req, reply) { reply diff --git a/test/transform-swagger.test.js b/test/transform-swagger.test.js index 6b592c5..2254f88 100644 --- a/test/transform-swagger.test.js +++ b/test/transform-swagger.test.js @@ -7,7 +7,7 @@ const fastifySwaggerUi = require('../index') const yaml = require('yaml') test('transformSpecification should modify the json', async (t) => { - t.plan(3) + t.plan(5) const fastify = Fastify() await fastify.register(fastifySwagger, { @@ -53,6 +53,8 @@ test('transformSpecification should modify the json', async (t) => { await fastify.register(fastifySwaggerUi, { transformSpecification: function (swaggerObject, req, reply) { t.not(swaggerObject, fastify.swagger()) + t.ok(req) + t.ok(reply) swaggerObject.swagger = '2.1' return swaggerObject } @@ -70,7 +72,7 @@ test('transformSpecification should modify the json', async (t) => { }) test('transformSpecificationClone false should not deepclone fastify.swagger() /1', async (t) => { - t.plan(2) + t.plan(4) const fastify = Fastify() await fastify.register(fastifySwagger, { @@ -117,6 +119,8 @@ test('transformSpecificationClone false should not deepclone fastify.swagger() / transformSpecificationClone: false, transformSpecification: function (swaggerObject, req, reply) { t.equal(swaggerObject, fastify.swagger()) + t.ok(req) + t.ok(reply) return swaggerObject } }) @@ -132,7 +136,7 @@ test('transformSpecificationClone false should not deepclone fastify.swagger() / }) test('transformSpecification should modify the yaml', async (t) => { - t.plan(2) + t.plan(4) const fastify = Fastify() await fastify.register(fastifySwagger, { @@ -178,6 +182,8 @@ test('transformSpecification should modify the yaml', async (t) => { await fastify.register(fastifySwaggerUi, { transformSpecification: function (swaggerObject, req, reply) { swaggerObject.swagger = '2.1' + t.ok(req) + t.ok(reply) return swaggerObject } }) @@ -195,7 +201,7 @@ test('transformSpecification should modify the yaml', async (t) => { }) test('transformSpecificationClone false should not deepclone fastify.swagger() /2', async (t) => { - t.plan(2) + t.plan(4) const fastify = Fastify() await fastify.register(fastifySwagger, { @@ -242,6 +248,8 @@ test('transformSpecificationClone false should not deepclone fastify.swagger() / transformSpecificationClone: false, transformSpecification: function (swaggerObject, req, reply) { t.equal(swaggerObject, fastify.swagger()) + t.ok(req) + t.ok(reply) return swaggerObject } })