From bad8153a41384a731adc5a8fcaf97d87a2c389ab Mon Sep 17 00:00:00 2001 From: Dave Gramlich Date: Thu, 2 Mar 2017 18:32:30 -0500 Subject: [PATCH] vision: add default formatter for unknown annotation types (#2044) --- packages/google-cloud-vision/src/index.js | 6 +++++- packages/google-cloud-vision/test/index.js | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/google-cloud-vision/src/index.js b/packages/google-cloud-vision/src/index.js index 001703bbc9c..ef58c1e7762 100644 --- a/packages/google-cloud-vision/src/index.js +++ b/packages/google-cloud-vision/src/index.js @@ -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); }; } diff --git a/packages/google-cloud-vision/test/index.js b/packages/google-cloud-vision/test/index.js index baf63fbf860..2b5dfd3384e 100644 --- a/packages/google-cloud-vision/test/index.js +++ b/packages/google-cloud-vision/test/index.js @@ -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 = {};