fastify-swagger
fastify-swagger copied to clipboard
Included types break usage of config object
Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.26.x
Plugin version
8.14.x
Node.js version
20.x
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
All
Description
The config object for routes in fastify is typed liberally: it is a union with unknown and you can use it to store arbitrary configuration. However, this module specifies a concrete type for the config option that breaks extensions:
https://github.com/fastify/fastify-swagger/blob/352f7d6c235445731e9843c1f83f313d5320992e/index.d.ts#L56-L58
Steps to Reproduce
import Fastify from 'fastify';
import swagger from '@fastify/swagger';
const fastify = Fastify();
fastify.route({
url: '/',
config: { output: 'hello world!' },
method: 'GET',
handler(req, reply) {
reply.send({ hello: 'world' });
},
});
fastify.listen({ port: 3000 });
Online repro: https://stackblitz.com/edit/node-59kmye?file=package.json,index.ts
Expected Behavior
It should be possible to use fastify-swagger without overwriting config types.
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.