Skip to content

Commit

Permalink
Support for pattern subeeshcbabu-zz#3
Browse files Browse the repository at this point in the history
  • Loading branch information
subeeshcbabu committed Jul 6, 2016
1 parent 3939406 commit ca7d518
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/generators/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ function stringMock(schema) {
* If `enum` is defined for the property
*/
mockStr = enumMock(schema);
} else if (schema.pattern) {
/**
* If `pattern` is defined for the property
*/
//Load only if pattern exist.
var randexp = require('randexp').randexp;
mockStr = randexp(schema.pattern);
} else if(Format[schema.format]) {
/**
* If a `format` is defined for the property
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"dependencies": {
"chance": "^1.0.3",
"moment": "^2.13.0",
"randexp": "^0.4.2",
"swagger-parser": "^3.4.1"
},
"devDependencies": {
Expand Down
8 changes: 8 additions & 0 deletions tests/fixture/petstore.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@
"required": true,
"type": "integer",
"format": "int64"
},
{
"name": "petName",
"in": "query",
"description": "Name of pet to return",
"required": true,
"type": "string",
"pattern": "awesome+ (pet|cat|bird)"
}],
"responses": {
"200": {
Expand Down
4 changes: 4 additions & 0 deletions tests/param_mockgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ describe('Parameter Mock generator', function () {
Assert.ok(params.path, 'Generated path parameter');
Assert.ok(params.path[0].name === 'petId', 'generated mock parameter for petId');
Assert.ok(Number.isInteger(params.path[0].value), 'OK value for petId');

Assert.ok(params.query, 'Generated query parameter');
Assert.ok(params.query[0].name === 'petName', 'generated mock parameter for petName');
Assert.ok(/awesome+ (pet|cat|bird)/.test(params.query[0].value), 'OK value for petName');
done();
});
});
Expand Down

0 comments on commit ca7d518

Please sign in to comment.