为什么fastify路由中没有其他成功的状态码?

问题描述 投票:0回答:1

所以我使用

fastify.route
创建了一条 fastify 路线。但我无法在响应中返回
201
statusCode。即使我返回 201 statusCode,它也会转换为 200 。

fastify.route({
  method: 'GET',
  url: '/',
  schema: {
    querystring: {
      name: { type: 'string' },
      excitement: { type: 'integer' }
    },
    response: {
      200: {
        type: 'object',
        properties: {
          hello: { type: 'string' }
        }
      }
    }
  },
  handler: function (request, reply) {
    reply.send({ hello: 'world' })
  }
})

编辑

我指的是 swagger 的代码

response: {
      200: {
        type: 'object',
        properties: {
          hello: { type: 'string' }
        }
      }
    }

这里我想用 201 替换 200,并给出必填字段,但似乎并没有像想象中那样抛出错误

这搞乱了我的发帖请求。

node.js fastify
1个回答
0
投票

我有同样的问题,似乎FastifySchema只支持200序列化并给出成功的响应

© www.soinside.com 2019 - 2024. All rights reserved.