Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #514 from mulesoft/raml-expander
Browse files Browse the repository at this point in the history
RamlExpander was discarding extra properties
  • Loading branch information
rciccone91 authored Apr 18, 2018
2 parents 6263005 + 84064b4 commit f95ae97
Show file tree
Hide file tree
Showing 9 changed files with 531 additions and 379 deletions.
21 changes: 8 additions & 13 deletions app/scripts/api-designer-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ function RamlExpander() {
if (expandedType) {
for (var key in expandedType) {
if (expandedType.hasOwnProperty(key)) {
if ((key === 'example' || key === 'examples') && valueHasExamples) {
continue;
if ((key === 'example' || key === 'examples') && valueHasExamples) { continue; }
if (key === 'properties') { // can have extra properties
value[key] = Object.assign(value.properties || {}, expandedType[key]);
} else {
value[key] = expandedType[key];
}
value[key] = expandedType[key];
}
}
}
Expand All @@ -39,10 +41,7 @@ function RamlExpander() {
}

function extractArrayType(arrayNode) {
if (arrayNode.items.type) {
return arrayNode.items.type[0];
}
return arrayNode.items;
return arrayNode.items && arrayNode.items.type ? arrayNode.items.type[0] : arrayNode.items;
}

function isNotObject(value) {
Expand All @@ -53,14 +52,10 @@ function RamlExpander() {
jsTraverse.traverse(raml).forEach(function (value) {
if (this.path.slice(-2).join('.') === 'body.application/json' && value.type && value.type[0] === 'array') {
var type = extractArrayType(value);
if (isNotObject(value.items)) {
value.items = {};
}
if (isNotObject(value.items)) { value.items = {}; }
replaceTypeIfExists(raml, type, value.items);

if (!value.examples && !value.example) {
generateArrayExampleIfPossible(value);
}
if (!value.examples && !value.example) { generateArrayExampleIfPossible(value); }
}
});

Expand Down
181 changes: 94 additions & 87 deletions dist/scripts/api-designer-parser.js

Large diffs are not rendered by default.

112 changes: 56 additions & 56 deletions dist/scripts/api-designer-parser.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit f95ae97

Please sign in to comment.