@@ -214,13 +214,25 @@ func (gc GeneratorCorpus) GenerateWithTemplate(templatePath, fieldsDefinitionPat
214214 return "" , errors .New ("you must provide a non empty template content" )
215215 }
216216
217- ctx := context .Background ()
218- flds , err := fields .LoadFieldsWithTemplate (ctx , fieldsDefinitionPath )
219- if err != nil {
220- return "" , err
217+ var fieldsDefinitions Fields
218+
219+ // If fieldsDefinitionPath is not provided, we use the fields types from the config
220+ if gc .config .HasFieldsMappings () && fieldsDefinitionPath == "" {
221+ configFieldsDefinitions , err := gc .config .LoadFieldsMappings ()
222+ if err != nil {
223+ return "" , err
224+ }
225+
226+ fieldsDefinitions = mapFields (configFieldsDefinitions )
227+ } else {
228+ ctx := context .Background ()
229+ fieldsDefinitions , err = fields .LoadFieldsWithTemplate (ctx , fieldsDefinitionPath )
230+ if err != nil {
231+ return "" , err
232+ }
221233 }
222234
223- err = gc .eventsPayloadFromFields (template , flds , totEvents , timeNow , randSeed , nil , f )
235+ err = gc .eventsPayloadFromFields (template , fieldsDefinitions , totEvents , timeNow , randSeed , nil , f )
224236 if err != nil {
225237 return "" , err
226238 }
@@ -242,3 +254,22 @@ func sanitizeFilename(s string) string {
242254 s = strings .Replace (s , "\\ " , "-" , - 1 )
243255 return s
244256}
257+
258+ // mapFields converts config fields mappings to generator fields.
259+ func mapFields (fieldDefinitions config.FieldsMappings ) Fields {
260+ fieldsDefinitions := make (Fields , 0 , len (fieldDefinitions ))
261+
262+ for _ , f := range fieldDefinitions {
263+ tempField := fields.Field {
264+ Name : f .Name ,
265+ Type : f .Type ,
266+ ObjectType : f .ObjectType ,
267+ Example : f .Example ,
268+ Value : f .Value ,
269+ }
270+
271+ fieldsDefinitions = append (fieldsDefinitions , tempField )
272+ }
273+
274+ return fieldsDefinitions
275+ }
0 commit comments