JSON-SCHEMA:获取额外的Properties列表?
是否可以获取 json-schema 找到的所有 additionalProperties
的列表?
例如,如果我的架构如下所示:
{
"type": "object",
"properties": {
"firstName": {
"type": "string",
},
"lastName": {
"type": "string",
},
"age": {
"type": "integer"
}
}
}
并且数据如下所示:
{
"firstName": "John",
"lastName": "Doe",
"age": 21,
"extraField": "some new data I was not expecting",
"anotherExtraField": "another unexpected data point"
}
在这种情况下,我想要一个列表作为返回,而不是由于 additionalProperties: false
而导致 json-schema 异常: [额外字段,另一个额外字段]
Is it possible to get a list of all additionalProperties
found by json-schema ?
For example, if my schema looks like this :
{
"type": "object",
"properties": {
"firstName": {
"type": "string",
},
"lastName": {
"type": "string",
},
"age": {
"type": "integer"
}
}
}
And data loooks like this :
{
"firstName": "John",
"lastName": "Doe",
"age": 21,
"extraField": "some new data I was not expecting",
"anotherExtraField": "another unexpected data point"
}
In this case, instead of an exception from json-schema because of additionalProperties: false
, I want a list in return, like : [extraField, anotherExtraField]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是支持带有注释的2019-09或2020-12的实现,那么您很幸运!
附加Properties
应产生其验证属性的注释结果( spec )。如果添加
附加Properties:true
,则所有额外的属性通过并通过关键字进行验证,这意味着应在注释结果中列出这些额外的属性。这会产生(在
详细
输出格式中)您可以在
如果您不使用.NET,则可以浏览实现页面其他库。其中一些也可能支持注释,但我不确定哪个是。
If you're using an implementation that supports 2019-09 or 2020-12 with annotations, you're in luck!
additionalProperties
should produce an annotation result of the properties it validates (spec).If you add
additionalProperties: true
, then all extra properties pass and are validated by the keyword, which means those extra properties should be listed in the annotation result.This yields (in the
Detailed
output format)You can try it on https://json-everything.net, which is powered by my validator, JsonSchema.Net.
If you're not using .Net, you can browse the implementations page for other libraries. Some of them may also support annotations, but I'm not sure which do.