Skip to content

Commit e124457

Browse files
committed
Correct for Discovery addDocument for json
1 parent 721993c commit e124457

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Node-RED Watson Nodes for IBM Cloud
77

88
<a href="https://cla-assistant.io/watson-developer-cloud/node-red-node-watson"><img src="https://cla-assistant.io/readme/badge/watson-developer-cloud/node-red-node-watson" alt="CLA assistant" /></a>
99

10+
### New in version 0.6.10
11+
- Needed to stringify json before addDocument in Discovery node.
12+
1013
### New in version 0.6.9
1114
- Implemented classify collection on Natural Language Classifier node. The collection can be
1215
in the form of multiple sentences, an array of strings, or an array of objects.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-watson",
3-
"version": "0.6.9",
3+
"version": "0.6.10",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"async": "^1.5.2",

services/discovery/discovery-utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ DiscoveryUtils.prototype = {
5858
params.file = this.isJsonObject(msg.payload) ?
5959
JSON.stringify(msg.payload) :
6060
msg.payload;
61+
params.file_content_type = 'application/json';
6162
}
6263
return params;
6364
},
@@ -313,7 +314,8 @@ DiscoveryUtils.prototype = {
313314
},
314315

315316
isJsonObject: function(str) {
316-
if (str instanceof Array || str instanceof Object) {
317+
if (str instanceof Array || str instanceof Object ||
318+
'object' === typeof str || Array.isArray(str)) {
317319
return true;
318320
}
319321
return false;

services/discovery/v1-document-loader.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,13 @@ module.exports = function (RED) {
141141
}
142142

143143
discovery = new DiscoveryV1(serviceSettings);
144-
// addJsonDocument is deprecated
145-
//if ('.json' === suffix) {
146-
// method = 'addJsonDocument';
144+
// modify as getting addJsonDocument will be deprecated messages
145+
if ('.json' === suffix) {
146+
//method = 'addJsonDocument';
147+
params.file = JSON.stringify(params.file);
147148
//} else {
148-
// method = 'addDocument';
149-
//}
149+
//method = 'addDocument';
150+
}
150151
method = 'addDocument';
151152

152153
discovery[method](params, function (err, response) {

0 commit comments

Comments
 (0)