【发布时间】:2019-07-25 23:32:01
【问题描述】:
从我的previous unresolved issue 继续,我正在使用json-schema-faker 和json-server,我目前正在尝试重用我的 json 架构中的一些数据。
我在 Github 的 this 页面中找到了属性:jsonPath,它准确地解释了我想要做什么以及我的问题是什么。
我正在尝试从生成这些数据的 JavaScript 应用程序以及我使用的库 json-schema-faker site 测试此属性。使用上述任何一种方式使用此属性,返回一个随机字符串而不是我所指的 id ("jsonPath": "$..properties.test.items.properties.id")
使用this 站点进行验证不会导致任何问题,并且使用jsonPath 可以正确获取我尝试重复使用的值。
我应该在我的 JavaScript 代码/模拟数据生成器中导入什么,或者我想要做的事情可能不受 json-schema 版本的支持?
我尝试使用的一些路径是:
$..id
$..test.items.properties.id
$..test.id
这是我的 json 架构:
{
"title": "teest",
"type": "object",
"required": [
"test"
],
"properties": {
"test": {
"type": "array",
"minItems": 1,
"maxItems": 3,
"uniqueItems": true,
"items": {
"type": "object",
"required": [
"id",
"samples"
],
"properties": {
"id": {
"type": "string",
"enum": [
"1,",
"2",
"3"
]
},
"samples": {
"type": "array",
"uniqueItems": true,
"items": {
"type": "object",
"properties": {
"test2": {
"type": "string",
"jsonPath": "$..properties.test.items.properties.id"
}
}
}
}
}
}
}
}
}
如果我在网上找不到任何帮助,我将不胜感激,而且我真的不想使用硬编码值来模拟这些数据。
【问题讨论】:
-
我不确定
jsonPath在这个库的上下文中做了什么。它不是标准的 JSON Schema 关键字。您是否尝试过在 json-schema-faker GitHub 存储库上提出问题?您肯定会在那里找到更多了解该图书馆的人。 -
我想我应该重新打开我在此处发布的 github 问题,或者按照您的建议打开一个新问题。感谢您的回复。
标签: javascript json mocking jsonschema faker