Javascript 如何获得;标题「;来自AJV错误?

Javascript 如何获得;标题「;来自AJV错误?,javascript,jsonschema,ajv,Javascript,Jsonschema,Ajv,我有一个JSON模式,如下所示: { "required": [ "instructions" ], "properties": { "instructions": { "title": "Instructions", "minItems": 3, "type": "array", "items": { "required": [ "typeId", "teamId

我有一个JSON模式,如下所示:

{
  "required": [
    "instructions"
  ],
  "properties": {
    "instructions": {
      "title": "Instructions",
      "minItems": 3,
      "type": "array",
      "items": {
        "required": [
          "typeId",
          "teamId",
          "disciplineId"
        ],
        "properties": {
          "typeId": {
            "minimum": 1,
            "title": "Appointment Type",
            "type": "integer"
          },
          "teamId": {
            "minimum": 1,
            "title": "Team",
            "type": "integer"
          },
          "disciplineId": {
            "minimum": 1,
            "title": "Discipline",
            "type": "integer"
          },
          "prefClinicianId": {
            "title": "Pref. Clinician",
            "anyOf": [
              {
                "type": "null"
              },
              {
                "minimum": 1,
                "type": "integer"
              }
            ]
          },
          "prefTime": {
            "title": "Pref. Time",
            "anyOf": [
              {
                "type": "null"
              },
              {
                "type": "integer"
              }
            ]
          },
          "childRequired": {
            "title": "Child Req'd",
            "type": "boolean"
          }
        },
        "type": "object"
      }
    }
  },
  "type": "object"
}
如您所见,我已在所有属性中添加了
title
s。但是,我返回的错误对象如下所示:

[
  {
    "keyword": "minItems",
    "dataPath": ".instructions",
    "schemaPath": "#/properties/instructions/minItems",
    "params": {
      "limit": 3
    },
    "message": "should NOT have less than 3 items"
  },
  {
    "keyword": "type",
    "dataPath": ".instructions[0].typeId",
    "schemaPath": "#/properties/instructions/items/properties/typeId/type",
    "params": {
      "type": "integer"
    },
    "message": "should be integer"
  },
  {
    "keyword": "type",
    "dataPath": ".instructions[0].teamId",
    "schemaPath": "#/properties/instructions/items/properties/teamId/type",
    "params": {
      "type": "integer"
    },
    "message": "should be integer"
  },
  {
    "keyword": "type",
    "dataPath": ".instructions[0].disciplineId",
    "schemaPath": "#/properties/instructions/items/properties/disciplineId/type",
    "params": {
      "type": "integer"
    },
    "message": "should be integer"
  }
]
如您所见,
标题
不在其中。我怎样才能得到有错误的标题


请注意,当您创建AJV对象集时,此问题特定于。

这将为原始模式的ajv错误添加一个
parentSchema
属性。它还将添加一个
schema
属性,该属性包含导致验证失败的特定schema属性

下面是一个例子:

var ajv=新ajv({
$data:true,
详细:正确
});
让模式={
标题:“对象标题”,
类型:“对象”,
特性:{
str:{
标题:“字符串属性”,
类型:“字符串”
}
}
};
让数据={
str:3
};
验证(模式、数据)
console.log('ERRORS:',this.ajv.ERRORS)

创建AJV对象时,请设置

这将为原始模式的ajv错误添加一个
parentSchema
属性。它还将添加一个
schema
属性,该属性包含导致验证失败的特定schema属性

下面是一个例子:

var ajv=新ajv({
$data:true,
详细:正确
});
让模式={
标题:“对象标题”,
类型:“对象”,
特性:{
str:{
标题:“字符串属性”,
类型:“字符串”
}
}
};
让数据={
str:3
};
验证(模式、数据)
console.log('ERRORS:',this.ajv.ERRORS)