diff --git a/edgefunctions/.openapi-generator/FILES b/edgefunctions/.openapi-generator/FILES index 101d37a..6c4f31d 100644 --- a/edgefunctions/.openapi-generator/FILES +++ b/edgefunctions/.openapi-generator/FILES @@ -7,6 +7,7 @@ client.go configuration.go docs/BadRequestResponse.md docs/CreateEdgeFunctionRequest.md +docs/CreateEdgeFunctionRequestJsonArgs.md docs/EdgeFunctionResponse.md docs/EdgeFunctionsAPI.md docs/ErrorResponse.md @@ -20,6 +21,7 @@ go.mod go.sum model_bad_request_response.go model_create_edge_function_request.go +model_create_edge_function_request_json_args.go model_edge_function_response.go model_error_response.go model_links.go diff --git a/edgefunctions/.openapi-generator/VERSION b/edgefunctions/.openapi-generator/VERSION index 73a86b1..5f84a81 100644 --- a/edgefunctions/.openapi-generator/VERSION +++ b/edgefunctions/.openapi-generator/VERSION @@ -1 +1 @@ -7.0.1 \ No newline at end of file +7.12.0 diff --git a/edgefunctions/README.md b/edgefunctions/README.md index 77e4aab..3dbe477 100644 --- a/edgefunctions/README.md +++ b/edgefunctions/README.md @@ -7,26 +7,27 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat - API version: 2.0.0 - Package version: 1.0.0 +- Generator version: 7.12.0 - Build package: org.openapitools.codegen.languages.GoClientCodegen ## Installation Install the following dependencies: -```shell +```sh go get github.com/stretchr/testify/assert go get golang.org/x/net/context ``` Put the package under your project folder and add the following in import: -```golang +```go import edgefunctions "github.com/GIT_USER_ID/GIT_REPO_ID" ``` To use a proxy, set the environment variable `HTTP_PROXY`: -```golang +```go os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port") ``` @@ -36,17 +37,17 @@ Default configuration comes with `Servers` field that contains server objects as ### Select Server Configuration -For using other server than the one defined on index 0 set context value `sw.ContextServerIndex` of type `int`. +For using other server than the one defined on index 0 set context value `edgefunctions.ContextServerIndex` of type `int`. -```golang +```go ctx := context.WithValue(context.Background(), edgefunctions.ContextServerIndex, 1) ``` ### Templated Server URL -Templated server URL is formatted using default variables from configuration or from context value `sw.ContextServerVariables` of type `map[string]string`. +Templated server URL is formatted using default variables from configuration or from context value `edgefunctions.ContextServerVariables` of type `map[string]string`. -```golang +```go ctx := context.WithValue(context.Background(), edgefunctions.ContextServerVariables, map[string]string{ "basePath": "v2", }) @@ -58,9 +59,9 @@ Note, enum values are always validated and all unused variables are silently ign Each operation can use different server URL defined using `OperationServers` map in the `Configuration`. An operation is uniquely identified by `"{classname}Service.{nickname}"` string. -Similar rules for overriding default operation server index and variables applies by using `sw.ContextOperationServerIndices` and `sw.ContextOperationServerVariables` context maps. +Similar rules for overriding default operation server index and variables applies by using `edgefunctions.ContextOperationServerIndices` and `edgefunctions.ContextOperationServerVariables` context maps. -```golang +```go ctx := context.WithValue(context.Background(), edgefunctions.ContextOperationServerIndices, map[string]int{ "{classname}Service.{nickname}": 2, }) @@ -89,6 +90,7 @@ Class | Method | HTTP request | Description - [BadRequestResponse](docs/BadRequestResponse.md) - [CreateEdgeFunctionRequest](docs/CreateEdgeFunctionRequest.md) + - [CreateEdgeFunctionRequestJsonArgs](docs/CreateEdgeFunctionRequestJsonArgs.md) - [EdgeFunctionResponse](docs/EdgeFunctionResponse.md) - [ErrorResponse](docs/ErrorResponse.md) - [Links](docs/Links.md) @@ -108,16 +110,16 @@ Authentication schemes defined for the API: - **API key parameter name**: Authorization - **Location**: HTTP header -Note, each API key must be added to a map of `map[string]APIKey` where the key is: Authorization and passed in as the auth context for each request. +Note, each API key must be added to a map of `map[string]APIKey` where the key is: tokenAuth and passed in as the auth context for each request. Example -```golang +```go auth := context.WithValue( context.Background(), - sw.ContextAPIKeys, - map[string]sw.APIKey{ - "Authorization": {Key: "API_KEY_STRING"}, + edgefunctions.ContextAPIKeys, + map[string]edgefunctions.APIKey{ + "tokenAuth": {Key: "API_KEY_STRING"}, }, ) r, err := client.Service.Operation(auth, args) diff --git a/edgefunctions/api/openapi.yaml b/edgefunctions/api/openapi.yaml index a853b10..655a557 100644 --- a/edgefunctions/api/openapi.yaml +++ b/edgefunctions/api/openapi.yaml @@ -357,6 +357,8 @@ components: required: true schemas: ErrorResponse: + example: + detail: detail properties: detail: type: string @@ -467,7 +469,7 @@ components: name: name active: true language: language - json_args: "" + json_args: {} initiator_type: edge_application properties: name: @@ -476,7 +478,8 @@ components: type: string code: type: string - json_args: {} + json_args: + $ref: '#/components/schemas/CreateEdgeFunctionRequest_json_args' initiator_type: enum: - edge_application @@ -488,6 +491,19 @@ components: type: boolean type: object BadRequestResponse: + example: + code: + - code + - code + name: + - name + - name + active: + - active + - active + language: + - language + - language properties: name: items: @@ -532,7 +548,7 @@ components: code: code name: name active: true - json_args: "" + json_args: {} language: language initiator_type: edge_application properties: @@ -540,7 +556,8 @@ components: type: string code: type: string - json_args: {} + json_args: + $ref: '#/components/schemas/CreateEdgeFunctionRequest_json_args' active: type: boolean initiator_type: @@ -558,18 +575,25 @@ components: code: code name: name active: true - json_args: "" + json_args: {} properties: name: type: string code: type: string - json_args: {} + json_args: + $ref: '#/components/schemas/CreateEdgeFunctionRequest_json_args' active: type: boolean is_proprietary_code: type: boolean type: object + CreateEdgeFunctionRequest_json_args: + oneOf: + - type: object + - items: + type: object + type: array securitySchemes: tokenAuth: description: | diff --git a/edgefunctions/api_edge_functions.go b/edgefunctions/api_edge_functions.go index 4ea442e..124b1d2 100644 --- a/edgefunctions/api_edge_functions.go +++ b/edgefunctions/api_edge_functions.go @@ -91,16 +91,16 @@ func (a *EdgeFunctionsAPIService) EdgeFunctionsGetExecute(r ApiEdgeFunctionsGetR localVarFormParams := url.Values{} if r.page != nil { - parameterAddToHeaderOrQuery(localVarQueryParams, "page", r.page, "") + parameterAddToHeaderOrQuery(localVarQueryParams, "page", r.page, "form", "") } if r.pageSize != nil { - parameterAddToHeaderOrQuery(localVarQueryParams, "page_size", r.pageSize, "") + parameterAddToHeaderOrQuery(localVarQueryParams, "page_size", r.pageSize, "form", "") } if r.sort != nil { - parameterAddToHeaderOrQuery(localVarQueryParams, "sort", r.sort, "") + parameterAddToHeaderOrQuery(localVarQueryParams, "sort", r.sort, "form", "") } if r.orderBy != nil { - parameterAddToHeaderOrQuery(localVarQueryParams, "order_by", r.orderBy, "") + parameterAddToHeaderOrQuery(localVarQueryParams, "order_by", r.orderBy, "form", "") } // to determine the Content-Type header localVarHTTPContentTypes := []string{} diff --git a/edgefunctions/client.go b/edgefunctions/client.go index 423092b..0d5c645 100644 --- a/edgefunctions/client.go +++ b/edgefunctions/client.go @@ -35,8 +35,8 @@ import ( ) var ( - jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`) - xmlCheck = regexp.MustCompile(`(?i:(?:application|text)/xml)`) + JsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?json)`) + XmlCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?xml)`) queryParamSplit = regexp.MustCompile(`(^|&)([^&]+)`) queryDescape = strings.NewReplacer( "%5B", "[", "%5D", "]" ) ) @@ -127,6 +127,10 @@ func typeCheckParameter(obj interface{}, expected string, name string) error { func parameterValueToString( obj interface{}, key string ) string { if reflect.TypeOf(obj).Kind() != reflect.Ptr { + if actualObj, ok := obj.(interface{ GetActualInstanceValue() interface{} }); ok { + return fmt.Sprintf("%v", actualObj.GetActualInstanceValue()) + } + return fmt.Sprintf("%v", obj) } var param,ok = obj.(MappedNullable) @@ -142,7 +146,7 @@ func parameterValueToString( obj interface{}, key string ) string { // parameterAddToHeaderOrQuery adds the provided object to the request header or url query // supporting deep object syntax -func parameterAddToHeaderOrQuery(headerOrQueryParams interface{}, keyPrefix string, obj interface{}, collectionType string) { +func parameterAddToHeaderOrQuery(headerOrQueryParams interface{}, keyPrefix string, obj interface{}, style string, collectionType string) { var v = reflect.ValueOf(obj) var value = "" if v == reflect.ValueOf(nil) { @@ -158,11 +162,11 @@ func parameterAddToHeaderOrQuery(headerOrQueryParams interface{}, keyPrefix stri if err != nil { return } - parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, dataMap, collectionType) + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, dataMap, style, collectionType) return } if t, ok := obj.(time.Time); ok { - parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, t.Format(time.RFC3339), collectionType) + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, t.Format(time.RFC3339Nano), style, collectionType) return } value = v.Type().String() + " value" @@ -174,7 +178,11 @@ func parameterAddToHeaderOrQuery(headerOrQueryParams interface{}, keyPrefix stri var lenIndValue = indValue.Len() for i:=0;i 1 { // more than 1 match + // reset to nil + dst.ArrayOfMapmapOfStringAny = nil + dst.MapmapOfStringAny = nil + + return fmt.Errorf("data matches more than one schema in oneOf(CreateEdgeFunctionRequestJsonArgs)") + } else if match == 1 { + return nil // exactly one match + } else { // no match + return fmt.Errorf("data failed to match schemas in oneOf(CreateEdgeFunctionRequestJsonArgs)") + } +} + +// Marshal data from the first non-nil pointers in the struct to JSON +func (src CreateEdgeFunctionRequestJsonArgs) MarshalJSON() ([]byte, error) { + if src.ArrayOfMapmapOfStringAny != nil { + return json.Marshal(&src.ArrayOfMapmapOfStringAny) + } + + if src.MapmapOfStringAny != nil { + return json.Marshal(&src.MapmapOfStringAny) + } + + return nil, nil // no data in oneOf schemas +} + +// Get the actual instance +func (obj *CreateEdgeFunctionRequestJsonArgs) GetActualInstance() (interface{}) { + if obj == nil { + return nil + } + if obj.ArrayOfMapmapOfStringAny != nil { + return obj.ArrayOfMapmapOfStringAny + } + + if obj.MapmapOfStringAny != nil { + return obj.MapmapOfStringAny + } + + // all schemas are nil + return nil +} + +// Get the actual instance value +func (obj CreateEdgeFunctionRequestJsonArgs) GetActualInstanceValue() (interface{}) { + if obj.ArrayOfMapmapOfStringAny != nil { + return *obj.ArrayOfMapmapOfStringAny + } + + if obj.MapmapOfStringAny != nil { + return *obj.MapmapOfStringAny + } + + // all schemas are nil + return nil +} + +type NullableCreateEdgeFunctionRequestJsonArgs struct { + value *CreateEdgeFunctionRequestJsonArgs + isSet bool +} + +func (v NullableCreateEdgeFunctionRequestJsonArgs) Get() *CreateEdgeFunctionRequestJsonArgs { + return v.value +} + +func (v *NullableCreateEdgeFunctionRequestJsonArgs) Set(val *CreateEdgeFunctionRequestJsonArgs) { + v.value = val + v.isSet = true +} + +func (v NullableCreateEdgeFunctionRequestJsonArgs) IsSet() bool { + return v.isSet +} + +func (v *NullableCreateEdgeFunctionRequestJsonArgs) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableCreateEdgeFunctionRequestJsonArgs(val *CreateEdgeFunctionRequestJsonArgs) *NullableCreateEdgeFunctionRequestJsonArgs { + return &NullableCreateEdgeFunctionRequestJsonArgs{value: val, isSet: true} +} + +func (v NullableCreateEdgeFunctionRequestJsonArgs) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableCreateEdgeFunctionRequestJsonArgs) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/edgefunctions/model_patch_edge_function_request.go b/edgefunctions/model_patch_edge_function_request.go index d7eff78..2fca9a4 100644 --- a/edgefunctions/model_patch_edge_function_request.go +++ b/edgefunctions/model_patch_edge_function_request.go @@ -21,7 +21,7 @@ var _ MappedNullable = &PatchEdgeFunctionRequest{} type PatchEdgeFunctionRequest struct { Name *string `json:"name,omitempty"` Code *string `json:"code,omitempty"` - JsonArgs interface{} `json:"json_args,omitempty"` + JsonArgs *CreateEdgeFunctionRequestJsonArgs `json:"json_args,omitempty"` Active *bool `json:"active,omitempty"` IsProprietaryCode *bool `json:"is_proprietary_code,omitempty"` } @@ -107,37 +107,36 @@ func (o *PatchEdgeFunctionRequest) SetCode(v string) { o.Code = &v } -// GetJsonArgs returns the JsonArgs field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *PatchEdgeFunctionRequest) GetJsonArgs() interface{} { - if o == nil { - var ret interface{} +// GetJsonArgs returns the JsonArgs field value if set, zero value otherwise. +func (o *PatchEdgeFunctionRequest) GetJsonArgs() CreateEdgeFunctionRequestJsonArgs { + if o == nil || IsNil(o.JsonArgs) { + var ret CreateEdgeFunctionRequestJsonArgs return ret } - return o.JsonArgs + return *o.JsonArgs } // GetJsonArgsOk returns a tuple with the JsonArgs field value if set, nil otherwise // and a boolean to check if the value has been set. -// NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *PatchEdgeFunctionRequest) GetJsonArgsOk() (*interface{}, bool) { +func (o *PatchEdgeFunctionRequest) GetJsonArgsOk() (*CreateEdgeFunctionRequestJsonArgs, bool) { if o == nil || IsNil(o.JsonArgs) { return nil, false } - return &o.JsonArgs, true + return o.JsonArgs, true } // HasJsonArgs returns a boolean if a field has been set. func (o *PatchEdgeFunctionRequest) HasJsonArgs() bool { - if o != nil && IsNil(o.JsonArgs) { + if o != nil && !IsNil(o.JsonArgs) { return true } return false } -// SetJsonArgs gets a reference to the given interface{} and assigns it to the JsonArgs field. -func (o *PatchEdgeFunctionRequest) SetJsonArgs(v interface{}) { - o.JsonArgs = v +// SetJsonArgs gets a reference to the given CreateEdgeFunctionRequestJsonArgs and assigns it to the JsonArgs field. +func (o *PatchEdgeFunctionRequest) SetJsonArgs(v CreateEdgeFunctionRequestJsonArgs) { + o.JsonArgs = &v } // GetActive returns the Active field value if set, zero value otherwise. @@ -220,7 +219,7 @@ func (o PatchEdgeFunctionRequest) ToMap() (map[string]interface{}, error) { if !IsNil(o.Code) { toSerialize["code"] = o.Code } - if o.JsonArgs != nil { + if !IsNil(o.JsonArgs) { toSerialize["json_args"] = o.JsonArgs } if !IsNil(o.Active) { diff --git a/edgefunctions/model_put_edge_function_request.go b/edgefunctions/model_put_edge_function_request.go index d551414..a25edd9 100644 --- a/edgefunctions/model_put_edge_function_request.go +++ b/edgefunctions/model_put_edge_function_request.go @@ -21,7 +21,7 @@ var _ MappedNullable = &PutEdgeFunctionRequest{} type PutEdgeFunctionRequest struct { Name *string `json:"name,omitempty"` Code *string `json:"code,omitempty"` - JsonArgs interface{} `json:"json_args,omitempty"` + JsonArgs *CreateEdgeFunctionRequestJsonArgs `json:"json_args,omitempty"` Active *bool `json:"active,omitempty"` InitiatorType *string `json:"initiator_type,omitempty"` Language *string `json:"language,omitempty"` @@ -109,37 +109,36 @@ func (o *PutEdgeFunctionRequest) SetCode(v string) { o.Code = &v } -// GetJsonArgs returns the JsonArgs field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *PutEdgeFunctionRequest) GetJsonArgs() interface{} { - if o == nil { - var ret interface{} +// GetJsonArgs returns the JsonArgs field value if set, zero value otherwise. +func (o *PutEdgeFunctionRequest) GetJsonArgs() CreateEdgeFunctionRequestJsonArgs { + if o == nil || IsNil(o.JsonArgs) { + var ret CreateEdgeFunctionRequestJsonArgs return ret } - return o.JsonArgs + return *o.JsonArgs } // GetJsonArgsOk returns a tuple with the JsonArgs field value if set, nil otherwise // and a boolean to check if the value has been set. -// NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *PutEdgeFunctionRequest) GetJsonArgsOk() (*interface{}, bool) { +func (o *PutEdgeFunctionRequest) GetJsonArgsOk() (*CreateEdgeFunctionRequestJsonArgs, bool) { if o == nil || IsNil(o.JsonArgs) { return nil, false } - return &o.JsonArgs, true + return o.JsonArgs, true } // HasJsonArgs returns a boolean if a field has been set. func (o *PutEdgeFunctionRequest) HasJsonArgs() bool { - if o != nil && IsNil(o.JsonArgs) { + if o != nil && !IsNil(o.JsonArgs) { return true } return false } -// SetJsonArgs gets a reference to the given interface{} and assigns it to the JsonArgs field. -func (o *PutEdgeFunctionRequest) SetJsonArgs(v interface{}) { - o.JsonArgs = v +// SetJsonArgs gets a reference to the given CreateEdgeFunctionRequestJsonArgs and assigns it to the JsonArgs field. +func (o *PutEdgeFunctionRequest) SetJsonArgs(v CreateEdgeFunctionRequestJsonArgs) { + o.JsonArgs = &v } // GetActive returns the Active field value if set, zero value otherwise. @@ -286,7 +285,7 @@ func (o PutEdgeFunctionRequest) ToMap() (map[string]interface{}, error) { if !IsNil(o.Code) { toSerialize["code"] = o.Code } - if o.JsonArgs != nil { + if !IsNil(o.JsonArgs) { toSerialize["json_args"] = o.JsonArgs } if !IsNil(o.Active) { diff --git a/edgefunctions/model_results.go b/edgefunctions/model_results.go index 100543a..b5bfcd9 100644 --- a/edgefunctions/model_results.go +++ b/edgefunctions/model_results.go @@ -199,7 +199,7 @@ func (o *Results) GetJsonArgsOk() (*interface{}, bool) { // HasJsonArgs returns a boolean if a field has been set. func (o *Results) HasJsonArgs() bool { - if o != nil && IsNil(o.JsonArgs) { + if o != nil && !IsNil(o.JsonArgs) { return true } diff --git a/edgefunctions/utils.go b/edgefunctions/utils.go index e995bd9..58db04e 100644 --- a/edgefunctions/utils.go +++ b/edgefunctions/utils.go @@ -11,7 +11,9 @@ API version: 2.0.0 package edgefunctions import ( + "bytes" "encoding/json" + "fmt" "reflect" "time" ) @@ -320,7 +322,7 @@ func NewNullableTime(val *time.Time) *NullableTime { } func (v NullableTime) MarshalJSON() ([]byte, error) { - return v.value.MarshalJSON() + return json.Marshal(v.value) } func (v *NullableTime) UnmarshalJSON(src []byte) error { @@ -345,3 +347,15 @@ func IsNil(i interface{}) bool { type MappedNullable interface { ToMap() (map[string]interface{}, error) } + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} \ No newline at end of file