Skip to content

How i can pass fastify response schema from nest to fastify? #4149

@femike

Description

@femike

May be have decorator?
May be in the nest it differently?
Or where i can pass router schema data to fastify?

For example:
In Nest

@Post()
login() {
// get user bla bla bla
user = { password: 'changeme', username: 'admin' }
const { password, ..data } = user;
return data;
}

response return { username: 'admin' }

in Fastify

fastify.route({ url: '/login', method: ["GET"],
schema: {
  response: {
    201: {
       type: 'object',
       properties: { username: {type: 'string' } }
   }
},
handler: (req, resp) {
   // get user bla bla bla
   user = { password: 'changeme', username: 'admin' }
   return resp.code(201).send(user);
}

response return { username: 'admin' } without password according to the scheme

Sorry for google translate eng.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions