diff --git a/generators/base-application/support/prepare-field.ts b/generators/base-application/support/prepare-field.ts index 28ce865c9a81..029db72462ac 100644 --- a/generators/base-application/support/prepare-field.ts +++ b/generators/base-application/support/prepare-field.ts @@ -122,7 +122,7 @@ function generateFakeDataForField(this: CoreGenerator, field: Field, faker: Fake if (field.fakerTemplate) { data = faker.helpers.fake(field.fakerTemplate); } else if (field.fieldValidate && field.fieldValidateRules?.includes('pattern')) { - const generated = field.generateFromPattern!(); + const generated = field.generateFakeDataFromPattern!(); if (!generated) { return undefined; } @@ -325,7 +325,7 @@ function prepareCommonFieldForTemplates(entityWithConfig: Entity, field: Field, } const faker = entityWithConfig.faker; - field.generateFromPattern = () => { + field.generateFakeDataFromPattern = () => { // check if regex is valid. If not, issue warning and we skip fake data generation. try { new RegExp(field.fieldValidateRulesPattern!); @@ -333,11 +333,6 @@ function prepareCommonFieldForTemplates(entityWithConfig: Entity, field: Field, generator.log.warn(`${field.fieldName} pattern is not valid: ${field.fieldValidateRulesPattern}. Skipping generating fake data. `); return undefined; } - try { - return faker.helpers.fromRegExp(field.fieldValidateRulesPattern!); - } catch { - // if faker fails to generate data, we will try using RandExp. - } const re = faker.createRandexp(field.fieldValidateRulesPattern!); if (!re) { generator.log.warn(`Error creating generator for pattern ${field.fieldValidateRulesPattern}`); @@ -353,11 +348,6 @@ function prepareCommonFieldForTemplates(entityWithConfig: Entity, field: Field, generator.log.warn(`${field.fieldName} pattern is not valid: ${field.fieldValidateRulesPattern}. Skipping generating fake data. `); return undefined; } - try { - return faker.helpers.fromRegExp(field.fieldValidateRulesPattern!); - } catch { - // if faker fails to generate data, we will try using RandExp. - } const re = faker.createRandexp(field.fieldValidateRulesPattern!); if (!re) { generator.log.warn(`Error creating generator for pattern ${field.fieldValidateRulesPattern}`); diff --git a/generators/spring-boot/templates/src/test/java/_package_/_entityPackage_/web/rest/_entityClass_ResourceIT.java.ejs b/generators/spring-boot/templates/src/test/java/_package_/_entityPackage_/web/rest/_entityClass_ResourceIT.java.ejs index 43f946382278..d0924e51658b 100644 --- a/generators/spring-boot/templates/src/test/java/_package_/_entityPackage_/web/rest/_entityClass_ResourceIT.java.ejs +++ b/generators/spring-boot/templates/src/test/java/_package_/_entityPackage_/web/rest/_entityClass_ResourceIT.java.ejs @@ -331,23 +331,23 @@ if (field.fieldTypeString || field.blobContentTypeText) { const patternRegExp = new RegExp(field.fieldValidateRulesPattern); // set infinite repetitions max range if (!patternRegExp.test(sampleTextString.replace(/\\"/g, '"').replace(/\\\\/g, '\\'))) { - const value = field.generateFromPattern(); + const value = field.generateFakeDataFromPattern(); sampleTextString = value.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); } if (!patternRegExp.test(updatedTextString.replace(/\\"/g, '"').replace(/\\\\/g, '\\'))) { - const value = field.generateFromPattern(); + const value = field.generateFakeDataFromPattern(); updatedTextString = value.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); } } catch (error) { - this.log(this.chalkRed('Error generating test value for entity "' + entityClass + + this.log.warn('Error generating test value for entity "' + entityClass + '" field "' + field.fieldName + '" with pattern "' + field.fieldValidateRulesPattern + - '", generating default values for this field. Detailed error message: "' + error.message + '".')); + '", generating default values for this field. Detailed error message: "' + error.message + '".'); } if (sampleTextString === updatedTextString) { updatedTextString = updatedTextString + "B"; - this.log(this.chalkRed('Randomly generated first and second test values for entity "' + entityClass + + this.log.warn('Randomly generated first and second test values for entity "' + entityClass + '" field "' + field.fieldName + '" with pattern "' + field.fieldValidateRulesPattern + - '" in file "' + entityClass + 'ResourceIT" where equal, added symbol "B" to second value.')); + '" in file "' + entityClass + 'ResourceIT" where equal, added symbol "B" to second value.'); } } _%> diff --git a/lib/types/application/field.d.ts b/lib/types/application/field.d.ts index 2e74fc7fd633..91ae11190585 100644 --- a/lib/types/application/field.d.ts +++ b/lib/types/application/field.d.ts @@ -37,7 +37,7 @@ export interface Field extends BaseField { // Temporary fields for Faker uniqueValue?: any[]; - generateFromPattern?: () => string | undefined; + generateFakeDataFromPattern?: () => string | undefined; /** @deprecated */ createRandexp: () => any;