Skip to content

Commit 48817e7

Browse files
authored
Merge pull request #9 from adanilov-fastec/form_unqualified
Добавил тест, который проверяет аттрибут form=unqualified
2 parents 0864515 + 7c02a9a commit 48817e7

3 files changed

Lines changed: 50 additions & 7 deletions

File tree

__data__/202510/wsdl_112.xsd

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
3+
xmlns:tns="http://eiim.service112.iskratel.si/"
4+
targetNamespace="http://eiim.service112.iskratel.si/"
5+
elementFormDefault="qualified"
6+
attributeFormDefault="unqualified"
7+
>
8+
<xs:element name="Code" type="xs:string"/>
9+
<xs:element name="CodeDescr" type="xs:string"/>
10+
<xs:element name="UpdateCardResponse" type="tns:UpdateCardResponse"/>
11+
12+
<xs:complexType name="UpdateCardResponse">
13+
<xs:sequence>
14+
<xs:element form="unqualified" name="Code" type="xs:string"/>
15+
<xs:element form="unqualified" name="CodeDescr" type="xs:string" minOccurs="0"/>
16+
</xs:sequence>
17+
</xs:complexType>
18+
</xs:schema>

__tests__/XMLMarshaller.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,31 @@ test ('nillable', () => {
315315

316316
})
317317

318+
test ('form="unqualified"', () => {
319+
320+
const xsdPath = Path.join (__dirname, '..', '__data__', '202510', 'wsdl_112.xsd')
321+
322+
const xs = getXSSync (xsdPath)
323+
324+
function stringify (data, options) {
325+
326+
const xml = xs.createMarshaller ('UpdateCardResponse', 'http://eiim.service112.iskratel.si/').stringify (data, options)
327+
328+
execSync (`xmllint --schema ${xsdPath} -`, {input: xml, stdio: 'pipe'})
329+
330+
return xml
331+
332+
}
333+
334+
let xml = stringify ({
335+
"Code": 200,
336+
"CodeDescr": "Descr"
337+
})
338+
339+
expect (xml).toMatch ('<ns2:UpdateCardResponse xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:ns2=\"http://eiim.service112.iskratel.si/\"><Code>200</Code><CodeDescr>Descr</CodeDescr></ns2:UpdateCardResponse>')
340+
341+
})
342+
318343
test ('att simple type', () => {
319344

320345
const xsdPath = Path.join (__dirname, '..', '__data__', 'att.xsd')

lib/XMLSchema.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,18 @@ const XMLSchema = class extends Map {
110110
const {localName} = node
111111

112112
for (const e of node.children) this.copyTargetNamespace (e, localName === 'schema')
113-
113+
114114
const {formDefault} = this; if (!(localName in formDefault)) return
115-
115+
116116
if (!force) {
117-
118-
const {form} = node.attributes
119-
120-
if (form !== FORM_Q && formDefault [localName] !== FORM_Q) return
117+
118+
const form = node.attributes?.form || formDefault [localName]
119+
120+
if (form !== FORM_Q) return
121121

122122
}
123123

124-
node.targetNamespace = this.targetNamespace
124+
node.targetNamespace = this.targetNamespace
125125

126126
}
127127

0 commit comments

Comments
 (0)