JSON模板

以JSON对象或数组方法编辑JSON格式的数据格式模板进行判断校验。


JSON是一种数据的组织形式,主要用于数据的传输。可以选择从最近执行历史执行导入生成模板,也可以根据JSON格式定义转换生成模板或根据JSON书写规则写入JSON模板,保存即可。遵循json schema的规则,可以参考json schema官方文档。

如响应body为:

BODY
"{...}":
"name": "487MVH"
"phoneNum": "1542286461188"
"class": "com.arthur.dubboapi.entity.User"
"email": "75768877968@163.com"

JSON模式:

  • 描述现有数据格式。
  • 易于人的阅读编写,也易于机器的解析和生成。
  • 完整的结构验证,有利于自动化测试。
  • 完整的结构验证,可用于验证客户端提交的数据。

JSON类型:

1、数组方式

{
  "definitions": {},
  "$schema": "http://json-schema.org/draft-06/schema#",
  "$id": "http://example.com/root.json",
  "type": "object",
  "title": "The Root Schema",
  "required": [
    "data"
  ],
  "properties": {
    "data": {
      "$id": "#/properties/data",
      "type": "array",
      "title": "The Data Schema",
      "items": {
        "$id": "#/properties/data/items",
        "type": "object",
        "title": "The Items Schema",
        "required": [
          "position_name",
          "level"
        ],
        "properties": {
          "position_name": {
            "$id": "#/properties/data/items/properties/position_name",
            "type": "string",
            "title": "The Position_name Schema",
            "default": "",
            "examples": [
              "杭州"
            ],
            "pattern": "^(.*)$"
          },
          "level": {
            "$id": "#/properties/data/items/properties/level",
            "type": "string",
            "title": "The Level Schema",
            "default": "",
            "examples": [
              "良"
            ],
            "pattern": "^(.*)$"
          }
        }
      }
    }
  }
}

2、对象方式

{
  "definitions": {},
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "http://example.com/root.json",
  "type": "object",
  "title": "The Root Schema",
  "required": [
    "ShortUrl",
    "LongUrl",
    "Code"
  ],
  "properties": {
    "ShortUrl": {
      "$id": "#/properties/ShortUrl",
      "type": "string",
      "title": "The Shorturl Schema",
      "default": "",
      "examples": [
        "https://dwz.cn/oHvt1KD7"
      ],
      "pattern": "^(.*)$"
    },
    "LongUrl": {
      "$id": "#/properties/LongUrl",
      "type": "string",
      "title": "The Longurl Schema",
      "default": "",
      "examples": [
        "https://www.baidu.com/"
      ],
      "pattern": "^(.*)$"
    },
    "Code": {
      "$id": "#/properties/Code",
      "type": "integer",
      "title": "The Code Schema",
      "default": 0,
      "examples": [
        0
      ]
    }
  }
}

若JSON语法书写错误,点击保存则提示:check-body保存失败:JSON模板不合法。建议点击转换,再进行修改JSON模板保存。

注:在接口测试用例校验body使用JSON模板,在场景用例中参数校验才会显示JSON模板校验框,默认判断识别JSON语法格式,并提示。自动保存JSON模板内容。

Copyright © GoApi 2018 all right reserved,powered by Gitbook该文件修订时间: 2023-08-24 14:35:00

results matching ""

    No results matching ""