@@ -1086,7 +1086,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
10861086 name ,
10871087 opts . properties
10881088 ) ;
1089- this . _xmlProcessDataProperty ( doc , main , item , xmlName || name , isWrapped ) ;
1089+ this . _xmlProcessDataProperty ( doc , main , item , xmlName || name , { isWrapped } ) ;
10901090 }
10911091 const s = new XMLSerializer ( ) ;
10921092 let value = s . serializeToString ( doc ) ;
@@ -1576,6 +1576,14 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
15761576 return undefined ;
15771577 }
15781578
1579+ _nameTagWithPrefix ( name , prefix ) {
1580+ let type = normalizeXmlTagName ( name ) ;
1581+ if ( prefix ) {
1582+ type = `${ prefix } :${ type } `
1583+ }
1584+ return type
1585+ }
1586+
15791587 /**
15801588 * Computes example from a range's properties for XML media type.
15811589 *
@@ -1587,14 +1595,13 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
15871595 * @return {String }
15881596 */
15891597 _xmlExampleFromProperties ( properties , typeName , parentType , xmlNamespace , xmlPrefix ) {
1590- const type = normalizeXmlTagName ( typeName ) ;
1598+ const type = this . _nameTagWithPrefix ( typeName , xmlPrefix )
15911599 let parent = parentType ;
15921600 if ( parent ) {
15931601 parent = normalizeXmlTagName ( parent ) ;
15941602 }
1595- const namespace = xmlNamespace ? `${ xmlPrefix } :${ xmlNamespace } ` : '' ;
15961603 const doc = document . implementation . createDocument (
1597- namespace ,
1604+ xmlNamespace ,
15981605 parent || type ,
15991606 null
16001607 ) ;
@@ -1646,6 +1653,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
16461653 isWrapped = false ,
16471654 xmlAttribute,
16481655 xmlName,
1656+ xmlPrefix
16491657 } = this . _computeXmlSerializationData ( serialization ) ;
16501658 const eKey = this . _getAmfKey ( this . ns . aml . vocabularies . apiContract . examples ) ;
16511659 const examples = this . _ensureArray ( range [ eKey ] ) ;
@@ -1657,7 +1665,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
16571665 this . ns . w3 . shacl . name
16581666 ) ) ;
16591667 }
1660- this . _xmlFromExamples ( doc , node , examples [ 0 ] , name ) ;
1668+ this . _xmlFromExamples ( doc , node , examples [ 0 ] , name , { xmlPrefix } ) ;
16611669 return ;
16621670 }
16631671 if ( this . _hasType ( range , this . ns . aml . vocabularies . shapes . UnionShape ) ) {
@@ -1685,7 +1693,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
16851693 return ;
16861694 }
16871695 if ( this . _hasType ( range , this . ns . aml . vocabularies . shapes . ArrayShape ) ) {
1688- this . _appendXmlArray ( doc , node , range , { isWrapped, xmlName } ) ;
1696+ this . _appendXmlArray ( doc , node , range , { isWrapped, xmlName, xmlPrefix } ) ;
16891697 return ;
16901698 }
16911699 this . _appendXmlElement ( doc , node , range ) ;
@@ -1700,8 +1708,9 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
17001708 * @param {Element } node A node to which append values
17011709 * @param {Object } example AMF's example definition.
17021710 * @param {String } propertyName Name of the property being processed
1711+ * @param {XmlData= } xmlData XMLData
17031712 */
1704- _xmlFromExamples ( doc , node , example , propertyName ) {
1713+ _xmlFromExamples ( doc , node , example , propertyName , xmlData ) {
17051714 const sKey = this . _getAmfKey (
17061715 this . ns . aml . vocabularies . document . structuredValue
17071716 ) ;
@@ -1712,7 +1721,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
17121721 if ( ! structure ) {
17131722 return ;
17141723 }
1715- this . _xmlProcessDataProperty ( doc , node , structure , propertyName ) ;
1724+ this . _xmlProcessDataProperty ( doc , node , structure , propertyName , xmlData ) ;
17161725 }
17171726
17181727 /**
@@ -1769,10 +1778,13 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
17691778 * @return {Element|null } Newly created element
17701779 */
17711780 _appendXmlElement ( doc , node , range , xmlData = { } ) {
1772- const name = xmlData . xmlName || this . _getXmlNormalizedName ( range ) ;
1781+ let name = xmlData . xmlName || this . _getXmlNormalizedName ( range ) ;
17731782 if ( ! name ) {
17741783 return null ;
17751784 }
1785+ if ( xmlData . xmlPrefix ) {
1786+ name = xmlData . xmlPrefix + ':' + name
1787+ }
17761788 let nodeValue = this . _getValue ( range , this . ns . w3 . shacl . defaultValueStr ) ;
17771789 if ( ! nodeValue ) {
17781790 const eKey = this . _getAmfKey (
@@ -1885,13 +1897,14 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
18851897 * @param {Element } node Current node
18861898 * @param {Object } property AMF property
18871899 * @param {string } name Current property name
1888- * @param {Boolean } isWrapped Whether the `wrapped` property is set.
1900+ * @param {XmlData= } xmlData XMLData
18891901 */
1890- _xmlProcessDataProperty ( doc , node , property , name , isWrapped = false ) {
1902+ _xmlProcessDataProperty ( doc , node , property , name , xmlData = { } ) {
1903+ const isWrapped = xmlData . isWrapped || false ;
18911904 if ( ! property || ! name ) {
18921905 return ;
18931906 }
1894- const tagName = normalizeXmlTagName ( name ) ;
1907+ const tagName = this . _nameTagWithPrefix ( name , xmlData . xmlPrefix ) ;
18951908 const arrayProperty = this . _hasType (
18961909 property ,
18971910 this . ns . aml . vocabularies . data . Array
0 commit comments