@@ -94,10 +94,10 @@ export const formatXml = xml => {
94
94
const type = single
95
95
? 'single'
96
96
: closing
97
- ? 'closing'
98
- : opening
99
- ? 'opening'
100
- : 'other' ;
97
+ ? 'closing'
98
+ : opening
99
+ ? 'opening'
100
+ : 'other' ;
101
101
const fromTo = lastType + '->' + type ;
102
102
lastType = type ;
103
103
let padding = '' ;
@@ -395,7 +395,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
395
395
}
396
396
this . _resolve ( schema ) ;
397
397
const xmlSerialization = this . xmlSerialization ( schema ) ;
398
- const { xmlName, xmlNamespace, xmlPrefix} = this . _computeXmlSerializationData ( xmlSerialization )
398
+ const { xmlName, xmlNamespace, xmlPrefix } = this . _computeXmlSerializationData ( xmlSerialization )
399
399
if ( ! options . typeName ) {
400
400
const typeName = this . computeTypeName ( schema , xmlName ) ;
401
401
if ( typeName ) {
@@ -650,6 +650,44 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
650
650
const referenceIdData = this . _ensureArray ( example [ referenceIdKey ] ) ;
651
651
if ( Array . isArray ( referenceIdData ) && referenceIdData . length > 0 ) {
652
652
raw = ( this . _getValue ( referenceIdData [ 0 ] , this . ns . aml . vocabularies . document . raw ) ) ;
653
+
654
+ // Map raw to external fragment
655
+ if ( ! raw ) {
656
+ // It first retrieves the @id property from the first element
657
+ // of referenceIdData array and assigns it to referenceId.
658
+ const referenceId = referenceIdData [ 0 ] [ '@id' ]
659
+
660
+ // It calls the _computeReferences method with this.amf as an
661
+ // argument to get the root references and assigns
662
+ // the result to rootReferences.
663
+ const rootReferences = this . _computeReferences ( this . amf )
664
+
665
+ // It maps over each item in rootReferences,
666
+ // and for each item, it computes references twice in a nested manner.
667
+ // It then gets the second element from externalFragments and computes its encodes.
668
+ // The result of this map operation is an array of
669
+ // encoded external fragments, which is assigned to encodesOfExternalFragments.
670
+ const encodesOfExternalFragments = rootReferences . map ( ( item ) => {
671
+ const shapeFragment = this . _computeReferences ( item )
672
+ const externalFragments = this . _computeReferences ( shapeFragment )
673
+ // Get second element from externalFragments
674
+ const externalFragmentExample = externalFragments [ 1 ]
675
+ return this . _computeEncodes ( externalFragmentExample )
676
+ } )
677
+
678
+ // It finds an element in encodesOfExternalFragments where
679
+ // the @id property matches referenceId and assigns
680
+ // it to exmapleExternalFragmentByReferenceId.
681
+ const exmapleExternalFragmentByReferenceId = encodesOfExternalFragments . find ( externalFrament => (
682
+ externalFrament [ '@id' ] === referenceId
683
+ ) )
684
+
685
+ const rawKey = this . _getAmfKey ( this . ns . aml . vocabularies . document . raw )
686
+ // Finally, it calls the _getValue method with
687
+ // exmapleExternalFragmentByReferenceId and rawKey
688
+ // as arguments and assigns the result to raw.
689
+ raw = this . _getValue ( exmapleExternalFragmentByReferenceId , rawKey )
690
+ }
653
691
}
654
692
}
655
693
let title = /** @type {string } */ ( this . _getValue (
@@ -762,11 +800,11 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
762
800
if ( result . raw ) {
763
801
try {
764
802
result . value = this . computeRaw ( raw )
765
- return result
803
+ return result
766
804
} catch ( _ ) {
767
805
// ...
768
806
}
769
- }
807
+ }
770
808
771
809
result . value = JSON . stringify ( parts , null , 2 ) ;
772
810
return result ;
@@ -807,7 +845,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
807
845
* @param {String } raw
808
846
* @returns string JSON formatted
809
847
*/
810
- computeRaw ( raw ) {
848
+ computeRaw ( raw ) {
811
849
const accountEntries = raw . split ( '-\n' ) ;
812
850
const accounts = [ ] ;
813
851
for ( const entry of accountEntries ) {
@@ -817,15 +855,15 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
817
855
for ( const line of lines ) {
818
856
if ( line !== '' ) {
819
857
const [ key , value ] = line . split ( ': ' ) ;
820
- account [ key . trim ( ) ] = Number ( value ) ? Number ( value ) : value . trim ( )
858
+ account [ key . trim ( ) ] = Number ( value ) ? Number ( value ) : value . trim ( )
821
859
}
822
860
}
823
861
accounts . push ( account ) ;
824
862
}
825
863
}
826
864
return JSON . stringify ( accounts , null , 2 ) ;
827
865
}
828
-
866
+
829
867
830
868
/**
831
869
* Computes list of examples for an array shape.
@@ -1114,7 +1152,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
1114
1152
* @param {ExampleOptions= } opts Examples processing options
1115
1153
* @return {String }
1116
1154
*/
1117
- _xmlFromStructure ( structure , opts = { } ) {
1155
+ _xmlFromStructure ( structure , opts = { } ) {
1118
1156
let typeName = ( opts && opts . typeName ) || UNKNOWN_TYPE ;
1119
1157
typeName = normalizeXmlTagName ( typeName ) ;
1120
1158
const doc = document . implementation . createDocument ( '' , typeName , null ) ;
@@ -1310,17 +1348,17 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
1310
1348
} ) ;
1311
1349
} else {
1312
1350
const aKey = this . _getAmfKey ( this . ns . aml . vocabularies . shapes . anyOf ) ;
1313
- let value
1351
+ let value
1314
1352
const anyOf = this . _ensureArray ( range [ aKey ] ) ;
1315
- if ( anyOf ) {
1316
- for ( let anyOfIndex = 0 ; anyOfIndex < anyOf . length ; anyOfIndex ++ ) {
1353
+ if ( anyOf ) {
1354
+ for ( let anyOfIndex = 0 ; anyOfIndex < anyOf . length ; anyOfIndex ++ ) {
1317
1355
const exampleValue = this . _computeJsonPropertyValue ( anyOf [ anyOfIndex ] ) ;
1318
- if ( exampleValue !== null ) {
1356
+ if ( exampleValue !== null ) {
1319
1357
value = exampleValue ;
1320
1358
break ;
1321
1359
}
1322
1360
}
1323
- } else {
1361
+ } else {
1324
1362
value = this . _computeJsonPropertyValue ( range ) ;
1325
1363
}
1326
1364
if ( value === undefined ) {
@@ -1585,7 +1623,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
1585
1623
examples . push ( propertiesExamples ) ;
1586
1624
}
1587
1625
}
1588
- return examples . reduce ( ( acc , value ) => ( { ...acc , ...value } ) , { } ) ;
1626
+ return examples . reduce ( ( acc , value ) => ( { ...acc , ...value } ) , { } ) ;
1589
1627
}
1590
1628
1591
1629
/**
@@ -1772,7 +1810,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
1772
1810
}
1773
1811
if ( serialization ) {
1774
1812
if ( xmlAttribute ) {
1775
-
1813
+
1776
1814
this . _appendXmlAttribute ( node , range , xmlName , examples [ 0 ] ) ;
1777
1815
return ;
1778
1816
}
0 commit comments