mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-10 13:12:43 +00:00
issue #2535, added authentication header for GO
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
package swagger
|
||||
|
||||
import (
|
||||
|
||||
"encoding/base64"
|
||||
)
|
||||
|
||||
type Configuration struct {
|
||||
UserName string `json:"userName,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
ApiKey string `json:"apiKey,omitempty"`
|
||||
Debug bool `json:"debug,omitempty"`
|
||||
DebugFile string `json:"debugFile,omitempty"`
|
||||
@@ -14,6 +15,7 @@ type Configuration struct {
|
||||
BasePath string `json:"basePath,omitempty"`
|
||||
Host string `json:"host,omitempty"`
|
||||
Scheme string `json:"scheme,omitempty"`
|
||||
AccessToken string `json:"accessToken,omitempty"`
|
||||
}
|
||||
|
||||
func NewConfiguration() *Configuration {
|
||||
@@ -22,4 +24,8 @@ func NewConfiguration() *Configuration {
|
||||
UserName: "",
|
||||
Debug: false,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Configuration) GetBasicAuthEncodedString() string {
|
||||
return base64.StdEncoding.EncodeToString([]byte(c.UserName + ":" + c.Password))
|
||||
}
|
||||
@@ -40,6 +40,12 @@ func (a PetApi) AddPet (body Pet) (error) {
|
||||
|
||||
_sling := sling.New().Post(a.Configuration.BasePath)
|
||||
|
||||
// authentication (petstore_auth) required
|
||||
// oauth required
|
||||
if a.Configuration.AccessToken != ""{
|
||||
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
|
||||
}
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/pet"
|
||||
|
||||
@@ -101,6 +107,12 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) {
|
||||
|
||||
_sling := sling.New().Delete(a.Configuration.BasePath)
|
||||
|
||||
// authentication (petstore_auth) required
|
||||
// oauth required
|
||||
if a.Configuration.AccessToken != ""{
|
||||
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
|
||||
}
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/pet/{petId}"
|
||||
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
|
||||
@@ -162,6 +174,12 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
|
||||
|
||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||
|
||||
// authentication (petstore_auth) required
|
||||
// oauth required
|
||||
if a.Configuration.AccessToken != ""{
|
||||
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
|
||||
}
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/pet/findByStatus"
|
||||
|
||||
@@ -224,6 +242,12 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
|
||||
|
||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||
|
||||
// authentication (petstore_auth) required
|
||||
// oauth required
|
||||
if a.Configuration.AccessToken != ""{
|
||||
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
|
||||
}
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/pet/findByTags"
|
||||
|
||||
@@ -286,6 +310,8 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) {
|
||||
|
||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||
|
||||
// authentication (api_key) required
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/pet/{petId}"
|
||||
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
|
||||
@@ -345,6 +371,12 @@ func (a PetApi) UpdatePet (body Pet) (error) {
|
||||
|
||||
_sling := sling.New().Put(a.Configuration.BasePath)
|
||||
|
||||
// authentication (petstore_auth) required
|
||||
// oauth required
|
||||
if a.Configuration.AccessToken != ""{
|
||||
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
|
||||
}
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/pet"
|
||||
|
||||
@@ -407,6 +439,12 @@ func (a PetApi) UpdatePetWithForm (petId int64, name string, status string) (err
|
||||
|
||||
_sling := sling.New().Post(a.Configuration.BasePath)
|
||||
|
||||
// authentication (petstore_auth) required
|
||||
// oauth required
|
||||
if a.Configuration.AccessToken != ""{
|
||||
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
|
||||
}
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/pet/{petId}"
|
||||
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
|
||||
@@ -473,6 +511,12 @@ func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.Fil
|
||||
|
||||
_sling := sling.New().Post(a.Configuration.BasePath)
|
||||
|
||||
// authentication (petstore_auth) required
|
||||
// oauth required
|
||||
if a.Configuration.AccessToken != ""{
|
||||
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
|
||||
}
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/pet/{petId}/uploadImage"
|
||||
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
|
||||
|
||||
@@ -39,6 +39,7 @@ func (a StoreApi) DeleteOrder (orderId string) (error) {
|
||||
|
||||
_sling := sling.New().Delete(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/store/order/{orderId}"
|
||||
path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1)
|
||||
@@ -97,6 +98,8 @@ func (a StoreApi) GetInventory () (map[string]int32, error) {
|
||||
|
||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||
|
||||
// authentication (api_key) required
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/store/inventory"
|
||||
|
||||
@@ -155,6 +158,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) {
|
||||
|
||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/store/order/{orderId}"
|
||||
path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1)
|
||||
@@ -214,6 +218,7 @@ func (a StoreApi) PlaceOrder (body Order) (Order, error) {
|
||||
|
||||
_sling := sling.New().Post(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/store/order"
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ func (a UserApi) CreateUser (body User) (error) {
|
||||
|
||||
_sling := sling.New().Post(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/user"
|
||||
|
||||
@@ -99,6 +100,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) {
|
||||
|
||||
_sling := sling.New().Post(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/user/createWithArray"
|
||||
|
||||
@@ -159,6 +161,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) {
|
||||
|
||||
_sling := sling.New().Post(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/user/createWithList"
|
||||
|
||||
@@ -219,6 +222,7 @@ func (a UserApi) DeleteUser (username string) (error) {
|
||||
|
||||
_sling := sling.New().Delete(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/user/{username}"
|
||||
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
|
||||
@@ -278,6 +282,7 @@ func (a UserApi) GetUserByName (username string) (User, error) {
|
||||
|
||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/user/{username}"
|
||||
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
|
||||
@@ -338,6 +343,7 @@ func (a UserApi) LoginUser (username string, password string) (string, error) {
|
||||
|
||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/user/login"
|
||||
|
||||
@@ -400,6 +406,7 @@ func (a UserApi) LogoutUser () (error) {
|
||||
|
||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/user/logout"
|
||||
|
||||
@@ -459,6 +466,7 @@ func (a UserApi) UpdateUser (username string, body User) (error) {
|
||||
|
||||
_sling := sling.New().Put(a.Configuration.BasePath)
|
||||
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/user/{username}"
|
||||
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
|
||||
|
||||
Reference in New Issue
Block a user