Skip to content

Commit 71c52dc

Browse files
committed
Fix issue with initialization of action params
That could cause them to end up with the wrong type when inherited from the resource or design base parameters in which case they would always end up being string instead of the type defined in the design.
1 parent e47d129 commit 71c52dc

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

design/definitions.go

+32-16
Original file line numberDiff line numberDiff line change
@@ -831,26 +831,42 @@ func (r *ResourceDefinition) Finalize() {
831831
}
832832
}
833833
// 2. Create implicit action parameters for path wildcards that dont' have one
834-
for _, r := range a.Routes {
835-
wcs := ExtractWildcards(r.FullPath())
836-
for _, wc := range wcs {
834+
for _, ro := range a.Routes {
835+
for _, wc := range ro.Params() {
837836
found := false
838-
var o Object
839-
if all := a.Params; all != nil {
840-
o = all.Type.ToObject()
841-
} else {
842-
o = Object{}
843-
a.Params = &AttributeDefinition{Type: o}
844-
}
845-
for n := range o {
846-
if n == wc {
847-
found = true
848-
break
837+
search := func(params *AttributeDefinition) {
838+
if params == nil {
839+
return
840+
}
841+
for n, att := range params.Type.ToObject() {
842+
if n == wc {
843+
if a.Params == nil {
844+
a.Params = &AttributeDefinition{Type: Object{}}
845+
}
846+
a.Params.Type.ToObject()[wc] = att
847+
found = true
848+
break
849+
}
849850
}
850851
}
851-
if !found {
852-
o[wc] = &AttributeDefinition{Type: String}
852+
search(a.Params)
853+
parent := r
854+
for !found && parent != nil {
855+
bp := parent.BaseParams
856+
parent = parent.Parent()
857+
search(bp)
858+
}
859+
if found {
860+
continue
861+
}
862+
search(Design.BaseParams)
863+
if found {
864+
continue
865+
}
866+
if a.Params == nil {
867+
a.Params = &AttributeDefinition{Type: Object{}}
853868
}
869+
a.Params.Type.ToObject()[wc] = &AttributeDefinition{Type: String}
854870
}
855871
}
856872
// 3. Compute QueryParams from Params and set all path params as non zero attributes

0 commit comments

Comments
 (0)