cycloid-cli icon indicating copy to clipboard operation
cycloid-cli copied to clipboard

Merge with default values doesn't work on cy create-stackforms-env

Open fhacloid opened this issue 1 year ago • 1 comments

When creating a project using the new stackforms command cy create-stackforms-env -> create-env.go I added logic to fetch the defaults values first to merge them with the values provided by the user.

The merge doesn't happend because the lib i'm using (mergo) can merge only 2 similar structs.

On this line:

		mergo.Merge(&vars, defaultValues, mergo.WithOverride)

The DefaultValues are recovered from the common.ParseFormsConfig() function that take a *model.FormUseCase and return a map[string]map[string]map[string]any (which is the format expected for a vars input for stackforms).

The vars variable is a map[string]interface{} and so, since it's not the same type as DefaultValues it doesn't merge the values.

We need to use the same types for both, this means changing the vars type, but it will require to refactor the common.UpdateMapField() function that is used to apply the -V args. This function is also related to this issue.

fhacloid avatar Jul 09 '24 10:07 fhacloid

It'd be nice to also look into https://github.com/darccio/mergo?tab=readme-ov-file#transformers to see if it can be done by writing our own transformer

kerak19 avatar Jul 15 '24 09:07 kerak19

fixed by #313

fhacloid avatar Dec 10 '24 10:12 fhacloid