Skip to content

Commit 5a38529

Browse files
committed
fix: REST API cannot foreach undefined error
fixes #9157
1 parent e7366e2 commit 5a38529

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

templates/common/RestApi.common.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,20 @@ exports.transform = function (model) {
8282
}
8383
}
8484
model.definitions = [];
85-
model.tags.forEach(function(tag) {
86-
tag.children.forEach(function(child) {
87-
child.parameters.forEach(function(parameter) { addComplexTypeMetadata(parameter.schema, model.definitions); });
88-
child.responses.forEach(function(response) { addComplexTypeMetadata(response.schema, model.definitions); });
85+
if (model.tags) {
86+
model.tags.forEach(function(tag) {
87+
(tag.children || []).forEach(function(child) {
88+
(child.parameters || []).forEach(function(parameter) { addComplexTypeMetadata(parameter.schema, model.definitions); });
89+
(child.responses || []).forEach(function(response) { addComplexTypeMetadata(response.schema, model.definitions); });
90+
});
91+
});
92+
}
93+
if (model.children) {
94+
model.children.forEach(function(child) {
95+
(child.parameters || []).forEach(function(parameter) { addComplexTypeMetadata(parameter.schema, model.definitions); });
96+
(child.responses || []).forEach(function(response) { addComplexTypeMetadata(response.schema, model.definitions); });
8997
});
90-
});
91-
model.children.forEach(function(child) {
92-
child.parameters.forEach(function(parameter) { addComplexTypeMetadata(parameter.schema, model.definitions); });
93-
child.responses.forEach(function(response) { addComplexTypeMetadata(response.schema, model.definitions); });
94-
});
98+
}
9599

96100
return model;
97101

0 commit comments

Comments
 (0)