terraform-provider-stackitp.../pkg/iaasbeta/model_create_protocol.go
Marcel S. Henselin 9f41c4da7f
Some checks failed
Publish / Check GoReleaser config (push) Successful in 4s
Release / goreleaser (push) Failing after 29s
Publish / Publish provider (push) Failing after 4m24s
feat: auto generated files and new structure (#4)
## Description

<!-- **Please link some issue here describing what you are trying to achieve.**

In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->

relates to #1234

## Checklist

- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] Docs are up-to-date: `make generate-docs` (will be checked by CI)
- [ ] Unit tests got implemented or updated
- [ ] Acceptance tests got implemented or updated (see e.g. [here](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)

Reviewed-on: #4
Reviewed-by: Andre_Harms <andre.harms@stackit.cloud>
Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Co-committed-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
2026-01-29 14:10:25 +00:00

144 lines
3.3 KiB
Go

/*
STACKIT IaaS API
This API allows you to create and modify IaaS resources.
API version: 2beta1
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package iaasbeta
import (
"encoding/json"
"fmt"
)
// CreateProtocol - The schema for a protocol when creating a security group rule.
type CreateProtocol struct {
Int64 *int64
String *string
}
// int64AsCreateProtocol is a convenience function that returns int64 wrapped in CreateProtocol
func Int64AsCreateProtocol(v *int64) CreateProtocol {
return CreateProtocol{
Int64: v,
}
}
// stringAsCreateProtocol is a convenience function that returns string wrapped in CreateProtocol
func StringAsCreateProtocol(v *string) CreateProtocol {
return CreateProtocol{
String: v,
}
}
// Unmarshal JSON data into one of the pointers in the struct
func (dst *CreateProtocol) UnmarshalJSON(data []byte) error {
var err error
match := 0
// Workaround until upstream issue is fixed:
// https://github.com/OpenAPITools/openapi-generator/issues/21751
// Tracking issue on our side: https://jira.schwarz/browse/STACKITSDK-226
// try to unmarshal data into Int64
dstCreateProtocol1 := &CreateProtocol{}
err = json.Unmarshal(data, &dstCreateProtocol1.Int64)
if err == nil {
jsonInt64, _ := json.Marshal(&dstCreateProtocol1.Int64)
if string(jsonInt64) != "{}" { // empty struct
dst.Int64 = dstCreateProtocol1.Int64
match++
}
}
// try to unmarshal data into String
dstCreateProtocol2 := &CreateProtocol{}
err = json.Unmarshal(data, &dstCreateProtocol2.String)
if err == nil {
jsonString, _ := json.Marshal(&dstCreateProtocol2.String)
if string(jsonString) != "{}" { // empty struct
dst.String = dstCreateProtocol2.String
match++
}
}
if match > 1 { // more than 1 match
// reset to nil
dst.Int64 = nil
dst.String = nil
return fmt.Errorf("data matches more than one schema in oneOf(CreateProtocol)")
} else if match == 1 {
return nil // exactly one match
} else { // no match
return fmt.Errorf("data failed to match schemas in oneOf(CreateProtocol)")
}
}
// Marshal data from the first non-nil pointers in the struct to JSON
func (src CreateProtocol) MarshalJSON() ([]byte, error) {
if src.Int64 != nil {
return json.Marshal(&src.Int64)
}
if src.String != nil {
return json.Marshal(&src.String)
}
return []byte("{}"), nil // no data in oneOf schemas => empty JSON object
}
// Get the actual instance
func (obj *CreateProtocol) GetActualInstance() interface{} {
if obj == nil {
return nil
}
if obj.Int64 != nil {
return obj.Int64
}
if obj.String != nil {
return obj.String
}
// all schemas are nil
return nil
}
type NullableCreateProtocol struct {
value *CreateProtocol
isSet bool
}
func (v NullableCreateProtocol) Get() *CreateProtocol {
return v.value
}
func (v *NullableCreateProtocol) Set(val *CreateProtocol) {
v.value = val
v.isSet = true
}
func (v NullableCreateProtocol) IsSet() bool {
return v.isSet
}
func (v *NullableCreateProtocol) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableCreateProtocol(val *CreateProtocol) *NullableCreateProtocol {
return &NullableCreateProtocol{value: val, isSet: true}
}
func (v NullableCreateProtocol) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableCreateProtocol) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}