@@ -259,7 +259,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
259259 result [ result . length ] = mime ;
260260 }
261261 }
262-
262+
263263 return result ;
264264 }
265265
@@ -637,7 +637,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
637637 * @return {Example|undefined }
638638 */
639639 _generateFromExample ( example , mime , opts ) {
640- let raw = /** @type {string } */ ( this . _getValue (
640+ let raw = /** @type {string|number|Boolean } */ ( this . _getValue (
641641 example ,
642642 this . ns . aml . vocabularies . document . raw
643643 ) ) ;
@@ -646,6 +646,11 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
646646 example ,
647647 this . ns . w3 . shacl . raw
648648 ) ) ;
649+ const referenceIdKey = this . _getAmfKey ( this . ns . aml . vocabularies . document . referenceId ) ;
650+ const referenceIdData = this . _ensureArray ( example [ referenceIdKey ] ) ;
651+ if ( Array . isArray ( referenceIdData ) && referenceIdData . length > 0 ) {
652+ raw = ( this . _getValue ( referenceIdData [ 0 ] , this . ns . aml . vocabularies . document . raw ) ) ;
653+ }
649654 }
650655 let title = /** @type {string } */ ( this . _getValue (
651656 example ,
@@ -743,7 +748,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
743748 let data ;
744749 if ( isJson ) {
745750 data = this . _jsonFromStructure ( member ) ;
746-
751+
747752 } else if ( isXml ) {
748753 data = this . _xmlFromStructure ( member , { ...opts , ignoreXmlHeader : true } ) ;
749754 }
@@ -754,7 +759,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
754759 if ( isJson ) {
755760 result . value = JSON . stringify ( parts , null , 2 ) ;
756761 return result ;
757- }
762+ }
758763 if ( isXml ) {
759764 result . value = parts . join ( '\n' ) ;
760765 return result ;
@@ -818,6 +823,38 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
818823 return undefined ;
819824 }
820825
826+ /**
827+ * Computes list of examples for an array shape.
828+ * @param {Object } schema The AMF's array shape
829+ * @param {String } mime Current mime type
830+ * @param {ExampleOptions } [opts={}]
831+ * @return {Array<Example>|undefined }
832+ */
833+ _computeExampleSchemaShape ( schema , mime , opts = { } ) {
834+ const options = { ...opts } ;
835+ const iKey = this . _getAmfKey ( this . ns . aml . vocabularies . shapes . items ) ;
836+ debugger
837+ const items = this . _ensureArray ( schema [ iKey ] ) ;
838+ if ( ! items ) {
839+ return undefined ;
840+ }
841+ const isJson = mime . indexOf ( 'json' ) !== - 1 ;
842+ options . parentName = options . typeName ;
843+ delete options . typeName ;
844+ // We need only first type here as arras can have different types
845+ for ( let i = 0 , len = items . length ; i < len ; i ++ ) {
846+ const item = items [ i ] ;
847+ const result = this . computeExamples ( item , mime , options ) ;
848+ if ( result ) {
849+ if ( isJson ) {
850+ processJsonArrayExamples ( result ) ;
851+ }
852+ return result ;
853+ }
854+ }
855+ return undefined ;
856+ }
857+
821858 /**
822859 * Computes example for an `and` shape.
823860 * @param {Object } schema The AMF's array shape
@@ -1110,7 +1147,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
11101147
11111148 /**
11121149 * Adds XML schema header.
1113- * @param {string } value
1150+ * @param {string } value
11141151 * @returns {string }
11151152 */
11161153 _appendXmlHeader ( value ) {
0 commit comments