From 6472fddb9f8a3938cbaf3d719ba87abb7e3e3cbc Mon Sep 17 00:00:00 2001 From: Wei Guo Date: Wed, 11 Apr 2018 19:34:03 +0800 Subject: [PATCH] fix(service): Consumes and Produces of descriptor should affect current definitions (#201) Automatic merge from submit-queue. fix(service): Consumes and Produces of descriptor should affect current definitions **What this PR does / why we need it**: Descriptor's Consumes and Produces can't impact its definitions. **Which issue(s) this PR fixes** *(optional, close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: /cc @yejiayu **Release note**: ```release-note NONE ``` --- service/builder.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/service/builder.go b/service/builder.go index 4d8f0325..4ea177f5 100644 --- a/service/builder.go +++ b/service/builder.go @@ -89,6 +89,12 @@ func (b *builder) AddDescriptor(descriptors ...definition.Descriptor) error { func (b *builder) addDescriptor(prefix string, consumes []string, produces []string, descriptor definition.Descriptor) { path := strings.Join([]string{prefix, strings.Trim(descriptor.Path, "/")}, "/") + if descriptor.Consumes != nil { + consumes = descriptor.Consumes + } + if descriptor.Produces != nil { + produces = descriptor.Produces + } if len(descriptor.Middlewares) > 0 || len(descriptor.Definitions) > 0 { bd, ok := b.bindings[path] if !ok { @@ -110,12 +116,6 @@ func (b *builder) addDescriptor(prefix string, consumes []string, produces []str } } } - if descriptor.Consumes != nil { - consumes = descriptor.Consumes - } - if descriptor.Produces != nil { - produces = descriptor.Produces - } for _, child := range descriptor.Children { b.addDescriptor(strings.TrimRight(path, "/"), consumes, produces, child) }