Bug 38503: Do not generate too long strings

Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Jonathan Druart 2025-01-20 13:38:34 +01:00 committed by Katrin Fischer
parent a5eb0ba010
commit 55c3840588
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
1 changed files with 5 additions and 2 deletions

View File

@ -2,12 +2,15 @@ const { faker } = require("@faker-js/faker");
const { readYamlFile } = require("./../plugins/readYamlFile.js");
const fs = require('fs');
const generateMockData = type => {
const generateMockData = (type, properties) => {
if (Array.isArray(type)) {
type = type.filter(t => t != '"null"')[0];
}
switch (type) {
case "string":
if(properties?.maxLength){
return faker.string.alpha({ length: { min: properties.minLength || 1, max: properties.maxLength } })
}
return faker.lorem.words(3);
case "integer":
return faker.number.int();
@ -36,7 +39,7 @@ const generateDataFromSchema = (properties, values = {}) => {
value?.format == "date" || value?.format == "date-time"
? value.format
: value.type;
mockData[key] = generateMockData(type);
mockData[key] = generateMockData(type, value);
}
});
return mockData;