Closed
Description
💬 Question here
By default, fastify allows the request body to have additional properties but by default the response has any additional properties removed. I could not find some documentation on this.
Is there a simple way to allow additional properties on all responses similar to the default for request bodies? Thanks.
const Fastify = require('fastify');
const fOpts = {};
const fastify = Fastify(fOpts);
const schema = {
description: 'test',
body: {
type: 'object',
properties: {
test1: { type: 'string' },
},
},
response: {
200: {
type: 'object',
properties: {
test3: { type: 'string' },
},
},
},
};
fastify.post('/test', { schema }, async (req: any, res: any) => {
console.log({
body: req.body,
})
// curl -X POST http://localhost:3003/test \
// -H "Content-Type: application/json" \
// -d '{
// "test1": "test1",
// "test2": "test2"
// }'
// { body: { test1: 'test1', test2: 'test2' } }
return res.status(200).send({
test3: 'test3',
test4: 'test4',
});
// client receives: {"test3":"test3"}
});
const run = async () => {
await fastify.listen({
host: 'localhost',
port: 3003,
});
};
run();
export { };
Your Environment
- node version: 18
- fastify version: 4.28.1
- os: Windows
- any other relevant information