1
1
/* eslint-disable */
2
2
const _ = require ( 'lodash' ) ;
3
3
4
- function convertSchemaToXML ( name , schema , attribute , indentChar , inden ) {
4
+ function convertSchemaToXML ( name , schema , attribute , indentChar , indent ) {
5
5
var tagPrefix = '' ,
6
- cInden = _ . times ( inden , _ . constant ( indentChar ) ) . join ( '' ) ;
6
+ cIndent = _ . times ( indent , _ . constant ( indentChar ) ) . join ( '' ) ;
7
7
name = _ . get ( schema , 'xml.name' , name || 'element' ) ;
8
8
if ( _ . get ( schema , 'xml.prefix' ) ) {
9
9
tagPrefix = schema . xml . prefix ? `${ schema . xml . prefix } :` : '' ;
@@ -25,26 +25,26 @@ function convertSchemaToXML(name, schema, attribute, indentChar, inden) {
25
25
return actualValue ;
26
26
}
27
27
else {
28
- var retVal = '\n' + cInden + '<' + tagPrefix + name ;
28
+ var retVal = `\n ${ cIndent } < ${ tagPrefix + name } ` ;
29
29
if ( _ . get ( schema , 'xml.namespace' ) ) {
30
- retVal += ' xmlns:' + tagPrefix . slice ( 0 , - 1 ) + '="' + schema . xml . namespace + '"'
30
+ retVal += ` xmlns:${ tagPrefix . slice ( 0 , - 1 ) } =" ${ schema . xml . namespace } "`
31
31
}
32
- retVal += '>' + actualValue + '</' + tagPrefix + name + '>' ;
32
+ retVal += `> ${ actualValue } </ ${ tagPrefix } ${ name } >` ;
33
33
}
34
34
}
35
35
else if ( schema . type === 'object' ) {
36
36
// go through all properties
37
- var retVal = '\n' + cInden + `<${ tagPrefix } ${ name } ` , propVal , attributes = [ ] , childNodes = '' ;
37
+ var retVal = '\n' + cIndent + `<${ tagPrefix } ${ name } ` , propVal , attributes = [ ] , childNodes = '' ;
38
38
if ( _ . get ( schema , 'xml.namespace' ) ) {
39
39
let formattedTagPrefix = tagPrefix ?
40
40
`:${ tagPrefix . slice ( 0 , - 1 ) } ` :
41
41
'' ;
42
42
retVal += ` xmlns${ formattedTagPrefix } ="${ schema . xml . namespace } "`
43
43
}
44
44
_ . forOwn ( schema . properties , ( value , key ) => {
45
- propVal = convertSchemaToXML ( key , value , _ . get ( value , 'xml.attribute' ) , indentChar , inden + 1 ) ;
45
+ propVal = convertSchemaToXML ( key , value , _ . get ( value , 'xml.attribute' ) , indentChar , indent + 1 ) ;
46
46
if ( _ . get ( value , 'xml.attribute' ) ) {
47
- attributes . push ( key + '="' + propVal + '"' ) ;
47
+ attributes . push ( ` ${ key } =" ${ propVal } "` ) ;
48
48
}
49
49
else {
50
50
childNodes += propVal ;
@@ -55,19 +55,21 @@ function convertSchemaToXML(name, schema, attribute, indentChar, inden) {
55
55
}
56
56
retVal += '>' ;
57
57
retVal += childNodes ;
58
- retVal += `\n${ cInden } </${ tagPrefix + name } >` ;
58
+ retVal += `\n${ cIndent } </${ tagPrefix } ${ name } >` ;
59
59
}
60
60
else if ( schema . type === 'array' ) {
61
61
// schema.items must be an object
62
62
var isWrapped = _ . get ( schema , 'xml.wrapped' ) ,
63
- extraIndent = isWrapped ? 1 : 0 ;
64
- var arrayElemName = _ . get ( schema , 'items.xml.name' , name , 'arrayItem' ) ;
65
- var schemaItemsWithXmlProps = _ . cloneDeep ( schema . items ) ;
63
+ extraIndent = isWrapped ? 1 : 0 ,
64
+ arrayElemName = _ . get ( schema , 'items.xml.name' , name , 'arrayItem' ) ,
65
+ schemaItemsWithXmlProps = _ . cloneDeep ( schema . items ) ,
66
+ contents ;
67
+
66
68
schemaItemsWithXmlProps . xml = schema . xml ;
67
- var contents = convertSchemaToXML ( arrayElemName , schemaItemsWithXmlProps , false , indentChar , inden + extraIndent ) +
68
- convertSchemaToXML ( arrayElemName , schemaItemsWithXmlProps , false , indentChar , inden + extraIndent ) ;
69
+ contents = convertSchemaToXML ( arrayElemName , schemaItemsWithXmlProps , false , indentChar , indent + extraIndent ) +
70
+ convertSchemaToXML ( arrayElemName , schemaItemsWithXmlProps , false , indentChar , indent + extraIndent ) ;
69
71
if ( isWrapped ) {
70
- return `\n${ cInden } <${ tagPrefix } ${ name } >${ contents } \n${ cInden } </${ tagPrefix } ${ name } >` ;
72
+ return `\n${ cIndent } <${ tagPrefix } ${ name } >${ contents } \n${ cIndent } </${ tagPrefix } ${ name } >` ;
71
73
}
72
74
else {
73
75
return contents ;
0 commit comments