Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Mollweide committed Jun 11, 2016
2 parents 62ddf69 + 2c82634 commit 7ff4e8d
Show file tree
Hide file tree
Showing 58 changed files with 2,152 additions and 746 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
"setTimeout": true,
"clearTimeout": true,
"jQuery": true,
"describe": true,
"bind": true,
"it": true,
"$": true
}
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ node_modules
/example_rest_folder/*/*/*/mock/response.txt
rest
/test/tmp
/test/func-imported
/tmp
npm-debug.log
npm-debug.log
/func-imported
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ test
src/swagger
/tmp
tmp
/func-imported
func-imported
npm-debug.log
.eslintrc
17 changes: 11 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@

var mockServer = require('./mock-server.js'),
dest = __dirname + '/example_rest_folder';
dest = __dirname + '/example_rest_folder',
replacePathsStr = '/v2/{baseSiteId}',
responseFuncPath = __dirname + '/func-imported';

//dest = __dirname + '/test/tmp/swagger-import';
dest = __dirname + '/test/tmp/swagger-import';
replacePathsStr = '/v2/{id}';

mockServer({
restPath: dest,
dirName: __dirname,
funcPath: [
__dirname + '/func',
__dirname + '/func2'
__dirname + '/func2',
responseFuncPath
],
swaggerImport: {
protocol: 'http',
authUser: undefined,
authPass: undefined,
host: 'localhost',
port: 3001,
path: __dirname + '/src/swagger/swagger-demo-docs.json',
path: '/src/swagger/swagger-api-docs.json',
dest: dest,
replacePathsStr: '/v2/{baseSiteId}',
replacePathsStr: replacePathsStr,
createErrorFile: true,
createEmptyFile: true,
overwriteExistingDescriptions: true,
maxRefDeep: 1
responseFuncPath: responseFuncPath
}
});
11 changes: 11 additions & 0 deletions controller/AppController.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ AppController.prototype = extend(AppController.prototype, {
* @method init
* called by constructor
* @param {object} options
* @param {string} options.dirName
* @param {object} options.swaggerImport
* @param {string|undefined} options.jsVersion
* @public
*/
Expand All @@ -55,6 +57,15 @@ AppController.prototype = extend(AppController.prototype, {
this.options = options;
this.app = app;

if (!this.options.dirName) {
console.error('options.dirName is required (dirName: __dirname)');
return;
}

if (this.options.swaggerImport) {
this.options.swaggerImport.dirName = this.options.dirName;
}

app.listen(options.port, function () {
if (process.env.NODE_ENV !== 'test') {
console.log('server started at port ' + options.port);
Expand Down
7 changes: 5 additions & 2 deletions controller/MockController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
'use strict';

var Utils = require('../lib/Utils'),
util = require('util'),
extend = util._extend,
extend = require('util')._extend,
ejs = require('ejs'),
faker = require('faker'),
AppControllerSingleton = require('./AppController'),
Expand Down Expand Up @@ -109,6 +108,10 @@ MockController.prototype = extend(MockController.prototype, {
responseData = extend(responseData, this._getFunc(this.options.funcPath));
responseData = extend(responseData, this._getDynamicPathParams(options));
responseData = extend(responseData, this._getResponseFiles(options, responseData));
responseData = extend(responseData, {
require: require,
__dirname: this.options.dirName
});
outStr = ejs.render(responseFile, responseData);
} catch (err) {
console.log(err);
Expand Down
19 changes: 13 additions & 6 deletions controller/ResponseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,23 @@ ResponseController.prototype = extend(ResponseController.prototype, {
_viewResponse: function (req, res) {
var data,
response = new GetResponse({
path: req.query.path,
method: req.query.method,
expected: req.query.expected
}, this.options);
path: req.query.path,
method: req.query.method,
expected: req.query.expected
}, this.options);

data = response.get();

if (typeof data === 'object') {
res.send(JSON.stringify(data, null, 2));
res.end();
return;
}

try {
data = JSON.parse(data);
data = JSON.stringify(data, null, 2);
res.send(JSON.stringify(JSON.parse(data), null, 2));
res.end();
return;
} catch (err) {}

res.send(data);
Expand Down
47 changes: 47 additions & 0 deletions example_rest_folder/_DTO/CardDTO.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "string",
"username": "string",
"email": "string",
"phone": "string",
"website": "string",
"entries": [
"$ref-CardDTO"
],
"posts": [
{
"words": "string",
"sentence": "string",
"sentences": "string",
"paragraph": "string"
}
],
"accountHistory": [
{
"name": "string",
"type": "string",
"account": "string",
"amount": "string",
"date": "string",
"business": "string"
}
],
"address": {
"streetA": "string",
"streetB": "string",
"streetC": "string",
"streetD": "string",
"city": "string",
"state": "string",
"country": "string",
"zipcode": "string",
"geo": {
"lat": "string",
"lng": "string"
},
"company": {
"name": "string",
"catchPhrase": "string",
"bs": "string"
}
}
}
4 changes: 4 additions & 0 deletions example_rest_folder/_DTO/PriceDTO.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"currency": "string",
"price": "number"
}
10 changes: 1 addition & 9 deletions example_rest_folder/products/#/GET/response_schema.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "ProductSearch",
"type": "object",
"description": "Description",
"properties": {
"success": {
"type": "boolean"
}
}
"success": "boolean"
}
10 changes: 1 addition & 9 deletions example_rest_folder/products/#search/GET/response_schema.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "ProductSearch",
"type": "object",
"description": "Description",
"properties": {
"success": {
"type": "boolean"
}
}
"success": "boolean"
}
17 changes: 10 additions & 7 deletions example_rest_folder/products/#{productCode}/GET/.store.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
{
"validation": {
"request-data": {
"counter": 1
},
"success": {
"counter": 1
"faker": {
"counter": 6
},
"func": {
"counter": 0
},
"faker": {
"counter": 8
"request-data": {
"counter": 1
},
"success-1": {
"counter": 3
Expand All @@ -20,6 +17,12 @@
},
"success-default": {
"counter": 1
},
"success": {
"counter": 1
},
"deep-validation": {
"counter": 0
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"productCode": "string",
"price": {
"currency": "string",
"price": 0.44
},
"email": "string",
"success": true,
"highlight": true,
"quantity": 231,
"currentPage": "string",
"cards": [
{
"name": "string",
"username": "string",
"email": "string",
"phone": "string",
"website": "string",
"posts": [
{
"words": "string",
"sentence": "string",
"sentences": "string",
"paragraph": "string"
}
],
"accountHistory": [
{
"name": "string",
"type": "string",
"account": "string",
"amount": "string",
"date": "string",
"business": "string"
}
],
"address": {
"streetA": "string",
"streetB": "string",
"streetC": "string",
"streetD": "string",
"city": "string",
"state": "string",
"country": "string",
"zipcode": "string",
"geo": {
"lat": "string",
"lng": "string"
},
"company": {
"name": "string",
"catchPhrase": "string",
"bs": "string"
}
}
}
],
"arrayString": [
"23423423"
],
"arrayNumber": [
23423423
],
"arrayObject": [
{
"name": "firstName lastName"
}
],
"arrayArray": [
[
{
"name": "firstName lastName"
}
]
],
"image": {
"url": "string",
"alt": "string"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"price": <%-price(12,'CHF');%>,
"email": "<%-faker.internet.email();%>",
"card": <%-JSON.stringify(faker.helpers.createCard());%>
"cards": [<%-JSON.stringify(faker.helpers.createCard());%>]
}
Loading

0 comments on commit 7ff4e8d

Please sign in to comment.