From f814b489db5ad11074ff62bc6593a4e68e98410c Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 27 Oct 2021 15:29:48 +0300 Subject: [PATCH] update Signed-off-by: Vasiliy Tolstov --- openapiv3.go | 16 ++++++++++++++++ util.go | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/openapiv3.go b/openapiv3.go index 7ba260b..20d689c 100644 --- a/openapiv3.go +++ b/openapiv3.go @@ -222,6 +222,15 @@ func (g *openapiv3Generator) buildOperationV3( parameters = append(parameters, opt.Parameters...) } + sparameters := make(map[string]struct{}) + for _, paramOrRef := range parameters { + parameter := paramOrRef.GetParameter() + if parameter == nil { + continue + } + sparameters[parameter.Name] = struct{}{} + } + // Build a list of path parameters. pathParameters := make([]string, 0) if matches := g.namePattern.FindStringSubmatch(path); matches != nil { @@ -244,6 +253,10 @@ func (g *openapiv3Generator) buildOperationV3( } // Add the path parameters to the operation parameters. for _, pathParameter := range pathParameters { + if _, ok := sparameters[pathParameter]; ok { + continue + } + parameters = append(parameters, &v3.ParameterOrReference{ Oneof: &v3.ParameterOrReference_Parameter{ @@ -268,6 +281,9 @@ func (g *openapiv3Generator) buildOperationV3( for _, field := range inputMessage.Fields { fieldName := string(field.Desc.Name()) if !contains(coveredParameters, fieldName) { + if _, ok := sparameters[fieldName]; ok { + continue + } // Get the field description from the comments. fieldDescription := g.filterCommentString(field.Comments.Leading) parameters = append(parameters, diff --git a/util.go b/util.go index 7157467..dbaa3ab 100644 --- a/util.go +++ b/util.go @@ -269,7 +269,7 @@ func generateServiceServerMethods(gfile *protogen.GeneratedFile, service *protog } if len(parameters) > 0 { - gfile.P(microServerHttpPackage.Ident("FillRequest"), `(req, `) + gfile.P(microServerHttpPackage.Ident("FillRequest"), `(ctx, req, `) for pk, pv := range parameters { params := make([]string, 0, len(pv)/2) for k, v := range pv {