-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* global security * improve test
- Loading branch information
Showing
6 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package api | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
// @Summary default security | ||
// @Success 200 | ||
// @Router /testapi/application [get] | ||
func GetApplication(w http.ResponseWriter, r *http.Request) {} | ||
|
||
// @Summary no security | ||
// @Security | ||
// @Success 200 | ||
// @Router /testapi/nosec [get] | ||
func GetNoSec(w http.ResponseWriter, r *http.Request) {} | ||
|
||
// @Summary basic security | ||
// @Security BasicAuth | ||
// @Success 200 | ||
// @Router /testapi/basic [get] | ||
func GetBasic(w http.ResponseWriter, r *http.Request) {} | ||
|
||
// @Summary oauth2 write | ||
// @Security OAuth2Application[write] | ||
// @Success 200 | ||
// @Router /testapi/oauth/write [get] | ||
func GetOAuthWrite(w http.ResponseWriter, r *http.Request) {} | ||
|
||
// @Summary oauth2 admin | ||
// @Security OAuth2Application[admin] | ||
// @Success 200 | ||
// @Router /testapi/oauth/admin [get] | ||
func GetOAuthAdmin(w http.ResponseWriter, r *http.Request) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"title": "Swagger Example API", | ||
"contact": {}, | ||
"version": "1.0" | ||
}, | ||
"paths": { | ||
"/testapi/application": { | ||
"get": { | ||
"summary": "default security", | ||
"responses": { | ||
"200": { | ||
"description": "OK" | ||
} | ||
} | ||
} | ||
}, | ||
"/testapi/basic": { | ||
"get": { | ||
"security": [ | ||
{ | ||
"BasicAuth": [] | ||
} | ||
], | ||
"summary": "basic security", | ||
"responses": { | ||
"200": { | ||
"description": "OK" | ||
} | ||
} | ||
} | ||
}, | ||
"/testapi/nosec": { | ||
"get": { | ||
"security": [], | ||
"summary": "no security", | ||
"responses": { | ||
"200": { | ||
"description": "OK" | ||
} | ||
} | ||
} | ||
}, | ||
"/testapi/oauth/admin": { | ||
"get": { | ||
"security": [ | ||
{ | ||
"OAuth2Application": [ | ||
"admin" | ||
] | ||
} | ||
], | ||
"summary": "oauth2 admin", | ||
"responses": { | ||
"200": { | ||
"description": "OK" | ||
} | ||
} | ||
} | ||
}, | ||
"/testapi/oauth/write": { | ||
"get": { | ||
"security": [ | ||
{ | ||
"OAuth2Application": [ | ||
"write" | ||
] | ||
} | ||
], | ||
"summary": "oauth2 write", | ||
"responses": { | ||
"200": { | ||
"description": "OK" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"securityDefinitions": { | ||
"APIKeyAuth": { | ||
"type": "apiKey", | ||
"name": "Authorization", | ||
"in": "header" | ||
}, | ||
"BasicAuth": { | ||
"type": "basic" | ||
}, | ||
"OAuth2Application": { | ||
"type": "oauth2", | ||
"flow": "application", | ||
"tokenUrl": "https://example.com/oauth/token", | ||
"scopes": { | ||
"admin": " Grants read and write access to administrative information", | ||
"write": " Grants write access" | ||
} | ||
} | ||
}, | ||
"security": [ | ||
{ | ||
"APIKeyAuth": [], | ||
"OAuth2Application": [] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package global_security | ||
|
||
// @title Swagger Example API | ||
// @version 1.0 | ||
|
||
// @securityDefinitions.apikey APIKeyAuth | ||
// @in header | ||
// @name Authorization | ||
|
||
// @securityDefinitions.basic BasicAuth | ||
|
||
// @securityDefinitions.oauth2.application OAuth2Application | ||
// @tokenUrl https://example.com/oauth/token | ||
// @scope.write Grants write access | ||
// @scope.admin Grants read and write access to administrative information | ||
|
||
// @security APIKeyAuth || OAuth2Application | ||
func main() {} |