[英]json schema faker with fake pattern
I'm using the json-schema-faker and i'm using it with Faker which allows me to get random "real" format values, like emails, image url etc.我正在使用json-schema-faker并且我将它与Faker一起使用,它允许我获得随机的“真实”格式值,如电子邮件、图像 url 等。
this scheme works well:这个方案效果很好:
{
"type": "object",
"properties": {
"myPattern":{
"type": "string",
"pattern": "pattern1||pattern2"
},
"image": {
"type": "string",
"faker": "image.city"
}
},
"required": [
"myPattern",
"image"
]
}
But what i really wants is that the faker
will get a pattern like the property myPattern
gets.但我真正想要的是,
faker
将获得类似于myPattern
获得的属性的模式。
I've tried some variations but none works.我尝试了一些变体,但没有一个奏效。
Some syntax I've tried:我尝试过的一些语法:
"faker": "image.city||image.food"
"faker": {
"fake": {
"pattern": "image.city||image.food"
}
}
- ——
"faker": {
"pattern": "image.city||image.food"
}
when you use:当您使用:
"faker": {
"pattern": "image.city||image.food"
}
the code executed behind will be similar to this: faker.pattern("image.city||image.food")
后面执行的代码类似于:
faker.pattern("image.city||image.food")
To fix your specific case you need to wrap possible variations of faker calls as oneOf
:要解决您的特定情况,您需要将 faker 调用的可能变体包装为
oneOf
:
{
"type": "object",
"properties": {
"myPattern":{
"type": "string",
"pattern": "pattern1||pattern2"
},
"image": {
"type": "string",
"oneOf": [
{ "faker": "image.city" },
{ "faker": "image.food" }
]
}
},
"required": [
"myPattern",
"image"
]
}
It seems to be working now: http://json-schema-faker.js.org/#gist/9c5cb08965aeeb46b11ca6856251aa80/0.4.3它现在似乎正在工作: http : //json-schema-faker.js.org/#gist/9c5cb08965aeeb46b11ca6856251aa80/0.4.3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.