utils/xml: fix parsing of simpleContent XML schema (#63191)
This commit is contained in:
parent
7d30f3fcf9
commit
fb7fcf5f88
|
@ -337,8 +337,9 @@ class JSONSchemaFromXMLSchema:
|
||||||
if not xmltype.attributes:
|
if not xmltype.attributes:
|
||||||
schema = base_schema
|
schema = base_schema
|
||||||
else:
|
else:
|
||||||
cls.attributegroup_to_jsonschema(xmltype.attributes) # pylint: disable=no-value-for-parameter
|
schema = OrderedDict({'type': 'object', 'properties': OrderedDict()})
|
||||||
schema['properties']['$'] = base_schema
|
schema['properties']['$'] = base_schema
|
||||||
|
cls.attributegroup_to_jsonschema(xmltype.attributes, schema)
|
||||||
return schema
|
return schema
|
||||||
else:
|
else:
|
||||||
if xmltype.has_mixed_content() or xmltype.name == xmlschema_names.XSD_ANY_TYPE:
|
if xmltype.has_mixed_content() or xmltype.name == xmlschema_names.XSD_ANY_TYPE:
|
||||||
|
|
|
@ -0,0 +1,146 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||||
|
<xs:element name="PACS" type="PacsType"/>
|
||||||
|
<xs:simpleType name="testSimpleType">
|
||||||
|
<xs:restriction base="xs:integer">
|
||||||
|
<xs:minInclusive value="0"/>
|
||||||
|
<xs:maxInclusive value="1000"/>
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
<xs:complexType name="PacsType">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="partenaire1" type="PartenaireType" />
|
||||||
|
<xs:element name="partenaire2" type="PartenaireType" />
|
||||||
|
<xs:element name="convention" type="ConventionType" maxOccurs="1" minOccurs="1" />
|
||||||
|
<xs:element name="residenceCommune" type="AdresseType" />
|
||||||
|
<xs:element name="attestationHonneur" type="AttestationHonneurType" />
|
||||||
|
<!-- extending a simple content element with an attribute -->
|
||||||
|
<xs:element name="testSimpleContent" minOccurs="0">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:simpleContent>
|
||||||
|
<!-- populationType is a simple type -->
|
||||||
|
<xs:extension base="testSimpleType">
|
||||||
|
<xs:attribute name="attribute" type="xs:string" use="required"/>
|
||||||
|
</xs:extension>
|
||||||
|
</xs:simpleContent>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
<xs:complexType name = "AttestationHonneurType">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="nonParente" type="xs:boolean"/>
|
||||||
|
<xs:element name="residenceCommune" type="xs:boolean"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
<xs:complexType name="PartenaireType">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="civilite" type="CiviliteType"></xs:element>
|
||||||
|
<xs:element name="nomNaissance" type="xs:string" />
|
||||||
|
<xs:element name="prenoms" type="xs:string" />
|
||||||
|
<xs:element name="codeNationalite" type="xs:string" maxOccurs="unbounded"/>
|
||||||
|
<xs:element name="jourNaissance" type="xs:integer" maxOccurs="1" minOccurs="0" />
|
||||||
|
<xs:element name="moisNaissance" type="xs:integer" maxOccurs="1" minOccurs="0" />
|
||||||
|
<xs:element name="anneeNaissance" type="xs:integer" />
|
||||||
|
<xs:element name="LieuNaissance" type="LieuNaissanceType" />
|
||||||
|
<xs:element name="ofpra" type="xs:boolean" />
|
||||||
|
<xs:element name="mesureJuridique" type="xs:boolean" />
|
||||||
|
<xs:element name="adressePostale" type="AdresseType" />
|
||||||
|
<xs:element name="adresseElectronique" type="xs:string" />
|
||||||
|
<xs:element name="telephone" type="xs:string" minOccurs="0"/>
|
||||||
|
<xs:element name="filiationParent1" type="FiliationType" minOccurs="0"/>
|
||||||
|
<xs:element name="filiationParent2" type="FiliationType" minOccurs="0" />
|
||||||
|
<xs:element name="titreIdentiteVerifie" type="xs:boolean"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
<xs:complexType name="ConventionType">
|
||||||
|
<xs:choice>
|
||||||
|
<xs:element name="conventionType" type="ConventionTypeType" />
|
||||||
|
<xs:element name="conventionSpecifique" type="xs:boolean" />
|
||||||
|
</xs:choice>
|
||||||
|
</xs:complexType>
|
||||||
|
<xs:complexType name="ConventionTypeType">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="aideMaterielMontant" type="xs:double" maxOccurs="1" minOccurs="0"/>
|
||||||
|
<xs:element name="regimePacs" type="regimePacsType" />
|
||||||
|
<xs:element name="aideMateriel" type="AideMaterielType" />
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
<xs:complexType name="AdresseType">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="NumeroLibelleVoie" type="xs:string" minOccurs="0" />
|
||||||
|
<xs:element name="Complement1" type="xs:string" minOccurs="0" />
|
||||||
|
<xs:element name="Complement2" type="xs:string" minOccurs="0" />
|
||||||
|
<xs:element name="LieuDitBpCommuneDeleguee" type="xs:string" minOccurs="0" />
|
||||||
|
<xs:element name="CodePostal" type="codePostalType" />
|
||||||
|
<xs:element name="Localite" type="localiteType" />
|
||||||
|
<xs:element name="Pays" type="xs:string" />
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
<xs:complexType name="LieuNaissanceType">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="localite" type="localiteType"/>
|
||||||
|
<xs:element name="codePostal" type="xs:string"/>
|
||||||
|
<xs:element name="codeInsee" type="xs:string" minOccurs="0"/>
|
||||||
|
<xs:element name="departement" type="xs:string" maxOccurs="1" minOccurs="0"/>
|
||||||
|
<xs:element name="codePays" type="xs:string"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
<xs:simpleType name="localiteType">
|
||||||
|
<xs:restriction base="xs:string">
|
||||||
|
<xs:minLength value="1" />
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
<xs:simpleType name="codePostalType">
|
||||||
|
<xs:restriction base="xs:string">
|
||||||
|
<xs:length value="5" />
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
<xs:simpleType name="regimePacsType">
|
||||||
|
<xs:restriction base="xs:string">
|
||||||
|
<xs:enumeration value="indivision"/>
|
||||||
|
<xs:enumeration value="legal"/>
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
<xs:complexType name="FiliationType">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:choice>
|
||||||
|
<xs:element name="filiationInconnu" type="xs:boolean"></xs:element>
|
||||||
|
<xs:element name="filiationConnu" type="FiliationConnuType">
|
||||||
|
</xs:element>
|
||||||
|
</xs:choice>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
<xs:simpleType name="CiviliteType">
|
||||||
|
<xs:restriction base="xs:string">
|
||||||
|
<xs:enumeration value="M"></xs:enumeration>
|
||||||
|
<xs:enumeration value="MME"></xs:enumeration>
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
<xs:simpleType name="TypeAideMaterielType">
|
||||||
|
<xs:restriction base="xs:string">
|
||||||
|
<xs:enumeration value="aideFixe"/>
|
||||||
|
<xs:enumeration value="aideProportionnel"/>
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
<xs:complexType name="AideMaterielType">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="typeAideMateriel" type="TypeAideMaterielType"></xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
<xs:complexType name="FiliationConnuType">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="sexe" type="SexeType"/>
|
||||||
|
<xs:element name="nomNaissance" type="xs:string" maxOccurs="1" minOccurs="0" />
|
||||||
|
<xs:element name="prenoms" type="xs:string" maxOccurs="1" minOccurs="0" />
|
||||||
|
<xs:element name="dateNaissance" type="xs:string" maxOccurs="1" minOccurs="0" />
|
||||||
|
<xs:element name="lieuNaissance" type="LieuNaissanceType" maxOccurs="1" minOccurs="0" />
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
<xs:simpleType name="SexeType">
|
||||||
|
<xs:restriction base="xs:string">
|
||||||
|
<xs:enumeration value="M"/>
|
||||||
|
<xs:enumeration value="F"/>
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
</xs:schema>
|
|
@ -15,6 +15,8 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
from collections import OrderedDict
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
import jsonschema
|
import jsonschema
|
||||||
import xmlschema
|
import xmlschema
|
||||||
|
@ -56,7 +58,7 @@ def test_to_json():
|
||||||
|
|
||||||
|
|
||||||
def test_xmlschema_to_jsonschema():
|
def test_xmlschema_to_jsonschema():
|
||||||
schema_path = 'passerelle/apps/sp_fr/depotDossierPACS.XSD'
|
schema_path = 'tests/exemple.xsd'
|
||||||
|
|
||||||
# go from XML to JSON,
|
# go from XML to JSON,
|
||||||
# convert XMLSchema to JSONSchema
|
# convert XMLSchema to JSONSchema
|
||||||
|
@ -82,3 +84,23 @@ def test_xmlschema_to_jsonschema():
|
||||||
tree = schema.elements['PACS'].encode(d2['PACS'], converter=xmlschema.UnorderedConverter)
|
tree = schema.elements['PACS'].encode(d2['PACS'], converter=xmlschema.UnorderedConverter)
|
||||||
d3 = schema.elements['PACS'].decode(tree)
|
d3 = schema.elements['PACS'].decode(tree)
|
||||||
assert d == {'PACS': d3}
|
assert d == {'PACS': d3}
|
||||||
|
|
||||||
|
assert json_schema.json_schema['properties']['PACS']['properties']['testSimpleContent'] == OrderedDict(
|
||||||
|
[
|
||||||
|
('type', 'object'),
|
||||||
|
(
|
||||||
|
'properties',
|
||||||
|
OrderedDict(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
'$',
|
||||||
|
OrderedDict(
|
||||||
|
[('type', 'integer'), ('minimum', Decimal('0')), ('maximum', Decimal('1000'))]
|
||||||
|
),
|
||||||
|
),
|
||||||
|
('attribute', {'type': 'string'}),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue