go.mod: Update oapi-codegen and kin-openapi
This commit is contained in:
parent
add17bba45
commit
a83cf95d5b
156 changed files with 29663 additions and 2248 deletions
107
vendor/github.com/getkin/kin-openapi/openapi3/security_scheme.go
generated
vendored
107
vendor/github.com/getkin/kin-openapi/openapi3/security_scheme.go
generated
vendored
|
|
@ -6,18 +6,36 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/getkin/kin-openapi/jsoninfo"
|
||||
"github.com/go-openapi/jsonpointer"
|
||||
)
|
||||
|
||||
type SecuritySchemes map[string]*SecuritySchemeRef
|
||||
|
||||
func (s SecuritySchemes) JSONLookup(token string) (interface{}, error) {
|
||||
ref, ok := s[token]
|
||||
if ref == nil || ok == false {
|
||||
return nil, fmt.Errorf("object has no field %q", token)
|
||||
}
|
||||
|
||||
if ref.Ref != "" {
|
||||
return &Ref{Ref: ref.Ref}, nil
|
||||
}
|
||||
return ref.Value, nil
|
||||
}
|
||||
|
||||
var _ jsonpointer.JSONPointable = (*SecuritySchemes)(nil)
|
||||
|
||||
type SecurityScheme struct {
|
||||
ExtensionProps
|
||||
|
||||
Type string `json:"type,omitempty" yaml:"type,omitempty"`
|
||||
Description string `json:"description,omitempty" yaml:"description,omitempty"`
|
||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||
In string `json:"in,omitempty" yaml:"in,omitempty"`
|
||||
Scheme string `json:"scheme,omitempty" yaml:"scheme,omitempty"`
|
||||
BearerFormat string `json:"bearerFormat,omitempty" yaml:"bearerFormat,omitempty"`
|
||||
Flows *OAuthFlows `json:"flows,omitempty" yaml:"flows,omitempty"`
|
||||
Type string `json:"type,omitempty" yaml:"type,omitempty"`
|
||||
Description string `json:"description,omitempty" yaml:"description,omitempty"`
|
||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||
In string `json:"in,omitempty" yaml:"in,omitempty"`
|
||||
Scheme string `json:"scheme,omitempty" yaml:"scheme,omitempty"`
|
||||
BearerFormat string `json:"bearerFormat,omitempty" yaml:"bearerFormat,omitempty"`
|
||||
Flows *OAuthFlows `json:"flows,omitempty" yaml:"flows,omitempty"`
|
||||
OpenIdConnectUrl string `json:"openIdConnectUrl,omitempty" yaml:"openIdConnectUrl,omitempty"`
|
||||
}
|
||||
|
||||
func NewSecurityScheme() *SecurityScheme {
|
||||
|
|
@ -32,6 +50,13 @@ func NewCSRFSecurityScheme() *SecurityScheme {
|
|||
}
|
||||
}
|
||||
|
||||
func NewOIDCSecurityScheme(oidcUrl string) *SecurityScheme {
|
||||
return &SecurityScheme{
|
||||
Type: "openIdConnect",
|
||||
OpenIdConnectUrl: oidcUrl,
|
||||
}
|
||||
}
|
||||
|
||||
func NewJWTSecurityScheme() *SecurityScheme {
|
||||
return &SecurityScheme{
|
||||
Type: "http",
|
||||
|
|
@ -78,63 +103,65 @@ func (ss *SecurityScheme) WithBearerFormat(value string) *SecurityScheme {
|
|||
return ss
|
||||
}
|
||||
|
||||
func (ss *SecurityScheme) Validate(c context.Context) error {
|
||||
func (value *SecurityScheme) Validate(ctx context.Context) error {
|
||||
hasIn := false
|
||||
hasBearerFormat := false
|
||||
hasFlow := false
|
||||
switch ss.Type {
|
||||
switch value.Type {
|
||||
case "apiKey":
|
||||
hasIn = true
|
||||
case "http":
|
||||
scheme := ss.Scheme
|
||||
scheme := value.Scheme
|
||||
switch scheme {
|
||||
case "bearer":
|
||||
hasBearerFormat = true
|
||||
case "basic":
|
||||
case "basic", "negotiate", "digest":
|
||||
default:
|
||||
return fmt.Errorf("Security scheme of type 'http' has invalid 'scheme' value '%s'", scheme)
|
||||
return fmt.Errorf("security scheme of type 'http' has invalid 'scheme' value %q", scheme)
|
||||
}
|
||||
case "oauth2":
|
||||
hasFlow = true
|
||||
case "openIdConnect":
|
||||
return fmt.Errorf("Support for security schemes with type '%v' has not been implemented", ss.Type)
|
||||
if value.OpenIdConnectUrl == "" {
|
||||
return fmt.Errorf("no OIDC URL found for openIdConnect security scheme %q", value.Name)
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("Security scheme 'type' can't be '%v'", ss.Type)
|
||||
return fmt.Errorf("security scheme 'type' can't be %q", value.Type)
|
||||
}
|
||||
|
||||
// Validate "in" and "name"
|
||||
if hasIn {
|
||||
switch ss.In {
|
||||
switch value.In {
|
||||
case "query", "header", "cookie":
|
||||
default:
|
||||
return fmt.Errorf("Security scheme of type 'apiKey' should have 'in'. It can be 'query', 'header' or 'cookie', not '%s'", ss.In)
|
||||
return fmt.Errorf("security scheme of type 'apiKey' should have 'in'. It can be 'query', 'header' or 'cookie', not %q", value.In)
|
||||
}
|
||||
if ss.Name == "" {
|
||||
return errors.New("Security scheme of type 'apiKey' should have 'name'")
|
||||
if value.Name == "" {
|
||||
return errors.New("security scheme of type 'apiKey' should have 'name'")
|
||||
}
|
||||
} else if len(ss.In) > 0 {
|
||||
return fmt.Errorf("Security scheme of type '%s' can't have 'in'", ss.Type)
|
||||
} else if len(ss.Name) > 0 {
|
||||
return errors.New("Security scheme of type 'apiKey' can't have 'name'")
|
||||
} else if len(value.In) > 0 {
|
||||
return fmt.Errorf("security scheme of type %q can't have 'in'", value.Type)
|
||||
} else if len(value.Name) > 0 {
|
||||
return errors.New("security scheme of type 'apiKey' can't have 'name'")
|
||||
}
|
||||
|
||||
// Validate "format"
|
||||
// "bearerFormat" is an arbitrary string so we only check if the scheme supports it
|
||||
if !hasBearerFormat && len(ss.BearerFormat) > 0 {
|
||||
return fmt.Errorf("Security scheme of type '%v' can't have 'bearerFormat'", ss.Type)
|
||||
if !hasBearerFormat && len(value.BearerFormat) > 0 {
|
||||
return fmt.Errorf("security scheme of type %q can't have 'bearerFormat'", value.Type)
|
||||
}
|
||||
|
||||
// Validate "flow"
|
||||
if hasFlow {
|
||||
flow := ss.Flows
|
||||
flow := value.Flows
|
||||
if flow == nil {
|
||||
return fmt.Errorf("Security scheme of type '%v' should have 'flows'", ss.Type)
|
||||
return fmt.Errorf("security scheme of type %q should have 'flows'", value.Type)
|
||||
}
|
||||
if err := flow.Validate(c); err != nil {
|
||||
return fmt.Errorf("Security scheme 'flow' is invalid: %v", err)
|
||||
if err := flow.Validate(ctx); err != nil {
|
||||
return fmt.Errorf("security scheme 'flow' is invalid: %v", err)
|
||||
}
|
||||
} else if ss.Flows != nil {
|
||||
return fmt.Errorf("Security scheme of type '%s' can't have 'flows'", ss.Type)
|
||||
} else if value.Flows != nil {
|
||||
return fmt.Errorf("security scheme of type %q can't have 'flows'", value.Type)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -164,20 +191,20 @@ func (flows *OAuthFlows) UnmarshalJSON(data []byte) error {
|
|||
return jsoninfo.UnmarshalStrictStruct(data, flows)
|
||||
}
|
||||
|
||||
func (flows *OAuthFlows) Validate(c context.Context) error {
|
||||
func (flows *OAuthFlows) Validate(ctx context.Context) error {
|
||||
if v := flows.Implicit; v != nil {
|
||||
return v.Validate(c, oAuthFlowTypeImplicit)
|
||||
return v.Validate(ctx, oAuthFlowTypeImplicit)
|
||||
}
|
||||
if v := flows.Password; v != nil {
|
||||
return v.Validate(c, oAuthFlowTypePassword)
|
||||
return v.Validate(ctx, oAuthFlowTypePassword)
|
||||
}
|
||||
if v := flows.ClientCredentials; v != nil {
|
||||
return v.Validate(c, oAuthFlowTypeClientCredentials)
|
||||
return v.Validate(ctx, oAuthFlowTypeClientCredentials)
|
||||
}
|
||||
if v := flows.AuthorizationCode; v != nil {
|
||||
return v.Validate(c, oAuthFlowAuthorizationCode)
|
||||
return v.Validate(ctx, oAuthFlowAuthorizationCode)
|
||||
}
|
||||
return errors.New("No OAuth flow is defined")
|
||||
return errors.New("no OAuth flow is defined")
|
||||
}
|
||||
|
||||
type OAuthFlow struct {
|
||||
|
|
@ -196,19 +223,19 @@ func (flow *OAuthFlow) UnmarshalJSON(data []byte) error {
|
|||
return jsoninfo.UnmarshalStrictStruct(data, flow)
|
||||
}
|
||||
|
||||
func (flow *OAuthFlow) Validate(c context.Context, typ oAuthFlowType) error {
|
||||
func (flow *OAuthFlow) Validate(ctx context.Context, typ oAuthFlowType) error {
|
||||
if typ == oAuthFlowAuthorizationCode || typ == oAuthFlowTypeImplicit {
|
||||
if v := flow.AuthorizationURL; v == "" {
|
||||
return errors.New("An OAuth flow is missing 'authorizationUrl in authorizationCode or implicit '")
|
||||
return errors.New("an OAuth flow is missing 'authorizationUrl in authorizationCode or implicit '")
|
||||
}
|
||||
}
|
||||
if typ != oAuthFlowTypeImplicit {
|
||||
if v := flow.TokenURL; v == "" {
|
||||
return errors.New("An OAuth flow is missing 'tokenUrl in not implicit'")
|
||||
return errors.New("an OAuth flow is missing 'tokenUrl in not implicit'")
|
||||
}
|
||||
}
|
||||
if v := flow.Scopes; v == nil {
|
||||
return errors.New("An OAuth flow is missing 'scopes'")
|
||||
return errors.New("an OAuth flow is missing 'scopes'")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue