Merge pull request #765 from trheyi/main

Add default value for Upload API if not provided in props
This commit is contained in:
Max 2024-10-24 20:39:47 +08:00 committed by GitHub
commit 2a070f6bc6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View file

@ -28,6 +28,11 @@ func (dsl DSL) Map() map[string]interface{} {
"props": map[string]interface{}(dsl.Props),
}
// Add Default Value for Upload api
if dsl.Type == "Upload" && dsl.Props != nil && !dsl.Props.Has("api") {
res["props"].(map[string]interface{})["$api"] = map[string]interface{}{"process": "fs.data.Upload"}
}
if dsl.HideLabel {
res["hideLabel"] = true
}

View file

@ -179,6 +179,18 @@ func (p PropsDSL) parseCloudProps(xpath string, component string, props map[stri
return res, nil
}
// Has check if the prop exists in the props
func (p PropsDSL) Has(name string) bool {
_, has := p[name]
if has {
return has
}
// check if the prop is a cloud prop
_, has = p[fmt.Sprintf("$%s", name)]
return has
}
// Parse parse cloud props
func (cProp *CloudPropsDSL) Parse(v interface{}) error {