bunnyshell.com/sdk@v0.16.0/model_template_validate_action_source.go (about) 1 /* 2 API Bunnyshell Environments 3 4 Interact with Bunnyshell Platform 5 6 API version: 1.1.0 7 Contact: osi+support@bunnyshell.com 8 */ 9 10 // Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. 11 12 package sdk 13 14 import ( 15 "encoding/json" 16 "fmt" 17 ) 18 19 // TemplateValidateActionSource - struct for TemplateValidateActionSource 20 type TemplateValidateActionSource struct { 21 ValidateSourceGit *ValidateSourceGit 22 ValidateSourceString *ValidateSourceString 23 } 24 25 // ValidateSourceGitAsTemplateValidateActionSource is a convenience function that returns ValidateSourceGit wrapped in TemplateValidateActionSource 26 func ValidateSourceGitAsTemplateValidateActionSource(v *ValidateSourceGit) TemplateValidateActionSource { 27 return TemplateValidateActionSource{ 28 ValidateSourceGit: v, 29 } 30 } 31 32 // ValidateSourceStringAsTemplateValidateActionSource is a convenience function that returns ValidateSourceString wrapped in TemplateValidateActionSource 33 func ValidateSourceStringAsTemplateValidateActionSource(v *ValidateSourceString) TemplateValidateActionSource { 34 return TemplateValidateActionSource{ 35 ValidateSourceString: v, 36 } 37 } 38 39 // Unmarshal JSON data into one of the pointers in the struct 40 func (dst *TemplateValidateActionSource) UnmarshalJSON(data []byte) error { 41 var err error 42 match := 0 43 // try to unmarshal data into ValidateSourceGit 44 err = json.Unmarshal(data, &dst.ValidateSourceGit) 45 if err == nil { 46 jsonValidateSourceGit, _ := json.Marshal(dst.ValidateSourceGit) 47 if string(jsonValidateSourceGit) == "{}" { // empty struct 48 dst.ValidateSourceGit = nil 49 } else { 50 match++ 51 } 52 } else { 53 dst.ValidateSourceGit = nil 54 } 55 56 // try to unmarshal data into ValidateSourceString 57 err = json.Unmarshal(data, &dst.ValidateSourceString) 58 if err == nil { 59 jsonValidateSourceString, _ := json.Marshal(dst.ValidateSourceString) 60 if string(jsonValidateSourceString) == "{}" { // empty struct 61 dst.ValidateSourceString = nil 62 } else { 63 match++ 64 } 65 } else { 66 dst.ValidateSourceString = nil 67 } 68 69 if match > 1 { // more than 1 match 70 // reset to nil 71 dst.ValidateSourceGit = nil 72 dst.ValidateSourceString = nil 73 74 return fmt.Errorf("data matches more than one schema in oneOf(TemplateValidateActionSource)") 75 } else if match == 1 { 76 return nil // exactly one match 77 } else { // no match 78 return fmt.Errorf("data failed to match schemas in oneOf(TemplateValidateActionSource)") 79 } 80 } 81 82 // Marshal data from the first non-nil pointers in the struct to JSON 83 func (src TemplateValidateActionSource) MarshalJSON() ([]byte, error) { 84 if src.ValidateSourceGit != nil { 85 return json.Marshal(&src.ValidateSourceGit) 86 } 87 88 if src.ValidateSourceString != nil { 89 return json.Marshal(&src.ValidateSourceString) 90 } 91 92 return nil, nil // no data in oneOf schemas 93 } 94 95 // Get the actual instance 96 func (obj *TemplateValidateActionSource) GetActualInstance() interface{} { 97 if obj == nil { 98 return nil 99 } 100 if obj.ValidateSourceGit != nil { 101 return obj.ValidateSourceGit 102 } 103 104 if obj.ValidateSourceString != nil { 105 return obj.ValidateSourceString 106 } 107 108 // all schemas are nil 109 return nil 110 } 111 112 type NullableTemplateValidateActionSource struct { 113 value *TemplateValidateActionSource 114 isSet bool 115 } 116 117 func (v NullableTemplateValidateActionSource) Get() *TemplateValidateActionSource { 118 return v.value 119 } 120 121 func (v *NullableTemplateValidateActionSource) Set(val *TemplateValidateActionSource) { 122 v.value = val 123 v.isSet = true 124 } 125 126 func (v NullableTemplateValidateActionSource) IsSet() bool { 127 return v.isSet 128 } 129 130 func (v *NullableTemplateValidateActionSource) Unset() { 131 v.value = nil 132 v.isSet = false 133 } 134 135 func NewNullableTemplateValidateActionSource(val *TemplateValidateActionSource) *NullableTemplateValidateActionSource { 136 return &NullableTemplateValidateActionSource{value: val, isSet: true} 137 } 138 139 func (v NullableTemplateValidateActionSource) MarshalJSON() ([]byte, error) { 140 return json.Marshal(v.value) 141 } 142 143 func (v *NullableTemplateValidateActionSource) UnmarshalJSON(src []byte) error { 144 v.isSet = true 145 return json.Unmarshal(src, &v.value) 146 }