You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XSD转JSON Schema转换器未正确识别必填字段问题反馈

XSD转JSON Schema转换器的必填字段遗漏问题

当XSD元素设置为minOccurs >= 1(或使用默认值,XSD元素默认minOccurs为1)时,XSD to JSON Schema Converter会错误地将这类元素转换为JSON Schema中的可选字段。以下示例中,TestDocument.Name和TestDocument.Address.Line就没有被纳入对应的必填属性列表。

XML Schema示例

<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid Studio-->
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element id="TD0001" name="TestDocument">
        <xs:complexType>
            <xs:sequence>
                <xs:element id="TE0003" name="Address">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="CityName" type="xs:string" minOccurs="0" />
                            <xs:element name="Line" type="xs:string" maxOccurs="2" />
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element id="TE0002" name="Name" type="xs:string" maxOccurs="2" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Liquid Studio输出的JSON Schema

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
        "TestDocument": {
            "$ref": "#/$defs/TestDocument"
        }
    },
    "additionalProperties": false,
    "required": [
        "TestDocument"
    ],
    "$defs": {
        "TestDocument": {
            "type": "object",
            "properties": {
                "Address": {
                    "type": "object",
                    "properties": {
                        "CityName": {
                            "type": "string"
                        },
                        "Line": {
                            "type": "array",
                            "maxItems": 2,
                            "minItems": 1,
                            "items": {
                                "type": "string"
                            }
                        }
                    },
                    "additionalProperties": false
                },
                "Name": {
                    "type": "array",
                    "maxItems": 2,
                    "minItems": 1,
                    "items": {
                        "type": "string"
                    }
                }
            },
            "additionalProperties": false,
            "required": [
                "Address"
            ]
        }
    }
}

问题点说明

在上述XSD中:

  • TestDocument.Name未指定minOccurs,遵循XSD默认规则即minOccurs="1",属于必填元素;
  • TestDocument.Address.Line同样默认minOccurs="1",且允许最多出现2次,也属于必填元素。

但转换后的JSON Schema中:

  • $defs.TestDocument的required数组仅包含Address,遗漏了Name;
  • $defs.TestDocument.properties.Address的required数组为空,遗漏了Line。

这导致原本在XSD中必填的字段,在JSON Schema中变成了可选字段,违反了原XSD的约束逻辑。

内容的提问来源于stack exchange,提问作者BaKaSo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 18:55:07