forked from loafle/openapi-generator-original
issue #2535, added authentication header for GO
This commit is contained in:
parent
3e13f69b53
commit
fc80bce82f
@ -43,6 +43,21 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{
|
|||||||
|
|
||||||
_sling := sling.New().{{httpMethod}}(a.Configuration.BasePath)
|
_sling := sling.New().{{httpMethod}}(a.Configuration.BasePath)
|
||||||
|
|
||||||
|
{{#authMethods}}// authentication ({{name}}) required
|
||||||
|
{{#isBasic}}
|
||||||
|
// http basic authentication required
|
||||||
|
if a.Configuration.Username != "" || a.Configuration.Password != ""{
|
||||||
|
_sling.Set("Authorization", "Basic " + a.Configuration.GetBasicAuthEncodedString())
|
||||||
|
}
|
||||||
|
{{/isBasic}}
|
||||||
|
{{#isOAuth}}
|
||||||
|
// oauth required
|
||||||
|
if a.Configuration.AccessToken != ""{
|
||||||
|
_sling.Set("Authorization", "Bearer " + a.Configuration.AccessToken)
|
||||||
|
}
|
||||||
|
{{/isOAuth}}
|
||||||
|
{{/authMethods}}
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "{{basePathWithoutHost}}{{path}}"
|
path := "{{basePathWithoutHost}}{{path}}"
|
||||||
{{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1)
|
{{#pathParams}} path = strings.Replace(path, "{" + "{{baseName}}" + "}", fmt.Sprintf("%v", {{paramName}}), -1)
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package {{packageName}}
|
package {{packageName}}
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
UserName string `json:"userName,omitempty"`
|
UserName string `json:"userName,omitempty"`
|
||||||
|
Password string `json:"password,omitempty"`
|
||||||
ApiKey string `json:"apiKey,omitempty"`
|
ApiKey string `json:"apiKey,omitempty"`
|
||||||
Debug bool `json:"debug,omitempty"`
|
Debug bool `json:"debug,omitempty"`
|
||||||
DebugFile string `json:"debugFile,omitempty"`
|
DebugFile string `json:"debugFile,omitempty"`
|
||||||
@ -14,6 +15,7 @@ type Configuration struct {
|
|||||||
BasePath string `json:"basePath,omitempty"`
|
BasePath string `json:"basePath,omitempty"`
|
||||||
Host string `json:"host,omitempty"`
|
Host string `json:"host,omitempty"`
|
||||||
Scheme string `json:"scheme,omitempty"`
|
Scheme string `json:"scheme,omitempty"`
|
||||||
|
AccessToken string `json:"accessToken,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfiguration() *Configuration {
|
func NewConfiguration() *Configuration {
|
||||||
@ -22,4 +24,8 @@ func NewConfiguration() *Configuration {
|
|||||||
UserName: "",
|
UserName: "",
|
||||||
Debug: false,
|
Debug: false,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Configuration) GetBasicAuthEncodedString() string {
|
||||||
|
return base64.StdEncoding.EncodeToString([]byte(c.UserName + ":" + c.Password))
|
||||||
}
|
}
|
@ -1,11 +1,12 @@
|
|||||||
package swagger
|
package swagger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
UserName string `json:"userName,omitempty"`
|
UserName string `json:"userName,omitempty"`
|
||||||
|
Password string `json:"password,omitempty"`
|
||||||
ApiKey string `json:"apiKey,omitempty"`
|
ApiKey string `json:"apiKey,omitempty"`
|
||||||
Debug bool `json:"debug,omitempty"`
|
Debug bool `json:"debug,omitempty"`
|
||||||
DebugFile string `json:"debugFile,omitempty"`
|
DebugFile string `json:"debugFile,omitempty"`
|
||||||
@ -14,6 +15,7 @@ type Configuration struct {
|
|||||||
BasePath string `json:"basePath,omitempty"`
|
BasePath string `json:"basePath,omitempty"`
|
||||||
Host string `json:"host,omitempty"`
|
Host string `json:"host,omitempty"`
|
||||||
Scheme string `json:"scheme,omitempty"`
|
Scheme string `json:"scheme,omitempty"`
|
||||||
|
AccessToken string `json:"accessToken,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfiguration() *Configuration {
|
func NewConfiguration() *Configuration {
|
||||||
@ -22,4 +24,8 @@ func NewConfiguration() *Configuration {
|
|||||||
UserName: "",
|
UserName: "",
|
||||||
Debug: false,
|
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)
|
_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
|
// create path and map variables
|
||||||
path := "/v2/pet"
|
path := "/v2/pet"
|
||||||
|
|
||||||
@ -101,6 +107,12 @@ func (a PetApi) DeletePet (petId int64, apiKey string) (error) {
|
|||||||
|
|
||||||
_sling := sling.New().Delete(a.Configuration.BasePath)
|
_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
|
// create path and map variables
|
||||||
path := "/v2/pet/{petId}"
|
path := "/v2/pet/{petId}"
|
||||||
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
|
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)
|
_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
|
// create path and map variables
|
||||||
path := "/v2/pet/findByStatus"
|
path := "/v2/pet/findByStatus"
|
||||||
|
|
||||||
@ -224,6 +242,12 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
|
|||||||
|
|
||||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
_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
|
// create path and map variables
|
||||||
path := "/v2/pet/findByTags"
|
path := "/v2/pet/findByTags"
|
||||||
|
|
||||||
@ -286,6 +310,8 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) {
|
|||||||
|
|
||||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||||
|
|
||||||
|
// authentication (api_key) required
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/pet/{petId}"
|
path := "/v2/pet/{petId}"
|
||||||
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
|
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)
|
_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
|
// create path and map variables
|
||||||
path := "/v2/pet"
|
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)
|
_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
|
// create path and map variables
|
||||||
path := "/v2/pet/{petId}"
|
path := "/v2/pet/{petId}"
|
||||||
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
|
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)
|
_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
|
// create path and map variables
|
||||||
path := "/v2/pet/{petId}/uploadImage"
|
path := "/v2/pet/{petId}/uploadImage"
|
||||||
path = strings.Replace(path, "{" + "petId" + "}", fmt.Sprintf("%v", petId), -1)
|
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)
|
_sling := sling.New().Delete(a.Configuration.BasePath)
|
||||||
|
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/store/order/{orderId}"
|
path := "/v2/store/order/{orderId}"
|
||||||
path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1)
|
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)
|
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||||
|
|
||||||
|
// authentication (api_key) required
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/store/inventory"
|
path := "/v2/store/inventory"
|
||||||
|
|
||||||
@ -155,6 +158,7 @@ func (a StoreApi) GetOrderById (orderId int64) (Order, error) {
|
|||||||
|
|
||||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||||
|
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/store/order/{orderId}"
|
path := "/v2/store/order/{orderId}"
|
||||||
path = strings.Replace(path, "{" + "orderId" + "}", fmt.Sprintf("%v", orderId), -1)
|
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)
|
_sling := sling.New().Post(a.Configuration.BasePath)
|
||||||
|
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/store/order"
|
path := "/v2/store/order"
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ func (a UserApi) CreateUser (body User) (error) {
|
|||||||
|
|
||||||
_sling := sling.New().Post(a.Configuration.BasePath)
|
_sling := sling.New().Post(a.Configuration.BasePath)
|
||||||
|
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/user"
|
path := "/v2/user"
|
||||||
|
|
||||||
@ -99,6 +100,7 @@ func (a UserApi) CreateUsersWithArrayInput (body []User) (error) {
|
|||||||
|
|
||||||
_sling := sling.New().Post(a.Configuration.BasePath)
|
_sling := sling.New().Post(a.Configuration.BasePath)
|
||||||
|
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/user/createWithArray"
|
path := "/v2/user/createWithArray"
|
||||||
|
|
||||||
@ -159,6 +161,7 @@ func (a UserApi) CreateUsersWithListInput (body []User) (error) {
|
|||||||
|
|
||||||
_sling := sling.New().Post(a.Configuration.BasePath)
|
_sling := sling.New().Post(a.Configuration.BasePath)
|
||||||
|
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/user/createWithList"
|
path := "/v2/user/createWithList"
|
||||||
|
|
||||||
@ -219,6 +222,7 @@ func (a UserApi) DeleteUser (username string) (error) {
|
|||||||
|
|
||||||
_sling := sling.New().Delete(a.Configuration.BasePath)
|
_sling := sling.New().Delete(a.Configuration.BasePath)
|
||||||
|
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/user/{username}"
|
path := "/v2/user/{username}"
|
||||||
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
|
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)
|
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||||
|
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/user/{username}"
|
path := "/v2/user/{username}"
|
||||||
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
|
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)
|
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||||
|
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/user/login"
|
path := "/v2/user/login"
|
||||||
|
|
||||||
@ -400,6 +406,7 @@ func (a UserApi) LogoutUser () (error) {
|
|||||||
|
|
||||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||||
|
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/user/logout"
|
path := "/v2/user/logout"
|
||||||
|
|
||||||
@ -459,6 +466,7 @@ func (a UserApi) UpdateUser (username string, body User) (error) {
|
|||||||
|
|
||||||
_sling := sling.New().Put(a.Configuration.BasePath)
|
_sling := sling.New().Put(a.Configuration.BasePath)
|
||||||
|
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
path := "/v2/user/{username}"
|
path := "/v2/user/{username}"
|
||||||
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
|
path = strings.Replace(path, "{" + "username" + "}", fmt.Sprintf("%v", username), -1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user