本文介绍了为什么空手道 tf 在 POST 请求时从输入 json 中删除 1 个父块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在以下前提条件下执行 POST 请求:json 有 2 个具有相同概念名称但属性不同的父概念,例如

I need to execute POST request with the following preconditions:json has 2 parent concepts with the same concept name, but different properties, like

{
"dictionary": {
 "concept": {
   "c1": {
    "logicalName": "c1",
    "isNull": true
   },
   "c1": {
    "logicalName": "c1",
    "isNull": false
   }
 }
}}

但是在发布请求之后,我观察到第一个带有 json 属性isNull"的概念:true 被删除了.但我希望在这种情况下系统会失败并显示正确的错误代码并显示正确的验证消息.

but after post request i observed that 1st concept with json property "isNull": true was removed. But i'm expecting that in this case system will fail with proper error code and shown proper validation message.

我仔细检查了常规 cURL 和来自文件的相同输入 json - 一切看起来都很好.

i double checked with the regular cURL and the same input json from file - everything looks fine.

为什么空手道从 json 输入中删除了 1 个块?可以请教吗?

Why karate removes 1 block from json input?Could you please advice?

谢谢

推荐答案

这是无效的 JSON.如果您希望 Karate 不解析 JSON 我猜是否定测试",请使用 文本.

This is invalid JSON. If you want Karate to not parse the JSON I guess for a "negative test", please use text.

* url 'https://httpbin.org/anything'
* text body =
"""
{
   "dictionary":{
      "concept":{
         "c1":{
            "logicalName":"c1",
            "isNull":true
         },
         "c1":{
            "logicalName":"c1",
            "isNull":false
         }
      }
   }
}
"""
* header Content-Type = 'application/json'
* request body
* method post

即使请求日志可能显示有效"JSON,你可以运行上面的请求,看到响应echo"实际请求 - 这将是您想要的.

Even though the request log may show "valid" JSON, you can run the above request and see the response "echo" the actual request - which will be what you want.

14:47:03.100 [main] DEBUG com.intuit.karate - response time in milliseconds: 1219
1 < 200
1 < Date: Mon, 12 Jul 2021 09:17:03 GMT
1 < Content-Type: application/json
1 < Content-Length: 871
1 < Connection: keep-alive
1 < Server: gunicorn/19.9.0
1 < Access-Control-Allow-Origin: *
1 < Access-Control-Allow-Credentials: true
{"args":{},"data":"{\n   \"dictionary\":{\n      \"concept\":{\n         \"c1\":{\n            \"logicalName\":\"c1\",\n            \"isNull\":true\n         },\n         \"c1\":{\n            \"logicalName\":\"c1\",\n            \"isNull\":false\n         }\n      }\n   }\n}", "more": "..."}

这篇关于为什么空手道 tf 在 POST 请求时从输入 json 中删除 1 个父块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 23:25