JSON模式等效于XSD Maxoccurs
我已经搜索了几个小时,但是找不到查询的示例。我有一个XSD模式(这是一个非常削减的版本),
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Transaction-Header">
<xs:complexType>
<xs:sequence>
<xs:element name="Origin" type="xs:string" minOccurs="1" maxOccurs="1">
</xs:element>
<xs:element name="Type" type="xs:string" minOccurs="0" maxOccurs="1">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Transaction">
<xs:complexType>
<xs:sequence>
<xs:element ref="Transaction-Header" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我将其转换为Jsonschema(这是一个巨大的XSD),并取得了很大的成功。
本质上,总是只有1个交易头 IE
{
"Transaction": {
"Transaction-Header": {
"Origin": "Origin",
"Type": "Type"
}
}
}
无效:
{
"Transaction": {
"Transaction-Header": {
"Origin": "Origin",
"Type": "Type"
},
"Transaction-Header": {
"Origin": "Origin",
"Type": "Type"
}
}
}
我知道这可以通过使用数组Minitems / MaxItems功能来完成,但是这些确实是元素,而不是数组,我真的不想在可能的情况下定义它们。
有人知道这是怎么可能(甚至是)这是可能的吗?
I have been searching around for a few hours now but I can't find examples for the query I have. I have an XSD schema (this is a really cut down version)
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Transaction-Header">
<xs:complexType>
<xs:sequence>
<xs:element name="Origin" type="xs:string" minOccurs="1" maxOccurs="1">
</xs:element>
<xs:element name="Type" type="xs:string" minOccurs="0" maxOccurs="1">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Transaction">
<xs:complexType>
<xs:sequence>
<xs:element ref="Transaction-Header" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I am converting it to JSONSchema (it's a massive xsd) with a lot of success but what I can't seem to figure out is how to incorporate the minOccurs and maxOccurs restrictions.
Essentially, there should always only ever be 1 Transaction-Header
i.e.
{
"Transaction": {
"Transaction-Header": {
"Origin": "Origin",
"Type": "Type"
}
}
}
Invalid:
{
"Transaction": {
"Transaction-Header": {
"Origin": "Origin",
"Type": "Type"
},
"Transaction-Header": {
"Origin": "Origin",
"Type": "Type"
}
}
}
I understand this can be done by using the array minItems / maxItems functionality, but these are really elements and not arrays and I don't really want to have to define them as such if possible.
Anyone know how (or even if) this is possible please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JSON Schema使用JSON文档模型,您的第二个示例不是有效的JSON-属性名称不能出现两次。您必须重命名您的属性,以使其唯一或使用数组。
如果使用数组,则可以使用
包含
和mincontains
/maxContains
来指定数组中项目的限制。JSON Schema uses the JSON document model, and your second example is not valid JSON -- a property name cannot appear twice. You'll have to rename your properties so they are unique, or use an array.
If you use an array, you can use
contains
andminContains
/maxContains
to specify limitations on items in the array.