From a0743019ac2a25d9b66a926b2d786b104549e663 Mon Sep 17 00:00:00 2001 From: soasurs Date: Fri, 15 Apr 2022 12:59:22 +0800 Subject: [PATCH] feat: apply separate security requirement object for each route Signed-off-by: soasurs --- generate/parser.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/generate/parser.go b/generate/parser.go index 359f68b..a82e357 100644 --- a/generate/parser.go +++ b/generate/parser.go @@ -59,7 +59,7 @@ func applyGenerate(p *plugin.Plugin, host string, basePath string) (*swaggerObje newSecDefValue.In = "header" s.SecurityDefinitions["apiKey"] = newSecDefValue - s.Security = append(s.Security, swaggerSecurityRequirementObject{"apiKey": []string{}}) + //s.Security = append(s.Security, swaggerSecurityRequirementObject{"apiKey": []string{}}) requestResponseRefs := refMap{} renderServiceRoutes(p.Api.Service, p.Api.Service.Groups, s.Paths, requestResponseRefs) @@ -233,6 +233,10 @@ func renderServiceRoutes(service spec.Service, groups []spec.Group, paths swagge operationObject.Description = strings.ReplaceAll(operationObject.Description, "\"", "") + if group.Annotation.Properties["jwt"] != "" { + operationObject.Security = &[]swaggerSecurityRequirementObject{{"apiKey": []string{}}} + } + switch strings.ToUpper(route.Method) { case http.MethodGet: pathItemObject.Get = operationObject