fastify / fastify-swagger

Swagger documentation generator for Fastify
MIT License
889 stars 199 forks source link

Included types break usage of config object #784

Open tmcw opened 4 months ago

tmcw commented 4 months ago

Prerequisites

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.

mcollina commented 4 months ago

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.