@@ -206,7 +206,9 @@ export class AmfSerializer extends AmfHelperMixin(Object) {
206
206
const schemas = object [ this . _getAmfKey ( ns . aml . vocabularies . shapes . schema ) ] ;
207
207
if ( Array . isArray ( schemas ) && schemas . length ) {
208
208
const [ schema ] = schemas ;
209
- result . schema = this . unknownShape ( schema ) ;
209
+ result . schema = this . unknownShape ( schema , {
210
+ trackedId : object [ '@id' ] ,
211
+ } ) ;
210
212
}
211
213
const payloads = object [ this . _getAmfKey ( ns . aml . vocabularies . apiContract . payload ) ] ;
212
214
if ( Array . isArray ( payloads ) && payloads . length ) {
@@ -247,10 +249,10 @@ export class AmfSerializer extends AmfHelperMixin(Object) {
247
249
}
248
250
// this must be before the ArrayShape
249
251
if ( types . includes ( ns . aml . vocabularies . shapes . TupleShape ) ) {
250
- return this . tupleShape ( /** @type TupleShape */ ( object ) ) ;
252
+ return this . tupleShape ( /** @type TupleShape */ ( object ) , options ) ;
251
253
}
252
254
if ( types . includes ( ns . aml . vocabularies . shapes . ArrayShape ) || types . includes ( ns . aml . vocabularies . shapes . MatrixShape ) ) {
253
- return this . arrayShape ( /** @type ArrayShape */ ( object ) ) ;
255
+ return this . arrayShape ( /** @type ArrayShape */ ( object ) , options ) ;
254
256
}
255
257
if ( types . includes ( ns . aml . vocabularies . shapes . RecursiveShape ) ) {
256
258
return this . recursiveShape ( /** @type RecursiveShape */ ( object ) ) ;
@@ -410,8 +412,8 @@ export class AmfSerializer extends AmfHelperMixin(Object) {
410
412
const { ns } = this ;
411
413
const examples = target [ this . _getAmfKey ( ns . aml . vocabularies . apiContract . examples ) ] ;
412
414
if ( Array . isArray ( examples ) && examples . length ) {
413
- if ( options . payloadId ) {
414
- const filtered = this . filterTrackedExamples ( examples , options . payloadId ) ;
415
+ if ( options . trackedId ) {
416
+ const filtered = this . filterTrackedExamples ( examples , options . trackedId ) ;
415
417
result . examples = filtered . map ( ( item ) => this . example ( item ) ) ;
416
418
} else {
417
419
const filtered = this . filterNonTrackedExamples ( examples ) ;
@@ -431,19 +433,19 @@ export class AmfSerializer extends AmfHelperMixin(Object) {
431
433
}
432
434
433
435
/**
434
- * Filters examples that should be rendered for a payload identified by `payloadId `.
436
+ * Filters examples that should be rendered for a payload identified by `trackedId `.
435
437
*
436
438
* This function is copied from old `api-example-generator/ExampleGenerator`.
437
439
*
438
440
* @param {Example[] } examples
439
- * @param {string } payloadId
441
+ * @param {string } trackedId
440
442
* @returns {Example[] }
441
443
*/
442
- filterTrackedExamples ( examples , payloadId ) {
444
+ filterTrackedExamples ( examples , trackedId ) {
443
445
const { docSourceMaps } = this . ns . raml . vocabularies ;
444
446
const sourceKey = this . _getAmfKey ( docSourceMaps . sources ) ;
445
447
const trackedKey = this . _getAmfKey ( docSourceMaps . trackedElement ) ;
446
- const longId = payloadId . indexOf ( 'amf' ) === - 1 ? `amf://id${ payloadId } ` : payloadId ;
448
+ const longId = trackedId . indexOf ( 'amf' ) === - 1 ? `amf://id${ trackedId } ` : trackedId ;
447
449
return examples . filter ( ( item ) => {
448
450
let example = item ;
449
451
if ( Array . isArray ( example ) ) {
@@ -468,7 +470,7 @@ export class AmfSerializer extends AmfHelperMixin(Object) {
468
470
return true ;
469
471
}
470
472
const ids = value . split ( ',' ) ;
471
- if ( ids . indexOf ( longId ) !== - 1 || ids . indexOf ( payloadId ) !== - 1 ) {
473
+ if ( ids . indexOf ( longId ) !== - 1 || ids . indexOf ( trackedId ) !== - 1 ) {
472
474
return true ;
473
475
}
474
476
return false ;
@@ -675,7 +677,8 @@ export class AmfSerializer extends AmfHelperMixin(Object) {
675
677
const anyOf = /** @type Shape[] */ ( object [ this . _getAmfKey ( this . ns . aml . vocabularies . shapes . anyOf ) ] ) ;
676
678
const result = /** @type ApiUnionShape */ ( this . anyShape ( object , options ) ) ;
677
679
if ( Array . isArray ( anyOf ) && anyOf . length ) {
678
- result . anyOf = anyOf . map ( ( shape ) => this . unknownShape ( shape ) ) ;
680
+ const opt = { ...options , trackedId : undefined } ;
681
+ result . anyOf = anyOf . map ( ( shape ) => this . unknownShape ( shape , opt ) ) ;
679
682
} else {
680
683
result . anyOf = [ ] ;
681
684
}
@@ -811,11 +814,12 @@ export class AmfSerializer extends AmfHelperMixin(Object) {
811
814
812
815
/**
813
816
* @param {ArrayShape } object
817
+ * @param {ShapeProcessingOptions= } options
814
818
* @returns {ApiArrayShape }
815
819
*/
816
- arrayShape ( object ) {
820
+ arrayShape ( object , options = { } ) {
817
821
let target = object ;
818
- const result = /** @type ApiArrayShape */ ( this . dataArrangeShape ( target ) ) ;
822
+ const result = /** @type ApiArrayShape */ ( this . dataArrangeShape ( target , options ) ) ;
819
823
if ( this . isLink ( target ) ) {
820
824
const value = /** @type ArrayShape */ ( this . getLinkTarget ( target ) ) ;
821
825
if ( value ) {
@@ -833,11 +837,12 @@ export class AmfSerializer extends AmfHelperMixin(Object) {
833
837
834
838
/**
835
839
* @param {TupleShape } object
840
+ * @param {ShapeProcessingOptions= } options
836
841
* @returns {ApiTupleShape }
837
842
*/
838
- tupleShape ( object ) {
843
+ tupleShape ( object , options ) {
839
844
let target = object ;
840
- const result = /** @type ApiTupleShape */ ( this . dataArrangeShape ( target ) ) ;
845
+ const result = /** @type ApiTupleShape */ ( this . dataArrangeShape ( target , options ) ) ;
841
846
if ( this . isLink ( target ) ) {
842
847
const value = /** @type TupleShape */ ( this . getLinkTarget ( target ) ) ;
843
848
if ( value ) {
@@ -1445,7 +1450,7 @@ export class AmfSerializer extends AmfHelperMixin(Object) {
1445
1450
[ schema ] = schema ;
1446
1451
}
1447
1452
result . schema = this . unknownShape ( schema , {
1448
- payloadId : result . id ,
1453
+ trackedId : result . id ,
1449
1454
} ) ;
1450
1455
}
1451
1456
const examples = object [ this . _getAmfKey ( ns . aml . vocabularies . apiContract . examples ) ] ;
0 commit comments