Skip to content

Commit

Permalink
template: Fix duplicate items in required property when merging sections
Browse files Browse the repository at this point in the history
For #23
  • Loading branch information
mstokes-f5 committed Dec 9, 2021
1 parent ad7cef2 commit 051fc85
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# v0.17.0
## Fixed
* guiUtils: Prefer defaults from top-level templates when merging allOf templates
* template: Fix duplicate items in required property when merging sections (issue #23)

# v0.16.0
## Fixed
Expand Down
13 changes: 13 additions & 0 deletions lib/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,19 @@ class Template {
existingDef,
newDef
);

// De-dup required arrays
if (acc.properties[defName].required) {
acc.properties[defName].required = [
...new Set(acc.properties[defName].required)
];
}
if (acc.properties[defName].items && acc.properties[defName].items.required) {
acc.properties[defName].items.required = [
...new Set(acc.properties[defName].items.required)
];
}

if (this._isPropRequired(acc.properties[defName])) {
required.add(defName);
}
Expand Down
1 change: 1 addition & 0 deletions test/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ describe('Template class tests', function () {
template: |
{{#section}}{{foo}}{{/section}}
{{#section}}{{bar}}{{/section}}
{{#section}}{{foo}}{{/section}}
{{^section}}{{baz}}{{/section}}
`;

Expand Down

0 comments on commit 051fc85

Please sign in to comment.