Skip to content
This repository has been archived by the owner on Jul 2, 2019. It is now read-only.

Commit

Permalink
Merge pull request #165 from apiaryio/pksunkara/date
Browse files Browse the repository at this point in the history
Update faker to 0.5.0-rc13 to allow date and date-time
  • Loading branch information
kylef authored Mar 28, 2018
2 parents fd01b1e + 6e91130 commit 193b907
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.18.1

## Enhancements

- Allow `date` and `date-time` format support.

# 0.18.0

## Breaking
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions test/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 193b907

Please sign in to comment.