150 lines
3.6 KiB
Go
150 lines
3.6 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"
|
|
"regexp"
|
|
)
|
|
|
|
// AreaId - The identifier (ID) of an area.
|
|
type AreaId struct {
|
|
StaticAreaID *StaticAreaID
|
|
String *string
|
|
}
|
|
|
|
// StaticAreaIDAsAreaId is a convenience function that returns StaticAreaID wrapped in AreaId
|
|
func StaticAreaIDAsAreaId(v *StaticAreaID) AreaId {
|
|
return AreaId{
|
|
StaticAreaID: v,
|
|
}
|
|
}
|
|
|
|
// stringAsAreaId is a convenience function that returns string wrapped in AreaId
|
|
func StringAsAreaId(v *string) AreaId {
|
|
return AreaId{
|
|
String: v,
|
|
}
|
|
}
|
|
|
|
// Unmarshal JSON data into one of the pointers in the struct
|
|
func (dst *AreaId) 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 String
|
|
dstAreaId1 := &AreaId{}
|
|
err = json.Unmarshal(data, &dstAreaId1.String)
|
|
if err == nil {
|
|
jsonString, _ := json.Marshal(&dstAreaId1.String)
|
|
regex := `/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/`
|
|
regex = regexp.MustCompile("^\\/|\\/$").ReplaceAllString(regex, "$1") // Remove beginning slash and ending slash
|
|
regex = regexp.MustCompile("\\\\(.)").ReplaceAllString(regex, "$1") // Remove duplicate escaping char for dots
|
|
rawString := regexp.MustCompile(`^"|"$`).ReplaceAllString(*dstAreaId1.String, "$1") // Remove quotes
|
|
isMatched, _ := regexp.MatchString(regex, rawString)
|
|
if string(jsonString) != "{}" && isMatched { // empty struct
|
|
dst.String = dstAreaId1.String
|
|
match++
|
|
}
|
|
}
|
|
|
|
// try to unmarshal data into StaticAreaID
|
|
dstAreaId2 := &AreaId{}
|
|
err = json.Unmarshal(data, &dstAreaId2.StaticAreaID)
|
|
if err == nil {
|
|
jsonStaticAreaID, _ := json.Marshal(&dstAreaId2.StaticAreaID)
|
|
if string(jsonStaticAreaID) != "{}" { // empty struct
|
|
dst.StaticAreaID = dstAreaId2.StaticAreaID
|
|
match++
|
|
}
|
|
}
|
|
|
|
if match > 1 { // more than 1 match
|
|
// reset to nil
|
|
dst.StaticAreaID = nil
|
|
dst.String = nil
|
|
|
|
return fmt.Errorf("data matches more than one schema in oneOf(AreaId)")
|
|
} else if match == 1 {
|
|
return nil // exactly one match
|
|
} else { // no match
|
|
return fmt.Errorf("data failed to match schemas in oneOf(AreaId)")
|
|
}
|
|
}
|
|
|
|
// Marshal data from the first non-nil pointers in the struct to JSON
|
|
func (src AreaId) MarshalJSON() ([]byte, error) {
|
|
if src.StaticAreaID != nil {
|
|
return json.Marshal(&src.StaticAreaID)
|
|
}
|
|
|
|
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 *AreaId) GetActualInstance() interface{} {
|
|
if obj == nil {
|
|
return nil
|
|
}
|
|
if obj.StaticAreaID != nil {
|
|
return obj.StaticAreaID
|
|
}
|
|
|
|
if obj.String != nil {
|
|
return obj.String
|
|
}
|
|
|
|
// all schemas are nil
|
|
return nil
|
|
}
|
|
|
|
type NullableAreaId struct {
|
|
value *AreaId
|
|
isSet bool
|
|
}
|
|
|
|
func (v NullableAreaId) Get() *AreaId {
|
|
return v.value
|
|
}
|
|
|
|
func (v *NullableAreaId) Set(val *AreaId) {
|
|
v.value = val
|
|
v.isSet = true
|
|
}
|
|
|
|
func (v NullableAreaId) IsSet() bool {
|
|
return v.isSet
|
|
}
|
|
|
|
func (v *NullableAreaId) Unset() {
|
|
v.value = nil
|
|
v.isSet = false
|
|
}
|
|
|
|
func NewNullableAreaId(val *AreaId) *NullableAreaId {
|
|
return &NullableAreaId{value: val, isSet: true}
|
|
}
|
|
|
|
func (v NullableAreaId) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(v.value)
|
|
}
|
|
|
|
func (v *NullableAreaId) UnmarshalJSON(src []byte) error {
|
|
v.isSet = true
|
|
return json.Unmarshal(src, &v.value)
|
|
}
|