Skip to content

ValidateMapCtx does not support validating []map[string]interface{} in []interface #955

Open
@leftjs

Description

@leftjs
  • I have looked at the documentation here first?
  • I have looked at the examples provided that may showcase my question here?

Package version eg. v9, v10:

v10

Issue, Question or Enhancement:

Issue & Enhancement

Code sample, to showcase or reproduce:

json.Unmarshal() will convert JSON Array to []interface, currently ValidateMapCtx does not support validating []map[string]interface{} in []interface

It should support checking []map[string]interface{} in []interface, e.g.

bs, err := ioutil.ReadFile("./test/deployment.json")
if err != nil {
	panic(err)
}

var mmm map[string]interface{}
err = json.Unmarshal(bs, &mmm)
if err != nil {
	panic(err)
}

bs, err = ioutil.ReadFile("./test/rule.json")
if err != nil {
	panic(err)
}

var rules map[string]interface{}
_ = json.Unmarshal(bs, &rules)

res := validate.ValidateMapCtx(context.Background(), mmm, rules)

k8s deployment may contain multiple container definitions, so rule.json is defined as follows

{
    "spec": {
        "replicas": "required,number,gte=1,lte=300",
        "template": {
            "spec": {
                "terminationGracePeriodSeconds": "gte=0,lte=120",
                "containers": [
                    {
                        "name": "required,min=1,max=64,containername"
                    }
                ]
            }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions