Bug 38503: Do not list the objects
No need to list all the objects, just retrieve the spec depending on the "object" var we pass. Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
ddd22c7887
commit
9f5f4aa1d6
|
|
@ -1,14 +1,7 @@
|
|||
const { faker } = require("@faker-js/faker");
|
||||
const { readYamlFile } = require("./../plugins/readYamlFile.js");
|
||||
const fs = require('fs');
|
||||
|
||||
const objects = {
|
||||
patron: {
|
||||
spec: "patron",
|
||||
},
|
||||
library: {
|
||||
spec: "library",
|
||||
},
|
||||
};
|
||||
const generateMockData = type => {
|
||||
if (Array.isArray(type)) {
|
||||
type = type.filter(t => t != '"null"')[0];
|
||||
|
|
@ -50,10 +43,12 @@ const generateDataFromSchema = (properties, values = {}) => {
|
|||
};
|
||||
|
||||
const buildSampleObjects = ({ object, values, count = 1 }) => {
|
||||
if (!objects.hasOwnProperty(object)) {
|
||||
throw new Error(`Object type not supported: ${object}`);
|
||||
const yamlPath = `api/v1/swagger/definitions/${object}.yaml`;
|
||||
if (!fs.existsSync(yamlPath)) {
|
||||
throw new Error(
|
||||
`Object type not supported: '${object}'. No spec file.`
|
||||
);
|
||||
}
|
||||
const yamlPath = `api/v1/swagger/definitions/${objects[object].spec}.yaml`;
|
||||
const schema = readYamlFile(yamlPath);
|
||||
return Array.from({ length: count }, () =>
|
||||
generateDataFromSchema(schema.properties, values)
|
||||
|
|
|
|||
Loading…
Reference in New Issue