Lines 26-52
const generateMockData = type => {
Link Here
|
26 |
} |
26 |
} |
27 |
}; |
27 |
}; |
28 |
|
28 |
|
29 |
const generateDataFromSchema = properties => { |
29 |
const generateDataFromSchema = (properties, values = {}) => { |
30 |
const mockData = {}; |
30 |
const mockData = {}; |
31 |
Object.entries(properties).forEach(([key, value]) => { |
31 |
Object.entries(properties).forEach(([key, value]) => { |
32 |
mockData[key] = generateMockData(value.type); |
32 |
if (values.hasOwnProperty(key)) { |
|
|
33 |
mockData[key] = values[key]; |
34 |
} else { |
35 |
mockData[key] = generateMockData(value.type); |
36 |
} |
33 |
}); |
37 |
}); |
34 |
return mockData; |
38 |
return mockData; |
35 |
}; |
39 |
}; |
36 |
|
40 |
|
37 |
const buildSampleObjects = ({ object, count = 1 }) => { |
41 |
const buildSampleObjects = ({ object, values, count = 1 }) => { |
38 |
if (!objects.hasOwnProperty(object)) { |
42 |
if (!objects.hasOwnProperty(object)) { |
39 |
throw new Error(`Object type not supported: ${object}`); |
43 |
throw new Error(`Object type not supported: ${object}`); |
40 |
} |
44 |
} |
41 |
const yamlPath = `api/v1/swagger/definitions/${objects[object].spec}.yaml`; |
45 |
const yamlPath = `api/v1/swagger/definitions/${objects[object].spec}.yaml`; |
42 |
const schema = readYamlFile(yamlPath); |
46 |
const schema = readYamlFile(yamlPath); |
43 |
return Array.from({ length: count }, () => |
47 |
return Array.from({ length: count }, () => |
44 |
generateDataFromSchema(schema.properties) |
48 |
generateDataFromSchema(schema.properties, values) |
45 |
); |
49 |
); |
46 |
}; |
50 |
}; |
47 |
|
51 |
|
48 |
const buildSampleObject = object => { |
52 |
const buildSampleObject = ({ object, values = {} }) => { |
49 |
return buildSampleObjects({ object })[0]; |
53 |
return buildSampleObjects({ object, values })[0]; |
50 |
}; |
54 |
}; |
51 |
|
55 |
|
52 |
module.exports = { |
56 |
module.exports = { |
53 |
- |
|
|