bunnyshell.com/sdk@v0.16.0/model_environment_create_action_genesis.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  // EnvironmentCreateActionGenesis - The environment creation method
    20  type EnvironmentCreateActionGenesis struct {
    21  	FromGit      *FromGit
    22  	FromGitSpec  *FromGitSpec
    23  	FromString   *FromString
    24  	FromTemplate *FromTemplate
    25  }
    26  
    27  // FromGitAsEnvironmentCreateActionGenesis is a convenience function that returns FromGit wrapped in EnvironmentCreateActionGenesis
    28  func FromGitAsEnvironmentCreateActionGenesis(v *FromGit) EnvironmentCreateActionGenesis {
    29  	return EnvironmentCreateActionGenesis{
    30  		FromGit: v,
    31  	}
    32  }
    33  
    34  // FromGitSpecAsEnvironmentCreateActionGenesis is a convenience function that returns FromGitSpec wrapped in EnvironmentCreateActionGenesis
    35  func FromGitSpecAsEnvironmentCreateActionGenesis(v *FromGitSpec) EnvironmentCreateActionGenesis {
    36  	return EnvironmentCreateActionGenesis{
    37  		FromGitSpec: v,
    38  	}
    39  }
    40  
    41  // FromStringAsEnvironmentCreateActionGenesis is a convenience function that returns FromString wrapped in EnvironmentCreateActionGenesis
    42  func FromStringAsEnvironmentCreateActionGenesis(v *FromString) EnvironmentCreateActionGenesis {
    43  	return EnvironmentCreateActionGenesis{
    44  		FromString: v,
    45  	}
    46  }
    47  
    48  // FromTemplateAsEnvironmentCreateActionGenesis is a convenience function that returns FromTemplate wrapped in EnvironmentCreateActionGenesis
    49  func FromTemplateAsEnvironmentCreateActionGenesis(v *FromTemplate) EnvironmentCreateActionGenesis {
    50  	return EnvironmentCreateActionGenesis{
    51  		FromTemplate: v,
    52  	}
    53  }
    54  
    55  // Unmarshal JSON data into one of the pointers in the struct
    56  func (dst *EnvironmentCreateActionGenesis) UnmarshalJSON(data []byte) error {
    57  	var err error
    58  	match := 0
    59  	// try to unmarshal data into FromGit
    60  	err = json.Unmarshal(data, &dst.FromGit)
    61  	if err == nil {
    62  		jsonFromGit, _ := json.Marshal(dst.FromGit)
    63  		if string(jsonFromGit) == "{}" { // empty struct
    64  			dst.FromGit = nil
    65  		} else {
    66  			match++
    67  		}
    68  	} else {
    69  		dst.FromGit = nil
    70  	}
    71  
    72  	// try to unmarshal data into FromGitSpec
    73  	err = json.Unmarshal(data, &dst.FromGitSpec)
    74  	if err == nil {
    75  		jsonFromGitSpec, _ := json.Marshal(dst.FromGitSpec)
    76  		if string(jsonFromGitSpec) == "{}" { // empty struct
    77  			dst.FromGitSpec = nil
    78  		} else {
    79  			match++
    80  		}
    81  	} else {
    82  		dst.FromGitSpec = nil
    83  	}
    84  
    85  	// try to unmarshal data into FromString
    86  	err = json.Unmarshal(data, &dst.FromString)
    87  	if err == nil {
    88  		jsonFromString, _ := json.Marshal(dst.FromString)
    89  		if string(jsonFromString) == "{}" { // empty struct
    90  			dst.FromString = nil
    91  		} else {
    92  			match++
    93  		}
    94  	} else {
    95  		dst.FromString = nil
    96  	}
    97  
    98  	// try to unmarshal data into FromTemplate
    99  	err = json.Unmarshal(data, &dst.FromTemplate)
   100  	if err == nil {
   101  		jsonFromTemplate, _ := json.Marshal(dst.FromTemplate)
   102  		if string(jsonFromTemplate) == "{}" { // empty struct
   103  			dst.FromTemplate = nil
   104  		} else {
   105  			match++
   106  		}
   107  	} else {
   108  		dst.FromTemplate = nil
   109  	}
   110  
   111  	if match > 1 { // more than 1 match
   112  		// reset to nil
   113  		dst.FromGit = nil
   114  		dst.FromGitSpec = nil
   115  		dst.FromString = nil
   116  		dst.FromTemplate = nil
   117  
   118  		return fmt.Errorf("data matches more than one schema in oneOf(EnvironmentCreateActionGenesis)")
   119  	} else if match == 1 {
   120  		return nil // exactly one match
   121  	} else { // no match
   122  		return fmt.Errorf("data failed to match schemas in oneOf(EnvironmentCreateActionGenesis)")
   123  	}
   124  }
   125  
   126  // Marshal data from the first non-nil pointers in the struct to JSON
   127  func (src EnvironmentCreateActionGenesis) MarshalJSON() ([]byte, error) {
   128  	if src.FromGit != nil {
   129  		return json.Marshal(&src.FromGit)
   130  	}
   131  
   132  	if src.FromGitSpec != nil {
   133  		return json.Marshal(&src.FromGitSpec)
   134  	}
   135  
   136  	if src.FromString != nil {
   137  		return json.Marshal(&src.FromString)
   138  	}
   139  
   140  	if src.FromTemplate != nil {
   141  		return json.Marshal(&src.FromTemplate)
   142  	}
   143  
   144  	return nil, nil // no data in oneOf schemas
   145  }
   146  
   147  // Get the actual instance
   148  func (obj *EnvironmentCreateActionGenesis) GetActualInstance() interface{} {
   149  	if obj == nil {
   150  		return nil
   151  	}
   152  	if obj.FromGit != nil {
   153  		return obj.FromGit
   154  	}
   155  
   156  	if obj.FromGitSpec != nil {
   157  		return obj.FromGitSpec
   158  	}
   159  
   160  	if obj.FromString != nil {
   161  		return obj.FromString
   162  	}
   163  
   164  	if obj.FromTemplate != nil {
   165  		return obj.FromTemplate
   166  	}
   167  
   168  	// all schemas are nil
   169  	return nil
   170  }
   171  
   172  type NullableEnvironmentCreateActionGenesis struct {
   173  	value *EnvironmentCreateActionGenesis
   174  	isSet bool
   175  }
   176  
   177  func (v NullableEnvironmentCreateActionGenesis) Get() *EnvironmentCreateActionGenesis {
   178  	return v.value
   179  }
   180  
   181  func (v *NullableEnvironmentCreateActionGenesis) Set(val *EnvironmentCreateActionGenesis) {
   182  	v.value = val
   183  	v.isSet = true
   184  }
   185  
   186  func (v NullableEnvironmentCreateActionGenesis) IsSet() bool {
   187  	return v.isSet
   188  }
   189  
   190  func (v *NullableEnvironmentCreateActionGenesis) Unset() {
   191  	v.value = nil
   192  	v.isSet = false
   193  }
   194  
   195  func NewNullableEnvironmentCreateActionGenesis(val *EnvironmentCreateActionGenesis) *NullableEnvironmentCreateActionGenesis {
   196  	return &NullableEnvironmentCreateActionGenesis{value: val, isSet: true}
   197  }
   198  
   199  func (v NullableEnvironmentCreateActionGenesis) MarshalJSON() ([]byte, error) {
   200  	return json.Marshal(v.value)
   201  }
   202  
   203  func (v *NullableEnvironmentCreateActionGenesis) UnmarshalJSON(src []byte) error {
   204  	v.isSet = true
   205  	return json.Unmarshal(src, &v.value)
   206  }