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:
Jonathan Druart 2024-12-04 14:05:51 +01:00 committed by Katrin Fischer
parent ddd22c7887
commit 9f5f4aa1d6
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
1 changed files with 6 additions and 11 deletions

View File

@ -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)