Skip to content

Commit

Permalink
Merge pull request #160 from conductor-sdk/fix/refactoring-api-client…
Browse files Browse the repository at this point in the history
…-code

More client refactoring and cleanup
  • Loading branch information
jmigueprieto authored Nov 6, 2024
2 parents fe8fd81 + 7d4a675 commit 283f031
Show file tree
Hide file tree
Showing 19 changed files with 396 additions and 3,762 deletions.
317 changes: 32 additions & 285 deletions sdk/client/api_application_resource.go

Large diffs are not rendered by default.

65 changes: 8 additions & 57 deletions sdk/client/api_authorization_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,15 @@ func (a *AuthorizationResourceApiService) GetPermissions(ctx context.Context, ty
returnValue interface{}
)

// create path and map variables
path := "/auth/authorization/{type}/{id}"
path = strings.Replace(path, "{"+"type"+"}", fmt.Sprintf("%v", type_), -1)
path = strings.Replace(path, "{"+"id"+"}", fmt.Sprintf("%v", id), -1)

headerParams := make(map[string]string)
headerParams["Accept"] = "application/json"

queryParams := url.Values{}
formParams := url.Values{}

// to determine the Content-Type header
contentTypes := []string{}

// set Content-Type header
contentType := selectHeaderContentType(contentTypes)
if contentType != "" {
headerParams["Content-Type"] = contentType
}

// to determine the Accept header
headerAccepts := []string{"application/json"}

