【发布时间】:2019-07-11 02:03:03
【问题描述】:
我正在空手道下面尝试。
我在 .json 文件中有一个 json 架构(用于响应验证)。在许多模式中,很少有常见的 REGEX。我想将它们作为键值对提取到一个通用文件中,并在其他模式中使用它。是否可以?如果是这样,我该怎么做? json 模式中是否允许模板化?
示例:
示例 Json 架构文件 (sample-response.json):
{
"response": {
"name": "#string",
"amount": "#regex ^(-?)([0]|[1-9][0-9]{0,15})[.][0-9]{2}$"
}
}
功能文件
Feature: Example feature
Background:
* def sampleResponse = read('./sample-response.json');
Scenario: Example scenario
When url 'https://someurl.com'
And method get
Then status 200
And match response == sampleResponse
我想做什么?
我想将数量正则表达式存储在 json 文件中作为可重用变量,并使用 json 文件中的模板来替换它。 是否可以?
{
"response": {
"name": "#string",
"amount": "{{get regex from this template}}"
}
}
【问题讨论】:
-
编辑你的问题,给出一两个简单的例子,然后再试一次。另请阅读:stackoverflow.com/help/minimal-reproducible-example
-
嗨@PeterThomas,更新了更多细节
-
您可以在 JSON Schema 中使用 $ref 关键字来引用其他 JSON Schema 文件的部分内容。抱歉,我现在无法提供更多详细信息。
标签: jsonschema karate