Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: call transformSpecification correctly #97

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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