From d8258b79adeeb6dc380ec9caa46ac54bc1585ac0 Mon Sep 17 00:00:00 2001 From: Jeremy Hayes Date: Tue, 13 Nov 2018 18:16:13 -0500 Subject: [PATCH] add primitive factory method for string/date --- src/core/plugins/samples/fn.js | 1 + test/core/plugins/samples/fn.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/core/plugins/samples/fn.js b/src/core/plugins/samples/fn.js index 574bbd2cf85..99d5b13f112 100644 --- a/src/core/plugins/samples/fn.js +++ b/src/core/plugins/samples/fn.js @@ -6,6 +6,7 @@ const primitives = { "string": () => "string", "string_email": () => "user@example.com", "string_date-time": () => new Date().toISOString(), + "string_date": () => new Date().toISOString().substring(0, 10), "number": () => 0, "number_float": () => 0.0, "integer": () => 0, diff --git a/test/core/plugins/samples/fn.js b/test/core/plugins/samples/fn.js index 697da7f1fcd..3ada0dcc70e 100644 --- a/test/core/plugins/samples/fn.js +++ b/test/core/plugins/samples/fn.js @@ -238,6 +238,28 @@ describe("sampleFromSchema", function() { expect(sampleFromSchema(definition, { includeWriteOnly: true })).toEqual(expected) }) + it("returns example value for date-time property", function() { + var definition = { + type: "string", + format: "date-time" + } + + var expected = new Date().toISOString() + + expect(sampleFromSchema(definition)).toEqual(expected) + }) + + it("returns example value for date property", function() { + var definition = { + type: "string", + format: "date" + } + + var expected = new Date().toISOString().substring(0, 10) + + expect(sampleFromSchema(definition)).toEqual(expected) + }) + describe("for array type", function() { it("returns array with sample of array type", function() { var definition = {