@api-components/api-example-generator
Advanced tools
Comparing version
@@ -273,2 +273,3 @@ import {PolymerElement} from '../../@polymer/polymer/polymer-element.js'; | ||
_computeFromExamples(examples, mime, opts) { | ||
examples = this._processExamples(examples); | ||
examples = this._listTypeExamples(examples, opts.typeId); | ||
@@ -289,2 +290,25 @@ if (!examples) { | ||
/** | ||
* In AMF 4 the examples model changes from being an array of examples | ||
* to an object that contains an array of examples. | ||
* This function extracts the array of examples back to the `examples` variable, | ||
* respecting that the compact model can be an object instead of array. | ||
* If the argument is an array with more than one item it means it's pre-4.0.0 | ||
* model. | ||
* @param {Array|Object} examples Examples model. | ||
* @return {Array|undefined} List of examples to process. | ||
*/ | ||
_processExamples(examples) { | ||
const key = this._getAmfKey(this.ns.raml.vocabularies.document + 'examples'); | ||
if (!(examples instanceof Array)) { | ||
if (this._hasType(examples, this.ns.raml.vocabularies.document + 'NamedExamples')) { | ||
return this._ensureArray(examples[key]); | ||
} | ||
return; | ||
} | ||
if (examples.length === 1 && this._hasType(examples[0], this.ns.raml.vocabularies.document + 'NamedExamples')) { | ||
return this._ensureArray(examples[0][key]); | ||
} | ||
return examples; | ||
} | ||
/** | ||
* Uses Example shape's source maps to determine which examples should be rendered. | ||
@@ -898,2 +922,16 @@ * @param {Array<Object>} examples List of AMF Example schapes. | ||
} | ||
_extractExampleRawValue(example) { | ||
if (example instanceof Array) { | ||
example = example[0]; | ||
} | ||
if (this._hasType(example, this.ns.raml.vocabularies.document + 'NamedExamples')) { | ||
const key = this._getAmfKey(this.ns.raml.vocabularies.document + 'examples'); | ||
example = example[key]; | ||
if (example instanceof Array) { | ||
example = example[0]; | ||
} | ||
} | ||
return this._getValue(example, this.ns.w3.shacl.name + 'raw'); | ||
} | ||
/** | ||
@@ -916,6 +954,3 @@ * Gets a value from a Range shape for a scalar value. | ||
if (ex) { | ||
if (ex instanceof Array) { | ||
ex = ex[0]; | ||
} | ||
return this._getValue(ex, this.ns.w3.shacl.name + 'raw'); | ||
return this._extractExampleRawValue(ex); | ||
} | ||
@@ -1065,6 +1100,3 @@ } | ||
if (example) { | ||
if (example instanceof Array) { | ||
example = example[0]; | ||
} | ||
nodeValue = this._getValue(example, this.ns.w3.shacl.name + 'raw'); | ||
nodeValue = this._extractExampleRawValue(example); | ||
} | ||
@@ -1071,0 +1103,0 @@ } |
@@ -11,3 +11,3 @@ { | ||
"name": "@api-components/api-example-generator", | ||
"version": "3.0.0-preview.4", | ||
"version": "3.0.0-preview.5", | ||
"license": "Apache-2.0", | ||
@@ -20,3 +20,3 @@ "main": "api-example-generator.js", | ||
"devDependencies": { | ||
"@api-components/api-model-generator": "^0.1.10", | ||
"@api-components/api-model-generator": "^0.2.0-preview.1", | ||
"@api-components/api-navigation": "^3.0.0-preview.2", | ||
@@ -23,0 +23,0 @@ "@polymer/gen-typescript-declarations": "^1.6.1", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
93665
1.48%1492
2.12%0
-100%