Lines 1-14
Link Here
|
1 |
const { faker } = require("@faker-js/faker"); |
1 |
const { faker } = require("@faker-js/faker"); |
2 |
const { readYamlFile } = require("./../plugins/readYamlFile.js"); |
2 |
const { readYamlFile } = require("./../plugins/readYamlFile.js"); |
|
|
3 |
const fs = require('fs'); |
3 |
|
4 |
|
4 |
const objects = { |
|
|
5 |
patron: { |
6 |
spec: "patron", |
7 |
}, |
8 |
library: { |
9 |
spec: "library", |
10 |
}, |
11 |
}; |
12 |
const generateMockData = type => { |
5 |
const generateMockData = type => { |
13 |
if (Array.isArray(type)) { |
6 |
if (Array.isArray(type)) { |
14 |
type = type.filter(t => t != '"null"')[0]; |
7 |
type = type.filter(t => t != '"null"')[0]; |
Lines 50-59
const generateDataFromSchema = (properties, values = {}) => {
Link Here
|
50 |
}; |
43 |
}; |
51 |
|
44 |
|
52 |
const buildSampleObjects = ({ object, values, count = 1 }) => { |
45 |
const buildSampleObjects = ({ object, values, count = 1 }) => { |
53 |
if (!objects.hasOwnProperty(object)) { |
46 |
const yamlPath = `api/v1/swagger/definitions/${object}.yaml`; |
54 |
throw new Error(`Object type not supported: ${object}`); |
47 |
if (!fs.existsSync(yamlPath)) { |
|
|
48 |
throw new Error( |
49 |
`Object type not supported: '${object}'. No spec file.` |
50 |
); |
55 |
} |
51 |
} |
56 |
const yamlPath = `api/v1/swagger/definitions/${objects[object].spec}.yaml`; |
|
|
57 |
const schema = readYamlFile(yamlPath); |
52 |
const schema = readYamlFile(yamlPath); |
58 |
return Array.from({ length: count }, () => |
53 |
return Array.from({ length: count }, () => |
59 |
generateDataFromSchema(schema.properties, values) |
54 |
generateDataFromSchema(schema.properties, values) |
60 |
- |
|
|