kcl-lang / kcl

KCL Programming Language (CNCF Sandbox Project). https://kcl-lang.io
https://kcl-lang.io
Apache License 2.0
1.41k stars 110 forks source link

How to check dict type in schema #1430

Closed LinYunling closed 1 week ago

LinYunling commented 1 week ago

Define a schema, use dict type:

schema Attr:
    attr: {str:str}

How to check the key and value? Such as key match ^[a-z][a-z0-9]{0,63}$

Peefy commented 1 week ago

Here's a simple example:

import regex

schema Attr:
    attr: {str:str}

    check:
        all k in attr {
            regex.match(k, r"^[a-z][a-z0-9]{0,63}$")
        }

a = Attr{
    attr: {"+==": "aaa"}
}
LinYunling commented 1 week ago

thanks