remove-event-stream-ops.js
1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Removes operations from the model if they require event streams.
* Specifically looks at input and output shapes.
* @param {Object} model - JSON parsed API model (*.normal.json)
*/
function removeEventStreamOperations(model) {
var modifiedModel = false;
// loop over all operations
var operations = model.operations;
var operationNames = Object.keys(operations);
for (var i = 0; i < operationNames.length; i++) {
var operationName = operationNames[i];
var operation = operations[operationName];
// check input and output shapes
var inputShapeName = operation.input && operation.input.shape;
var outputShapeName = operation.output && operation.output.shape;
var requiresEventStream = false;
if (inputShapeName && hasEventStream(model.shapes[inputShapeName], model)) {
requiresEventStream = true;
}
if (requiresEventStream) {
modifiedModel = true;
// remove the operation from the model
console.log('Removing ' + operationName + ' because it depends on event streams on input.');
delete model.operations[operationName];
}
}
return modifiedModel;
}
function hasEventStream(shape, model) {
if (shape.eventstream) {
return true;
} else {
// check each member shape
var memberNames = Object.keys(shape.members);
for (var i = 0; i < memberNames.length; i++) {
var member = shape.members[memberNames[i]];
if (member.eventstream) {
return true;
}
var memberShape = model.shapes[member.shape];
if (memberShape.eventstream) {
return true;
}
}
}
}
module.exports = {
removeEventStreamOperations: removeEventStreamOperations
};