Skip to content

Commit dccd549

Browse files
authored
feat(schema): set hide true for websockets (#336)
* feat(schema): set hide true for websockets Signed-off-by: Roberto Bianchi <[email protected]> * update Signed-off-by: Roberto Bianchi <[email protected]> --------- Signed-off-by: Roberto Bianchi <[email protected]>
1 parent d6348f0 commit dccd549

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ function fastifyWebsocket (fastify, opts, next) {
162162
isWebsocketRoute = true
163163

164164
if (routeOptions.websocket) {
165+
if (!routeOptions.schema) {
166+
routeOptions.schema = {}
167+
}
168+
routeOptions.schema.hide = true
169+
165170
wsHandler = routeOptions.handler
166171
handler = function (_, reply) {
167172
reply.code(404).send()

test/hooks.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ const WebSocket = require('ws')
88
const split = require('split2')
99

1010
test('Should run onRequest, preValidation, preHandler hooks', (t, end) => {
11-
t.plan(7)
11+
t.plan(8)
1212
const fastify = Fastify()
1313

1414
t.after(() => fastify.close())
1515

1616
fastify.register(fastifyWebsocket)
1717

1818
fastify.register(async function (fastify) {
19-
fastify.addHook('onRequest', async () => t.assert.ok('called', 'onRequest'))
19+
fastify.addHook('onRequest', async ({ routeOptions: { schema: { hide } } }) => {
20+
t.assert.ok('called', 'onRequest')
21+
t.assert.strictEqual(hide, true, 'schema hide property should be set to true when route option is websocket')
22+
})
2023
fastify.addHook('preParsing', async () => t.assert.ok('called', 'preParsing'))
2124
fastify.addHook('preValidation', async () => t.assert.ok('called', 'preValidation'))
2225
fastify.addHook('preHandler', async () => t.assert.ok('called', 'preHandler'))

0 commit comments

Comments
 (0)