When reusing a schema added with fastify.addSchema directly in response, fastify throw Error: schema with key or id "UserDisplay" already exists. It works if I try to encapsulate the result in {type:'array', items: 'ref#'}
const schema = {
GET: {
response: {
200: {
type: 'array',
items: 'UserDisplay#'
}
}
},
POST: {
body: 'UserCreate#',
response: {
200: 'UserDisplay#' // Works if I replace it with the same response schema as GET
}
}
};
export default function(fastify, opts, next) {
fastify.get('/', { schema: schema.GET }, getUserList);
fastify.post('/', { schema: schema.POST }, createUser);
next();
}
Error: schema with key or id "UserDisplay" already exists
Route registered with success
I can reproduce it, I'll investigate. Thank you for reporting!
It should be solved now, you just need to update your dependencies.
I've opened a pr with your test case, thanks for reporting!
Yep, works with the new version of fast-json-stringify. Thanks !