-
-
Save coryhouse/300ed803148caaf9d4f3f45d1a03874d to your computer and use it in GitHub Desktop.
export const schema = { | |
"type": "object", | |
"properties": { | |
"users": { | |
"type": "array", | |
"minItems": 3, | |
"maxItems": 5, | |
"items": { | |
"type": "object", | |
"properties": { | |
"id": { | |
"type": "number", | |
"unique": true, | |
"minimum": 1 | |
}, | |
"firstName": { | |
"type": "string", | |
"faker": "name.firstName" | |
}, | |
"lastName": { | |
"type": "string", | |
"faker": "name.lastName" | |
}, | |
"email": { | |
"type": "string", | |
"faker": "internet.email" | |
} | |
}, | |
"required": ["id", "firstName", "lastName", "email"] | |
} | |
} | |
}, | |
"required": ["users"] | |
}; |
Working generateMockData.js file below: I also had to run 'npm install faker'
/* This script generates mock data for local development.
*/
/* eslint-disable no-console */
import jsf from 'json-schema-faker';
import {schema} from './mockDataSchema';
import fs from 'fs';
import chalk from 'chalk';
import faker from "faker"
jsf.extend("faker", function() {
return faker
})
var outputFile = './src/api/db.json';
//const json = JSON.stringify(jsf(schema));
jsf.resolve(schema).then(function(result) {
fs.writeFile(outputFile, JSON.stringify(result, null, 2), function(err){
if (err) {
return (console.log(r(err)));
} else {
console.log(Mock Data Generated Here: ${outputFile}
);
}
});
});
I uninstalled gel pack (--save) and it worked!
Check out the updated branch of Cory's repository:
https://github.com/coryhouse/javascript-development-environment/blob/update-dependencies/buildScripts/generateMockData.js
To get it to work, make sure Faker is installed and included in the package.json.
For me it kept creating floats instead of whole numbers.
This fix to the number generating part seemed to do the trick.
id: {
type: 'number',
faker: 'random.number',
unique: true,
minimum: 1
},
There's no data coming out from the json file to the webpage on
http://localhost:3000/
. Any fixes?http://localhost:3001/users
is working fine. Its just that no data is rendered in the table from thedb.json
file.