fastify 无法序列化具有流畅 json 模式的响应模式 FST_ERR_SCH_SERIALIZATION_BUILD data.properties 应该是对象

fastify fail to serialize response schema with fluent json schema FST_ERR_SCH_SERIALIZATION_BUILD data.properties should be object

这是我的路线

app.patch(
  `/${root}/item/:itemId`,
  {
    schema: item_schema,
  },
  items // controller
);

这是我的架构文件

import schema from "fluent-json-schema";
const body = schema
  .object()
  .prop(
    "itemTitle",
    schema.string().required()
  );

const response = schema
  .object()
  .prop(
    "payload",
    schema
      .object()
      .prop("itemTitle",schema.string().required())
  );

export item_schema = {
  body,
  response,
};

问题在于响应

"msg":"Failed building the serialization schema for PATCH: /v4/item/:itemId, due to error schema is invalid: data.properties should be object"

我试过做出简单的回应,它奏效了

  const response = {
    response: {
      type: "object",
      properties: {
        payload: {
          type: "object",
          properties: {
            itemTitle: { type: "string" },
          },
          required:["itemTitle"]
        },
      },
    },
  };

现在我正在尝试使用流畅的模式来完成它,但仍然出现错误

缺少响应包装器:

const response = {
  response: schema
    .object()
    .prop(
      "payload",
      schema
        .object()
        .prop(
          "deactivation_reason",
          schema.string().maxLength(255).minLength(10)
        )
    ),
};