Skip to content

Commit 7d247e5

Browse files
committed
Add ErrUnauthorized error variable
For use in security middlewares.
1 parent b5e986f commit 7d247e5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

design/apidsl/security.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ import (
1111
//
1212
// The scheme refers to previous definitions of either OAuth2Security, BasicAuthSecurity,
1313
// APIKeySecurity or JWTSecurity. It can be a string, corresponding to the first parameter of
14-
// those definitions, or a SecuritySchemeDefinition, returned by those same functions.
14+
// those definitions, or a SecuritySchemeDefinition, returned by those same functions. Examples:
15+
//
16+
// Security(BasicAuth)
17+
//
18+
// Security("oauth2", func() {
19+
// Scope("api:read") // Requires "api:read" oauth2 scope
20+
// })
21+
//
1522
func Security(scheme interface{}, dsl ...func()) {
1623
var def *design.SecurityDefinition
1724
switch val := scheme.(type) {

error.go

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ var (
3333
// ErrBadRequest is a generic bad request error.
3434
ErrBadRequest = NewErrorClass("bad_request", 400)
3535

36+
// ErrUnauthorized is a generic unauthorized error.
37+
ErrUnauthorized = NewErrorClass("unauthorized", 401)
38+
3639
// ErrInvalidRequest is the class of errors produced by the generated code when a request
3740
// parameter or payload fails to validate.
3841
ErrInvalidRequest = NewErrorClass("invalid_request", 400)

0 commit comments

Comments
 (0)