Skip to content

Commit 9f0aa95

Browse files
authored
Merge pull request #58 from advanced-rest-client/fix/W-14102462/ACM-wrongly-shows-API-Example-"(no-value-in-example)"-though-it-is-visible-on-Exchange-and-Design-Center
Fix[W-14102462] acm wrongly shows api example no value in example though it is visible on exchange and design center
2 parents 0e85ed8 + b22be00 commit 9f0aa95

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@api-components/api-example-generator",
33
"description": "Examples generator from AMF model",
4-
"version": "4.4.22",
4+
"version": "4.4.23",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/ExampleGenerator.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
@@ -1110,7 +1115,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
11101115

11111116
/**
11121117
* Adds XML schema header.
1113-
* @param {string} value
1118+
* @param {string} value
11141119
* @returns {string}
11151120
*/
11161121
_appendXmlHeader(value) {

0 commit comments

Comments
 (0)