From da8505337697f41052ac0a0f72a69d9cd250fe6b Mon Sep 17 00:00:00 2001 From: SDK Generator Bot Date: Tue, 23 Sep 2025 14:16:04 +0000 Subject: [PATCH] Generate git --- services/git/api_default.go | 207 +++++++++++ services/git/api_default_test.go | 56 +++ services/git/model_create_instance_payload.go | 2 +- services/git/model_patch_operation.go | 325 ++++++++++++++++++ services/git/model_patch_operation_test.go | 58 ++++ 5 files changed, 647 insertions(+), 1 deletion(-) create mode 100644 services/git/model_patch_operation.go create mode 100644 services/git/model_patch_operation_test.go diff --git a/services/git/api_default.go b/services/git/api_default.go index d18b9c364..f756e7d55 100644 --- a/services/git/api_default.go +++ b/services/git/api_default.go @@ -117,6 +117,27 @@ type DefaultApi interface { */ ListInstancesExecute(ctx context.Context, projectId string) (*ListInstances, error) + /* + PatchInstance Patch Instance. + Patches the Instance. + + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param projectId Project identifier. + @param instanceId Instance identifier. + @return ApiPatchInstanceRequest + */ + PatchInstance(ctx context.Context, projectId string, instanceId string) ApiPatchInstanceRequest + /* + PatchInstanceExecute executes the request + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param projectId Project identifier. + @param instanceId Instance identifier. + @return Instance + + */ + PatchInstanceExecute(ctx context.Context, projectId string, instanceId string) (*Instance, error) } type ApiCreateInstanceRequest interface { @@ -141,6 +162,11 @@ type ApiListInstancesRequest interface { Execute() (*ListInstances, error) } +type ApiPatchInstanceRequest interface { + PatchOperation(patchOperation []PatchOperation) ApiPatchInstanceRequest + Execute() (*Instance, error) +} + // DefaultApiService DefaultApi service type DefaultApiService service @@ -973,3 +999,184 @@ func (a *APIClient) ListInstancesExecute(ctx context.Context, projectId string) } return r.Execute() } + +type PatchInstanceRequest struct { + ctx context.Context + apiService *DefaultApiService + projectId string + instanceId string + patchOperation *[]PatchOperation +} + +func (r PatchInstanceRequest) PatchOperation(patchOperation []PatchOperation) ApiPatchInstanceRequest { + r.patchOperation = &patchOperation + return r +} + +func (r PatchInstanceRequest) Execute() (*Instance, error) { + var ( + localVarHTTPMethod = http.MethodPatch + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Instance + ) + a := r.apiService + client, ok := a.client.(*APIClient) + if !ok { + return localVarReturnValue, fmt.Errorf("could not parse client to type APIClient") + } + localBasePath, err := client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.PatchInstance") + if err != nil { + return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/v1beta/projects/{projectId}/instances/{instanceId}" + localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"instanceId"+"}", url.PathEscape(ParameterValueToString(r.instanceId, "instanceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if strlen(r.projectId) < 36 { + return localVarReturnValue, fmt.Errorf("projectId must have at least 36 elements") + } + if strlen(r.projectId) > 36 { + return localVarReturnValue, fmt.Errorf("projectId must have less than 36 elements") + } + if strlen(r.instanceId) < 36 { + return localVarReturnValue, fmt.Errorf("instanceId must have at least 36 elements") + } + if strlen(r.instanceId) > 36 { + return localVarReturnValue, fmt.Errorf("instanceId must have less than 36 elements") + } + if r.patchOperation == nil { + return localVarReturnValue, fmt.Errorf("patchOperation is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json-patch+json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.patchOperation + req, err := client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, err + } + + contextHTTPRequest, ok := r.ctx.Value(config.ContextHTTPRequest).(**http.Request) + if ok { + *contextHTTPRequest = req + } + + localVarHTTPResponse, err := client.callAPI(req) + contextHTTPResponse, ok := r.ctx.Value(config.ContextHTTPResponse).(**http.Response) + if ok { + *contextHTTPResponse = localVarHTTPResponse + } + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &oapierror.GenericOpenAPIError{ + StatusCode: localVarHTTPResponse.StatusCode, + Body: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v GenericErrorResponse + err = client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v UnauthorizedResponse + err = client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v GenericErrorResponse + err = client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + } + return localVarReturnValue, newErr + } + + err = client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &oapierror.GenericOpenAPIError{ + StatusCode: localVarHTTPResponse.StatusCode, + Body: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, newErr + } + + return localVarReturnValue, nil +} + +/* +PatchInstance: Patch Instance. + +Patches the Instance. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param projectId Project identifier. + @param instanceId Instance identifier. + @return ApiPatchInstanceRequest +*/ +func (a *APIClient) PatchInstance(ctx context.Context, projectId string, instanceId string) ApiPatchInstanceRequest { + return PatchInstanceRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + instanceId: instanceId, + } +} + +func (a *APIClient) PatchInstanceExecute(ctx context.Context, projectId string, instanceId string) (*Instance, error) { + r := PatchInstanceRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + instanceId: instanceId, + } + return r.Execute() +} diff --git a/services/git/api_default_test.go b/services/git/api_default_test.go index 879d2386d..4273838d6 100644 --- a/services/git/api_default_test.go +++ b/services/git/api_default_test.go @@ -284,4 +284,60 @@ func Test_git_DefaultApiService(t *testing.T) { } }) + t.Run("Test DefaultApiService PatchInstance", func(t *testing.T) { + _apiUrlPath := "/v1beta/projects/{projectId}/instances/{instanceId}" + projectIdValue := randString(36) + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) + instanceIdValue := randString(36) + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"instanceId"+"}", url.PathEscape(ParameterValueToString(instanceIdValue, "instanceId")), -1) + + testDefaultApiServeMux := http.NewServeMux() + testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) { + data := Instance{} + w.Header().Add("Content-Type", "application/json") + json.NewEncoder(w).Encode(data) + }) + testServer := httptest.NewServer(testDefaultApiServeMux) + defer testServer.Close() + + configuration := &config.Configuration{ + DefaultHeader: make(map[string]string), + UserAgent: "OpenAPI-Generator/1.0.0/go", + Debug: false, + Region: "test_region", + Servers: config.ServerConfigurations{ + { + URL: testServer.URL, + Description: "Localhost for git_DefaultApi", + Variables: map[string]config.ServerVariable{ + "region": { + DefaultValue: "test_region.", + EnumValues: []string{ + "test_region.", + }, + }, + }, + }, + }, + OperationServers: map[string]config.ServerConfigurations{}, + } + apiClient, err := NewAPIClient(config.WithCustomConfiguration(configuration), config.WithoutAuthentication()) + if err != nil { + t.Fatalf("creating API client: %v", err) + } + + projectId := projectIdValue + instanceId := instanceIdValue + patchOperation := []PatchOperation{} + + resp, reqErr := apiClient.PatchInstance(context.Background(), projectId, instanceId).PatchOperation(patchOperation).Execute() + + if reqErr != nil { + t.Fatalf("error in call: %v", reqErr) + } + if IsNil(resp) { + t.Fatalf("response not present") + } + }) + } diff --git a/services/git/model_create_instance_payload.go b/services/git/model_create_instance_payload.go index 3a1e20ed6..3c722d067 100644 --- a/services/git/model_create_instance_payload.go +++ b/services/git/model_create_instance_payload.go @@ -185,7 +185,7 @@ type CreateInstancePayloadGetNameRetType = string // CreateInstancePayload Request a STACKIT Git instance to be created with these properties. type CreateInstancePayload struct { - // Restricted ACL for instance access. + // A list of CIDR network addresses that are allowed to access the instance. Acl CreateInstancePayloadGetAclAttributeType `json:"acl,omitempty"` // Desired instance flavor. Must be one of the defined enum values Flavor CreateInstancePayloadGetFlavorAttributeType `json:"flavor,omitempty"` diff --git a/services/git/model_patch_operation.go b/services/git/model_patch_operation.go new file mode 100644 index 000000000..f6b4dd6c4 --- /dev/null +++ b/services/git/model_patch_operation.go @@ -0,0 +1,325 @@ +/* +STACKIT Git API + +STACKIT Git management API. + +API version: 1beta.0.4 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package git + +import ( + "encoding/json" + "fmt" +) + +// checks if the PatchOperation type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &PatchOperation{} + +/* + types and functions for op +*/ + +// isEnum + +// PatchOperationOp The patch operation to perform. +// value type for enums +type PatchOperationOp string + +// List of Op +const ( + PATCHOPERATIONOP_ADD PatchOperationOp = "add" + PATCHOPERATIONOP_REMOVE PatchOperationOp = "remove" +) + +// All allowed values of PatchOperation enum +var AllowedPatchOperationOpEnumValues = []PatchOperationOp{ + "add", + "remove", +} + +func (v *PatchOperationOp) UnmarshalJSON(src []byte) error { + // use a type alias to prevent infinite recursion during unmarshal, + // see https://biscuit.ninja/posts/go-avoid-an-infitine-loop-with-custom-json-unmarshallers + type TmpJson PatchOperationOp + var value TmpJson + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + // Allow unmarshalling zero value for testing purposes + var zeroValue TmpJson + if value == zeroValue { + return nil + } + enumTypeValue := PatchOperationOp(value) + for _, existing := range AllowedPatchOperationOpEnumValues { + if existing == enumTypeValue { + *v = enumTypeValue + return nil + } + } + + return fmt.Errorf("%+v is not a valid PatchOperation", value) +} + +// NewPatchOperationOpFromValue returns a pointer to a valid PatchOperationOp +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewPatchOperationOpFromValue(v PatchOperationOp) (*PatchOperationOp, error) { + ev := PatchOperationOp(v) + if ev.IsValid() { + return &ev, nil + } else { + return nil, fmt.Errorf("invalid value '%v' for PatchOperationOp: valid values are %v", v, AllowedPatchOperationOpEnumValues) + } +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v PatchOperationOp) IsValid() bool { + for _, existing := range AllowedPatchOperationOpEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to OpOp value +func (v PatchOperationOp) Ptr() *PatchOperationOp { + return &v +} + +type NullablePatchOperationOp struct { + value *PatchOperationOp + isSet bool +} + +func (v NullablePatchOperationOp) Get() *PatchOperationOp { + return v.value +} + +func (v *NullablePatchOperationOp) Set(val *PatchOperationOp) { + v.value = val + v.isSet = true +} + +func (v NullablePatchOperationOp) IsSet() bool { + return v.isSet +} + +func (v *NullablePatchOperationOp) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullablePatchOperationOp(val *PatchOperationOp) *NullablePatchOperationOp { + return &NullablePatchOperationOp{value: val, isSet: true} +} + +func (v NullablePatchOperationOp) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullablePatchOperationOp) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type PatchOperationGetOpAttributeType = *PatchOperationOp +type PatchOperationGetOpArgType = PatchOperationOp +type PatchOperationGetOpRetType = PatchOperationOp + +func getPatchOperationGetOpAttributeTypeOk(arg PatchOperationGetOpAttributeType) (ret PatchOperationGetOpRetType, ok bool) { + if arg == nil { + return ret, false + } + return *arg, true +} + +func setPatchOperationGetOpAttributeType(arg *PatchOperationGetOpAttributeType, val PatchOperationGetOpRetType) { + *arg = &val +} + +/* + types and functions for path +*/ + +// isNotNullableString +type PatchOperationGetPathAttributeType = *string + +func getPatchOperationGetPathAttributeTypeOk(arg PatchOperationGetPathAttributeType) (ret PatchOperationGetPathRetType, ok bool) { + if arg == nil { + return ret, false + } + return *arg, true +} + +func setPatchOperationGetPathAttributeType(arg *PatchOperationGetPathAttributeType, val PatchOperationGetPathRetType) { + *arg = &val +} + +type PatchOperationGetPathArgType = string +type PatchOperationGetPathRetType = string + +/* + types and functions for value +*/ + +// isNotNullableString +type PatchOperationGetValueAttributeType = *string + +func getPatchOperationGetValueAttributeTypeOk(arg PatchOperationGetValueAttributeType) (ret PatchOperationGetValueRetType, ok bool) { + if arg == nil { + return ret, false + } + return *arg, true +} + +func setPatchOperationGetValueAttributeType(arg *PatchOperationGetValueAttributeType, val PatchOperationGetValueRetType) { + *arg = &val +} + +type PatchOperationGetValueArgType = string +type PatchOperationGetValueRetType = string + +// PatchOperation Request a STACKIT Git instance to be patch with these properties. +type PatchOperation struct { + // The patch operation to perform. + // REQUIRED + Op PatchOperationGetOpAttributeType `json:"op" required:"true"` + // An RFC6901 JSON Pointer to the target location. + // REQUIRED + Path PatchOperationGetPathAttributeType `json:"path" required:"true"` + // The value to be used for 'add' and 'remove' operations. + Value PatchOperationGetValueAttributeType `json:"value,omitempty"` +} + +type _PatchOperation PatchOperation + +// NewPatchOperation instantiates a new PatchOperation object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewPatchOperation(op PatchOperationGetOpArgType, path PatchOperationGetPathArgType) *PatchOperation { + this := PatchOperation{} + setPatchOperationGetOpAttributeType(&this.Op, op) + setPatchOperationGetPathAttributeType(&this.Path, path) + return &this +} + +// NewPatchOperationWithDefaults instantiates a new PatchOperation object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewPatchOperationWithDefaults() *PatchOperation { + this := PatchOperation{} + return &this +} + +// GetOp returns the Op field value +func (o *PatchOperation) GetOp() (ret PatchOperationGetOpRetType) { + ret, _ = o.GetOpOk() + return ret +} + +// GetOpOk returns a tuple with the Op field value +// and a boolean to check if the value has been set. +func (o *PatchOperation) GetOpOk() (ret PatchOperationGetOpRetType, ok bool) { + return getPatchOperationGetOpAttributeTypeOk(o.Op) +} + +// SetOp sets field value +func (o *PatchOperation) SetOp(v PatchOperationGetOpRetType) { + setPatchOperationGetOpAttributeType(&o.Op, v) +} + +// GetPath returns the Path field value +func (o *PatchOperation) GetPath() (ret PatchOperationGetPathRetType) { + ret, _ = o.GetPathOk() + return ret +} + +// GetPathOk returns a tuple with the Path field value +// and a boolean to check if the value has been set. +func (o *PatchOperation) GetPathOk() (ret PatchOperationGetPathRetType, ok bool) { + return getPatchOperationGetPathAttributeTypeOk(o.Path) +} + +// SetPath sets field value +func (o *PatchOperation) SetPath(v PatchOperationGetPathRetType) { + setPatchOperationGetPathAttributeType(&o.Path, v) +} + +// GetValue returns the Value field value if set, zero value otherwise. +func (o *PatchOperation) GetValue() (res PatchOperationGetValueRetType) { + res, _ = o.GetValueOk() + return +} + +// GetValueOk returns a tuple with the Value field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *PatchOperation) GetValueOk() (ret PatchOperationGetValueRetType, ok bool) { + return getPatchOperationGetValueAttributeTypeOk(o.Value) +} + +// HasValue returns a boolean if a field has been set. +func (o *PatchOperation) HasValue() bool { + _, ok := o.GetValueOk() + return ok +} + +// SetValue gets a reference to the given string and assigns it to the Value field. +func (o *PatchOperation) SetValue(v PatchOperationGetValueRetType) { + setPatchOperationGetValueAttributeType(&o.Value, v) +} + +func (o PatchOperation) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if val, ok := getPatchOperationGetOpAttributeTypeOk(o.Op); ok { + toSerialize["Op"] = val + } + if val, ok := getPatchOperationGetPathAttributeTypeOk(o.Path); ok { + toSerialize["Path"] = val + } + if val, ok := getPatchOperationGetValueAttributeTypeOk(o.Value); ok { + toSerialize["Value"] = val + } + return toSerialize, nil +} + +type NullablePatchOperation struct { + value *PatchOperation + isSet bool +} + +func (v NullablePatchOperation) Get() *PatchOperation { + return v.value +} + +func (v *NullablePatchOperation) Set(val *PatchOperation) { + v.value = val + v.isSet = true +} + +func (v NullablePatchOperation) IsSet() bool { + return v.isSet +} + +func (v *NullablePatchOperation) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullablePatchOperation(val *PatchOperation) *NullablePatchOperation { + return &NullablePatchOperation{value: val, isSet: true} +} + +func (v NullablePatchOperation) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullablePatchOperation) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/services/git/model_patch_operation_test.go b/services/git/model_patch_operation_test.go new file mode 100644 index 000000000..307efe3fd --- /dev/null +++ b/services/git/model_patch_operation_test.go @@ -0,0 +1,58 @@ +/* +STACKIT Git API + +STACKIT Git management API. + +API version: 1beta.0.4 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package git + +import ( + "testing" +) + +// isEnum + +func TestPatchOperationOp_UnmarshalJSON(t *testing.T) { + type args struct { + src []byte + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: `success - possible enum value no. 1`, + args: args{ + src: []byte(`"add"`), + }, + wantErr: false, + }, + { + name: `success - possible enum value no. 2`, + args: args{ + src: []byte(`"remove"`), + }, + wantErr: false, + }, + { + name: "fail", + args: args{ + src: []byte("\"FOOBAR\""), + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := PatchOperationOp("") + if err := v.UnmarshalJSON(tt.args.src); (err != nil) != tt.wantErr { + t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +}