github.com/safedep/dry@v0.0.0-20241016050132-a15651f0548b/apiguard/tykgen/api_schema.go (about)

     1  
     2  /*
     3   * Tyk Gateway API
     4   *
     5   * The Tyk Gateway API is the primary means for integrating your application with the Tyk API Gateway system. This API is very small, and has no granular permissions system. It is intended to be used purely for internal automation and integration.  **Warning: Under no circumstances should outside parties be granted access to this API.**  The Tyk Gateway API is capable of:  * Managing session objects (key generation) * Managing and listing policies * Managing and listing API Definitions (only when not using the Dashboard) * Hot reloads / reloading a cluster configuration * OAuth client creation (only when not using the Dashboard)   In order to use the Gateway API, you'll need to set the `secret` parameter in your tyk.conf file.  The shared secret you set should then be sent along as a header with each Gateway API Request in order for it to be successful:  ``` x-tyk-authorization: <your-secret> ``` <br/> <b>The Tyk Gateway API is subsumed by the Tyk Dashboard API in Pro installations.</b>
     6   *
     7   * API version: 5.5.0
     8   * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
     9   */
    10  package swagger
    11  
    12  import (
    13  	"context"
    14  	"io/ioutil"
    15  	"net/http"
    16  	"net/url"
    17  	"strings"
    18  	"github.com/antihax/optional"
    19  )
    20  
    21  // Linger please
    22  var (
    23  	_ context.Context
    24  )
    25  
    26  type SchemaApiService service
    27  /*
    28  SchemaApiService
    29  Get OAS schema
    30   * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
    31   * @param optional nil or *SchemaApiGetSchemaOpts - Optional Parameters:
    32       * @param "OasVersion" (optional.String) -  The OAS version
    33  @return OasSchemaResponse
    34  */
    35  
    36  type SchemaApiGetSchemaOpts struct {
    37      OasVersion optional.String
    38  }
    39  
    40  func (a *SchemaApiService) GetSchema(ctx context.Context, localVarOptionals *SchemaApiGetSchemaOpts) (OasSchemaResponse, *http.Response, error) {
    41  	var (
    42  		localVarHttpMethod = strings.ToUpper("Get")
    43  		localVarPostBody   interface{}
    44  		localVarFileName   string
    45  		localVarFileBytes  []byte
    46  		localVarReturnValue OasSchemaResponse
    47  	)
    48  
    49  	// create path and map variables
    50  	localVarPath := a.client.cfg.BasePath + "/tyk/schema"
    51  
    52  	localVarHeaderParams := make(map[string]string)
    53  	localVarQueryParams := url.Values{}
    54  	localVarFormParams := url.Values{}
    55  
    56  	if localVarOptionals != nil && localVarOptionals.OasVersion.IsSet() {
    57  		localVarQueryParams.Add("oasVersion", parameterToString(localVarOptionals.OasVersion.Value(), ""))
    58  	}
    59  	// to determine the Content-Type header
    60  	localVarHttpContentTypes := []string{}
    61  
    62  	// set Content-Type header
    63  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
    64  	if localVarHttpContentType != "" {
    65  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
    66  	}
    67  
    68  	// to determine the Accept header
    69  	localVarHttpHeaderAccepts := []string{"application/json"}
    70  
    71  	// set Accept header
    72  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
    73  	if localVarHttpHeaderAccept != "" {
    74  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
    75  	}
    76  	if ctx != nil {
    77  		// API Key Authentication
    78  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
    79  			var key string
    80  			if auth.Prefix != "" {
    81  				key = auth.Prefix + " " + auth.Key
    82  			} else {
    83  				key = auth.Key
    84  			}
    85  			localVarHeaderParams["X-Tyk-Authorization"] = key
    86  			
    87  		}
    88  	}
    89  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
    90  	if err != nil {
    91  		return localVarReturnValue, nil, err
    92  	}
    93  
    94  	localVarHttpResponse, err := a.client.callAPI(r)
    95  	if err != nil || localVarHttpResponse == nil {
    96  		return localVarReturnValue, localVarHttpResponse, err
    97  	}
    98  
    99  	localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
   100  	localVarHttpResponse.Body.Close()
   101  	if err != nil {
   102  		return localVarReturnValue, localVarHttpResponse, err
   103  	}
   104  
   105  	if localVarHttpResponse.StatusCode < 300 {
   106  		// If we succeed, return the data, otherwise pass on to decode error.
   107  		err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   108  		if err == nil { 
   109  			return localVarReturnValue, localVarHttpResponse, err
   110  		}
   111  	}
   112  
   113  	if localVarHttpResponse.StatusCode >= 300 {
   114  		newErr := GenericSwaggerError{
   115  			body: localVarBody,
   116  			error: localVarHttpResponse.Status,
   117  		}
   118  		if localVarHttpResponse.StatusCode == 200 {
   119  			var v OasSchemaResponse
   120  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   121  				if err != nil {
   122  					newErr.error = err.Error()
   123  					return localVarReturnValue, localVarHttpResponse, newErr
   124  				}
   125  				newErr.model = v
   126  				return localVarReturnValue, localVarHttpResponse, newErr
   127  		}
   128  		if localVarHttpResponse.StatusCode == 400 {
   129  			var v OasSchemaResponse
   130  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   131  				if err != nil {
   132  					newErr.error = err.Error()
   133  					return localVarReturnValue, localVarHttpResponse, newErr
   134  				}
   135  				newErr.model = v
   136  				return localVarReturnValue, localVarHttpResponse, newErr
   137  		}
   138  		if localVarHttpResponse.StatusCode == 404 {
   139  			var v OasSchemaResponse
   140  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   141  				if err != nil {
   142  					newErr.error = err.Error()
   143  					return localVarReturnValue, localVarHttpResponse, newErr
   144  				}
   145  				newErr.model = v
   146  				return localVarReturnValue, localVarHttpResponse, newErr
   147  		}
   148  		return localVarReturnValue, localVarHttpResponse, newErr
   149  	}
   150  
   151  	return localVarReturnValue, localVarHttpResponse, nil
   152  }