diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000..dfc11570bd --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +version: '2' +services: + node: + image: docker.io/smoebody/dev-nodejs:6 + volumes: + - ./:/app:z + - npm-cache:/home/dev/.npm:z + ports: + - 127.0.0.1:5858:5858 + environment: + - NODE_ENV=development + command: + - npm test + +volumes: + npm-cache: {} diff --git a/test/2.0/test-middleware-swagger-validator.js b/test/2.0/test-middleware-swagger-validator.js index 45130672b2..7a36102375 100644 --- a/test/2.0/test-middleware-swagger-validator.js +++ b/test/2.0/test-middleware-swagger-validator.js @@ -37,6 +37,8 @@ var async = require('async'); var helpers = require('../helpers'); var request = require('supertest'); var stream = require('stream'); +var fs = require('fs'); +var crypto = require('crypto'); var petStoreJson = _.cloneDeep(require('../../samples/2.0/petstore.json')); @@ -1575,6 +1577,55 @@ describe('Swagger Validator Middleware v2.0', function () { }); }); + it('should validate file and return it (issue #463)', function (done) { + var cPetStore = _.cloneDeep(petStoreJson); + + cPetStore.paths['/image'] = { + get: { + summary: 'Get image', + description: 'Retrieves image.', + operationId: 'getImage', + produces: ['image/png'], + responses: { + '200': { + description: 'OK', + schema: { + type: 'file' + } + } + } + } + }; + + helpers.createServer([cPetStore], { + swaggerRouterOptions: { + controllers: { + getImage: function (req, res) { + res.setHeader('Content-type', 'image/png'); + return fs.createReadStream('test/image.png').pipe(res); + } + } + }, + swaggerValidatorOptions: { + validateResponse: true + } + }, function (app) { + try { + request(app) + .get('/api/image') + .end(function(err, res) { + assert.strictEqual( + crypto.createHash('sha256').update(fs.readFileSync('test/image.png')).digest('hex'), //expected + crypto.createHash('sha256').update(res.body).digest('hex') //actual + ); + done(err); + }); + } catch (err) { + done(); + } + }); + }); + it('should not throw an error for empty responses that validate void (new issue)', function (done) { var cPetStoreJson = _.cloneDeep(petStoreJson); diff --git a/test/image.png b/test/image.png new file mode 100644 index 0000000000..bdcadbd1d0 Binary files /dev/null and b/test/image.png differ