diff --git a/service/session/option.go b/service/session/option.go index 0620217b..c16a15a4 100644 --- a/service/session/option.go +++ b/service/session/option.go @@ -16,6 +16,7 @@ type ( kindLocator *locator.KindLocator namedParameters state.NamedParameters locatorOptions []locator.Option //resousrce, route level options + locatorOpt *locator.Options codecOptions []codec.Option types []*state.Type indirectState bool @@ -26,6 +27,12 @@ type ( Option func(o *Options) ) +func (o *Options) HasInputParameters() bool { + if o.locatorOpt == nil { + return false + } + return len(o.locatorOpt.InputParameters) > 0 +} func (o *Options) shallReportNotAssignable() bool { if o.reportNotAssignable == nil { return true @@ -39,6 +46,7 @@ func (o *Options) Indirect(flag bool, options ...locator.Option) *Options { ret.locatorOptions = append(ret.locatorOptions, options...) ret.kindLocator = locator.NewKindsLocator(ret.kindLocator, ret.locatorOptions...) } + ret.locatorOpt = locator.NewOptions(ret.locatorOptions) return &ret } @@ -89,6 +97,7 @@ func WithLocators(locators *locator.KindLocator) Option { func WithLocatorOptions(options ...locator.Option) Option { return func(s *Options) { s.locatorOptions = options + s.locatorOpt = locator.NewOptions(options) } } diff --git a/service/session/state.go b/service/session/state.go index e126da39..28f55c01 100644 --- a/service/session/state.go +++ b/service/session/state.go @@ -154,7 +154,10 @@ func (s *Session) viewLookupOptions(aView *view.View, parameters state.NamedPara result = append(result, locator.WithParameterLookup(func(ctx context.Context, parameter *state.Parameter) (interface{}, bool, error) { return s.LookupValue(ctx, parameter, opts) })) - result = append(result, locator.WithInputParameters(parameters)) + + if !opts.HasInputParameters() { + result = append(result, locator.WithInputParameters(parameters)) + } result = append(result, locator.WithReadInto(s.ReadInto)) viewState := s.state.Lookup(aView) result = append(result, locator.WithState(viewState.Template)) diff --git a/view/resource.go b/view/resource.go index cc411d10..853dfe33 100644 --- a/view/resource.go +++ b/view/resource.go @@ -217,13 +217,21 @@ func (r *Resource) mergeParameters(resource *Resource) { if len(resource.Parameters) == 0 { return } - views := r.paramByName() + namedParameters := r.Parameters.Index() + byKindNameParameters := r.Parameters.ByKindName() for i, candidate := range resource.Parameters { - _, ok := views[candidate.Name] + if _, ok := byKindNameParameters[candidate.In.Name]; ok { + byKindNameParameters[candidate.In.Name].Value = candidate.Value + continue + } + _, ok := namedParameters[candidate.Name] if !ok { param := *resource.Parameters[i] r.Parameters = append(r.Parameters, ¶m) + } else { + namedParameters[candidate.Name].Value = candidate.Value } + } } @@ -272,17 +280,6 @@ func (r *Resource) MBusResourceByName() MessageBuses { return MessageBusSlice(r.MessageBuses).Index() } -func (r *Resource) paramByName() map[string]*state.Parameter { - index := map[string]*state.Parameter{} - if len(r.Parameters) == 0 { - return index - } - for i, param := range r.Parameters { - index[param.Name] = r.Parameters[i] - } - return index -} - func (r *Resource) typeByName() map[string]*TypeDefinition { index := map[string]*TypeDefinition{} if len(r.Parameters) == 0 { diff --git a/view/state/kind/locator/options.go b/view/state/kind/locator/options.go index 9b722aaa..a62091df 100644 --- a/view/state/kind/locator/options.go +++ b/view/state/kind/locator/options.go @@ -170,7 +170,7 @@ func WithInputParameters(parameters state.NamedParameters) Option { for k, v := range parameters { o.InputParameters[k] = v if v.In.Kind == state.KindConst { - o.resourceConstants[v.Name] = v.Value + o.resourceConstants[v.In.Name] = v.Value } } diff --git a/view/state/parameters.go b/view/state/parameters.go index 96afb18a..0f24b983 100644 --- a/view/state/parameters.go +++ b/view/state/parameters.go @@ -460,6 +460,24 @@ func (p Parameters) Lookup(name string) *Parameter { return nil } +// ByKindName indexes parameters by Parameter.In.Name +func (p Parameters) ByKindName() NamedParameters { + result := NamedParameters(make(map[string]*Parameter)) + for i, parameter := range p { + if _, ok := result[parameter.In.Name]; ok { + continue + } + result[parameter.In.Name] = p[i] + for _, item := range parameter.Object { + result[item.In.Name] = item + } + for _, item := range parameter.Repeated { + result[item.In.Name] = item + } + } + return result +} + // Index indexes parameters by Parameter.Name func (p Parameters) Index() NamedParameters { result := NamedParameters(make(map[string]*Parameter))