Skip to content

Commit

Permalink
Merge pull request #111 from trayio/CN-39/f/function-afterheaders
Browse files Browse the repository at this point in the history
CN-39: handling threadneedle update for afterHeaders support for function ops
  • Loading branch information
Johnbastian authored Mar 4, 2019
2 parents 97ae562 + d42ee0d commit b01fdb5
Show file tree
Hide file tree
Showing 12 changed files with 1,185 additions and 852 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ as on the operational level.
* [Project structuring](#project-structuring)
* [Schema](#schema)
* [Model](#model)
* [after_headers](#after_headers)
* [Sample response](#sample-response)
* [Global models](#global-models)
* [Global message schemas](#global-message-schemas)
Expand Down Expand Up @@ -152,6 +153,15 @@ module.exports = {

Variables passed in the input schema will be passed into a Mustache template system.

#### after_headers
For function models (only), the afterHeaders function can be specified in a `after_headers.js` file, exporting a function accepting the arguments `error`, `body`, and `params`.
```js
module.exports = function (error, params, body) {
return {
//Must return an object
};
};
```

### Sample response

Expand Down
13 changes: 13 additions & 0 deletions exampleTwo/connectors.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@
},
"dynamic_output": false
},
{
"name": "test_op_function",
"title": "Test function operation",
"input_schema": {
"type": "object",
"properties": {},
"required": [],
"advanced": [],
"$schema": "http://json-schema.org/draft-04/schema#",
"additionalProperties": false
},
"dynamic_output": false
},
{
"name": "test_op",
"title": "Test operation",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function (error, params, body) {
return (
params.ahFlag ?
when.resolve({ gotHeader: true, modelError: !!error }) :
when.reject(new Error('Failed afterHeader'))
);
};
7 changes: 7 additions & 0 deletions exampleTwo/connectors/testconnector/test_op_function/model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function (params) {
return (
params.modelFlag ?
when.resolve(params) :
when.reject(new Error('Failed function'))
);
};
12 changes: 12 additions & 0 deletions exampleTwo/connectors/testconnector/test_op_function/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {

title: 'Test function operation',

globals: false,

input: {

},


};
9 changes: 9 additions & 0 deletions exampleTwo/docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ <h2>Configuration</h2>
</td>
</tr>

<tr>
<td>
<em>Test function operation</em>
</td>
<td>

</td>
</tr>

<tr>
<td>
<em>Test operation</em>
Expand Down
2 changes: 1 addition & 1 deletion lib/bindConnectors/bindMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function (message, threadneedle, connectorConfig) {
message = interceptAfterSuccess(message);

// Add the threadneedle method
threadneedle.addMethod(methodName, message.model);
threadneedle.addMethod(methodName, message.model, message.afterHeaders);

/* Add the threadneedle method to the falafel global -
The falafel version of the operation should expose only
Expand Down
6 changes: 6 additions & 0 deletions lib/getConnectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,16 @@ module.exports = function (directory) {
output.schema.responseSample = requireFile(messageDir + '/response.sample.json', '/response.sample.json');
}

//Check if output.js is available
if (files.indexOf('output.js') !== -1) {
output['dynamicOutput'] = requireFile(messageDir + '/output', 'output.js');
}

//Check if afterHeaders.js is available
if (files.indexOf('after_headers.js') !== -1) {
output['afterHeaders'] = requireFile(messageDir + '/after_headers', 'after_headers.js');
}

// Set the name on the top level
output.name = _.get(output, 'schema.name', message);

Expand Down
Loading

0 comments on commit b01fdb5

Please sign in to comment.