Skip to content

Commit

Permalink
Enable to clear default security configuration in operationObject.Sec…
Browse files Browse the repository at this point in the history
…urity (to make public api)

protoc-gen-swagger doesn't allow empty array (and it causes segfault) in operationObject.Security but it is really needed
resetting security requirement configuration by Swagger.
  • Loading branch information
co3k committed Jun 20, 2018
1 parent 9b9677c commit bd32f3d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions protoc-gen-swagger/genswagger/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,21 +653,26 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re
}
if opts.Security != nil {
newSecurity := []swaggerSecurityRequirementObject{}
if operationObject.Security == nil {
newSecurity = []swaggerSecurityRequirementObject{}
} else {
newSecurity = operationObject.Security
if operationObject.Security != nil {
newSecurity = *operationObject.Security
}
for _, secReq := range opts.Security {
newSecReq := swaggerSecurityRequirementObject{}
for secReqKey, secReqValue := range secReq.SecurityRequirement {
if secReqValue == nil {
continue
}

newSecReqValue := make([]string, len(secReqValue.Scope))
copy(newSecReqValue, secReqValue.Scope)
newSecReq[secReqKey] = newSecReqValue
}
newSecurity = append(newSecurity, newSecReq)

if len(newSecReq) > 0 {
newSecurity = append(newSecurity, newSecReq)
}
}
operationObject.Security = newSecurity
operationObject.Security = &newSecurity
}
if opts.Responses != nil {
for name, resp := range opts.Responses {
Expand Down
2 changes: 1 addition & 1 deletion protoc-gen-swagger/genswagger/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type swaggerOperationObject struct {
Tags []string `json:"tags,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`

Security []swaggerSecurityRequirementObject `json:"security,omitempty"`
Security *[]swaggerSecurityRequirementObject `json:"security,omitempty"`
ExternalDocs *swaggerExternalDocumentationObject `json:"externalDocs,omitempty"`
}

Expand Down

0 comments on commit bd32f3d

Please sign in to comment.