Skip to content

Commit

Permalink
improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
nameoffnv committed Jul 5, 2023
1 parent c934bdf commit f28882c
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 25 deletions.
32 changes: 22 additions & 10 deletions testdata/global_security/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,31 @@ import (
"net/http"
)

// @Summary Get application
// @Description test get application
// @Summary default security
// @Success 200
// @Router /testapi/application [get]
func GetApplication(w http.ResponseWriter, r *http.Request) {
//write your code
}
func GetApplication(w http.ResponseWriter, r *http.Request) {}

// Summary Get no security
// @Description override global security
// @Summary no security
// @Security
// @Success 200
// @Router /testapi/nosec [get]
func GetNoSec(w http.ResponseWriter, r *http.Request) {
//write your code
}
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) {}
69 changes: 65 additions & 4 deletions testdata/global_security/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,22 @@
"paths": {
"/testapi/application": {
"get": {
"description": "test get application",
"summary": "Get application",
"summary": "default security",
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/testapi/basic": {
"get": {
"security": [
{
"BasicAuth": []
}
],
"summary": "basic security",
"responses": {
"200": {
"description": "OK"
Expand All @@ -20,7 +34,41 @@
"/testapi/nosec": {
"get": {
"security": [],
"description": "override global 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"
Expand All @@ -34,11 +82,24 @@
"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": []
"APIKeyAuth": [],
"OAuth2Application": []
}
]
}
20 changes: 9 additions & 11 deletions testdata/global_security/main.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package global_security

import (
"net/http"

"github.com/swaggo/swag/testdata/global_security/api"
)

// @title Swagger Example API
// @version 1.0

// @securityDefinitions.apikey APIKeyAuth
// @in header
// @name Authorization

// @security APIKeyAuth
func main() {
http.HandleFunc("/testapi/application", api.GetApplication)
http.ListenAndServe(":8080", nil)
}
// @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() {}

0 comments on commit f28882c

Please sign in to comment.