From 6cb6c65b233a7767a2bea7c2bc60cb850754e6d1 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Wed, 28 Mar 2018 13:39:19 +0200 Subject: [PATCH 1/2] feat: Update faker to 0.5.0-rc13 to allow date and date-time --- package.json | 4 ++-- src/generator.js | 2 +- test/generator.js | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 3a58f3e..e53f58f 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "dependencies": { "babel-runtime": "^6.23.0", "js-yaml": "^3.4.2", - "json-schema-faker": "0.5.0-rc11", + "json-schema-faker": "0.5.0-rc13", "lodash": "^4.15.0", "swagger-parser": "^3.3.0", "yaml-js": "^0.2.3", @@ -36,7 +36,7 @@ "minim": "^0.20.1", "minim-parse-result": "^0.10.0", "peasant": "1.1.0", - "swagger-zoo": "2.11.0" + "swagger-zoo": "2.12.0" }, "engines": { "node": ">=6" diff --git a/src/generator.js b/src/generator.js index 5d22e5b..fab03c6 100644 --- a/src/generator.js +++ b/src/generator.js @@ -71,7 +71,7 @@ export function bodyFromFormParameter(param, schema) { // If there's example value, we want to force the body generator // to use it. This is done using 'enum' with a single value. if (param['x-example'] !== undefined) { - paramSchema.enum = [param['x-example']]; + paramSchema.default = param['x-example']; } delete paramSchema.name; diff --git a/test/generator.js b/test/generator.js index 35f22bf..d120669 100644 --- a/test/generator.js +++ b/test/generator.js @@ -40,6 +40,30 @@ describe('bodyFromSchema', () => { expect(body).to.deep.equal({ name: 'doe' }); }); + it('can generate a JSON object for date format', () => { + const schema = { + type: 'string', + format: 'date', + }; + + const payload = { content: [] }; + const asset = bodyFromSchema(schema, payload, parser, 'application/json'); + + expect(asset.content).to.match(/^(19|20)[0-9]{2}-[0-1][0-9]-[0-3][0-9]$/); + }); + + it('can generate a JSON object for date format', () => { + const schema = { + type: 'string', + format: 'date-time', + }; + + const payload = { content: [] }; + const asset = bodyFromSchema(schema, payload, parser, 'application/json'); + + expect(asset.content).to.match(/^(19|20)[0-9]{2}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9]/); + }); + it('limits a strings min/max length to 256', () => { const schema = { type: 'string', From 6e91130f4a11eb484acbeed168de38fb6f122957 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Wed, 28 Mar 2018 13:42:58 +0200 Subject: [PATCH 2/2] chore: Release 0.18.1 --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35cde7c..99a1592 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.18.1 + +## Enhancements + +- Allow `date` and `date-time` format support. + # 0.18.0 ## Breaking diff --git a/package.json b/package.json index e53f58f..f5a6910 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fury-adapter-swagger", - "version": "0.18.0", + "version": "0.18.1", "description": "Swagger 2.0 parser for Fury.js", "main": "./lib/adapter.js", "tonicExampleFilename": "tonic-example.js",