From 2d8c565703891a7ea3740776a941e647acb99ddb Mon Sep 17 00:00:00 2001 From: Samuel Marks Date: Fri, 8 Dec 2017 18:57:29 -0500 Subject: [PATCH] Make the example check a bit stricter. --- lib/generators/index.js | 2 +- tests/fixture/petstore.json | 5 +++++ tests/response_mockgen.js | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/generators/index.js b/lib/generators/index.js index 9a300dd..7a8cac7 100644 --- a/lib/generators/index.js +++ b/lib/generators/index.js @@ -11,7 +11,7 @@ const mock = (schema, useExample) => { /** * Get the mock generator from the `type` of the schema */ - if (example && useExample) { + if (typeof example !== 'undefined' && useExample) { mock = example; } else { const generator = Generators[type]; diff --git a/tests/fixture/petstore.json b/tests/fixture/petstore.json index cf8c6a3..8e6d305 100644 --- a/tests/fixture/petstore.json +++ b/tests/fixture/petstore.json @@ -844,6 +844,11 @@ "type": "string", "description": "pet status in the store", "enum": ["available", "pending", "sold"] + }, + "mean": { + "type": "boolean", + "description": "whether or not the pet is mean", + "example": false } }, "xml": { diff --git a/tests/response_mockgen.js b/tests/response_mockgen.js index 5af1d85..ddd5861 100644 --- a/tests/response_mockgen.js +++ b/tests/response_mockgen.js @@ -78,6 +78,19 @@ describe('Response Mock generator', () => { }); }); + it('should use the example false when generating with examples for path /pet/{petId}', (done) => { + swagmock.responses({ + path: '/pet/{petId}', + operation: 'get', + response: '200', + useExamples: true + }, (err, mock) => { + let resp = mock.responses; + Assert.equal(resp.mean, false); + done(); + }); + }); + it('should generate response mock for path /pet/{petId}/uploadImage', (done) => { swagmock.responses({ path: '/pet/{petId}/uploadImage',