Fastify: schema with key or id already exist

Created on 3 May 2018  路  3Comments  路  Source: fastify/fastify

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();
}

What was the result you received?

Error: schema with key or id "UserDisplay" already exists

What did you expect?

Route registered with success

Context

  • node version: 10.0.0
  • fastify version: >=1.3.1
  • os: Mac
bug

All 3 comments

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 !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sebdeckers picture sebdeckers  路  4Comments

mcollina picture mcollina  路  3Comments

rqbazan picture rqbazan  路  3Comments

lfurzewaddock picture lfurzewaddock  路  3Comments

Jegannathan picture Jegannathan  路  3Comments