// set Accept header
headerAccept := selectHeaderAccept(headerAccepts)
if headerAccept != "" {
headerParams["Accept"] = headerAccept
}
r, err := a.prepareRequest(ctx, path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
return returnValue, nil, err
Expand Down Expand Up @@ -105,31 +88,15 @@ func (a *AuthorizationResourceApiService) GrantPermissions(ctx context.Context,
fileBytes []byte
)

// create path and map variables
path := "/auth/authorization"

headerParams := make(map[string]string)
headerParams["Accept"] = "application/json"
headerParams["Content-Type"] = "application/json"

queryParams := url.Values{}
formParams := url.Values{}

// to determine the Content-Type header
contentTypes := []string{"application/json"}

// set Content-Type header
contentType := selectHeaderContentType(contentTypes)
if contentType != "" {
headerParams["Content-Type"] = contentType
}

// to determine the Accept header
headerAccepts := []string{"application/json"}

// set Accept header
headerAccept := selectHeaderAccept(headerAccepts)
if headerAccept != "" {
headerParams["Accept"] = headerAccept
}
// body params
postBody = &body
r, err := a.prepareRequest(ctx, path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
Expand Down Expand Up @@ -168,31 +135,15 @@ func (a *AuthorizationResourceApiService) RemovePermissions(ctx context.Context,
fileBytes []byte
)

// create path and map variables
path := "/auth/authorization"

headerParams := make(map[string]string)
headerParams["Accept"] = "application/json"
headerParams["Content-Type"] = "application/json"

queryParams := url.Values{}
formParams := url.Values{}

// to determine the Content-Type header
contentTypes := []string{"application/json"}

// set Content-Type header
contentType := selectHeaderContentType(contentTypes)
if contentType != "" {
headerParams["Content-Type"] = contentType
}

// to determine the Accept header
headerAccepts := []string{"application/json"}

// set Accept header
headerAccept := selectHeaderAccept(headerAccepts)
if headerAccept != "" {
headerParams["Accept"] = headerAccept
}
// body params
postBody = &body
r, err := a.prepareRequest(ctx, path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
Expand Down
30 changes: 0 additions & 30 deletions sdk/client/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,36 +225,6 @@ func CacheExpires(r *http.Response) time.Time {
return expires
}

func selectHeaderContentType(contentTypes []string) string {
if len(contentTypes) == 0 {
return ""
}
if contains(contentTypes, "application/json") {
return "application/json"
}
return contentTypes[0] // use the first content type specified in 'consumes'
}

// selectHeaderAccept join all accept types and return
func selectHeaderAccept(accepts []string) string {
if len(accepts) == 0 {
return ""
}
if contains(accepts, "application/json") {
return "application/json"
}
return strings.Join(accepts, ",")
}

func contains(haystack []string, needle string) bool {
for _, a := range haystack {
if strings.EqualFold(a, needle) {
return true
}
}
return false
}

func parameterToString(obj interface{}, collectionFormat string) string {
var delimiter string

Expand Down
144 changes: 14 additions & 130 deletions sdk/client/api_environment_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,15 @@ func (a *EnvironmentResourceApiService) CreateOrUpdateEnvVariable(ctx context.Co
fileBytes []byte
)

// create path and map variables
path := "/environment/{key}"
path = strings.Replace(path, "{"+"key"+"}", fmt.Sprintf("%v", key), -1)

headerParams := make(map[string]string)
headerParams["Content-Type"] = "text/plain"

queryParams := url.Values{}
formParams := url.Values{}

// to determine the Content-Type header
contentTypes := []string{"text/plain"}

// set Content-Type header
contentType := selectHeaderContentType(contentTypes)
if contentType != "" {
headerParams["Content-Type"] = contentType
}

// to determine the Accept header
headerAccepts := []string{}

// set Accept header
headerAccept := selectHeaderAccept(headerAccepts)
if headerAccept != "" {
headerParams["Accept"] = headerAccept
}
// body params
postBody = &body
r, err := a.prepareRequest(ctx, path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
Expand Down Expand Up @@ -103,31 +86,14 @@ func (a *EnvironmentResourceApiService) DeleteEnvVariable(ctx context.Context, k
returnValue string
)

// create path and map variables
path := "/environment/{key}"
path = strings.Replace(path, "{"+"key"+"}", fmt.Sprintf("%v", key), -1)

headerParams := make(map[string]string)
headerParams["Accept"] = "application/json"

queryParams := url.Values{}
formParams := url.Values{}

// to determine the Content-Type header
contentTypes := []string{}

// set Content-Type header
contentType := selectHeaderContentType(contentTypes)
if contentType != "" {
headerParams["Content-Type"] = contentType
}

// to determine the Accept header
headerAccepts := []string{"application/json"}

// set Accept header
headerAccept := selectHeaderAccept(headerAccepts)
if headerAccept != "" {
headerParams["Accept"] = headerAccept
}
r, err := a.prepareRequest(ctx, path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
return returnValue, nil, err
Expand Down Expand Up @@ -168,32 +134,15 @@ func (a *EnvironmentResourceApiService) DeleteTagForEnvVar(ctx context.Context,
fileBytes []byte
)

// create path and map variables
path := "/environment/{name}/tags"
path = strings.Replace(path, "{"+"name"+"}", fmt.Sprintf("%v", name), -1)

headerParams := make(map[string]string)
headerParams["Content-Type"] = "application/json"

queryParams := url.Values{}
formParams := url.Values{}

// to determine the Content-Type header
contentTypes := []string{"application/json"}

// set Content-Type header
contentType := selectHeaderContentType(contentTypes)
if contentType != "" {
headerParams["Content-Type"] = contentType
}

// to determine the Accept header
headerAccepts := []string{}

// set Accept header
headerAccept := selectHeaderAccept(headerAccepts)
if headerAccept != "" {
headerParams["Accept"] = headerAccept
}
// body params
postBody = &body
r, err := a.prepareRequest(ctx, path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
Expand Down Expand Up @@ -233,31 +182,15 @@ func (a *EnvironmentResourceApiService) Get(ctx context.Context, key string) (st
returnValue string
)

// create path and map variables
path := "/environment/{key}"
path = strings.Replace(path, "{"+"key"+"}", fmt.Sprintf("%v", key), -1)

headerParams := make(map[string]string)
headerParams["Accept"] = "text/plain"

queryParams := url.Values{}
formParams := url.Values{}

// to determine the Content-Type header
contentTypes := []string{}

// set Content-Type header
contentType := selectHeaderContentType(contentTypes)
if contentType != "" {
headerParams["Content-Type"] = contentType
}

// to determine the Accept header
headerAccepts := []string{"text/plain"}

// set Accept header
headerAccept := selectHeaderAccept(headerAccepts)
if headerAccept != "" {
headerParams["Accept"] = headerAccept
}
r, err := a.prepareRequest(ctx, path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
return returnValue, nil, err
Expand Down Expand Up @@ -298,30 +231,14 @@ func (a *EnvironmentResourceApiService) GetAll(ctx context.Context) ([]model.Env
returnValue []model.EnvironmentVariable
)

// create path and map variables
path := "/environment"

headerParams := make(map[string]string)
headerParams["Accept"] = "application/json"

queryParams := url.Values{}
formParams := url.Values{}

// to determine the Content-Type header
contentTypes := []string{}

// set Content-Type header
contentType := selectHeaderContentType(contentTypes)
if contentType != "" {
headerParams["Content-Type"] = contentType
}

// to determine the Accept header
headerAccepts := []string{"application/json"}

// set Accept header
headerAccept := selectHeaderAccept(headerAccepts)
if headerAccept != "" {
headerParams["Accept"] = headerAccept
}
r, err := a.prepareRequest(ctx, path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
return returnValue, nil, err
Expand Down Expand Up @@ -363,31 +280,15 @@ func (a *EnvironmentResourceApiService) GetTagsForEnvVar(ctx context.Context, na
returnValue []model.Tag
)

// create path and map variables
path := "/environment/{name}/tags"
path = strings.Replace(path, "{"+"name"+"}", fmt.Sprintf("%v", name), -1)

headerParams := make(map[string]string)
headerParams["Accept"] = "application/json"

queryParams := url.Values{}
formParams := url.Values{}

// to determine the Content-Type header
contentTypes := []string{}

// set Content-Type header
contentType := selectHeaderContentType(contentTypes)
if contentType != "" {
headerParams["Content-Type"] = contentType
}

// to determine the Accept header
headerAccepts := []string{"application/json"}

// set Accept header
headerAccept := selectHeaderAccept(headerAccepts)
if headerAccept != "" {
headerParams["Accept"] = headerAccept
}
r, err := a.prepareRequest(ctx, path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
return returnValue, nil, err
Expand Down Expand Up @@ -428,32 +329,15 @@ func (a *EnvironmentResourceApiService) PutTagForEnvVar(ctx context.Context, bod
fileBytes []byte
)

// create path and map variables
path := "/environment/{name}/tags"
path = strings.Replace(path, "{"+"name"+"}", fmt.Sprintf("%v", name), -1)

headerParams := make(map[string]string)
headerParams["Content-Type"] = "application/json"

queryParams := url.Values{}
formParams := url.Values{}

// to determine the Content-Type header
contentTypes := []string{"application/json"}

// set Content-Type header
contentType := selectHeaderContentType(contentTypes)
if contentType != "" {
headerParams["Content-Type"] = contentType
}

// to determine the Accept header
headerAccepts := []string{}

// set Accept header
headerAccept := selectHeaderAccept(headerAccepts)
if headerAccept != "" {
headerParams["Accept"] = headerAccept
}
// body params
postBody = &body
r, err := a.prepareRequest(ctx, path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes)
if err != nil {
Expand Down
Loading

0 comments on commit 283f031

Please sign in to comment.