Skip to content

Commit 598f6a2

Browse files
authored
Merge pull request #61 from advanced-rest-client/fix/W-14651311/Show-attribute-to-xml-example
[W-14651311] add attribute to xml property when has example
2 parents 88a0988 + 7134a23 commit 598f6a2

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-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.25",
4+
"version": "4.4.26",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/ExampleGenerator.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,13 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
17351735
this.ns.w3.shacl.name
17361736
));
17371737
}
1738+
if (serialization) {
1739+
if (xmlAttribute) {
1740+
1741+
this._appendXmlAttribute(node, range, xmlName, examples[0]);
1742+
return;
1743+
}
1744+
}
17381745
this._xmlFromExamples(doc, node, examples[0], name, { xmlPrefix });
17391746
return;
17401747
}
@@ -1818,7 +1825,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
18181825
* @param {Object} range AMF range
18191826
* @param {String} xmlName Value of 'xmlName' property of AMF's object
18201827
*/
1821-
_appendXmlAttribute(node, range, xmlName) {
1828+
_appendXmlAttribute(node, range, xmlName, example) {
18221829
let name = /** @type {string} */ xmlName;
18231830
if (!name) {
18241831
name = /** @type {string} */ (this._getValue(
@@ -1832,11 +1839,23 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
18321839
if (name.indexOf('?') !== -1) {
18331840
name = name.replace('?', '');
18341841
}
1835-
let value = this._readDataType(range);
1836-
if (!value) {
1837-
value = '';
1842+
let exampleValue;
1843+
if (example) {
1844+
const sKey = this._getAmfKey(
1845+
this.ns.aml.vocabularies.document.structuredValue
1846+
);
1847+
const structure = example[sKey];
1848+
exampleValue = this._computeStructuredExampleValue(structure[0]);
1849+
}
1850+
if (exampleValue) {
1851+
node.setAttribute(name, String(exampleValue));
1852+
} else {
1853+
let value = this._readDataType(range);
1854+
if (!value) {
1855+
value = '';
1856+
}
1857+
node.setAttribute(name, value);
18381858
}
1839-
node.setAttribute(name, value);
18401859
}
18411860

18421861
/**

0 commit comments

Comments
 (0)