Skip to content

Commit

Permalink
vision: add default formatter for unknown annotation types (#2044)
Browse files Browse the repository at this point in the history
  • Loading branch information
callmehiphop committed Mar 2, 2017
1 parent 2047571 commit bad8153
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/google-cloud-vision/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,11 @@ Vision.prototype.detect = function(images, options, callback) {
textAnnotations: Vision.formatEntityAnnotation_
};

return formatMethodMap[type](annotation, options);
var formatMethod = formatMethodMap[type] || function(annotation) {
return annotation;
};

return formatMethod(annotation, options);
};
}

Expand Down
22 changes: 22 additions & 0 deletions packages/google-cloud-vision/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,28 @@ describe('Vision', function() {
});
});

it('should return the raw annotation for unknown types', function(done) {
var anno = { a: 'b', c: 'd' };

var annotations = [
{
faceAnnotations: anno
}
];

Vision.formatFaceAnnotation_ = null;

vision.annotate = function(config, callback) {
callback(null, annotations);
};

vision.detect(IMAGE, 'faces', function(err, detections) {
assert.ifError(err);
assert.strictEqual(detections, anno);
done();
});
});

it('should return an error from annotate()', function(done) {
var error = new Error('Error.');
var apiResponse = {};
Expand Down

0 comments on commit bad8153

Please sign in to comment.