邮差Json Schema验证失败

时间:2018-04-23 09:51:54

标签: json api automated-tests postman

我有这个小问题。我正在与邮递员一起构建API测试。 我的一个测试想要验证Json响应。

这是我收到的回应:

SecurityContextHolder.getcontext().setAuthentication(null)

所以我收到了一个像上面这样的对象数组。 这是我写的测试:

       {
        "comuni": [
         {
        "istat": "015002",
        "code": "A010",
        "comune": "ABBIATEGRASSO",
        "provincia": "MI",
        "cap": "20081",
        "latitude": 45.393036,
        "longitude": 8.919824,
        "soppresso": false,
        "regione": "Lombardia",
        "parte_italia": "nord",
        "is_provincia": 0,
        "nome_provincia": "Milano"
    },
    ...
    ...
    ]};

但测试失败了:

  

架构验证失败:未知属性(不在架构中)

显然我对架构做错了,但我不明白是什么。

1 个答案:

答案 0 :(得分:1)

您的架构不正确。它应该是这样的。

{
 "description": "Any validation failures are shown in the right-hand Messages pane.",
"type": "object",
"properties": {
 "foo": {
  "type": "number"
},
"bar": {
  "type": "string",
  "enum": [
    "a",
    "b",
    "c"
    ]
 }
 }
}

数据看起来应该是,

{
"foo": 12345,
"bar": "a"
}

请参阅以下链接了解更多examples,例如数组/对象等。

相关问题