gpt4 book ai didi

c# - 如何在字典值上强制使用正则表达式模式(njsonschema)

转载 作者:太空宇宙 更新时间:2023-11-03 15:03:17 26 4
gpt4 key购买 nike

使用 njsonschema ,我想生成一个模式,以确保写入字典的所有值都将根据正则表达式模式进行验证。

考虑以下类:

class File
{
[RegularExpression("^\\d+\\.\\d+\\.\\d+\\.\\d+$")]
public Dictionary<string, string> Versions { get; set; }
}

我希望 njsonschema 生成的模式部分是:

"Versions": {
"type": "object",
"additionalProperties": {
"type": "string",
"pattern": "^\\d+\\.\\d+\\.\\d+\\.\\d+$"
}
}

Instaed,njsonschema 生成如下内容:

"Versions": {
"type": "object",
"pattern": "^\\d+\\.\\d+\\.\\d+\\.\\d+$",
"additionalProperties": {
"type": "string"
}
}

有什么办法可以实现吗?

提前致谢!

最佳答案

此问题已在本次提交中修复:

https://github.com/RSuter/NJsonSchema/commit/fa1b36b68bb5ad7ec005b2a77002a5668d1aa2b4

已发布包含此修复的 NJsonSchema (v9.4.4+) 版本...

关于c# - 如何在字典值上强制使用正则表达式模式(njsonschema),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45014613/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com