forked from loafle/openapi-generator-original
added api prefix for authentication
This commit is contained in:
parent
7fda8699b1
commit
4e6ff1a567
@ -44,6 +44,13 @@ func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{
|
||||
_sling := sling.New().{{httpMethod}}(a.Configuration.BasePath)
|
||||
|
||||
{{#authMethods}}// authentication ({{name}}) required
|
||||
{{#isApiKey}}{{#isKeyInHeader}}
|
||||
// set key with prefix in header
|
||||
_sling.Set("{{keyParamName}}", a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}")
|
||||
{{/isKeyInHeader}}{{#isKeyInQuery}}
|
||||
// set key with prefix in querystring
|
||||
_sling.Set("{{keyParamName}}", a.Configuration.GetApiKeyWithPrefix("{{keyParamName}}")
|
||||
{{/isKeyInQuery}}{{/isApiKey}}
|
||||
{{#isBasic}}
|
||||
// http basic authentication required
|
||||
if a.Configuration.Username != "" || a.Configuration.Password != ""{
|
||||
|
@ -7,7 +7,8 @@ import (
|
||||
type Configuration struct {
|
||||
UserName string `json:"userName,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
ApiKey string `json:"apiKey,omitempty"`
|
||||
ApiKeyPrefix map[string] string `json:"apiKeyPrefix,omitempty"`
|
||||
ApiKey map[string] string `json:"apiKey,omitempty"`
|
||||
Debug bool `json:"debug,omitempty"`
|
||||
DebugFile string `json:"debugFile,omitempty"`
|
||||
OAuthToken string `json:"oAuthToken,omitempty"`
|
||||
@ -21,11 +22,15 @@ type Configuration struct {
|
||||
|
||||
func NewConfiguration() *Configuration {
|
||||
defaultHeader := make(map[string]string)
|
||||
apiKey := make(map[string]string)
|
||||
apiKeyPrefix := make(map[string]string)
|
||||
return &Configuration{
|
||||
BasePath: "{{basePath}}",
|
||||
UserName: "",
|
||||
Debug: false,
|
||||
DefaultHeader: defaultHeader,
|
||||
ApiKey: apiKey,
|
||||
ApiKeyPrefix: apiKeyPrefix,
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,4 +40,14 @@ func (c *Configuration) GetBasicAuthEncodedString() string {
|
||||
|
||||
func (c *Configuration) AddDefaultHeader(key string, value string) {
|
||||
c.DefaultHeader[key] = value
|
||||
}
|
||||
|
||||
func (c *Configuration) GetApiKeyWithPrefix(apiKeyIdentifier string) string {
|
||||
var returnValue = c.ApiKey[apiKeyIdentifier]
|
||||
var apiKeyPrefix = c.ApiKeyPrefix[apiKeyIdentifier]
|
||||
if apiKeyPrefix != ""{
|
||||
returnValue = apiKeyPrefix + " " + returnValue
|
||||
}
|
||||
|
||||
return returnValue
|
||||
}
|
@ -7,7 +7,8 @@ import (
|
||||
type Configuration struct {
|
||||
UserName string `json:"userName,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
ApiKey string `json:"apiKey,omitempty"`
|
||||
ApiKeyPrefix map[string] string `json:"apiKeyPrefix,omitempty"`
|
||||
ApiKey map[string] string `json:"apiKey,omitempty"`
|
||||
Debug bool `json:"debug,omitempty"`
|
||||
DebugFile string `json:"debugFile,omitempty"`
|
||||
OAuthToken string `json:"oAuthToken,omitempty"`
|
||||
@ -21,11 +22,15 @@ type Configuration struct {
|
||||
|
||||
func NewConfiguration() *Configuration {
|
||||
defaultHeader := make(map[string]string)
|
||||
apiKey := make(map[string]string)
|
||||
apiKeyPrefix := make(map[string]string)
|
||||
return &Configuration{
|
||||
BasePath: "http://petstore.swagger.io/v2",
|
||||
UserName: "",
|
||||
Debug: false,
|
||||
DefaultHeader: defaultHeader,
|
||||
ApiKey: apiKey,
|
||||
ApiKeyPrefix: apiKeyPrefix,
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,4 +40,14 @@ func (c *Configuration) GetBasicAuthEncodedString() string {
|
||||
|
||||
func (c *Configuration) AddDefaultHeader(key string, value string) {
|
||||
c.DefaultHeader[key] = value
|
||||
}
|
||||
|
||||
func (c *Configuration) GetApiKeyWithPrefix(apiKeyIdentifier string) string {
|
||||
var returnValue = c.ApiKey[apiKeyIdentifier]
|
||||
var apiKeyPrefix = c.ApiKeyPrefix[apiKeyIdentifier]
|
||||
if apiKeyPrefix != ""{
|
||||
returnValue = apiKeyPrefix + " " + returnValue
|
||||
}
|
||||
|
||||
return returnValue
|
||||
}
|
@ -41,6 +41,7 @@ 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)
|
||||
@ -113,6 +114,7 @@ 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)
|
||||
@ -185,6 +187,7 @@ 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)
|
||||
@ -258,6 +261,7 @@ 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)
|
||||
@ -331,6 +335,10 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) {
|
||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||
|
||||
// authentication (api_key) required
|
||||
|
||||
// set key with prefix in header
|
||||
_sling.Set("api_key", a.Configuration.GetApiKeyWithPrefix("api_key")
|
||||
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/pet/{petId}"
|
||||
@ -397,6 +405,7 @@ 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)
|
||||
@ -470,6 +479,7 @@ 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)
|
||||
@ -547,6 +557,7 @@ 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)
|
||||
|
@ -104,6 +104,10 @@ func (a StoreApi) GetInventory () (map[string]int32, error) {
|
||||
_sling := sling.New().Get(a.Configuration.BasePath)
|
||||
|
||||
// authentication (api_key) required
|
||||
|
||||
// set key with prefix in header
|
||||
_sling.Set("api_key", a.Configuration.GetApiKeyWithPrefix("api_key")
|
||||
|
||||
|
||||
// create path and map variables
|
||||
path := "/v2/store/inventory"
|
||||
|
Loading…
x
Reference in New Issue
Block a user