From 70327dce09fd9ee05d5fb99b26c589d05b883289 Mon Sep 17 00:00:00 2001 From: mcardosos Date: Tue, 16 Jan 2018 13:30:35 -0800 Subject: [PATCH] Feedback --- lib/validators/specResolver.js | 4 +- .../specification/contenttype/datalake.json | 125 +++++++++++++++++- .../polymorphic/EntitySearch.json | 25 ++-- .../examples/SuccessfulQueryRequest.json | 4 +- test/modelValidatorTests.js | 24 +--- 5 files changed, 139 insertions(+), 43 deletions(-) diff --git a/lib/validators/specResolver.js b/lib/validators/specResolver.js index 381e80c2..d9149d47 100644 --- a/lib/validators/specResolver.js +++ b/lib/validators/specResolver.js @@ -536,7 +536,9 @@ class SpecResolver { for (let statusCode in operation.responses) { let response = operation.responses[statusCode]; if (response.schema) { - response.schema = utils.relaxModelLikeEntities(response.schema); + if (operation.produces != 'application/octet-stream') { + response.schema = utils.relaxModelLikeEntities(response.schema); + } } } } diff --git a/test/modelValidation/swaggers/specification/contenttype/datalake.json b/test/modelValidation/swaggers/specification/contenttype/datalake.json index 0ff33f08..d4443d56 100644 --- a/test/modelValidation/swaggers/specification/contenttype/datalake.json +++ b/test/modelValidation/swaggers/specification/contenttype/datalake.json @@ -16,12 +16,12 @@ "application/json" ], "paths": { - "/open": { + "/open/object": { "get": { "tags": [ "Content" ], - "operationId": "Content_Produce", + "operationId": "Content_ProduceTypeObject", "description": "Operation to test produce application/octet-stream", "x-ms-examples": { "Downloads stream": { @@ -41,7 +41,58 @@ } } }, - "/append": { + "/open/file": { + "get": { + "tags": [ + "Content" + ], + "operationId": "Content_ProduceTypeFile", + "description": "Operation to test produce application/octet-stream", + "x-ms-examples": { + "Downloads stream": { + "$ref": "./examples/download.json" + } + }, + "produces": [ + "application/octet-stream" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "file" + } + } + } + } + }, + "/open/object/file": { + "get": { + "tags": [ + "Content" + ], + "operationId": "Content_ProduceTypeObjectFormatFile", + "description": "Operation to test produce application/octet-stream", + "x-ms-examples": { + "Downloads stream": { + "$ref": "./examples/download.json" + } + }, + "produces": [ + "application/octet-stream" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "format": "file" + } + } + } + } + }, + "/append/object": { "post": { "tags": [ "Content" @@ -49,7 +100,73 @@ "consumes": [ "application/octet-stream" ], - "operationId": "Content_Consume", + "operationId": "Content_ConsumeTypeObject", + "description": "Operation to test consume application/octet-stream", + "x-ms-examples": { + "Uploads stream": { + "$ref": "./examples/upload.json" + } + }, + "parameters": [ + { + "name": "streamContents", + "in": "body", + "schema": { + "type": "object" + }, + "required": true, + "description": "Stream parameter description" + } + ], + "responses": { + "200": { + "description": "OK" + } + } + } + }, + "/append/file": { + "post": { + "tags": [ + "Content" + ], + "consumes": [ + "application/octet-stream" + ], + "operationId": "Content_ConsumeTypeFile", + "description": "Operation to test consume application/octet-stream", + "x-ms-examples": { + "Uploads stream": { + "$ref": "./examples/upload.json" + } + }, + "parameters": [ + { + "name": "streamContents", + "in": "body", + "schema": { + "type": "file" + }, + "required": true, + "description": "Stream parameter description" + } + ], + "responses": { + "200": { + "description": "OK" + } + } + } + }, + "/append/object/file": { + "post": { + "tags": [ + "Content" + ], + "consumes": [ + "application/octet-stream" + ], + "operationId": "Content_ConsumeTypeObjectFormatFile", "description": "Operation to test consume application/octet-stream", "x-ms-examples": { "Uploads stream": { diff --git a/test/modelValidation/swaggers/specification/polymorphic/EntitySearch.json b/test/modelValidation/swaggers/specification/polymorphic/EntitySearch.json index 1e3a5203..eeef635a 100644 --- a/test/modelValidation/swaggers/specification/polymorphic/EntitySearch.json +++ b/test/modelValidation/swaggers/specification/polymorphic/EntitySearch.json @@ -121,23 +121,16 @@ "type": "string" }, { - "name": "ResponseFilter", + "name": "srs", "in": "query", - "description": "A comma-delimited list of answers to include in the response. If you do not specify this parameter, the response includes all search answers for which there's relevant data.", - "required": false, - "type": "array", - "items": { - "type": "string", - "enum": [ - "Entities", - "Places" - ], - "x-ms-enum": { - "name": "AnswerType", - "modelAsString": false - } - }, - "collectionFormat": "csv" + "description": "Projection used in describing the bbox", + "required": true, + "default": "EPSG:4326", + "enum": [ + "EPSG:4326", + "EPSG:3857" + ], + "type": "string" }, { "name": "ResponseFormat", diff --git a/test/modelValidation/swaggers/specification/polymorphic/examples/SuccessfulQueryRequest.json b/test/modelValidation/swaggers/specification/polymorphic/examples/SuccessfulQueryRequest.json index d907d4c5..ec86436b 100644 --- a/test/modelValidation/swaggers/specification/polymorphic/examples/SuccessfulQueryRequest.json +++ b/test/modelValidation/swaggers/specification/polymorphic/examples/SuccessfulQueryRequest.json @@ -1,7 +1,9 @@ { "parameters": { "Ocp-Apim-Subscription-Key": "{API key}", - "q": "tom cruise" + "q": "tom cruise", + "SafeSearch": "Strict", + "srs": "EPSG:4326" }, "responses": { "200": { diff --git a/test/modelValidatorTests.js b/test/modelValidatorTests.js index 8faa7c18..1f7e082c 100644 --- a/test/modelValidatorTests.js +++ b/test/modelValidatorTests.js @@ -311,32 +311,14 @@ describe('Model Validation', function () { describe('Content type - ', function () { it('should pass for consumes application/octet-stream', function (done) { let specPath = `${__dirname}/modelValidation/swaggers/specification/contenttype/datalake.json`; - let operationIds = "Content_Consume"; - validate.validateExamples(specPath, operationIds, { consoleLogLevel: 'off' }).then((result) => { - assert(result.validityStatus === true, `swagger "${specPath}" with operation "${operationIds}" contains model validation errors.`); + validate.validateExamples(specPath, undefined, { consoleLogLevel: 'off' }).then((result) => { + console.dir(result, { depth: null }); + assert(result.validityStatus === true, `swagger "${specPath}" contains model validation errors.`); console.log(result); done(); }).catch((err) => { done(err); }); }); - - it('should fail for invalid type response in produces application/octet-stream', function (done) { - let specPath = `${__dirname}/modelValidation/swaggers/specification/contenttype/datalake.json`; - let operationIds = "Content_Produce"; - validate.validateExamples(specPath, operationIds, { consoleLogLevel: 'off' }).then((result) => { - assert(result.validityStatus === false, `swagger "${specPath}" with operation "${operationIds}" contains passed incorrectly.`); - console.log(result); - done(); - }).catch((err) => { - try { - assert.equal(err.code, 'INVALID_RESPONSE_BODY'); - assert.equal(err.innerErrors[0].code, 'INVALID_TYPE'); - done(); - } catch (er) { - done(er); - } - }); - }); }); }); \ No newline at end of file