generated from sv-tools/go-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsecurity-requirement.go
41 lines (35 loc) · 1.54 KB
/
security-requirement.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package openapi
// SecurityRequirement is the lists of the required security schemes to execute this operation.
// The name used for each property MUST correspond to a security scheme declared in the Security Schemes under the Components Object.
// Security Requirement Objects that contain multiple schemes require that all schemes MUST be satisfied for a request to be authorized.
// This enables support for scenarios where multiple query parameters or HTTP headers are required to convey security information.
// When a list of Security Requirement Objects is defined on the OpenAPI Object or Operation Object,
// only one of the Security Requirement Objects in the list needs to be satisfied to authorize the request.
//
// https://spec.openapis.org/oas/v3.1.1#security-requirement-object
//
// Example:
//
// api_key: []
type SecurityRequirement map[string][]string
func (o *SecurityRequirement) validateSpec(path string, validator *Validator) []*validationError {
for k := range *o {
validator.visited[joinLoc("#", "components", "securitySchemes", k)] = true
}
return nil // nothing to validate
}
type SecurityRequirementBuilder struct {
spec SecurityRequirement
}
func NewSecurityRequirementBuilder() *SecurityRequirementBuilder {
return &SecurityRequirementBuilder{
spec: make(SecurityRequirement),
}
}
func (b *SecurityRequirementBuilder) Build() *SecurityRequirement {
return &b.spec
}
func (b *SecurityRequirementBuilder) Add(name string, scopes ...string) *SecurityRequirementBuilder {
b.spec[name] = append(b.spec[name], scopes...)
return b
}