Skip to content

Commit

Permalink
fix: call transformSpecification correctly (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
MunifTanjim authored Nov 6, 2023
1 parent da04d53 commit fd10ae9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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
Expand Down
16 changes: 12 additions & 4 deletions test/transform-swagger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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
}
Expand All @@ -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, {
Expand Down Expand Up @@ -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
}
})
Expand All @@ -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, {
Expand Down Expand Up @@ -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
}
})
Expand All @@ -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, {
Expand Down Expand Up @@ -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
}
})
Expand Down

0 comments on commit fd10ae9

Please sign in to comment.